/* ============================================================
   Qubee — neo-brutalist cubing app
   Design tokens + layout + components
   ============================================================ */
:root {
  /* surfaces + ink */
  --cream: #f4f1e9;      /* page background */
  --paper: #ffffff;      /* card / panel surface */
  --ink: #14130f;        /* text + borders */
  --ink-soft: #6f6a5e;   /* muted text */
  --ink-2: #35322b;      /* body copy */

  /* accents */
  --red: #ee3d34;
  --yellow: #ffcb1f;
  --blue: #177ee6;
  --orange: #f39a1a;
  --green: #23b34a;
  --green-play: #22b24b;
  --on-accent: #14130f;                /* text on a light accent fill — dark in every theme */

  /* theme-derived */
  --shadow-c: var(--ink);              /* hard offset shadow colour */
  --backdrop: rgba(0,0,0,.35);
  --field-hi: #ffe36b;                 /* stage inner glow */
  --floatie-line: rgba(0,0,0,.25);
  --floatie-fill-a: rgba(255,255,255,.18);
  --floatie-fill-b: rgba(0,0,0,.08);
  --on-color-soft: rgba(0,0,0,.6);     /* muted text sitting on a colour card */

  --line: 3px;                         /* unified border weight */
  --line-thin: 2.5px;
  --radius: 22px;
  --radius-sm: 14px;
  --radius-xs: 10px;
  --shadow: 5px 5px 0 var(--shadow-c);
  --shadow-sm: 3px 3px 0 var(--shadow-c);
  --shadow-press: 2px 2px 0 var(--shadow-c);
  --shadow-pop: 8px 8px 0 var(--shadow-c);

  /* accessible focus ring — high-contrast, on-brand, keyboard-only */
  --focus: #2a6bff;
  --focus-ring: 0 0 0 3px var(--paper), 0 0 0 6px var(--focus);

  --font: "Bricolage Grotesque", "Helvetica Neue", "Arial", system-ui, sans-serif;
  --font-black: "Bricolage Grotesque", "Arial Black", "Helvetica Neue", sans-serif;
  --letter: 0;

  /* spacing scale (4px base) for deliberate rhythm */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 22px; --sp-6: 32px; --sp-7: 48px;
  --gap: var(--sp-5);

  /* semantic z-index scale */
  --z-base: 1; --z-cursor-behind: 40; --z-corner: 70; --z-sheet: 100;
  --z-celebrate: 120; --z-wipe: 200; --z-cursor: 9999;
  color-scheme: light;
}

/* ---- DARK: same bold palette, on a deep neutral canvas ---- */
:root[data-theme="dark"] {
  --cream: #16161b;
  --paper: #24242b;
  --ink: #f2eee4;
  --ink-soft: #a29d94;
  --ink-2: #d8d3c8;
  --red: #f0554d; --yellow: #f4c531; --blue: #3b90e8; --orange: #f0a637; --green: #2fb85a; --green-play: #2fb85a;
  --shadow-c: #000000;
  --backdrop: rgba(0,0,0,.62);
  --field-hi: #f6d34d;
  --floatie-line: rgba(255,255,255,.22);
  --floatie-fill-a: rgba(255,255,255,.13);
  --floatie-fill-b: rgba(0,0,0,.24);
  --on-color-soft: rgba(0,0,0,.6);
  color-scheme: dark;
}

/* ---- NIGHT: warm, dimmed, low-contrast for late sessions ---- */
:root[data-theme="night"] {
  --cream: #100e0a;
  --paper: #1b1811;
  --ink: #ecdfc4;
  --ink-soft: #9a8f78;
  --ink-2: #cdbf9f;
  --red: #c9564a; --yellow: #d6a83a; --blue: #3f77b0; --orange: #cf8f39; --green: #4f9a57; --green-play: #4f9a57;
  --shadow-c: #000000;
  --backdrop: rgba(0,0,0,.7);
  --field-hi: #6a5a2e;
  --floatie-line: rgba(255,255,255,.16);
  --floatie-fill-a: rgba(255,255,255,.07);
  --floatie-fill-b: rgba(0,0,0,.3);
  --on-color-soft: rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* ---- font-style themes (offline system stacks) ---- */
:root[data-font="rounded"] {
  --font: "Chalkboard SE", "Comic Sans MS", "Marker Felt", system-ui, sans-serif;
  --font-black: "Chalkboard SE", "Comic Sans MS", "Marker Felt", system-ui, sans-serif;
}
:root[data-font="mono"] {
  --font: "SF Mono", "Menlo", "Consolas", "Courier New", monospace;
  --font-black: "SF Mono", "Menlo", "Consolas", "Courier New", monospace;
  --letter: -0.02em;
}
.brand__name, .home__title, .stage__move, .timer__display,
.notation, .steps__head, .panel__head, .btn { letter-spacing: var(--letter); }

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background-color .4s ease, color .4s ease;
}

/* ---- typography discipline ---- */
h1, .home__title, .stage__move, .steps__head, .celebrate__eyebrow { text-wrap: balance; }
.home__lede, .stage__desc, .celebrate__sub, .timer__hint { text-wrap: pretty; }

/* Bricolage Grotesque is a variable face (defaults to 400) — set the heavy
   display weight everywhere the old build relied on "Arial Black" being
   intrinsically heavy, and give body copy a touch more presence. */
