/* Gravity Stairs — soft clay, warm paper light and a deep plum night.
   Tokens first; light by default, dark by the system or the player's choice. */

:root {
  color-scheme: light;
  --bg: #f3ede4;
  --bg-2: #e9e0d2;
  --surface: #fffaf3;
  --surface-2: #f5eee3;
  --well: #e7ddcd;
  --text: #2a2430;
  --muted: #675d70;
  --line: rgba(70, 50, 40, 0.13);
  --accent: #e9955a;
  --accent-2: #4f3f86;
  --ca-accent: #ba5b19; /* the accounts SDK's buttons: white on it reaches 4.5:1 */
  --primary: #ba5b19;
  --primary-hi: #d06e2a;
  --accent-ink: #9a4a14;
  --clay-hi: rgba(255, 255, 255, 0.9);
  --clay-lo: rgba(90, 60, 35, 0.16);
  --shadow: 0 14px 30px -16px rgba(80, 50, 25, 0.5), 0 3px 8px -3px rgba(80, 50, 25, 0.2);
  --shadow-soft: 0 6px 16px -10px rgba(80, 50, 25, 0.45);
  --star: #f0ad32;
  --star-off: rgba(70, 50, 40, 0.16);
  --good: #3f8a5a;
  --focus: #4f3f86;
  --hud: rgba(255, 250, 243, 0.78);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-round: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", system-ui, sans-serif;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --r: 22px;
  --bar-h: 58px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16131b;
    --bg-2: #1c1823;
    --surface: #231e2a;
    --surface-2: #2b2533;
    --well: #1a1620;
    --text: #f1ebf4;
    --muted: #a79fb0;
    --line: rgba(255, 255, 255, 0.09);
    --accent-ink: #f2a46a;
    --clay-hi: rgba(255, 255, 255, 0.07);
    --clay-lo: rgba(0, 0, 0, 0.5);
    --shadow: 0 18px 34px -18px rgba(0, 0, 0, 0.85), 0 3px 8px -3px rgba(0, 0, 0, 0.5);
    --shadow-soft: 0 8px 18px -10px rgba(0, 0, 0, 0.8);
    --star-off: rgba(255, 255, 255, 0.14);
    --focus: #f2a46a;
    --hud: rgba(35, 30, 42, 0.78);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16131b;
  --bg-2: #1c1823;
  --surface: #231e2a;
  --surface-2: #2b2533;
  --well: #1a1620;
  --text: #f1ebf4;
  --muted: #a79fb0;
  --line: rgba(255, 255, 255, 0.09);
  --accent-ink: #f2a46a;
  --clay-hi: rgba(255, 255, 255, 0.07);
  --clay-lo: rgba(0, 0, 0, 0.5);
  --shadow: 0 18px 34px -18px rgba(0, 0, 0, 0.85), 0 3px 8px -3px rgba(0, 0, 0, 0.5);
  --shadow-soft: 0 8px 18px -10px rgba(0, 0, 0, 0.8);
  --star-off: rgba(255, 255, 255, 0.14);
  --focus: #f2a46a;
  --hud: rgba(35, 30, 42, 0.78);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; background: var(--bg); }
body {
  margin: 0;
  height: 100dvh;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(120% 70% at 50% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%),
    radial-gradient(90% 60% at 100% 110%, color-mix(in srgb, var(--accent-2) 12%, transparent), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 12px; }
[tabindex="-1"]:focus { outline: none; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 22px; height: 22px; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-round); letter-spacing: -0.015em; margin: 0; }
kbd { font: 600 11px/1 var(--font); padding: 2px 5px; border-radius: 5px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); }

/* ---- the top bar ---- */
.bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: calc(var(--bar-h) + var(--safe-t));
  padding: var(--safe-t) max(12px, var(--safe-r)) 0 max(12px, var(--safe-l));
  position: relative;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; border: 0; background: none; padding: 4px 6px; border-radius: 14px; }
.brand-icon { width: 34px; height: 34px; border-radius: 9px; box-shadow: var(--shadow-soft); flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; text-align: left; line-height: 1.15; }
.brand-title { font: 700 17px/1.15 var(--font-round); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-tools, .app-tools, .look-tools { display: flex; align-items: center; gap: 6px; flex: none; }
body[data-view="landing"] .app-tools, body[data-view="boot"] .app-tools { display: none; }
body:not([data-view="landing"]) .look-tools { display: none; }
.chip-slot { display: flex; align-items: center; min-width: 40px; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: inset 0 1px 0 var(--clay-hi), inset 0 -2px 0 var(--clay-lo), var(--shadow-soft);
  transition: transform 0.12s var(--ease), background 0.2s;
  flex: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.96); }

