:root {
  color-scheme: dark;
  --bg: #050814;
  --panel: #0b152c;
  --elevated: #10203f;
  --border: #16324f;
  --text: #e8f7ff;
  --muted: #8fb4c9;
  --accent: #22d3ee;
  --accent-fg: #041018;
  --live: #14b8a6;
  --radius: 16px;
  --radius-sm: 10px;
  --motion-quick: 150ms;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Outfit, "Noto Sans", "Noto Sans Arabic", "Noto Sans Ethiopic", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body {
  padding: calc(0.75rem + env(safe-area-inset-top)) 0.75rem calc(1.5rem + env(safe-area-inset-bottom));
  max-width: 72rem;
  margin: 0 auto;
}
button:not(:disabled), [role="button"]:not(:disabled) { cursor: pointer; }
button { font: inherit; color: inherit; }
.tabular { font-variant-numeric: tabular-nums; }

.top {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}
html[dir="rtl"] .top { flex-direction: row-reverse; justify-content: flex-end; }
.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
  min-height: 44px;
}
.brand img { width: 36px; height: 36px; }
.brand strong {
  display: block;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.brand em {
  display: block;
  font-style: normal;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}
.top-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }

.help {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin: 0 0 0.9rem;
}
.help h2 { margin: 0 0 0.4rem; font-size: 1rem; font-weight: 750; }
.help ol, .help p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-weight: 500;
  font-size: 0.92rem;
}
.help ol { padding-left: 1.2rem; margin-bottom: 0.5rem; }
.help a { color: var(--accent); font-weight: 650; }