body { font-weight: 500; }
.home__title, .brand__name, .stage__move, .timer__display, .notation, .notation--big,
.steps__head, .panel__head, .btn, .pill, .chip, .modeswitch__btn, .segbar__btn,
.step, .statrow b, .statrow span, .stage__eyebrow, .timer__state, .speedbtn, .inspectbtn,
.inspect-hint, .sheet__head, .celebrate__eyebrow, .celebrate__time, .celebrate__delta,
.history__row b, .move-tok, .stat, .cbtn { font-weight: 800; }

/* ---- accessible keyboard focus (never on mouse) ---- */
:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:focus-visible, .chip:focus-visible, .step:focus-visible,
.modeswitch__btn:focus-visible, .segbar__btn:focus-visible,
.iconbtn:focus-visible, .minibtn:focus-visible, .cbtn:focus-visible,
.transport__btn:focus-visible, .speedbtn:focus-visible, .inspectbtn:focus-visible,
.brand:focus-visible, .setting select:focus-visible, .timer__display:focus-visible {
  box-shadow: var(--focus-ring);
}
#timerCard:focus-visible { box-shadow: inset 0 0 0 3px var(--paper), inset 0 0 0 6px var(--focus); }
/* keep the pressed offset-shadow from fighting the ring on active press */
.btn:focus-visible:active { box-shadow: var(--focus-ring); }

kbd {
  font-family: var(--font);
  font-weight: 800;
  background: var(--ink);
  color: var(--cream);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 0.85em;
}

/* ---------- Screens ---------- */
.screen { display: none; min-height: 100dvh; }
.screen.is-active { display: block; }
[hidden] { display: none !important; }

/* =========================================================
   HOME
   ========================================================= */
.home {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: clamp(20px, 5vw, 64px);
}
.home__bg { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.floatie {
  position: absolute;
  border: var(--line) solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow-sm);
  opacity: 0.9;
  animation: bob 7s ease-in-out infinite;
}
.floatie.f1 { width: 92px; height: 92px; background: var(--red);    top: 10%;  left: 8%;  transform: rotate(-12deg); }
.floatie.f2 { width: 64px; height: 64px; background: var(--yellow); top: 22%;  right: 12%; animation-delay: .6s; transform: rotate(10deg); }
.floatie.f3 { width: 120px;height: 120px;background: var(--blue);   bottom: 12%; left: 14%; animation-delay: 1.2s; }
.floatie.f4 { width: 72px; height: 72px; background: var(--green);  bottom: 18%; right: 10%; animation-delay: .3s; transform: rotate(-8deg); }
.floatie.f5 { width: 54px; height: 54px; background: var(--orange); top: 54%;  left: 46%; animation-delay: .9s; transform: rotate(16deg); }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(var(--r,0)); } 50% { transform: translateY(-18px) rotate(var(--r,0)); } }

.home__inner {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  align-items: center;
  gap: clamp(24px, 5vw, 72px);
  max-width: 1120px;
  width: 100%;
}
.home__cube { display: grid; place-items: center; }
.home__copy { display: flex; flex-direction: column; align-items: flex-start; gap: 18px; }

.home__title {
  font-family: var(--font-black);
  font-size: clamp(38px, 6vw, 76px);
  line-height: 0.96;
  letter-spacing: -0.02em;
}
.home__lede { font-size: clamp(15px, 1.5vw, 19px); line-height: 1.5; max-width: 46ch; color: var(--ink-2); }
.home__hint { font-size: 13px; font-weight: 700; color: var(--ink-soft); }

/* =========================================================
   BRAND
   ========================================================= */
.brand {
  display: inline-flex; align-items: center; gap: 12px;
  background: none; border: none; cursor: pointer; color: var(--ink);
}
.brand__dots { display: inline-flex; gap: 5px; }
.brand__dots i {
  width: 26px; height: 26px; border-radius: 8px;
  border: 3px solid var(--ink); display: block;
}
.brand__dots i:nth-child(1) { background: var(--red); }
.brand__dots i:nth-child(2) { background: var(--yellow); }
.brand__dots i:nth-child(3) { background: var(--blue); }
.brand__name { font-family: var(--font-black); font-size: 26px; letter-spacing: -0.01em; }
.brand--xl .brand__name { font-size: 30px; }
.brand--xl .brand__dots i { width: 30px; height: 30px; }

/* =========================================================
   BUTTONS
   ========================================================= */
