:root {
  --bg: #0b0f17;
  --surface: #131a26;
  --surface-2: #1a2333;
  --border: rgba(255, 255, 255, 0.1);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #22c55e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(circle at 20% 10%, #151e30 0%, #0b0f17 60%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", sans-serif;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  touch-action: manipulation;
}

.app {
  max-width: 1240px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: color 0.15s, border-color 0.15s;
}

.back-link:hover {
  color: var(--text);
  border-color: var(--accent);
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tab-btn {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  background: var(--accent);
  color: #06121e;
  border-color: transparent;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  align-items: start;
}

.stage-card,
.controls-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

.stage-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.stage-lead {
  margin: 6px 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.canvas-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #070a10;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  padding: 8px;
}

canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.science-note {
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(56, 189, 248, 0.08);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 0.87rem;
  line-height: 1.55;
  color: #cbd5e1;
}

.control-group {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.control-group.active {
  display: flex;
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

button {
  font-family: inherit;
}

.toggle-btn,
.action-btn,
.preset-btn,
.step-btn,
.mini-btn {
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.toggle-btn.is-on {
  background: rgba(34, 197, 94, 0.18);
  border-color: rgba(34, 197, 94, 0.55);
  color: #86efac;
}

.action-btn {
  background: var(--accent);
  color: #06121e;
  border-color: transparent;
}

.action-btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.toggle-btn:active,
.action-btn:active,
.preset-btn:active,
.step-btn:active {
  transform: scale(0.98);
}

.preset-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.label-sm {
  font-size: 0.8rem;
  color: var(--muted);
}

.preset-btns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.preset-btn {
  padding: 7px 6px;
  font-size: 0.8rem;
}

.preset-btn.active {
  background: var(--accent);
  color: #06121e;
  border-color: transparent;
}

.note-sm {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
  background: rgba(255, 255, 255, 0.03);
  padding: 8px 10px;
  border-radius: 8px;
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider-row label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: #cbd5e1;
}

.slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

details.accordion {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

details.accordion summary {
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 600;
  color: #e2e8f0;
  margin-bottom: 6px;
}

details.accordion .slider-row {
  margin-top: 6px;
}

.color-pickers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.color-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.color-item input[type="color"] {
  width: 34px;
  height: 26px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.timer-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.88rem;
}

.mini-btn {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.stepper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.9rem;
}

.stepper-btns {
  display: flex;
  gap: 6px;
}

.step-btn {
  width: 36px;
  height: 34px;
  padding: 0;
  font-size: 1.1rem;
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}