.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 14px; background: var(--well); box-shadow: inset 0 1px 3px var(--clay-lo); flex-wrap: wrap; justify-content: flex-end; }
.seg button { border: 0; background: none; padding: 6px 10px; min-height: 34px; border-radius: 11px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-soft), inset 0 1px 0 var(--clay-hi); }
.seg-lang button { padding: 6px 8px; min-width: 40px; min-height: 40px; }

/* ---- buttons and cards ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  font-weight: 650;
  box-shadow: inset 0 1px 0 var(--clay-hi), inset 0 -3px 0 var(--clay-lo), var(--shadow-soft);
  transition: transform 0.12s var(--ease), background 0.2s, box-shadow 0.2s;
  text-align: center;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.96); }
.btn-primary { background: linear-gradient(180deg, var(--primary-hi), var(--primary)); color: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), inset 0 -3px 0 rgba(90, 30, 0, 0.35), 0 10px 22px -12px rgba(186, 91, 25, 0.9); }
.btn-primary:hover { background: linear-gradient(180deg, #da7836, var(--primary)); }
.btn-ghost { background: transparent; box-shadow: none; color: var(--muted); }
.btn-big { min-height: 56px; font-size: 17px; padding: 0 26px; border-radius: 18px; }
.btn-small { min-height: 44px; padding: 0 14px; font-size: 14px; }
.btn-link { border: 0; background: none; color: var(--accent-ink); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; padding: 10px 4px; min-height: 44px; }
.card { background: var(--surface); border-radius: var(--r); box-shadow: inset 0 1px 0 var(--clay-hi), inset 0 -3px 0 var(--clay-lo), var(--shadow); }
.clay-well { background: var(--well); border-radius: 28px; box-shadow: inset 0 3px 10px var(--clay-lo), inset 0 -1px 0 var(--clay-hi); }

/* ---- views ---- */
main { flex: 1; position: relative; min-height: 0; }
.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: none;
  padding: 0 max(16px, var(--safe-r)) calc(16px + var(--safe-b)) max(16px, var(--safe-l));
  -webkit-overflow-scrolling: touch;
}
.view.on { display: block; animation: view-in 0.32s var(--ease) both; }
@keyframes view-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.page { max-width: 760px; margin: 0 auto; padding-top: 4px; }
.page-head { display: flex; align-items: center; gap: 12px; margin: 6px 0 14px; }
.page-head h2 { font-size: 24px; flex: 1; min-width: 0; }
.page-meta { color: var(--muted); font-size: 14px; display: inline-flex; gap: 6px; align-items: center; }
.page-meta svg { width: 16px; height: 16px; color: var(--star); }
.page-lead { color: var(--muted); margin: -4px 0 16px; max-width: 60ch; text-wrap: pretty; }