.btn {
  font-family: var(--font-black);
  font-size: 17px;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  padding: 14px 26px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:hover { transform: translate(-1px,-1px); box-shadow: 7px 7px 0 var(--shadow-c); }
.btn:active { transform: translate(4px,4px); box-shadow: var(--shadow-press); }
.btn--yellow { background: var(--yellow); }
.btn--jumbo { font-size: clamp(18px, 2.2vw, 24px); padding: 18px 34px; }

.iconbtn {
  width: 46px; height: 46px; border-radius: 50%;
  border: var(--line) solid var(--ink);
  background: var(--paper); color: var(--ink);
  cursor: pointer; display: grid; place-items: center;
  box-shadow: var(--shadow-sm); font-weight: 800; font-size: 16px;
  /* shared "physical button" feel — matches the theme/sound (.cbtn) controls */
  transition: transform .14s cubic-bezier(.3,1.5,.5,1), box-shadow .14s ease,
              background-color .3s ease, border-color .3s ease, color .3s ease;
}
.iconbtn:hover { transform: translate(-1px,-2px); box-shadow: 5px 6px 0 var(--shadow-c); }
.iconbtn:active { transform: translate(2px,2px); box-shadow: var(--shadow-press); }
.iconbtn--gear { background: var(--orange); }

.minibtn {
  font-family: var(--font); font-weight: 800; font-size: 12px;
  border: 2.5px solid var(--ink); border-radius: 999px;
  background: var(--paper); color: var(--ink); cursor: pointer;
  padding: 5px 12px; box-shadow: var(--shadow-press);
}
.minibtn:active { transform: translate(2px,2px); box-shadow: none; }
.minibtn--ghost { border-color: color-mix(in srgb, var(--ink) 22%, transparent); box-shadow: none; background: color-mix(in srgb, var(--paper) 65%, transparent); }

/* =========================================================
   APP LAYOUT
   ========================================================= */
.app { padding: clamp(12px, 2vw, 22px); max-width: 1400px; margin: 0 auto; }

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  background: var(--paper);
  border: var(--line) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 18px;
  margin-bottom: var(--gap);
}
.topbar .brand { justify-self: start; }
.topbar .iconbtn--gear { justify-self: end; }

.modeswitch {
  position: relative;
  justify-self: center;
  display: inline-flex;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  padding: 5px;
}
.modeswitch__btn {
  position: relative; z-index: 1;
  font-family: var(--font-black); font-size: 16px;
  border: none; background: none; cursor: pointer;
  padding: 9px 26px; border-radius: 999px; color: var(--ink-soft);
  transition: color .2s ease;
}
.modeswitch__btn.is-active { color: var(--ink); }
.modeswitch__thumb {
  position: absolute; top: 5px; bottom: 5px; left: 5px;
  width: calc(50% - 5px);
  background: var(--yellow);
  border: 3px solid var(--ink);
  border-radius: 999px;
  transition: transform .25s cubic-bezier(.3,1.4,.5,1);
  z-index: 0;
}
.modeswitch.is-practice .modeswitch__thumb { transform: translateX(100%); }

