:root {
  --bg: #0d0f14;
  --panel: #161a22;
  --raise: #1d222c;
  --line: #2a303d;
  --text: #eef0f5;
  --muted: #9198aa;
  --accent: #4f8cff;
  --accent-text: #ffffff;
  --ok: #3ccf7a;
  --bad: #ff4d6a;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef0f5;
    --panel: #ffffff;
    --raise: #f5f6fa;
    --line: #dde1ea;
    --text: #151821;
    --muted: #646b7d;
    --accent: #2f6fe8;
    --ok: #128a4a;
    --bad: #d61f45;
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { touch-action: manipulation; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
html, body { margin: 0; height: 100%; overflow: hidden; }
html { background: var(--bg); }
body {
  display: flex; flex-direction: column;
  height: 100dvh;
  background: radial-gradient(900px 520px at 50% 30%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%), var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .35; cursor: default; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

body:not([data-mode="intro"]) .intro-only,
body:not([data-mode="prep"]) .prep-only,
body:not([data-coach]) .coach-only,
body[data-coach] .solve-dock,
body:not([data-mode="paint"]) .paint-only,
body:not([data-mode="solve"]) .solve-only { display: none !important; }

/* ---------- the header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 800; }
.logo {
  width: 26px; height: 26px; border-radius: 7px;
  background: conic-gradient(#d7263d 0 25%, #1fa34a 0 50%, #ffd23f 0 75%, #1e5bd8 0);
  box-shadow: inset 0 0 0 3px var(--bg);
}
.actions { display: flex; gap: 8px; }
.hbtn {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 70%, transparent);
  backdrop-filter: blur(8px);
}
.hbtn.icon { width: 40px; padding: 0; justify-content: center; }
.hbtn:hover { border-color: var(--muted); }

/* ---------- the stage ---------- */
/* the canvas fills everything under the header and is never resized by the bars: they float over it */
.app { position: relative; flex: 1; min-height: 0; }
.stage { position: absolute; inset: 0; touch-action: none; }
.stage canvas { position: absolute; inset: 0; }
.stage canvas { display: block; width: 100%; height: 100%; }
body[data-mode="paint"] .stage canvas { cursor: pointer; }
body[data-mode="solve"] .stage canvas { cursor: grab; }
body[data-mode="solve"] .stage canvas:active { cursor: grabbing; }
.hint {
  position: absolute; bottom: calc(var(--below, 0px) + 2px); left: 0; right: 0; text-align: center; margin: 0;
  color: var(--muted); font-size: 12px; pointer-events: none;
}

/* above the cube, in the flow: the cube fits the space under it and is never covered */
.facebar {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%); z-index: 3;
  padding: 2px 0 6px; width: min(560px, calc(100% - 32px)); text-align: center;
}
.fb-title { display: inline-flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 800; }
.fb-dot { width: 18px; height: 18px; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.3); }
.fb-step { font-size: 13px; font-weight: 400; color: var(--muted); }
.fb-hold { color: var(--muted); font-size: 14px; }
.fb-how {
  margin: 4px auto 2px; padding: 6px 12px; border-radius: 12px; max-width: 460px; font-size: 13.5px; line-height: 1.55;
  background: color-mix(in srgb, #ffb020 16%, var(--panel)); border: 1px solid color-mix(in srgb, #ffb020 45%, transparent);
}
.fb-how:empty { visibility: hidden; }
/* the box keeps its room when empty, so the cube's space (and its canvas) never changes between faces */
.fb-how { min-height: calc(2 * 1.55em + 14px); }
.fb-hold b { color: var(--text); }

.intro {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 40px 24px 18px; text-align: center;
  background: linear-gradient(to top, var(--bg) 35%, transparent);
}
.intro h2 { margin: 0 0 4px; font-size: 26px; font-weight: 800; }
.intro p { margin: 0 auto 16px; max-width: 420px; color: var(--muted); }
.start {
  min-height: 56px; padding: 0 64px; border-radius: 999px; border: 0; font-size: 19px; font-weight: 800;
  background: var(--accent); color: var(--accent-text);
  box-shadow: 0 12px 32px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform .15s;
}
.start:hover { transform: translateY(-2px); }

/* the cards: how to hold the cube, and before the moves */
.card {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); z-index: 5;
  width: min(520px, calc(100% - 24px)); padding: 18px 18px 16px; border-radius: 22px;
  background: color-mix(in srgb, var(--panel) 94%, transparent); border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(0,0,0,.35); backdrop-filter: blur(10px); text-align: start;
  animation: rise .35s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 16px); } }