/* ---- landing ---- */
.landing { max-width: 980px; margin: 0 auto; padding: 8px 0 24px; }
.hero { display: grid; gap: 22px; align-items: center; grid-template-columns: 1fr; padding: 10px 0 26px; }
.hero-text h1 { font-size: clamp(34px, 8vw, 58px); line-height: 1.02; letter-spacing: -0.03em; }
.hero-lead { font-size: clamp(17px, 2.6vw, 21px); color: var(--muted); margin: 12px 0 20px; max-width: 32ch; text-wrap: balance; }
.hero-cta { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.hero-demo { aspect-ratio: 1; width: min(100%, 420px); justify-self: center; position: relative; overflow: hidden; }
.hero-demo canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.features { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 14px; grid-template-columns: 1fr; }
.feature { padding: 18px 18px 16px; }
.feature h3 { font-size: 18px; margin: 8px 0 4px; }
.feature p { margin: 0; color: var(--muted); font-size: 15px; }
.feat-art { height: 74px; display: flex; align-items: center; }
.feat-art svg { width: auto; height: 74px; overflow: visible; }
.fr-board { transform-origin: 40px 40px; animation: fr-turn 4s var(--ease) infinite; }
.fr-frame { fill: var(--well); stroke: var(--accent); stroke-width: 3; }
.fr-wall { fill: color-mix(in srgb, var(--accent-2) 55%, var(--surface)); }
.fr-ball { fill: #c98a52; animation: fr-ball 4s var(--ease) infinite; }
@keyframes fr-turn { 0%, 15% { transform: rotate(0); } 35%, 65% { transform: rotate(90deg); } 85%, 100% { transform: rotate(0); } }
@keyframes fr-ball { 0%, 30% { transform: translate(0, 0); } 45%, 65% { transform: translate(0, 30px); } 80%, 100% { transform: translate(0, 0); } }
.fs-star { color: var(--star); transform-box: fill-box; transform-origin: center; animation: fs-pop 3s var(--spring) infinite both; }
.fs2 { animation-delay: 0.15s; }
.fs3 { animation-delay: 0.3s; }
@keyframes fs-pop { 0% { transform: scale(0); opacity: 0; } 18%, 80% { transform: scale(1); opacity: 1; } 100% { transform: scale(0.6); opacity: 0; } }
.fc { fill: var(--well); stroke: var(--line); stroke-width: 2; transform-box: fill-box; transform-origin: center; animation: fc-tilt 3.6s var(--ease) infinite; }
.fc1 { fill: color-mix(in srgb, #a99a8a 60%, var(--surface)); }
.fc2 { fill: color-mix(in srgb, #a6c1d5 70%, var(--surface)); animation-delay: 0.3s; }
.fc3 { fill: color-mix(in srgb, #8b67c6 55%, var(--surface)); animation-delay: 0.6s; }
.fc-inf { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; stroke-dasharray: 90; animation: fc-draw 3.6s var(--ease) infinite; }
@keyframes fc-tilt { 0%, 20% { transform: rotate(0); } 40%, 100% { transform: rotate(90deg); } }
@keyframes fc-draw { from { stroke-dashoffset: 90; } 60%, to { stroke-dashoffset: 0; } }
.how { padding: 20px; margin-bottom: 16px; }
.how h2 { font-size: 21px; margin-bottom: 12px; }
.how-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; counter-reset: how; }
.how-steps li { display: flex; align-items: center; gap: 14px; counter-increment: how; }
.how-icon { width: 48px; height: 48px; border-radius: 16px; display: grid; place-items: center; background: var(--well); color: var(--accent-ink); flex: none; position: relative; }
.how-icon::after { content: counter(how); position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; background: var(--primary); color: #fff; font: 700 12px/20px var(--font); text-align: center; }
.info-box { padding: 16px 18px; border-radius: 18px; background: color-mix(in srgb, var(--accent-2) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent-2) 22%, transparent); margin: 0 0 18px; text-wrap: pretty; }
.landing-foot { display: flex; justify-content: center; padding-bottom: 12px; }
@media (min-width: 760px) {
  .hero { grid-template-columns: 1.05fr 1fr; padding: 28px 0 38px; }
  .features { grid-template-columns: repeat(3, 1fr); }
  .how-steps { grid-template-columns: repeat(3, 1fr); }
}

/* ---- menu ---- */
#v-menu { padding-top: 0; }
.menu-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.38; pointer-events: none; }
.menu { position: relative; max-width: 460px; margin: 0 auto; padding: min(6vh, 40px) 0 20px; display: flex; flex-direction: column; gap: 14px; }
.menu-title { font-size: clamp(30px, 8vw, 42px); text-align: center; line-height: 1.05; }
.menu-stars { text-align: center; color: var(--muted); margin: -6px 0 4px; display: flex; justify-content: center; gap: 6px; align-items: center; }
.menu-stars svg { width: 18px; height: 18px; color: var(--star); }
.menu-list { display: grid; gap: 10px; }
.menu-item, .menu-continue {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  border: 0;
  padding: 12px 16px;
  min-height: 70px;
  text-align: left;
  transition: transform 0.14s var(--ease);
}
.menu-item:active, .menu-continue:active { transform: scale(0.97); }
.menu-continue { min-height: 56px; background: color-mix(in srgb, var(--accent) 22%, var(--surface)); font-weight: 650; }
.menu-continue svg { color: var(--accent-ink); }
.mi-icon { width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center; background: var(--well); color: var(--accent-ink); flex: none; }
.mi-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.mi-text b { font: 700 18px/1.2 var(--font-round); }
.mi-text small { color: var(--muted); font-size: 14px; }
.mi-lock { display: none; color: var(--muted); }
.menu-item.locked .mi-lock { display: block; }
.menu-item.locked .mi-icon { color: var(--muted); }

/* ---- worlds and chambers ---- */
.worlds { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .worlds { grid-template-columns: 1fr 1fr; } }
.world { border: 0; padding: 0; text-align: left; overflow: hidden; display: flex; flex-direction: column; min-height: 170px; transition: transform 0.15s var(--ease); }
.world:active { transform: scale(0.98); }
.world-art { height: 96px; width: 100%; display: block; }
.world-art.w0 { background: linear-gradient(135deg, #efe5d3, #c9bdae 70%, #a99a8a); }
.world-art.w1 { background: linear-gradient(135deg, #f3f8fc, #d3e3ef 60%, #a6c1d5); }
.world-art.w2 { background: linear-gradient(135deg, #e4e8e5, #4f8592 75%, #356571); }
.world-art.w3 { background: linear-gradient(135deg, #f2eaf7, #b597e6 65%, #d66fb5); }
:root[data-theme="dark"] .world-art { filter: brightness(0.62) saturate(1.1); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .world-art { filter: brightness(0.62) saturate(1.1); } }
.world-body { padding: 12px 16px 14px; display: grid; gap: 4px; }
.world-name { font: 700 21px/1.1 var(--font-round); }
.world-mech { color: var(--muted); font-size: 14px; }
.world-stats { display: flex; gap: 14px; font-weight: 650; font-size: 15px; align-items: center; }
.world-stats span { display: inline-flex; gap: 5px; align-items: center; }
.world-stats svg { width: 16px; height: 16px; color: var(--star); }
.world-lock { color: var(--muted); display: flex; gap: 6px; align-items: center; font-size: 14px; }
.world-lock svg { width: 18px; height: 18px; }
.world.locked { opacity: 0.72; }
.chambers { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.chamber {
  aspect-ratio: 1;
  border: 0;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px;
  min-width: 0;
  transition: transform 0.14s var(--ease);
}
.chamber:active { transform: scale(0.95); }
.chamber-n { font: 800 clamp(17px, 4.6vw, 24px)/1 var(--font-round); }
.chamber-stars { display: flex; gap: 1px; }
.chamber-stars svg { width: clamp(10px, 2.8vw, 14px); height: clamp(10px, 2.8vw, 14px); color: var(--star-off); }
.chamber-stars svg.on { color: var(--star); }
.chamber-best { font-size: clamp(10px, 2.6vw, 12px); color: var(--muted); display: flex; align-items: center; gap: 2px; white-space: nowrap; }
.chamber-best svg { width: 12px; height: 12px; color: var(--good); }
.chamber.locked { background: var(--well); box-shadow: inset 0 2px 6px var(--clay-lo); color: var(--muted); }
.chamber.locked svg { width: 20px; height: 20px; }
.chamber.current { outline: 3px solid color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: 2px; }

/* ---- generated, daily, balls, boards ---- */
.diffs { display: grid; gap: 12px; }
@media (min-width: 640px) { .diffs { grid-template-columns: repeat(3, 1fr); } }
.diff { border: 0; padding: 16px; text-align: left; display: grid; gap: 6px; transition: transform 0.14s var(--ease); }
.diff:active { transform: scale(0.97); }
.diff-art { height: 70px; display: flex; gap: 4px; align-items: flex-end; }
.diff-art i { width: 18px; border-radius: 6px; background: var(--accent); display: block; }
.diff-name { font: 700 20px/1.1 var(--font-round); }
.diff-meta { color: var(--muted); font-size: 14px; }
.diff-counts { display: flex; gap: 12px; font-weight: 650; font-size: 14px; }
.daily-card { padding: 18px; display: grid; gap: 12px; }
.daily-date { font: 700 20px/1.2 var(--font-round); margin: 0; text-transform: capitalize; }
.daily-card .page-lead { margin: 0; }
.daily-row { display: flex; gap: 12px; align-items: stretch; flex-wrap: wrap; }
.daily-best { flex: 1; min-width: 150px; padding: 12px 14px; border-radius: 16px; background: var(--well); display: grid; }
.daily-best small { color: var(--muted); }
.daily-best b { font: 700 20px/1.3 var(--font-round); }
.daily-streak { padding: 12px 14px; border-radius: 16px; background: color-mix(in srgb, var(--accent) 16%, var(--surface)); display: flex; gap: 8px; align-items: center; font-weight: 650; }
.daily-streak svg { color: var(--primary); }
.daily-card h3 { font-size: 17px; }
.daily-top { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.daily-top li { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 12px; background: var(--surface-2); }
.daily-top li b { margin-left: auto; font-variant-numeric: tabular-nums; }
.daily-top .rank { width: 22px; height: 22px; border-radius: 50%; background: var(--star); color: #4a2a00; font: 700 12px/22px var(--font); text-align: center; flex: none; }
.daily-top .empty { color: var(--muted); background: none; padding-left: 0; }
.row-buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.row-buttons .btn { flex: 1 1 160px; }
.balls { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 560px) { .balls { grid-template-columns: repeat(4, 1fr); } }
.ball-card { border: 0; padding: 12px 10px 12px; display: grid; justify-items: center; gap: 4px; text-align: center; position: relative; transition: transform 0.14s var(--ease); }
.ball-card:active { transform: scale(0.96); }
.ball-card canvas { width: 76px; height: 76px; }
.ball-card b { font: 700 16px/1.2 var(--font-round); }
.ball-card small { color: var(--muted); font-size: 12.5px; line-height: 1.3; min-height: 2.6em; }
.ball-card .bar-p { width: 80%; height: 6px; border-radius: 3px; background: var(--well); overflow: hidden; }
.ball-card .bar-p i { display: block; height: 100%; background: var(--accent); border-radius: 3px; width: var(--p, 0%); transition: width 0.6s var(--ease); }
.ball-card[aria-checked="true"] { outline: 3px solid var(--primary); outline-offset: -3px; }
.ball-card .sel { position: absolute; top: 8px; right: 8px; font-size: 11px; font-weight: 700; color: #fff; background: var(--primary); border-radius: 8px; padding: 2px 6px; }
.ball-card.locked canvas { filter: grayscale(1) brightness(0.8); opacity: 0.5; }
.stats { padding: 18px; }
.stats h3 { font-size: 19px; margin-bottom: 10px; }
.stats-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 0; }
.stats-list div { background: var(--surface-2); border-radius: 14px; padding: 10px 12px; }
.stats-list dt { color: var(--muted); font-size: 13px; }
.stats-list dd { margin: 0; font: 700 20px/1.3 var(--font-round); font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 6px; padding: 4px; border-radius: 16px; background: var(--well); margin-bottom: 14px; }
.tabs button { flex: 1; border: 0; background: none; min-height: 44px; border-radius: 12px; font-weight: 650; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-soft); }
.board-panel { padding: 16px; min-height: 200px; }
.board-mine { margin: 0 0 10px; font-weight: 650; display: flex; gap: 8px; align-items: center; }
.board-mine canvas { width: 24px; height: 24px; }
.board-host { min-height: 120px; }
.yesterday { margin-bottom: 14px; border-radius: 14px; background: var(--surface-2); padding: 4px 12px; }
.yesterday summary { min-height: 44px; display: flex; align-items: center; font-weight: 650; cursor: pointer; }
.yesterday .daily-top { padding-bottom: 10px; }

/* ---- the game ---- */
#v-game { padding: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#v-game.on { display: grid; grid-template-rows: auto 1fr auto; grid-template-areas: "hud" "stage" "ctl"; }
.game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.hud { grid-area: hud; position: relative; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 6px max(12px, var(--safe-r)) 0 max(12px, var(--safe-l)); pointer-events: none; width: 100%; max-width: 820px; margin: 0 auto; }
.hud > * { pointer-events: auto; }
.hud-panel { background: var(--hud); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-radius: 16px; padding: 6px 12px; box-shadow: var(--shadow-soft); }
.hud-left { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hud-name { font-size: 17px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-limits { font-size: 13px; color: var(--muted); white-space: nowrap; transition: opacity 0.4s; }
.hud-limits .lost { opacity: 0.35; text-decoration: line-through; }
.hud-moves { display: flex; align-items: center; gap: 8px; }
.moves-num { font: 800 28px/1 var(--font-round); font-variant-numeric: tabular-nums; min-width: 1.2ch; text-align: right; display: inline-block; }
.moves-num.tick { animation: tick 0.28s var(--spring); }
@keyframes tick { 0% { transform: rotate(0) scale(1); } 40% { transform: rotate(-9deg) scale(1.18); } 100% { transform: none; } }
.moves-meta { display: flex; flex-direction: column; line-height: 1.1; }
.moves-meta small { color: var(--muted); font-size: 12px; }
.moves-o { font-size: 13px; color: var(--accent-ink); }
.hud-pause { width: 48px; height: 48px; }
.stage { grid-area: stage; position: relative; min-height: 0; pointer-events: none; }
.caption {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translate(-50%, 6px);
  margin: 0;
  max-width: min(92%, 420px);
  padding: 8px 14px;
  border-radius: 14px;
  background: var(--hud);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow-soft);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease);
  z-index: 3;
}
.caption.show { opacity: 1; transform: translate(-50%, 0); }
.controls { grid-area: ctl; position: relative; z-index: 2; display: flex; justify-content: center; align-items: center; gap: clamp(6px, 2.4vw, 14px); padding: 6px max(10px, var(--safe-r)) calc(10px + var(--safe-b)) max(10px, var(--safe-l)); }
.ctl {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--text);
  box-shadow: inset 0 1px 0 var(--clay-hi), inset 0 -3px 0 var(--clay-lo), var(--shadow);
  transition: transform 0.1s var(--ease), opacity 0.25s, background 0.2s;
  flex: none;
}
.ctl .ico { width: 26px; height: 26px; }
.ctl:active, .ctl.pressed { transform: scale(0.96); }
.ctl:disabled, .ctl[aria-disabled="true"] { opacity: 0.42; }
.ctl-rot { width: 70px; height: 70px; background: linear-gradient(180deg, var(--primary-hi), var(--primary)); color: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), inset 0 -4px 0 rgba(90, 30, 0, 0.35), 0 14px 26px -14px rgba(186, 91, 25, 0.95); }
.ctl-rot .ico { width: 32px; height: 32px; }
.ctl kbd { position: absolute; bottom: -6px; right: -4px; display: none; }
@media (hover: hover) and (pointer: fine) { .ctl kbd { display: block; } }
.ring { position: absolute; inset: -5px; width: calc(100% + 10px); height: calc(100% + 10px); transform: rotate(-90deg); pointer-events: none; }
.ring circle { fill: none; stroke-width: 3; }
.ring-bg { stroke: transparent; }
.ring-fill { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 182.2; stroke-dashoffset: 182.2; transition: stroke-dashoffset 0.12s linear, opacity 0.3s; opacity: 0; }
.ctl.busy .ring-fill { opacity: 0.9; }
.ctl-hint .ring-fill { stroke: var(--muted); }
.ctl-hint.cooling .ring-fill { opacity: 0.8; }
.ctl-hint .ring-bg { stroke: var(--line); }
.badge { position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; border-radius: 11px; background: var(--accent-2); color: #fff; font: 700 12px/22px var(--font); text-align: center; padding: 0 5px; box-shadow: var(--shadow-soft); }
.ctl.shake { animation: shake 0.28s var(--ease); }
@keyframes shake { 20% { transform: translateX(-3px) rotate(-3deg); } 50% { transform: translateX(3px) rotate(3deg); } 80% { transform: translateX(-1px); } }
.ctl.glow { animation: glow 1s ease-in-out 2; }
.ctl.soft-glow { animation: soft-glow 2s ease-in-out 2; }
@keyframes glow { 0%, 100% { box-shadow: var(--shadow), 0 0 0 0 rgba(255, 180, 40, 0); } 50% { box-shadow: var(--shadow), 0 0 0 9px rgba(255, 180, 40, 0.55); } }
@keyframes soft-glow { 0%, 100% { box-shadow: var(--shadow), 0 0 0 0 rgba(120, 100, 200, 0); } 50% { box-shadow: var(--shadow), 0 0 0 7px rgba(120, 100, 200, 0.35); } }
.legend { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 6; width: min(92%, 360px); padding: 16px; display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: center; animation: card-in 0.4s var(--spring) both; }
.legend-art { width: 96px; height: 96px; border-radius: 16px; background: var(--well); }
.legend-text { display: grid; gap: 2px; }
.legend-text small { color: var(--accent-ink); font-weight: 700; text-transform: uppercase; font-size: 11px; letter-spacing: 0.06em; }
.legend-text b { font: 700 18px/1.2 var(--font-round); }
.legend-text span { font-size: 14px; color: var(--muted); }
.legend .btn { grid-column: 1 / -1; }
@keyframes card-in { from { opacity: 0; transform: translate(-50%, -40%) scale(0.92); } to { opacity: 1; transform: translate(-50%, -50%); } }
.tutor { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
/* the guide on Stone 1: an arrow bouncing above each turn button */
body.tutoring .ctl-rot::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -30px;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  border-right: 5px solid var(--primary);
  border-bottom: 5px solid var(--primary);
  border-radius: 3px;
  transform: rotate(45deg);
  animation: point 1.1s var(--ease) infinite;
  pointer-events: none;
}
body.tutoring #c-right::after { animation-delay: 0.55s; }
@keyframes point { 0%, 100% { translate: 0 -6px; opacity: 0.55; } 50% { translate: 0 2px; opacity: 1; } }
.tutor-swipe { position: absolute; left: 50%; top: 45%; width: 120px; height: 10px; margin-left: -60px; border-radius: 5px; background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.85)); animation: swipe 2.2s var(--ease) infinite; display: none; }
@media (pointer: coarse) { .tutor-swipe { display: block; } }
@keyframes swipe { 0% { transform: translateX(-60px); opacity: 0; } 30% { opacity: 1; } 70% { transform: translateX(60px); opacity: 0; } 100% { opacity: 0; } }
@media (orientation: landscape) and (max-height: 560px) {
  /* a phone on its side: the chamber gets the height, the bar steps aside while playing
     (Pause holds Help, Settings and the way out; the account menu is on every other screen) */
  body[data-view="game"] .bar { display: none; }
  .hud { max-width: none; padding-top: max(6px, var(--safe-t)); }
  #v-game.on { grid-template-columns: auto 1fr auto; grid-template-rows: auto 1fr; grid-template-areas: "hud hud hud" "l stage r"; }
  .controls { display: contents; }
  #c-left, #c-undo, #c-hint { grid-area: l; }
  #c-right, #c-restart { grid-area: r; }
  #c-left { align-self: center; margin-left: max(14px, var(--safe-l)); }
  #c-undo { align-self: end; margin: 0 0 calc(12px + var(--safe-b)) max(20px, var(--safe-l)); }
  #c-hint { align-self: start; margin: 12px 0 0 max(20px, var(--safe-l)); }
  #c-right { align-self: center; margin-right: max(14px, var(--safe-r)); }
  #c-restart { align-self: end; margin: 0 max(20px, var(--safe-r)) calc(12px + var(--safe-b)) 0; }
}

/* ---- building a chamber ---- */
.building { position: absolute; inset: 0; z-index: 8; display: grid; place-content: center; justify-items: center; gap: 18px; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); font-weight: 650; animation: view-in 0.25s var(--ease); }
.cubes { width: 64px; height: 64px; position: relative; animation: cubes 1.6s var(--ease) infinite; }
.cubes i { position: absolute; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.4), inset 0 -3px 0 rgba(0, 0, 0, 0.18); }
.cubes i:nth-child(1) { left: 0; top: 0; }
.cubes i:nth-child(2) { right: 0; top: 0; background: #8b67c6; }
.cubes i:nth-child(3) { right: 0; bottom: 0; background: #a6c1d5; }
.cubes i:nth-child(4) { left: 0; bottom: 0; background: #a99a8a; animation: drop 1.6s var(--ease) infinite; }
@keyframes cubes { 0%, 20% { transform: rotate(0); } 50%, 70% { transform: rotate(90deg); } 100% { transform: rotate(180deg); } }
@keyframes drop { 0%, 40% { transform: translateY(-10px); } 60%, 100% { transform: none; } }

/* ---- sheets ---- */
dialog.sheet {
  border: 0;
  padding: 0;
  margin: auto auto 0;
  width: 100%;
  max-width: 520px;
  max-height: min(92dvh, 860px);
  border-radius: 26px 26px 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 -20px 60px -20px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  display: none;
  flex-direction: column;
}
dialog.sheet[open] { display: flex; animation: sheet-up 0.34s var(--ease) both; }
dialog.sheet::backdrop { background: rgba(20, 14, 26, 0.45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 640px) and (min-height: 560px) {
  dialog.sheet { margin: auto; border-radius: 26px; box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.6); }
  dialog.sheet[open] { animation: sheet-pop 0.34s var(--spring) both; }
}
@keyframes sheet-pop { from { transform: scale(0.94); opacity: 0; } to { transform: none; opacity: 1; } }
#d-pause, #d-result { padding: 22px 20px calc(18px + var(--safe-b)); }
#d-pause h2 { font-size: 22px; text-align: center; margin-bottom: 14px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 16px 10px 20px; border-bottom: 1px solid var(--line); flex: none; }
.sheet-head h2 { font-size: 21px; }
.sheet-body { overflow-y: auto; padding: 8px 20px calc(20px + var(--safe-b)); }
.sheet-stack { display: grid; gap: 10px; margin-top: 14px; }
.sheet-stack .btn { width: 100%; }
.group { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 18px 0 4px; font-family: var(--font); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); min-height: 56px; flex-wrap: wrap; }
.row > span:first-child { flex: 1 1 140px; }
.row-range { display: grid; grid-template-columns: 1fr 4ch; gap: 4px 12px; }
.row-range > span:first-child { grid-column: 1 / -1; }
.row-range input { width: 100%; }
.row output { min-width: 3.5ch; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
input[type="range"] { flex: 1 1 140px; accent-color: var(--primary); min-height: 32px; }
.switch { appearance: none; -webkit-appearance: none; width: 52px; height: 32px; border-radius: 16px; background: var(--well); box-shadow: inset 0 2px 4px var(--clay-lo); position: relative; transition: background 0.2s; cursor: pointer; flex: none; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25); transition: transform 0.22s var(--spring); }
.switch:checked { background: var(--primary); }
.switch:checked::after { transform: translateX(20px); }
.help h3 { font-size: 18px; margin: 20px 0 8px; }
.help p, .help li { text-wrap: pretty; }
.rules { padding-left: 22px; margin: 0; display: grid; gap: 6px; }
.lexicon { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.lexicon li { display: grid; grid-template-columns: 72px 1fr; gap: 12px; align-items: center; padding: 8px; border-radius: 16px; background: var(--surface-2); }
.lexicon canvas { width: 72px; height: 72px; border-radius: 12px; background: var(--well); }
.lexicon b { display: block; font-family: var(--font-round); }
.lexicon span { font-size: 14px; color: var(--muted); }
.example { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); font-size: 14px; }
.tools { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.tools li { display: flex; gap: 12px; align-items: flex-start; }
.tools svg { color: var(--accent-ink); margin-top: 2px; }
.table-wrap { overflow-x: auto; }
.controls-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.controls-table th, .controls-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.controls-table th { color: var(--muted); font-weight: 600; font-size: 13px; }
.note { color: var(--muted); font-size: 13px; margin: 0; text-align: center; }
.about { padding: 18px 22px calc(22px + var(--safe-b)); display: grid; justify-items: center; text-align: center; gap: 8px; }
.about img { border-radius: 18px; box-shadow: var(--shadow); }
.about-name { font: 700 22px/1.1 var(--font-round); margin: 4px 0 0; }
.version { color: var(--muted); font-size: 14px; margin: 0; }

/* ---- result ---- */
.sheet-result { text-align: center; }
.result-stars { display: flex; justify-content: center; gap: 6px; margin: 0 0 6px; }
.rs { width: 56px; height: 56px; color: var(--star-off); transform: scale(0.4); opacity: 0.4; }
.rs2 { width: 70px; height: 70px; margin-top: -10px; }
.rs.on { color: var(--star); animation: star-pop 0.5s var(--spring) both; filter: drop-shadow(0 4px 8px rgba(240, 173, 50, 0.5)); }
.rs.off { animation: star-fade 0.4s var(--ease) both; }
@keyframes star-pop { from { transform: scale(0.2) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes star-fade { to { transform: scale(0.85); opacity: 1; } }
#result-title { font-size: 26px; }
.result-moves { color: var(--muted); margin: 4px 0 10px; }
.result-break { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin: 0 auto 8px; max-width: 280px; font-size: 15px; }
.result-break dt { text-align: left; color: var(--muted); }
.result-break dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.result-total { display: flex; justify-content: space-between; align-items: baseline; max-width: 280px; margin: 0 auto 10px; padding-top: 8px; border-top: 1px solid var(--line); font-weight: 650; }
.result-total b { font: 800 32px/1 var(--font-round); font-variant-numeric: tabular-nums; color: var(--accent-ink); }
.badges { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.badges li { display: inline-flex; gap: 6px; align-items: center; padding: 6px 12px; border-radius: 12px; background: var(--surface-2); font-size: 14px; font-weight: 650; animation: badge 0.6s var(--spring) both; position: relative; overflow: hidden; }
.badges li svg { width: 18px; height: 18px; color: var(--accent-ink); }
.badges li canvas { width: 22px; height: 22px; }
.badges li::after { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.6) 50%, transparent 70%); transform: translateX(-100%); animation: glint 1.1s var(--ease) 0.4s both; }
@keyframes badge { from { transform: scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes glint { to { transform: translateX(100%); } }
.result-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.result-buttons .btn { flex: 1 1 0; padding: 0 8px; font-size: 15px; min-width: 0; }
.result-buttons .btn-primary { order: -1; flex: 1 1 100%; min-height: 54px; font-size: 17px; }
.friends { margin-top: 16px; text-align: left; }
.friends h3 { font-size: 16px; margin-bottom: 6px; }
@media (min-width: 640px) and (min-height: 700px) { #d-result { max-height: 92dvh; overflow-y: auto; } }
#d-result { overflow-y: auto; }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translate(-50%, 20px); z-index: 50; padding: 10px 16px; border-radius: 14px; background: var(--text); color: var(--bg); font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 0.3s, transform 0.3s var(--ease); max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- small phones ---- */
@media (max-width: 440px) {
  .brand-sub { display: none; }
  .brand-title { white-space: normal; font-size: 15px; line-height: 1.1; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .bar-tools, .app-tools { gap: 5px; }
}
@media (max-width: 400px) {
  .moves-meta small { display: none; }
  .hud-panel { padding: 6px 10px; }
  .hud { gap: 6px; }
}
@media (max-width: 380px) {
  .brand-sub { display: none; }
  .icon-btn { width: 44px; height: 44px; }
  .bar-tools, .app-tools { gap: 4px; }
  .controls { gap: 4px; padding-left: max(6px, var(--safe-l)); padding-right: max(6px, var(--safe-r)); }
  .ctl { width: 56px; height: 56px; }
  .ctl-rot { width: 58px; height: 58px; }
  .hud-name { font-size: 15px; }
  .hud-limits { font-size: 12px; }
  .moves-num { font-size: 24px; }
  .hud-pause { width: 44px; height: 44px; }
  .chambers { gap: 7px; }
}
@media (max-width: 340px) {
  .brand-text { display: none; }
  .seg-lang button { min-width: 34px; padding: 6px 4px; }
}

@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="full"]) *, :root:not([data-motion="full"]) *::before, :root:not([data-motion="full"]) *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  :root:not([data-motion="full"]) .view.on { animation: fade 0.2s both !important; }
}
:root[data-motion="reduce"] *, :root[data-motion="reduce"] *::before, :root[data-motion="reduce"] *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
@keyframes fade { from { opacity: 0; } }