/* ---------- View grid ---------- */
.view {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: var(--gap);
  align-items: start;
}
.view__main { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.view__side { display: flex; flex-direction: column; gap: var(--gap); }

/* =========================================================
   CARDS
   ========================================================= */
.card {
  background: var(--paper);
  border: var(--line) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card--notation { padding: 20px 24px; text-align: center; position: relative; }
.pill {
  display: inline-block;
  font-family: var(--font-black); font-size: 12px; letter-spacing: .06em;
  border: 3px solid var(--ink); border-radius: 999px; padding: 6px 16px;
  background: var(--paper);
}
.pill--yellow { background: var(--yellow); }
.pill--ghost { background: var(--paper); }

.notation {
  margin-top: 14px;
  font-family: var(--font-black);
  font-size: clamp(20px, 2.6vw, 30px);
  letter-spacing: .02em;
  display: flex; flex-wrap: wrap; gap: 8px 12px; justify-content: center;
}
.notation--big { font-size: clamp(20px, 3vw, 34px); }

.scramble-strip {
  font-family: var(--font); font-weight: 800;
  font-size: clamp(13px, 1.5vw, 17px);
  color: var(--ink-soft); letter-spacing: .04em;
  margin-top: 10px; word-spacing: 4px;
}
.card--notation #learnNewScramble { margin-top: 14px; }
.move-tok {
  padding: 2px 4px; border-radius: 8px; transition: background .15s ease, color .15s ease;
}
.move-tok.done { color: var(--ink-soft); }
.move-tok.active {
  background: var(--yellow);
  border: 2.5px solid var(--ink);
  padding: 2px 8px;
}

/* ---------- Stage ---------- */
.stage--blue { border-color: var(--ink); }
.card--stage { overflow: hidden; }
.stage {
  position: relative;
  margin: 8px;
  border: var(--line) solid var(--ink);
  border-radius: 20px;
  background: var(--blue);
  padding: 0;
  /* cube, then one playback bar. Nothing overlays the cube: it is the teaching
     surface, so the controls get their own row and the cube keeps the rest. */
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: clamp(360px, 50vh, 520px);
  overflow: clip;                       /* belt-and-braces: the 3D cube can never spill */
}
/* 1fr/auto/1fr keeps the transport optically centred whatever the side buttons weigh */
.stage__bar {
  position: relative; z-index: 3;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: var(--sp-3);
  /* the yellow field is inset ~10px, so --sp-6 padding leaves the controls a clean
     --sp-5 (22px) clear of the field edge on every side — no cramped corners */
  padding: 0 var(--sp-6) var(--sp-6);
}
.stage__bar .inspectbtn { justify-self: start; }
.stage__bar .speedbtn { justify-self: end; }
.stage::before { /* inner yellow field */
  content: ""; position: absolute; inset: 10px; border-radius: 12px;
  background: radial-gradient(120% 120% at 50% 20%, var(--field-hi), var(--yellow));
  border: 3px solid var(--ink);
}
.cube-scene--stage {
  position: relative; z-index: 1;
  min-height: 0;                        /* the 1fr row owns the cube's height */
  display: grid; place-items: center;
  /* --cube-fit is measured in app.js: the cube is a fixed ~259x288px projection,
     so it is scaled to whatever this row actually gets. */
  transform: scale(var(--cube-fit, 1));
  transform-origin: center;
}
/* speed + inspect: single-control pills in the same family as the transport they
   sit beside — 44px tall, pill radius, shadow-sm — instead of small flat chips.
   Interaction matches .cbtn (springy hover-lift, press, icon/label pop). */
.speedbtn {
  height: 44px; display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-black); font-size: 14px;
  border: var(--line) solid var(--ink); border-radius: var(--radius-sm);
  background: var(--paper); color: var(--ink);
  padding: 0 18px; cursor: pointer; box-shadow: var(--shadow-sm);
  transition: transform .14s cubic-bezier(.3,1.5,.5,1), box-shadow .14s ease,
              background-color .3s ease, border-color .3s ease, color .3s ease;
}
.speedbtn:hover:not(:disabled) { transform: translate(-1px,-2px); box-shadow: 5px 6px 0 var(--shadow-c); }
.speedbtn:active:not(:disabled) { transform: translate(2px,2px); box-shadow: var(--shadow-press); }
.speedbtn:disabled { opacity: .4; cursor: not-allowed; }

.inspectbtn {
  height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-family: var(--font-black); font-size: 14px;
  border: var(--line) solid var(--ink); border-radius: var(--radius-sm);
  background: var(--paper); color: var(--ink);
  padding: 0 18px; cursor: pointer; box-shadow: var(--shadow-sm);
  transition: transform .14s cubic-bezier(.3,1.5,.5,1), box-shadow .14s ease,
              background-color .3s ease, border-color .3s ease, color .3s ease;
}
.inspectbtn:hover { transform: translate(-1px,-2px); box-shadow: 5px 6px 0 var(--shadow-c); }
.inspectbtn:active { transform: translate(2px,2px); box-shadow: var(--shadow-press); }
.inspectbtn.is-on { background: var(--green-play); }
.inspect-hint {
  position: absolute; z-index: 3; top: 68px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  font-family: var(--font-black); font-size: 12px; letter-spacing: .03em;
  padding: 6px 12px; border-radius: 999px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.stage.is-inspecting .inspect-hint { opacity: .92; }
.cube-scene.is-inspecting { cursor: grab; touch-action: none; }
.cube-scene.is-inspecting:active { cursor: grabbing; }

.transport {
  position: relative; z-index: 3;
  justify-self: center;
  display: inline-flex; gap: 10px; align-items: center;
  background: var(--paper); border: var(--line) solid var(--ink);
  border-radius: 999px; padding: 8px 14px; box-shadow: var(--shadow-sm);
}
.transport__btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid var(--ink); background: var(--paper); color: var(--ink);
  cursor: pointer; display: grid; place-items: center;
  transition: transform .08s ease;
}
.transport__btn:active { transform: scale(.92); }
.transport__btn--play { background: var(--green-play); color: var(--ink); }
.transport__btn:disabled { opacity: .4; cursor: not-allowed; }

.stage__caption { padding: 18px 20px 22px; text-align: center; }
.stage__eyebrow { font-family: var(--font-black); font-size: 13px; letter-spacing: .12em; color: var(--ink-soft); }
.stage__move {
  font-family: var(--font-black);
  /* height-aware: this glyph sits in a viewport-fitted column, so on a wide but
     short screen sizing off vw alone starves the cube above it */
  font-size: clamp(30px, min(5vw, 6.2vh), 56px);
  line-height: 1; margin: 6px 0 10px; letter-spacing: .04em;
}
.stage__desc { font-size: 15px; font-weight: 600; color: var(--ink-2); max-width: 52ch; margin: 0 auto; min-height: 2.6em; }

/* =========================================================
   SIDE PANELS
   ========================================================= */
.card--selector { background: var(--orange); padding: 16px; }
.segbar {
  position: relative; display: grid; grid-template-columns: 1fr 1fr;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 999px;
  padding: 4px; margin-bottom: 14px;
}
.segbar__btn {
  position: relative; z-index: 1; font-family: var(--font-black); font-size: 15px;
  border: none; background: none; cursor: pointer; padding: 9px; border-radius: 999px;
  color: var(--ink-soft); transition: color .2s;
}
.segbar__btn.is-active { color: var(--ink); }
.segbar__thumb {
  position: absolute; z-index: 0; top: 4px; bottom: 4px; left: 4px; width: calc(50% - 4px);
  background: var(--yellow); border: 3px solid var(--ink); border-radius: 999px;
  transition: transform .25s cubic-bezier(.3,1.4,.5,1);
}
.segbar.is-right .segbar__thumb { transform: translateX(100%); }

.chipgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chip {
  font-family: var(--font-black); font-size: 13.5px; letter-spacing: .02em;
  border: 3px solid var(--ink); border-radius: 999px; background: var(--paper);
  color: var(--ink); cursor: pointer; padding: 13px 8px; box-shadow: var(--shadow-press);
  transition: transform .08s ease, box-shadow .08s ease;
}
.chip:hover { transform: translate(-1px,-1px); }
.chip:active { transform: translate(2px,2px); box-shadow: none; }
.chip.is-active { background: var(--yellow); box-shadow: none; transform: translate(2px,2px); }

/* ---------- Steps ---------- */
.card--steps { background: var(--green); padding: 18px; display: flex; flex-direction: column; min-height: 320px; }
.steps__head {
  font-family: var(--font-black); font-size: 20px; color: var(--ink);
  background: var(--paper); border: 3px solid var(--ink); border-radius: 14px;
  padding: 12px 16px; margin-bottom: 14px; box-shadow: var(--shadow-press);
}
.steps__list { display: flex; flex-direction: column; gap: 12px; flex: 1; }
.step {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--font-black); font-size: 15px;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 14px;
  padding: 14px 16px; cursor: pointer; text-align: left; color: var(--ink);
  box-shadow: var(--shadow-press);
  transition: transform .08s ease, background .15s ease;
}
.step:hover { transform: translate(-1px,-1px); }
.step.is-done { color: var(--ink-soft); }
.step.is-active { background: var(--yellow); }
.step__ico { width: 22px; height: 22px; flex: none; display: grid; place-items: center; }
.step__ico svg { width: 22px; height: 22px; }
.step.is-active .step__ico svg { animation: spin 1.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.steps__progress { display: flex; gap: 8px; margin-top: 16px; }
.steps__progress i {
  flex: 1; height: 12px; border-radius: 999px;
  border: 2.5px solid var(--ink); background: var(--paper);
}
.steps__progress i.done { background: var(--ink); }
.steps__progress i.active { background: var(--yellow); }

/* =========================================================
   PRACTICE
   ========================================================= */
.card--timer {
  position: relative; overflow: hidden;
  background: var(--blue);
  min-height: clamp(340px, 52vh, 520px);
  display: grid; place-content: center; justify-items: center; gap: 8px;
  cursor: pointer; outline: none;
}
.card--timer.is-holding { background: var(--red); }
.card--timer.is-running { background: var(--green); }
.card--timer .floatie { position: absolute; opacity: .5; animation: none; box-shadow: none; }
.card--timer .tf1 { width: 120px; height: 120px; background: var(--floatie-fill-a); border-color: var(--floatie-line); top: 12%; left: 8%; transform: rotate(-10deg); }
.card--timer .tf2 { width: 150px; height: 150px; background: var(--floatie-fill-b); border-color: var(--floatie-line); bottom: 8%; right: 8%; transform: rotate(12deg); }

.timer__display {
  position: relative; z-index: 1;
  font-family: var(--font-black);
  font-size: clamp(64px, 13vw, 150px);
  line-height: 1; letter-spacing: -0.02em;
  background: var(--paper); color: var(--ink);
  border: var(--line) solid var(--ink); border-radius: 24px;
  padding: 18px 40px; box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
}
.timer__state {
  position: relative; z-index: 1;
  font-family: var(--font-black); font-size: 16px; letter-spacing: .1em;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 999px;
  padding: 8px 22px; margin-top: 12px;
}
.timer__hint { position: relative; z-index: 1; font-weight: 700; font-size: 13px; color: var(--on-color-soft); margin-top: 4px; }

/* ---------- Stats / History ---------- */
.card--stats { background: var(--orange); padding: 16px; }
.panel__head {
  font-family: var(--font-black); font-size: 18px;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 12px;
  padding: 10px 14px; margin-bottom: 12px; box-shadow: var(--shadow-press);
  display: flex; justify-content: space-between; align-items: center;
}
.statrow, .history__row {
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--font-black); font-size: 16px;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 12px;
  padding: 12px 16px; margin-bottom: 10px;
}
.statrow span { color: var(--ink-soft); letter-spacing: .04em; text-transform: uppercase; font-size: 13px; }
.statrow b { font-size: 20px; }