.stage {
  background: #071018;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 6px);
  padding: 0.55rem;
  margin-bottom: 0.75rem;
  direction: ltr;
}
html[dir="rtl"] .stage,
html[dir="rtl"] .stage-canvas { direction: ltr; transform: none; }
.stage.wall-dusk { background: linear-gradient(145deg, #1e1b4b, #083344); }
.stage.wall-sunset { background: linear-gradient(145deg, #7c2d12, #312e81); }
.stage.wall-sea { background: linear-gradient(160deg, #042f2e, #0c4a6e); }
.stage.wall-aurora { background: linear-gradient(140deg, #064e3b, #4c1d95 55%, #083344); }
.stage.wall-candy { background: linear-gradient(145deg, #4c0519, #1e3a8a); }
.stage.frame-line { box-shadow: inset 0 0 0 2px rgba(232, 247, 255, 0.6); }
.stage.frame-glow { box-shadow: 0 0 0 2px #e8f7ff, 0 0 24px rgba(34, 211, 238, 0.45); }
.stage.frame-double { box-shadow: inset 0 0 0 1px #fff, inset 0 0 0 8px transparent, inset 0 0 0 9px rgba(255, 255, 255, 0.45); }
.stage.frame-rgb, .stage.is-rgb { animation: rgbframe 5s linear infinite; }
@keyframes rgbframe {
  0% { box-shadow: 0 0 0 3px #ef4444, 0 0 28px #ef4444; }
  33% { box-shadow: 0 0 0 3px #22c55e, 0 0 28px #22c55e; }
  66% { box-shadow: 0 0 0 3px #3b82f6, 0 0 28px #3b82f6; }
  100% { box-shadow: 0 0 0 3px #ef4444, 0 0 28px #ef4444; }
}
.layer { display: flex; gap: 0.35rem; align-items: center; margin: 0.28rem 0; }
.layer select { flex: 1; min-width: 0; }
.layer select, #wall, #frame {
  min-height: 44px; width: 100%; border-radius: 10px; border: 1px solid var(--border);
  background: #071018; color: inherit; font: inherit;
}
@media (prefers-reduced-motion: reduce) {
  .stage.frame-rgb, .stage.is-rgb { animation: none; box-shadow: 0 0 0 3px #e8f7ff; }
}
body.is-loop .stage {
  border-color: color-mix(in srgb, var(--accent) 58%, var(--border));
}
.stage-canvas {
  width: 100%;
  height: min(46vh, 420px);
  min-height: 220px;
  display: block;
  border-radius: var(--radius);
  background: #050814;
}
.stage-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem 0.85rem;
  padding: 0.65rem 0.2rem 0.15rem;
}
.lcd-name {
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-size: 1.15rem;
}
.lcd-readout {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
}
.stage-look {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  min-width: min(100%, 16rem);
}
.tool-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.7rem;
  margin-bottom: 0.7rem;
}
.play {
  width: auto;
  min-width: 5.5rem;
  height: 3.1rem;
  min-height: 48px;
  padding: 0 0.95rem;
  gap: 0.4rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.play-word, .stop-word, .menu-word { font-weight: 750; font-size: 0.92rem; }
.play:active { transform: scale(0.96); }
.play.is-on {
  background: var(--live);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 72%, transparent);
}
.play-icon {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 8px 0 8px 14px;
  border-color: transparent transparent transparent currentColor;
  margin-left: 2px;
}
.play.is-on .play-icon {
  width: 12px;
  height: 12px;
  border: 0;
  background: currentColor;
  border-radius: 1px;
  margin: 0;
}
.stop-icon {
  display: block;
  width: 11px;
  height: 11px;
  background: currentColor;
  border-radius: 2px;
}
#stop-btn { gap: 0.4rem; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-weight: 650;
  font-size: 0.92rem;
  text-decoration: none;
}
.btn:active { transform: scale(0.96); }
.btn:focus-visible, .play:focus-visible, .menu-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.btn.ghost { background: transparent; }
.btn.icon { width: auto; padding: 0.45rem 0.9rem; }
.menu-btn {
  min-width: 44px;
  min-height: 44px;
  height: 44px;
  padding: 0 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text);
  flex: 0 0 auto;
}
.menu-mark { font-size: 1.05rem; line-height: 1; }
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 30; }
body.menu-open .scrim { display: block; }
.drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(22rem, 88vw);
  background: #070b16;
  border-right: 1px solid var(--border);
  z-index: 40;
  overflow: auto;
  padding: 0.85rem 0.85rem 2rem;
  transform: translateX(-105%);
}
body.menu-open .drawer { transform: none; }
.drawer-plate { margin: 0 0 0.2rem; font-weight: 800; letter-spacing: -0.02em; }
.whats-line { margin: 0 0 0.7rem; color: var(--muted); line-height: 1.45; }
.drawer h2 { margin: 0.9rem 0 0.35rem; font-size: 0.75rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.drawer .chips { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem; flex-wrap: wrap; }
.drawer .btn { width: 100%; justify-content: flex-start; border-radius: 10px; }
.drawer .swatch-btn { width: 44px; min-width: 44px; justify-content: center; }
.drawer .feed { display: block; }
.drawer .feed .chips { grid-template-columns: 1fr; }
.title-row { display: grid; grid-template-columns: 4.5rem 1fr; gap: 0.4rem; align-items: center; margin: 0.35rem 0; }
.title-row select {
  min-height: 44px;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  padding: 0 0.5rem;
}
input[type="range"] { width: 100%; accent-color: var(--accent, #22d3ee); }
.drawer .chips .btn, .drawer .chips button { margin-top: 0; }
.drawer .swatch-btn { margin-top: 0; }
.lesson { padding: 0.65rem 0.75rem; }
.lesson-body { display: block; -webkit-line-clamp: unset; overflow: visible; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; }
.chips .btn svg { width: 16px; height: 16px; margin-right: 0.28rem; vertical-align: -3px; flex: 0 0 auto; }
.picks { display: flex; flex-direction: column; gap: 0.35rem; margin: 0.15rem 0 0.75rem; }
.pick {
  display: grid;
  grid-template-columns: 3.2rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.35rem;
}
.swatch-btn {
  width: 44px;
  min-width: 44px;
  padding: 0;
  border-radius: 999px;
  flex: 0 0 auto;
}
.swatch-btn i {
  display: block;
  width: 18px;
  height: 18px;
  margin: 0;
  border-radius: 50%;
}
.chips .btn.on {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: transparent;
}
.code-look {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.9rem;
  padding: 0.35rem 0.15rem 0.1rem;
}
.code-look[hidden] { display: none; }
.code-line {
  width: min(22rem, 100%);
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 0 0.7rem;
  font: inherit;
}
.code-note { margin: 0; color: var(--muted); font-size: 0.88rem; }
.code-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}
.code-group .btn { min-height: 44px; min-width: 44px; }
.feed {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}
.gizmos {
  display: block;
  margin: 0 0 0.85rem;
}
.gizmos summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  font-weight: 750;
  cursor: pointer;
}
.gizmos[open] {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.55rem 0.75rem;
}
.gizmos summary,
.gizmos #g-reset { grid-column: 1 / -1; }
.code-more { width: 100%; }
.code-more summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  font-weight: 750;
  cursor: pointer;
}
.gizmo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem 0.45rem;
  min-height: 44px;
  font-weight: 700;
}
.gizmo b { color: var(--live); font-weight: 750; }
.gizmo input { width: 100%; min-height: 44px; }
.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}
.tools .note { width: 100%; margin: 0; }
body.is-day .deep,
body:not(.show-more) .deep { display: none; }
#mute-btn, .play, #stop-btn { min-width: 48px; min-height: 48px; }
.now-line {
  margin: 0.2rem 0 0.75rem;
  min-height: 1.4em;
  font-size: 1.05rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}
.lesson-next.ready { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.spot { outline: 3px solid var(--accent); outline-offset: 3px; }
.lesson {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin: 0 0 0.8rem;
}
.lesson h2 { margin: 0.1rem 0 0.3rem; font-size: 1.15rem; }
.lesson-kicker { margin: 0; color: var(--muted); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.lesson-body { margin: 0.25rem 0 0; line-height: 1.45; }
.lesson-miss { margin: 0.4rem 0 0; min-height: 1.2em; font-weight: 750; }
.lesson-actions { display: flex; gap: 0.45rem; margin-top: 0.7rem; flex-wrap: wrap; }
.note {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  font-weight: 500;
}
.note a { color: var(--accent); font-weight: 650; }
.foot {
  margin: 1.1rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}
.foot a { color: var(--accent); font-weight: 650; text-decoration: none; }

@media (max-width: 760px) {
  .stage-canvas { height: min(38vh, 280px); min-height: 180px; }
  .chips.scroll .btn { flex: 0 0 auto; }
}
@media (prefers-reduced-motion: reduce) {
  .btn, .play { transition: none; }
  .btn:active, .play:active { transform: none; }
}