.card-step { font-size: 12px; color: var(--accent); font-weight: 700; }
.card h2 { margin: 2px 0 8px; font-size: 21px; font-weight: 800; }
.card p, .card li { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.card ol { margin: 0 0 10px; padding-inline-start: 20px; }
.card b { color: var(--text); }
.card .start { width: 100%; padding: 0; min-height: 52px; font-size: 17px; }
.c-w { box-shadow: inset 0 -3px 0 #e8e8e0; }
.c-g { box-shadow: inset 0 -3px 0 #1fa34a; }
body[data-coach] .dock { display: none; }

/* ---------- the bottom bar ---------- */
.dock { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; padding: 6px 16px max(12px, env(safe-area-inset-bottom)); }
.dock > div { width: min(560px, 100%); margin: 0 auto; }
.dock-row { display: flex; flex-direction: row-reverse; align-items: center; gap: 10px; }
.nav {
  height: 52px; min-width: 52px; border-radius: 16px; border: 1px solid var(--line); background: var(--panel);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 12px;
}
.nav.go.ready { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 800; }
.mid { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.dots { display: flex; gap: 7px; }
.dots i { width: 10px; height: 10px; border-radius: 3px; background: var(--line); transition: background .3s, transform .3s; }
.dots i.done { background: var(--c); }
.dots i.cur { transform: scale(1.4); box-shadow: 0 0 0 2px var(--accent); }
.left { font-size: 12px; color: var(--muted); }
.left.ok { color: var(--ok); }

/* the colour in hand */
.brush {
  display: inline-flex; align-items: center; gap: 10px; height: 52px; padding: 0 16px 0 12px; max-width: 100%;
  border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-weight: 700;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.brush:hover { border-color: var(--muted); }
.brush-sw {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: repeating-linear-gradient(45deg, var(--line) 0 4px, transparent 4px 8px);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.25);
}
.brush.armed { border-color: var(--accent); }
.brush.nudge { animation: nudge .5s; }
@keyframes nudge { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

.solve-dock { display: flex; flex-direction: column; gap: 10px; }
.now {
  display: flex; align-items: center; gap: 14px; padding: 10px 14px; border-radius: 16px;
  background: color-mix(in srgb, var(--accent) 12%, var(--panel)); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.now-move { font-size: 40px; color: #ffb020; font-weight: 800; min-width: 70px; text-align: center; font-family: ui-monospace, "Vazirmatn", monospace; }
.now-side { flex: 1; min-width: 0; }
.step { font-size: 12px; color: var(--muted); }
.now-text { font-size: 14px; }
.half { display: inline-block; margin-inline-start: 4px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: color-mix(in srgb, #ffb020 22%, transparent); color: var(--text); }
.moves { display: flex; gap: 6px; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.moves::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-width: 42px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel);
  font-family: ui-monospace, monospace; font-weight: 700;
}
.chip.done { color: var(--muted); opacity: .55; }
.chip.now { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.controls { display: flex; justify-content: center; align-items: center; gap: 10px; }
.controls button {
  width: 48px; height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel);
  display: inline-grid; place-items: center;
}
.controls .play { width: 64px; height: 56px; border-radius: 999px; background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.solve-links { display: flex; justify-content: space-between; }
.now-hint { font-size: 13px; color: var(--muted); text-align: center; }
.now-hint b { color: var(--text); }
.steer { display: flex; flex-direction: row-reverse; gap: 8px; }
.steer .nav { flex: none; }
.steer #btn-show { flex: 1; }
.steer .go { flex: 1.3; font-weight: 800; }
.pc:disabled { opacity: .35; }
.pc:disabled .n { color: var(--ok); }
.link { background: none; border: 0; color: var(--muted); padding: 6px 4px; font-size: 14px; }
.link:hover { color: var(--text); }

/* ---------- the colour popup, above the colour button ---------- */
.picker {
  position: fixed; z-index: 20; left: 50%; bottom: 96px; transform: translateX(-50%);
  width: min(320px, calc(100% - 32px)); padding: 14px; border-radius: 22px;
  background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
  animation: pop .18s ease-out;
}
.picker[hidden] { display: none; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 12px) scale(.96); } }
.picker-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pc {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0;
  border: 0; background: none; border-radius: 14px; font-size: 13px;
}
.pc:hover { background: var(--raise); }
.pc .sw { width: 52px; height: 52px; border-radius: 14px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.25); transition: transform .1s; }
.pc:hover .sw { transform: scale(1.06); }
.pc.cur .sw { box-shadow: 0 0 0 3px var(--panel), 0 0 0 5px var(--accent); }
.pc .n { color: var(--muted); font-size: 11px; }
.pc .n.full { color: var(--ok); }
.pc .n.over { color: var(--bad); }
.picker-clear { width: 100%; margin-top: 8px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: none; color: var(--muted); }
.picker-clear.cur { border-color: var(--accent); color: var(--text); }

/* ---------- toast and help ---------- */
.toast {
  position: fixed; z-index: 30; left: 50%; bottom: 110px; transform: translate(-50%, 20px);
  width: max-content; max-width: min(440px, calc(100% - 32px)); padding: 10px 16px; border-radius: 14px;
  background: var(--raise); border: 1px solid var(--line); box-shadow: 0 12px 30px rgba(0,0,0,.35);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { border-color: var(--bad); }
.toast.ok { border-color: var(--ok); }

.help {
  width: min(520px, calc(100% - 24px)); max-height: min(80dvh, 720px); padding: 0; border-radius: 22px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
.help::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(3px); }
.help-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.help-head h2 { margin: 0; font-size: 18px; }
.help-body { padding: 4px 18px 18px; }
.help-body h3 { font-size: 15px; margin: 16px 0 6px; }
.help-body p, .help-body li { color: var(--muted); }
.help-body b { color: var(--text); }
.help-body ol, .help-body ul { margin: 0; padding-inline-start: 20px; display: grid; gap: 6px; }

@media (min-width: 900px) {
  .fb-title { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  .picker, .brush.nudge, .card { animation: none; }
  .toast, .dots i, .start { transition: none; }
}