.card--history { background: var(--green); padding: 16px; display: flex; flex-direction: column; }
.history__list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.history__row span { color: var(--ink-soft); }
.history__row.is-best { background: var(--yellow); }
.history__empty { font-weight: 700; color: var(--on-color-soft); text-align: center; padding: 24px 0; }

/* =========================================================
   SETTINGS SHEET
   ========================================================= */
.sheet { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.sheet__backdrop { position: absolute; inset: 0; background: var(--backdrop); animation: pb-fade .22s ease both; }
.sheet__panel {
  position: relative; z-index: 1; width: min(420px, 100%); padding: 22px;
  display: flex; flex-direction: column; gap: 14px;
  transform-origin: center;                                   /* modal: appears centred */
  animation: sheet-pop .26s cubic-bezier(.2,1,.32,1) both;    /* ease-out, from scale .94 (never 0) */
}
@keyframes sheet-pop { from { opacity: 0; transform: scale(.94) translateY(8px); } to { opacity: 1; transform: none; } }
.sheet__head { display: flex; justify-content: space-between; align-items: center; font-family: var(--font-black); font-size: 22px; }
.setting { display: flex; justify-content: space-between; align-items: center; font-weight: 800; border: 3px solid var(--ink); border-radius: 12px; padding: 12px 14px; }
.setting select { font-family: var(--font); font-weight: 800; border: 2.5px solid var(--ink); border-radius: 8px; padding: 5px 8px; }
.setting input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--green); }
.sheet__foot { text-align: center; font-size: 12px; color: var(--ink-soft); font-weight: 700; }

