/* Blockfield — Material 3 (dark scheme, teal seed) over a 3D canvas */
@font-face {
  font-family: 'Fredoka';
  src: url('../fonts/fredoka.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
}
@font-face {
  font-family: 'Silkscreen';
  src: url('../fonts/silkscreen-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --md-primary: #80d5c7;
  --md-on-primary: #003731;
  --md-primary-container: #005048;
  --md-on-primary-container: #9cf2e3;
  --md-secondary-container: #334b47;
  --md-on-secondary-container: #cce8e2;
  --md-tertiary: #ffb77c;
  --md-tertiary-container: #6a3c00;
  --md-on-tertiary-container: #ffdcc2;
  --md-error: #ffb4ab;
  --md-error-container: #93000a;
  --md-surface: #0f1514;
  --md-surface-c-low: #171d1c;
  --md-surface-c: #1b2120;
  --md-surface-c-high: #252b2a;
  --md-surface-c-highest: #303635;
  --md-on-surface: #dee4e2;
  --md-on-surface-var: #bec9c6;
  --md-outline: #899390;
  --md-outline-var: #3f4947;
  --glass: rgba(15, 21, 20, .66);
  --glass-strong: rgba(23, 29, 28, .9);

  --shape-xs: 4px; --shape-s: 8px; --shape-m: 12px; --shape-l: 16px; --shape-xl: 28px; --shape-full: 999px;
  --ease-emph: cubic-bezier(.2, 0, 0, 1);
  --ease-std: cubic-bezier(.2, 0, 0, 1);
  --font-display: 'Fredoka', ui-rounded, 'Arial Rounded MT Bold', system-ui, sans-serif;
  --font-logo: 'Silkscreen', 'Courier New', monospace;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: #0f1514;
  color: var(--md-on-surface);
  font: 400 14px/1.45 var(--font-body);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic { width: 20px; height: 20px; fill: currentColor; flex: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; cursor: crosshair; }
[hidden] { display: none !important; }

/* ---------- logo ---------- */
.logo { display: inline-grid; grid-template-columns: 1fr 1fr; gap: 2px; width: 26px; height: 26px; transform: rotate(-8deg); }
.logo i {
  display: block; border-radius: 4px;
  background-repeat: no-repeat; background-position: center; background-size: 72% 72%;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.2), inset 0 2px 0 rgba(255,255,255,.35);
}
/* 1: untouched grass tile */
.logo i:nth-child(1) { background-color: #63c75f; }
/* 2: flagged grass tile (pixel-art flag) */
.logo i:nth-child(2) {
  background-color: #55b851;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 9' shape-rendering='crispEdges'%3E%3Crect x='3' y='1' width='1' height='6' fill='%23f2f2f2'/%3E%3Crect x='4' y='1' width='3' height='3' fill='%23ff4b4b'/%3E%3Crect x='7' y='2' width='1' height='1' fill='%23ff4b4b'/%3E%3Crect x='2' y='7' width='4' height='1' fill='%23263238'/%3E%3C/svg%3E");
}
/* 3: dug tile — sunken grass, pixel dirt hole */
.logo i:nth-child(3) {
  background-color: #3f8f3c;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 9' shape-rendering='crispEdges'%3E%3Crect x='1' y='2' width='7' height='5' fill='%236d4a2d'/%3E%3Crect x='2' y='1' width='5' height='7' fill='%236d4a2d'/%3E%3Crect x='2' y='2' width='5' height='2' fill='%234a301b'/%3E%3Crect x='5' y='5' width='1' height='1' fill='%238d6440'/%3E%3Crect x='3' y='6' width='1' height='1' fill='%238d6440'/%3E%3C/svg%3E");
  box-shadow: inset 0 3px 0 rgba(0,0,0,.28), inset 0 -2px 0 rgba(255,255,255,.18);
}
/* 4: grass tile with a pixel-art mine */
.logo i:nth-child(4) {
  background-color: #4cab48;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 9' shape-rendering='crispEdges' fill='%231d1b20'%3E%3Crect x='4' y='0' width='1' height='9'/%3E%3Crect x='0' y='4' width='9' height='1'/%3E%3Crect x='3' y='2' width='3' height='5'/%3E%3Crect x='2' y='3' width='5' height='3'/%3E%3Crect x='1' y='1' width='1' height='1'/%3E%3Crect x='7' y='1' width='1' height='1'/%3E%3Crect x='1' y='7' width='1' height='1'/%3E%3Crect x='7' y='7' width='1' height='1'/%3E%3Crect x='3' y='3' width='1' height='1' fill='%23ffffff'/%3E%3C/svg%3E");
}
.logo.big { width: 56px; height: 56px; gap: 4px; }
.logo.big i { border-radius: 7px; }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; pointer-events: none; }
.hud > * { pointer-events: auto; }
.topbar {
  position: absolute; left: 12px; right: 12px; top: calc(10px + var(--safe-t));
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.brand, .stats, .actions {
  display: flex; align-items: center; gap: 6px;
  background: var(--glass); backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid rgba(255,255,255,.07);
  border-radius: var(--shape-full); padding: 6px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.brand { padding: 6px 16px 6px 10px; gap: 10px; }
.brand-name { font: 700 16px/1 var(--font-logo); letter-spacing: 0; text-shadow: 0 2px 0 rgba(0,0,0,.35); }
.stats { padding: 5px 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: var(--shape-full);
  background: var(--md-surface-c-high);
  font: 600 16px/1 var(--font-display); font-variant-numeric: tabular-nums;
  min-width: 64px; justify-content: center;
}
.chip .ic { width: 18px; height: 18px; color: var(--md-primary); }
.chip.done { background: var(--md-primary-container); color: var(--md-on-primary-container); }
.hearts { gap: 2px; min-width: 0; padding: 0 10px; }
.hearts .ic { color: #ff6b6b; width: 19px; height: 19px; transition: color .3s, opacity .3s, transform .3s var(--ease-emph); }
.hearts .ic.lost { color: var(--md-outline); opacity: .45; transform: scale(.82); }

.icon-btn {
  position: relative; display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: var(--shape-full); border: 0;
  background: transparent; color: var(--md-on-surface-var); cursor: pointer;
  transition: background .2s var(--ease-std), color .2s, transform .15s;
  overflow: hidden;
}
.icon-btn::after { content: ''; position: absolute; inset: 0; background: currentColor; opacity: 0; transition: opacity .15s; border-radius: inherit; }
.icon-btn:hover::after { opacity: .08; }
.icon-btn:active::after { opacity: .14; }
.icon-btn:active { transform: scale(.94); }
.icon-btn:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 2px; }
.icon-btn.tonal { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.icon-btn.outlined { border: 1px solid var(--md-outline-var); }
.icon-btn .ic { width: 22px; height: 22px; }

/* toolbar */
.toolbar {
  position: absolute; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,.07);
  padding: 6px 14px 6px 6px; border-radius: var(--shape-full);
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.mode-badge { font: 500 12px/1 var(--font-body); letter-spacing: .4px; color: var(--md-on-surface-var); text-transform: uppercase; }

.seg { display: inline-flex; border: 1px solid var(--md-outline); border-radius: var(--shape-full); overflow: hidden; }
.seg button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border: 0; background: transparent; color: var(--md-on-surface);
  font: 500 14px/1 var(--font-body); letter-spacing: .1px; cursor: pointer;
  transition: background .25s var(--ease-std), color .25s;
}
.seg button + button { border-left: 1px solid var(--md-outline); }
.seg button[aria-checked="true"] { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.seg button:hover { background: rgba(255,255,255,.06); }
.seg button[aria-checked="true"]:hover { background: #3c5651; }
.seg button:focus-visible { outline: 2px solid var(--md-primary); outline-offset: -3px; }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; }

.keyhint {
  position: absolute; left: 16px; bottom: calc(18px + var(--safe-b)); margin: 0;
  padding: 8px 12px; border-radius: var(--shape-l);
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,.07);
  color: var(--md-on-surface-var); font-size: 12px;
  display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; max-width: 380px; pointer-events: none;
}
kbd {
  font: 600 11px/1 var(--font-body); padding: 4px 6px; border-radius: 6px;
  background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.2); border-bottom-width: 2px;
}

/* touch controls */
.touch { display: none; }
.joy {
  position: absolute; left: calc(24px + env(safe-area-inset-left, 0px)); bottom: calc(92px + var(--safe-b));
  width: 128px; height: 128px; border-radius: 50%;
  background: rgba(15,21,20,.35); border: 2px solid rgba(255,255,255,.18);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); touch-action: none;
  transition: background .2s;
}
.joy.active { background: rgba(15,21,20,.5); }
.knob {
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px;
  border-radius: 50%; background: rgba(255,255,255,.85); box-shadow: 0 4px 12px rgba(0,0,0,.35);
  transition: transform .12s var(--ease-emph);
}
.joy.active .knob { transition: none; }
.fab-jump {
  position: absolute; right: calc(24px + env(safe-area-inset-right, 0px)); bottom: calc(104px + var(--safe-b));
  width: 76px; height: 76px; border-radius: 24px; border: 0;
  background: var(--md-primary-container); color: var(--md-on-primary-container);
  box-shadow: 0 6px 18px rgba(0,0,0,.35); display: grid; place-items: center; touch-action: none;
}
.fab-jump .ic { width: 34px; height: 34px; }
.fab-jump:active { transform: scale(.94); background: #00675c; }
@media (pointer: coarse) {
  .touch { display: block; }
  .keyhint { display: none; }
  body .snackbar { bottom: auto; top: calc(118px + var(--safe-t)); }
}

/* snackbar */
.snackbar {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b));
  background: #dee4e2; color: #2b3130; padding: 12px 18px; border-radius: var(--shape-s);
  font-weight: 500; box-shadow: 0 6px 20px rgba(0,0,0,.35); opacity: 0; pointer-events: none;
  max-width: min(92vw, 480px); text-align: center; z-index: 50;
}

/* loader */
.loader {
  position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: radial-gradient(circle at 50% 40%, #1f3a36, #0f1514 70%); z-index: 100;
  font: 500 15px var(--font-display); color: var(--md-on-surface-var);
  transition: opacity .5s;
}
.loader .logo { animation: bob 1.1s var(--ease-emph) infinite alternate; }
.loader.done { opacity: 0; pointer-events: none; }
@keyframes bob { to { transform: rotate(8deg) translateY(-8px); } }

/* ---------- dialogs ---------- */
.dlg {
  border: 0; padding: 0; color: var(--md-on-surface);
  background: var(--md-surface-c-high);
  border-radius: var(--shape-xl);
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
  overflow: auto;
  scrollbar-width: thin;
}
.dlg::backdrop { background: rgba(5, 10, 9, .45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.dlg-body { padding: 24px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin: -4px -8px 12px 0; }
.dlg h1, .dlg h2 { font-family: var(--font-display); font-weight: 600; margin: 0; }
.dlg h2 { font-size: 24px; }
.label { font: 500 13px/1 var(--font-body) !important; letter-spacing: .5px; color: var(--md-on-surface-var); text-transform: uppercase; margin: 22px 0 10px !important; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; flex-wrap: wrap; }
.help-text { color: var(--md-on-surface-var); font-size: 13px; margin: 10px 2px 4px; }

.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 24px; border-radius: var(--shape-full); border: 0;
  font: 500 14px/1 var(--font-body); letter-spacing: .1px; cursor: pointer; overflow: hidden;
  transition: box-shadow .2s, transform .15s, background .2s;
}
.btn::after { content: ''; position: absolute; inset: 0; background: currentColor; opacity: 0; transition: opacity .15s; }
.btn:hover::after { opacity: .08; }
.btn:active::after { opacity: .14; }
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 2px; }
.btn .ic { width: 18px; height: 18px; margin-left: -6px; }
.btn.filled { background: var(--md-primary); color: var(--md-on-primary); }
.btn.filled:hover { box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.btn.tonal { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.btn.text { background: transparent; color: var(--md-primary); padding: 0 14px; }
#btnPlay { height: 52px; padding: 0 32px; font-size: 16px; border-radius: var(--shape-l); }

/* start */
.dlg-start { width: min(620px, calc(100vw - 24px)); }
.dlg-start .dlg-body { padding: 28px; }
.hero { display: flex; align-items: center; gap: 18px; }
.hero h1 { font: 700 36px/1 var(--font-logo); letter-spacing: 0; text-shadow: 0 3px 0 rgba(0,0,0,.4); }
.tagline { margin: 6px 0 0; color: var(--md-on-surface-var); font-size: 15px; }

.diff-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* daily — featured, full-width */
.daily-card {
  grid-column: 1 / -1;
  grid-template-columns: 1fr auto; column-gap: 16px;
  background: linear-gradient(120deg, rgba(255, 204, 77, .14), rgba(128, 213, 199, .08) 60%), var(--md-surface-c);
  border-color: rgba(255, 204, 77, .35);
}
.daily-card .dc-title, .daily-card .dc-meta { grid-column: 1; }
.daily-card .dc-lives { grid-column: 1; }
.daily-card:has(input:checked) { border-color: #ffcc4d; background: linear-gradient(120deg, rgba(255, 204, 77, .24), rgba(128, 213, 199, .1) 60%), var(--md-surface-c); }
.dc-badge {
  grid-column: 2; grid-row: 1 / span 2; align-self: start; justify-self: end;
  padding: 6px 10px; border-radius: var(--shape-s); background: #ffcc4d; color: #3d2e00;
  font: 700 11px/1 var(--font-logo); letter-spacing: .5px; white-space: nowrap;
}
.dc-best { grid-column: 2; grid-row: 3 / span 2; align-self: end; justify-self: end; font: 600 13px/1.2 var(--font-display); color: #ffd97a; text-align: right; }

/* custom board panel */
.custom-panel {
  border: 1px solid var(--md-outline-var); border-radius: var(--shape-l); margin: 10px 0 0; padding: 14px 16px 6px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 22px; background: var(--md-surface-c);
}
.custom-panel .help-text { grid-column: 1 / -1; margin: 2px 0 6px; }
.range { display: grid; gap: 6px; font-size: 13px; color: var(--md-on-surface-var); }
.range > span { display: flex; align-items: baseline; gap: 6px; }
.range output { font: 600 16px/1 var(--font-display); color: var(--md-on-surface); font-variant-numeric: tabular-nums; margin-left: auto; }
.range small { font-size: 11px; color: var(--md-outline); min-width: 30px; text-align: right; }

/* avatar editor */
.avatar-edit { display: grid; grid-template-columns: 96px 1fr; gap: 18px; align-items: center; background: var(--md-surface-c); border-radius: var(--shape-l); padding: 14px; }
.av-preview {
  --shirt: #2a9d8f; --pants: #264653; --cap: #f4a261; --skin: #f3c9a1;
  position: relative; width: 96px; height: 150px; margin: auto;
  filter: drop-shadow(0 6px 6px rgba(0,0,0,.35));
}
.av-preview i { position: absolute; display: block; border-radius: 3px; transition: background-color .25s; box-shadow: inset 0 -4px 0 rgba(0,0,0,.18), inset 0 3px 0 rgba(255,255,255,.18); }
.av-cap   { left: 25px; top: 4px;   width: 46px; height: 14px; background: var(--cap); }
.av-brim  { left: 30px; top: 15px;  width: 50px; height: 6px;  background: var(--cap); }
.av-head  { left: 27px; top: 16px;  width: 42px; height: 40px; background: var(--skin); }
.av-head b { position: absolute; top: 15px; width: 5px; height: 8px; border-radius: 2px; background: #1d1b20; }
.av-head b:first-child { left: 11px; } .av-head b:nth-child(2) { right: 11px; }
.av-head u { position: absolute; left: 15px; top: 27px; width: 12px; height: 4px; border-radius: 0 0 6px 6px; background: #1d1b20; }
.av-torso { left: 19px; top: 58px;  width: 58px; height: 50px; background: var(--shirt); }
.av-arm   { top: 58px; width: 18px; height: 46px; background: linear-gradient(var(--shirt) 0 42%, var(--skin) 42%); }
.av-arm.l { left: 0; } .av-arm.r { right: 0; }
.av-leg   { top: 108px; width: 26px; height: 40px; background: linear-gradient(var(--pants) 0 82%, #1d1b20 82%); }
.av-leg.l { left: 22px; } .av-leg.r { right: 22px; }
.av-preview.bounce { animation: avBounce .35s var(--ease-emph); }
@keyframes avBounce { 40% { transform: translateY(-6px) scale(1.03); } }
.av-rows { display: grid; gap: 10px; }
.av-row { display: grid; grid-template-columns: 52px 1fr; align-items: center; gap: 8px; }
.av-row > span { font-size: 12px; color: var(--md-on-surface-var); }
.av-swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.av-sw {
  width: 26px; height: 26px; border-radius: 8px; border: 0; padding: 0; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18), inset 0 -3px 0 rgba(0,0,0,.2);
  transition: transform .15s var(--ease-emph), box-shadow .15s;
}
.av-sw:hover { transform: translateY(-2px); }
.av-sw[aria-checked="true"] { box-shadow: 0 0 0 2px var(--md-surface-c), 0 0 0 4px var(--md-primary); }
.av-sw:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 3px; }
.diff-card {
  position: relative; display: grid; gap: 4px; padding: 14px; border-radius: var(--shape-l);
  background: var(--md-surface-c); border: 1px solid var(--md-outline-var); cursor: pointer;
  transition: border-color .2s, background .2s, transform .2s var(--ease-emph);
}
.diff-card:hover { background: var(--md-surface-c-highest); }
.diff-card input { position: absolute; opacity: 0; pointer-events: none; }
.diff-card:has(input:checked) { border-color: var(--md-primary); background: rgba(128, 213, 199, .1); }
.diff-card:has(input:focus-visible) { outline: 2px solid var(--md-primary); outline-offset: 2px; }
.dc-title { font: 600 18px/1.1 var(--font-display); }
.dc-meta { font-size: 12px; color: var(--md-on-surface-var); }
.dc-lives { display: flex; gap: 2px; margin-top: 4px; min-height: 16px; }
.dc-lives .ic { width: 15px; height: 15px; color: #ff6b6b; }

.scene-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.scene-swatch {
  position: relative; aspect-ratio: 1; border-radius: var(--shape-m); border: 2px solid transparent; cursor: pointer;
  padding: 0; box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); transition: transform .2s var(--ease-emph), border-color .2s;
}
.scene-swatch:hover { transform: translateY(-2px); }
.scene-swatch[aria-checked="true"] { border-color: var(--md-primary); }
.scene-swatch[aria-checked="true"]::after {
  content: ''; position: absolute; right: 4px; top: 4px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--md-primary); box-shadow: 0 0 0 2px var(--md-surface-c-high);
}
.scene-swatch:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 2px; }

.scene-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.scene-card {
  display: grid; gap: 8px; padding: 0 0 10px; border: 2px solid transparent; border-radius: var(--shape-l);
  background: var(--md-surface-c); color: var(--md-on-surface); cursor: pointer; overflow: hidden;
  font: 600 14px/1 var(--font-display); transition: border-color .2s, transform .2s var(--ease-emph);
}
.scene-card .sky { display: block; height: 76px; position: relative; overflow: hidden; }
.scene-card .sky::before { /* island silhouette */
  content: ''; position: absolute; left: 22%; right: 22%; bottom: 14px; height: 10px; border-radius: 3px;
  background: linear-gradient(#63c75f 0 45%, #7a5537 45%);
}
.scene-card:hover { transform: translateY(-2px); }
.scene-card[aria-checked="true"] { border-color: var(--md-primary); }
.scene-card:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 2px; }

/* settings */
.list { margin-top: 18px; display: grid; gap: 2px; border-radius: var(--shape-l); overflow: hidden; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 16px; background: var(--md-surface-c); cursor: pointer;
}
.list-item.col { flex-direction: column; align-items: stretch; gap: 12px; cursor: default; }
.list-item b { display: block; font-weight: 500; font-size: 15px; }
.list-item small { color: var(--md-on-surface-var); font-size: 12px; }

.switch {
  appearance: none; -webkit-appearance: none; position: relative; flex: none;
  width: 52px; height: 32px; border-radius: 16px; margin: 0; cursor: pointer;
  background: var(--md-surface-c-highest); border: 2px solid var(--md-outline);
  transition: background .2s, border-color .2s;
}
.switch::before {
  content: ''; position: absolute; top: 50%; left: 6px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--md-outline); transform: translateY(-50%);
  transition: left .25s var(--ease-emph), width .25s var(--ease-emph), height .25s, background .2s;
}
.switch:checked { background: var(--md-primary); border-color: var(--md-primary); }
.switch:checked::before { left: 22px; width: 24px; height: 24px; background: var(--md-on-primary); }
.switch:focus-visible { outline: 2px solid var(--md-primary); outline-offset: 2px; }

.slider { -webkit-appearance: none; appearance: none; width: 100%; height: 16px; background: transparent; cursor: pointer; }
.slider::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--md-secondary-container); }
.slider::-moz-range-track { height: 4px; border-radius: 2px; background: var(--md-secondary-container); }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -8px; border-radius: 50%; background: var(--md-primary); box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.slider::-moz-range-thumb { width: 20px; height: 20px; border: 0; border-radius: 50%; background: var(--md-primary); }

/* help carousel */
.dlg-help { width: min(720px, calc(100vw - 24px)); }
.carousel { overflow: hidden; border-radius: var(--shape-l); }
.slides { display: flex; transition: transform .45s var(--ease-emph); }
.slide { flex: 0 0 100%; display: grid; gap: 14px; }
.shot {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--shape-l); overflow: hidden;
  background: var(--md-surface-c); box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.step-badge {
  position: absolute; left: 12px; top: 12px; height: 28px; padding: 0 12px; border-radius: var(--shape-full);
  display: inline-flex; align-items: center; background: var(--md-tertiary-container); color: var(--md-on-tertiary-container);
  font: 600 13px/1 var(--font-display); letter-spacing: .3px;
}
.slide h3 { margin: 0; font: 600 20px/1.2 var(--font-display); }
.slide p { margin: 0; color: var(--md-on-surface-var); font-size: 14.5px; }
.slide .tip { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: var(--shape-m); background: var(--md-surface-c); color: var(--md-on-surface); font-size: 13px; }
.slide .tip .ic { color: var(--md-tertiary); width: 18px; height: 18px; margin-top: 1px; }
.car-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; }
.dots { display: flex; gap: 8px; }
.dots button { width: 8px; height: 8px; padding: 0; border: 0; border-radius: 4px; background: var(--md-outline-var); cursor: pointer; transition: width .3s var(--ease-emph), background .3s; }
.dots button[aria-selected="true"] { width: 26px; background: var(--md-primary); }

/* result */
.dlg-result { width: min(440px, calc(100vw - 24px)); text-align: center; }
.res-icon { width: 72px; height: 72px; margin: 4px auto 14px; border-radius: 24px; display: grid; place-items: center; background: var(--md-tertiary-container); color: var(--md-on-tertiary-container); }
.res-icon.lose { background: var(--md-error-container); color: #ffdad6; }
.res-icon .ic { width: 38px; height: 38px; }
.dlg-result h2 { font-size: 30px; }
.res-sub { color: var(--md-on-surface-var); margin: 6px 0 18px; }
.res-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.res-stats div { background: var(--md-surface-c); border-radius: var(--shape-m); padding: 12px 6px; }
.res-stats b { display: block; font: 600 22px/1.1 var(--font-display); font-variant-numeric: tabular-nums; }
.res-stats span { font-size: 12px; color: var(--md-on-surface-var); }
.dlg-result .dlg-actions { justify-content: center; }

/* leaderboard */
.seg.scope { margin-top: 10px; }
.seg.scope button { height: 34px; font-size: 13px; }
.board-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 4px; counter-reset: rank; }
.board-list li {
  counter-increment: rank;
  display: grid; grid-template-columns: 34px 1fr auto auto; align-items: center; gap: 12px;
  padding: 10px 14px 10px 10px; border-radius: var(--shape-m); background: var(--md-surface-c);
}
.board-list li::before {
  content: counter(rank); display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  font: 700 13px/1 var(--font-logo); background: var(--md-surface-c-highest); color: var(--md-on-surface-var);
}
.board-list li:nth-child(1)::before { background: #ffcc4d; color: #3d2e00; }
.board-list li:nth-child(2)::before { background: #cfd8dc; color: #263238; }
.board-list li:nth-child(3)::before { background: #e0a46e; color: #3e2108; }
.board-list .n { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list .t { font: 600 16px/1 var(--font-display); font-variant-numeric: tabular-nums; }
.board-list .d { font-size: 12px; color: var(--md-on-surface-var); min-width: 64px; text-align: right; }
.board-list li.me { background: rgba(128, 213, 199, .16); box-shadow: inset 0 0 0 1px var(--md-primary); }
.board-list .empty { display: block; text-align: center; color: var(--md-on-surface-var); padding: 22px; background: transparent; }
.board-list .empty::before { display: none; }
.board-list.compact { margin-top: 14px; text-align: left; max-height: 40vh; overflow: auto; }
.board-list.compact li { padding: 7px 12px 7px 8px; }
.board-list.compact .d { display: none; }
.board-list.compact li { grid-template-columns: 34px 1fr auto; }

/* name entry */
.name-form { display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; align-items: end; margin-top: 16px; text-align: left; }
.field { display: grid; gap: 6px; }
.field-label { font-size: 12px; color: var(--md-on-surface-var); padding-left: 4px; }
.field input {
  height: 48px; padding: 0 14px; border-radius: var(--shape-s);
  border: 1px solid var(--md-outline); background: transparent; color: var(--md-on-surface);
  font: 500 16px/1 var(--font-body); user-select: text; -webkit-user-select: text;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus { outline: none; border-color: var(--md-primary); box-shadow: inset 0 0 0 1px var(--md-primary); }
.field input[aria-invalid="true"] { border-color: var(--md-error); box-shadow: inset 0 0 0 1px var(--md-error); }
.name-form .btn { height: 48px; border-radius: var(--shape-m); }
.field-help { grid-column: 1 / -1; color: var(--md-on-surface-var); font-size: 12px; padding-left: 4px; }
.name-form.saving { opacity: .6; pointer-events: none; }
.res-rank { margin: 14px 0 0; font: 600 16px/1.3 var(--font-display); color: var(--md-primary); }

/* ---------- responsive ---------- */
@media (max-width: 1000px) { .keyhint { display: none; } }
@media (max-width: 760px) {
  .brand-name { display: none; }
  .brand { padding: 6px 10px; }
  .topbar { left: 8px; right: 8px; gap: 6px; flex-wrap: wrap; justify-content: center; }
  .stats { order: 3; }
  .chip { min-width: 0; padding: 0 10px; font-size: 15px; height: 32px; }
  .icon-btn { width: 36px; height: 36px; }
  .toolbar { bottom: calc(14px + var(--safe-b)); }
  .mode-badge { display: none; }
  .toolbar { padding: 6px; }
  .scene-row { grid-template-columns: repeat(3, 1fr); }
  .scene-grid { grid-template-columns: repeat(2, 1fr); }
  .diff-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .diff-card { padding: 12px; }
  .custom-panel { grid-template-columns: 1fr; }
  .avatar-edit { grid-template-columns: 1fr; }
  .av-row { grid-template-columns: 1fr; gap: 6px; }
  .hero h1 { font-size: 24px; }
  .dlg-body, .dlg-start .dlg-body { padding: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