/* =========================================================
   PERSONAL-BEST CELEBRATION
   ========================================================= */
.celebrate { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; }
.celebrate__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.42); animation: pb-fade .25s ease; }
.celebrate__card {
  position: relative; z-index: 2; width: min(400px, 100%);
  padding: 26px 24px 24px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  border-width: var(--line); box-shadow: var(--shadow);
  animation: pb-pop .5s cubic-bezier(.2,1.4,.5,1) both;
}
.celebrate__badge { font-size: 58px; line-height: 1; animation: pb-wiggle 1.1s ease-in-out infinite; }
.celebrate__eyebrow {
  font-family: var(--font-black); font-size: 15px; letter-spacing: .14em; color: var(--red);
}
.celebrate__time {
  font-family: var(--font-black); font-size: clamp(52px, 12vw, 74px);
  line-height: .95; letter-spacing: .02em; color: var(--ink);
}
.celebrate__delta {
  font-family: var(--font-black); font-size: 17px; color: var(--ink);
  background: var(--green); border: 3px solid var(--ink); border-radius: 999px;
  padding: 6px 16px; box-shadow: var(--shadow-press);
}
.celebrate__sub { font-size: 14px; font-weight: 700; color: var(--ink-soft); margin: 2px 0 6px; max-width: 30ch; }
.celebrate__card .btn { margin-top: 2px; }

/* confetti */
.celebrate__confetti { position: absolute; inset: 0; z-index: 1; overflow: hidden; pointer-events: none; }
.confetti-bit {
  position: absolute; top: -24px; width: 11px; height: 15px; border-radius: 2px;
  will-change: transform, opacity;
  animation: pb-fall linear forwards;
}
@keyframes pb-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pb-pop {
  0% { transform: scale(.6) rotate(-6deg); opacity: 0; }
  60% { transform: scale(1.04) rotate(2deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes pb-wiggle {
  0%,100% { transform: rotate(-9deg); }
  50% { transform: rotate(9deg); }
}
@keyframes pb-fall {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(108vh) rotate(720deg); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .celebrate__card, .celebrate__backdrop { animation: none; }
  .celebrate__badge { animation: none; }
  .confetti-bit { display: none; }
}

/* =========================================================
   3D CUBE
   ========================================================= */
.cube-scene { perspective: 900px; }
.cube-scene--hero { width: clamp(220px, 32vw, 320px); height: clamp(220px, 32vw, 320px); }
.cube {
  position: relative; width: 0; height: 0;
  transform-style: preserve-3d;
  transform: rotateX(-27deg) rotateY(-38deg);
}
.cubie { position: absolute; transform-style: preserve-3d; }
.sticker {
  position: absolute;
  border: 3.5px solid #14130f;
  border-radius: 8px;
  backface-visibility: hidden;
}
.face-body { position: absolute; background: #14130f; border-radius: 9px; }

/* =========================================================
   RESPONSIVE
   ========================================================= */
/* ---------- Tablet / small desktop: single column ---------- */
@media (max-width: 980px) {
  .view { grid-template-columns: 1fr; }
  .view__side { flex-direction: column; }
  .home__inner { grid-template-columns: 1fr; text-align: center; }
  .home__copy { align-items: center; }
  .home__cube { order: -1; }
  .home__bg { display: none; }            /* decorative floaties collide with the stacked layout */
  .chipgrid { grid-template-columns: 1fr 1fr; }
  .cube-scene--hero { width: clamp(200px, 40vw, 300px); height: clamp(200px, 40vw, 300px); }
}

/* ---------- Phones ---------- */
@media (max-width: 620px) {
  :root { --gap: 14px; --radius: 20px; --shadow: 5px 5px 0 var(--shadow-c); }
  .app { padding: 12px; }

  .topbar { grid-template-columns: auto 1fr auto; gap: 8px; padding: 10px 12px; }
  .brand__name { font-size: 20px; }
  .brand__dots { gap: 4px; }
  .brand__dots i { width: 18px; height: 18px; }
  .modeswitch { padding: 4px; }
  .modeswitch__btn { padding: 8px 15px; font-size: 14px; }
  .iconbtn { width: 42px; height: 42px; }

  .home { padding: 26px 18px 96px; }
  .home__title { font-size: clamp(34px, 10vw, 52px); }
  .home__lede { font-size: 15px; }
  .cube-scene--hero { width: clamp(180px, 56vw, 240px); height: clamp(180px, 56vw, 240px); }

  .card--notation { padding: 16px; }
  .notation { font-size: 18px; gap: 6px 10px; }
  .scramble-strip { font-size: 12px; }
  .stage { margin: 6px; min-height: clamp(300px, 54vh, 420px); }
  /* the three controls don't fit one narrow row with the label showing; the eye
     icon carries it here (aria-label keeps the accessible name) */
  .stage__bar { padding: 0 var(--sp-4) var(--sp-4); gap: var(--sp-2); }
  /* icon-only inspect on phones; the 44px height keeps it a comfortable target */
  .stage__bar .inspectbtn span { display: none; }
  .stage__bar .inspectbtn { padding: 0 13px; }
  .stage__bar .speedbtn { padding: 0 13px; }
  .stage__move { font-size: 36px; }
  .stage__caption { padding: 14px 14px 18px; }

  .chip { font-size: 12px; padding: 12px 6px; }
  .card--selector, .card--stats, .card--steps, .card--history { padding: 14px; }

  .timer__display { font-size: clamp(56px, 17vw, 110px); padding: 14px 26px; border-radius: 20px; }
  .card--timer { min-height: clamp(300px, 46vh, 460px); }

  /* corner controls: smaller + tucked in */
  .corner-ctl { right: 12px; bottom: 12px; gap: 8px; }
  .cbtn { width: 44px; height: 44px; border-radius: 13px; }
  .cbtn svg { width: 21px; height: 21px; }

  .sheet__panel { padding: 18px; }
  .celebrate__card { padding: 22px 18px 20px; }
}

/* ---------- Very small phones ---------- */
@media (max-width: 380px) {
  .brand__name { font-size: 18px; }
  .brand__dots i { width: 16px; height: 16px; }
  .modeswitch__btn { padding: 7px 11px; font-size: 13px; }
  .home__title { font-size: clamp(30px, 9.5vw, 44px); }
  .notation { font-size: 16px; }
  .segbar__btn { font-size: 14px; }
}

/* =========================================================
   DESKTOP: fit the app to one screen — no page scroll.
   The cube stage & timer flex to fill; over-long lists
   (notation, steps, history) scroll inside their card
   instead of being cut off or pushing the page taller.
   ========================================================= */
@media (min-width: 981px) {
  .screen.app.is-active {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .app > .topbar { flex: none; }
  .app > .view { flex: 1 1 auto; min-height: 0; align-items: stretch; }
  .view__main, .view__side { min-height: 0; height: 100%; }

  /* Learning: notation fixed-ish, cube stage flexes, steps scroll */
  .view--learning .card--notation { flex: none; }
  /* the cube is the teaching surface; notation supports it and scrolls past 13vh */
  .view--learning .notation { max-height: 13vh; overflow-y: auto; }
  .card--stage { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  /* height comes from flex here; the row structure stays the grid defined on .stage */
  .card--stage .stage { flex: 1 1 auto; min-height: 0; }
  .cube-scene--stage { min-height: 0; }   /* the 1fr row owns the cube's height */
  .stage__caption { flex: none; }
  .card--selector { flex: none; }
  .card--steps { flex: 1 1 auto; min-height: 0; }
  .steps__list { min-height: 0; overflow-y: auto; }

  /* Practice: timer flexes, history scrolls to fill */
  /* (short-desktop escape hatch lives in its own query below) */
  .view--practice .card--notation { flex: none; }
  .card--timer { flex: 1 1 auto; min-height: 0; }
  .card--stats { flex: none; }
  .card--history { flex: 1 1 auto; min-height: 0; }
  .card--history .history__list { max-height: none; flex: 1 1 auto; }
}

/* Short desktop screens can't honour "one screen, no scroll" AND keep the cube
   usable: the fixed chrome (topbar + notation + caption) already claims ~500px.
   Rather than crush the teaching surface, let these viewports scroll. */
@media (min-width: 981px) and (max-height: 860px) {
  .screen.app.is-active { height: auto; min-height: 100dvh; overflow: visible; }
  .card--stage .stage { min-height: clamp(380px, 52vh, 520px); }
}

/* =========================================================
   INTERACTION LAYER — cursor, corner controls, transitions
   ========================================================= */

/* ---- custom cursor (fine pointers only, toggled by JS) ---- */
.cursor-dot, .cursor-ring { display: none; }
body.qb-cursor .cursor-dot, body.qb-cursor .cursor-ring { display: block; }
@media (pointer: fine) {
  body.qb-cursor, body.qb-cursor a, body.qb-cursor button,
  body.qb-cursor .chip, body.qb-cursor .step, body.qb-cursor [role="tab"] { cursor: none; }
}
.cursor-dot, .cursor-ring {
  position: fixed; top: 0; left: 0; z-index: 9999; pointer-events: none;
  border-radius: 50%; transform: translate(-50%, -50%); will-change: transform;
}
.cursor-dot { width: 7px; height: 7px; background: var(--ink); transition: background-color .4s ease, opacity .2s; }
/* Fixed layout box; the visible ring is a ::before that scales on the GPU
   (transform) so hover/press never animate width/height (layout/paint). */
.cursor-ring { width: 44px; height: 44px; }
.cursor-ring::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 2.5px solid var(--ink); opacity: .75; transform: scale(.727);   /* ~32px */
  transition: transform .18s ease, opacity .2s ease, background-color .18s ease, border-color .4s ease;
}
.cursor-ring.is-hover::before { transform: scale(1.182); opacity: 1;      /* ~52px */
  background: color-mix(in srgb, var(--ink) 12%, transparent); }
.cursor-ring.is-press::before { transform: scale(.5); }                   /* ~22px */
.cursor-dot.is-hidden, .cursor-ring.is-hidden { opacity: 0; }

/* ---- corner controls (theme + sound) ---- */
.corner-ctl {
  position: fixed; right: 18px; bottom: 18px; z-index: 70;
  display: flex; flex-direction: column-reverse; gap: 10px;
}
.cbtn {
  position: relative;
  width: 50px; height: 50px; border-radius: 16px;
  border: var(--line) solid var(--ink); background: var(--paper); color: var(--ink);
  display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow-sm);
  transition: transform .14s cubic-bezier(.3,1.5,.5,1), box-shadow .14s ease,
              background-color .3s ease, border-color .3s ease, color .3s ease;
}
.cbtn:hover { transform: translate(-1px, -2px); box-shadow: 5px 6px 0 var(--shadow-c); }
.cbtn:active { transform: translate(2px, 2px); box-shadow: var(--shadow-press); }
.cbtn svg { width: 24px; height: 24px; display: block; }
.cbtn.pop svg,
.iconbtn.pop svg,
.inspectbtn.pop svg,
.speedbtn.pop span { animation: cbtn-pop .2s cubic-bezier(.3,1.5,.4,1); }
@keyframes cbtn-pop { 0% { transform: scale(.7) rotate(-18deg); } 100% { transform: scale(1) rotate(0); } }
/* sound on/off status dot */
.cbtn__dot {
  position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%;
  border: 2px solid var(--ink); background: var(--green); transition: background-color .2s;
}
.cbtn.is-off .cbtn__dot { background: color-mix(in srgb, var(--ink) 25%, transparent); }

/* ---- page-transition wipe ---- */
.page-wipe {
  position: fixed; inset: 0; z-index: 200; pointer-events: none;
  background: var(--ink); transform: translateY(100%);
  display: grid; place-items: center;
}
.page-wipe__mark { display: inline-flex; gap: 8px; opacity: 0; }
.page-wipe__mark i { width: 26px; height: 26px; border-radius: 8px; display: block; }
.page-wipe__mark i:nth-child(1) { background: var(--red); }
.page-wipe__mark i:nth-child(2) { background: var(--yellow); }
.page-wipe__mark i:nth-child(3) { background: var(--blue); }
.page-wipe.run { animation: wipe .55s cubic-bezier(.76,0,.24,1) forwards; }
.page-wipe.run .page-wipe__mark { animation: wipe-mark .55s ease forwards; }
@keyframes wipe {
  0% { transform: translateY(100%); }
  42% { transform: translateY(0); }
  58% { transform: translateY(0); }
  100% { transform: translateY(-100%); }
}
@keyframes wipe-mark {
  0%, 20% { opacity: 0; transform: scale(.6); }
  42%, 58% { opacity: 1; transform: scale(1); }
  80%, 100% { opacity: 0; transform: scale(.9); }
}

/* ---- entrance + micro-motion ---- */
.home.is-active .home__copy > * { animation: rise .46s cubic-bezier(.2,.8,.2,1) both; }
.home.is-active .home__copy > *:nth-child(1) { animation-delay: .04s; }
.home.is-active .home__copy > *:nth-child(2) { animation-delay: .10s; }
.home.is-active .home__copy > *:nth-child(3) { animation-delay: .16s; }
.home.is-active .home__copy > *:nth-child(4) { animation-delay: .22s; }
.home.is-active .home__copy > *:nth-child(5) { animation-delay: .28s; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

.view-enter { animation: viewIn .26s cubic-bezier(.2,.8,.2,1) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* brand dots: springy hover wobble (staggered) */
.brand__dots i { transition: transform .28s cubic-bezier(.3,1.6,.4,1); }
.brand:hover .brand__dots i:nth-child(1) { transform: translateY(-4px) rotate(-8deg); }
.brand:hover .brand__dots i:nth-child(2) { transform: translateY(-4px) rotate(6deg); transition-delay: .04s; }
.brand:hover .brand__dots i:nth-child(3) { transform: translateY(-4px) rotate(-5deg); transition-delay: .08s; }

[data-magnetic] { transition: transform .18s cubic-bezier(.3,1.2,.5,1); }

/* keep text readable on light accent fills across every theme */
.btn--yellow,
.pill--yellow,
.modeswitch__btn.is-active,
.segbar__btn.is-active,
.chip.is-active,
.step.is-active,
.history__row.is-best,
.history__row.is-best span,
.history__row.is-best b { color: var(--on-accent); }

/* Touch devices fire a sticky :hover on tap — drop hover-only motion there,
   keeping the :active press feedback (which is the correct tap response). */
@media (hover: none) {
  .btn:hover { transform: none; box-shadow: var(--shadow); }
  .cbtn:hover { transform: none; box-shadow: var(--shadow-sm); }
  .iconbtn:hover, .speedbtn:hover, .inspectbtn:hover { transform: none; box-shadow: var(--shadow-sm); }
  .chip:hover, .step:hover { transform: none; }
  .brand:hover .brand__dots i { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; }
  .page-wipe { display: none !important; }
  /* Drop position/scale movement; keep opacity & colour transitions so
     state changes (theme, active move, tabs) still read clearly. */
  .cursor-dot, .cursor-ring, .cursor-ring::before, [data-magnetic],
  .modeswitch__thumb, .segbar__thumb { transition: none !important; }
  .btn:hover, .chip:hover, .step:hover, .cbtn:hover,
  .iconbtn:hover, .speedbtn:hover, .inspectbtn:hover,
  .brand:hover .brand__dots i { transform: none !important; }
}
