/* Design tokens, shell, buttons and full-screen cards.
   The neon-arcade identity is the seed's and is non-negotiable — this file preserves it and only
   normalises the mechanics (4px spacing grid, logical RTL properties, 44px touch targets). */

:root {
  --neon: #00e5ff;
  --neon2: #7c4dff;
  --hot: #ff2d78;
  --lime: #b6ff3c;
  --gold: #ffc63d;
  --ink: #050a18;
  --ink2: #0b1430;
  --glass: rgba(12, 20, 45, .62);
  --line: rgba(255, 255, 255, .14);
  --ok: #25e08a;
  --bad: #ff4d5e;
  --f: 'Heebo', 'Rubik', 'Segoe UI', system-ui, sans-serif;
  --fd: 'Orbitron', 'Heebo', monospace;

  /* 4px spacing grid */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 20px;
  --s6: 24px;
  --s8: 32px;
  --s12: 48px;
  --tap: 44px;            /* minimum touch target */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #03060f;
  color: #eaf2ff;
  font-family: var(--f);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app { position: fixed; inset: 0; overflow: hidden; }
canvas#road { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hide { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.glass {
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .16);
}

/* ---------------------------------------------------------------- buttons */
.btn {
  font-family: var(--f);
  font-weight: 800;
  font-size: clamp(15px, 2.2vmin, 21px);
  color: #04101f;
  cursor: pointer;
  border: 0;
  border-radius: 16px;
  padding: .85em 1.5em;
  min-height: var(--tap);
  background: linear-gradient(180deg, #8ef7ff, #00c8e8);
  box-shadow: 0 8px 0 #026e85, 0 14px 26px rgba(0, 200, 232, .35);
  transition: transform .09s, box-shadow .09s, filter .2s;
}
.btn:active { transform: translateY(5px); box-shadow: 0 3px 0 #026e85, 0 8px 14px rgba(0, 200, 232, .3); }
.btn:focus-visible { outline: 3px solid var(--lime); outline-offset: 3px; }
.btn[disabled] { filter: grayscale(.7) brightness(.75); cursor: not-allowed; box-shadow: none; }
.btn.alt { background: linear-gradient(180deg, #d3b6ff, #7c4dff); color: #fff; box-shadow: 0 8px 0 #3d1f9e, 0 14px 26px rgba(124, 77, 255, .35); }
.btn.alt:active { box-shadow: 0 3px 0 #3d1f9e; }
.btn.ghost { background: rgba(255, 255, 255, .09); color: #dce9ff; border: 1px solid var(--line); box-shadow: none; }
.btn.ghost:active { transform: translateY(2px); }
.btn.hot { background: linear-gradient(180deg, #ff9dc0, #ff2d78); color: #fff; box-shadow: 0 8px 0 #a30f47, 0 14px 26px rgba(255, 45, 120, .35); }
.btn.hot:active { box-shadow: 0 3px 0 #a30f47; }
.btn.sm { font-size: clamp(13px, 1.9vmin, 16px); padding: .6em 1.1em; }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(10px);
  color: #dbe8ff;
  font-size: clamp(15px, 2.4vmin, 22px);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  transition: transform .1s, background .2s;
}
.icon-btn:active { transform: scale(.93); }
.icon-btn:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }

/* ---------------------------------------------------------------- screens */
.screen {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s5);
  background: radial-gradient(120% 100% at 50% 0%, rgba(20, 10, 60, .72), rgba(2, 4, 12, .94));
  backdrop-filter: blur(7px);
  animation: fadeIn .35s ease both;
  overflow: auto;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.card {
  width: min(980px, 96vw);
  padding: clamp(16px, 3.2vmin, 32px);
  text-align: center;
  position: relative;
  max-height: 96vh;
  overflow: auto;
}
.card.narrow { width: min(560px, 94vw); }
.card.mid { width: min(720px, 95vw); }

.title {
  font-family: var(--fd);
  font-weight: 900;
  letter-spacing: .5px;
  margin: 0;
  line-height: 1;
  font-size: clamp(34px, 8.4vmin, 84px);
  background: linear-gradient(180deg, #fff 10%, #8ef7ff 45%, #7c4dff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 18px rgba(0, 229, 255, .45));
}
.title-he {
  font-family: var(--f);
  font-weight: 900;
  font-size: clamp(26px, 6.2vmin, 56px);
  margin: .15em 0 0;
  background: linear-gradient(90deg, #ffc63d, #ff2d78 60%, #7c4dff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.sub { opacity: .82; font-size: clamp(13px, 2vmin, 18px); margin: .7em 0 1.4em; font-weight: 600; line-height: 1.6; }
.foot { margin-top: var(--s4); font-size: 12px; opacity: .5; font-weight: 600; }

.row { display: flex; gap: var(--s3); justify-content: center; flex-wrap: wrap; margin-top: var(--s5); }
.mini { position: absolute; top: var(--s3); inset-inline-start: var(--s3); display: flex; gap: var(--s2); z-index: 2; }

/* ------------------------------------------------------------ track cards */
.tracks { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
@media (max-width: 640px) { .tracks { grid-template-columns: 1fr; } }
.tcard {
  position: relative;
  padding: var(--s5);
  border-radius: 22px;
  cursor: pointer;
  text-align: start;
  border: 1px solid var(--line);
  overflow: hidden;
  transition: transform .18s, box-shadow .18s;
  background: linear-gradient(160deg, rgba(0, 229, 255, .16), rgba(12, 20, 45, .75));
}
.tcard.b { background: linear-gradient(160deg, rgba(255, 45, 120, .18), rgba(12, 20, 45, .75)); }
.tcard.c { background: linear-gradient(160deg, rgba(182, 255, 60, .16), rgba(12, 20, 45, .75)); }
.tcard:active { transform: scale(.985); }
@media (hover: hover) {
  .tcard:hover { transform: translateY(-5px) scale(1.015); box-shadow: 0 22px 44px rgba(0, 0, 0, .5); }
}
.tcard .em { font-size: clamp(34px, 6vmin, 54px); line-height: 1; }
.tcard h3 { margin: .35em 0 .15em; font-size: clamp(19px, 3.1vmin, 29px); font-weight: 900; }
.tcard p { margin: 0; opacity: .8; font-size: clamp(12px, 1.8vmin, 16px); font-weight: 600; line-height: 1.5; }
.tcard .rng {
  display: inline-block; margin-top: var(--s3);
  font-family: var(--fd); font-size: 13px;
  padding: var(--s1) var(--s3); border-radius: 999px;
  background: rgba(255, 255, 255, .13); border: 1px solid var(--line);
}
.tcard .prog { margin-top: var(--s3); height: 8px; border-radius: 99px; background: rgba(0, 0, 0, .4); overflow: hidden; }
.tcard .prog i { display: block; height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, #b6ff3c, #00e5ff); transition: width .5s; }
.tcard .stars { margin-top: var(--s1); font-size: 13px; opacity: .85; font-weight: 700; }

/* -------------------------------------------------------------- level grid */
.lvgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s3); margin-top: var(--s5); }
@media (max-width: 520px) { .lvgrid { grid-template-columns: repeat(2, 1fr); } }
.lv {
  position: relative;
  padding: var(--s4) var(--s3);
  border-radius: 18px;
  cursor: pointer;
  min-height: var(--tap);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, .11), rgba(6, 12, 30, .7));
  transition: transform .15s, box-shadow .15s;
  text-align: center;
  overflow: hidden;
}
@media (hover: hover) {
  .lv:hover { transform: translateY(-4px); box-shadow: 0 16px 30px rgba(0, 0, 0, .45); border-color: rgba(0, 229, 255, .55); }
}
.lv:active { transform: scale(.96); }
.lv .n { font-family: var(--fd); font-size: clamp(20px, 3.4vmin, 32px); font-weight: 900; color: #8ef7ff; text-shadow: 0 0 16px rgba(0, 229, 255, .6); }
.lv .nm { font-size: 13px; font-weight: 800; margin-top: var(--s1); line-height: 1.35; min-height: 2.6em; display: flex; align-items: center; justify-content: center; }
.lv .st { font-size: clamp(12px, 1.9vmin, 17px); letter-spacing: 2px; margin-top: var(--s1); color: var(--gold); }
.lv.locked { opacity: .45; cursor: not-allowed; filter: grayscale(.7); }
.lv.locked:hover { transform: none; box-shadow: none; }
.lv.done { border-color: rgba(182, 255, 60, .5); background: linear-gradient(180deg, rgba(182, 255, 60, .16), rgba(6, 12, 30, .7)); }
.lv .lk { position: absolute; top: var(--s1); inset-inline-start: var(--s2); font-size: 16px; filter: drop-shadow(0 2px 4px #000); }

/* --------------------------------------------------------- difficulty picker */
.diff { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s2); margin-top: var(--s4); }
@media (max-width: 420px) { .diff { grid-template-columns: repeat(2, 1fr); } }
.diff-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: var(--s2) var(--s1);
  min-height: var(--tap);
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .07);
  color: #dce9ff;
  font-family: var(--f);
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  transition: background .2s, border-color .2s, transform .12s;
}
.diff-btn:active { transform: scale(.96); }
.diff-btn .d-em { font-size: 18px; line-height: 1; }
.diff-btn.on { background: rgba(0, 229, 255, .22); border-color: rgba(0, 229, 255, .6); color: #fff; }
.diff-btn.on.d-hard { background: rgba(255, 45, 120, .22); border-color: rgba(255, 45, 120, .6); }
.diff-btn.on.d-champion { background: rgba(255, 198, 61, .22); border-color: rgba(255, 198, 61, .65); }
.diff-btn:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }
.diff-blurb { margin: var(--s3) 0 0; font-size: 13px; font-weight: 600; opacity: .78; min-height: 2.6em; line-height: 1.5; }

/* ------------------------------------------------------------- toggle pills */
.toggles { display: flex; gap: var(--s3); justify-content: center; flex-wrap: wrap; margin-top: var(--s4); }
.tg {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s4); border-radius: 99px; cursor: pointer;
  font-weight: 800; font-size: 14px; min-height: var(--tap);
  background: rgba(255, 255, 255, .08); border: 1px solid var(--line);
  transition: background .2s, border-color .2s;
}
.tg.on { background: rgba(0, 229, 255, .22); border-color: rgba(0, 229, 255, .5); }
.tg .dot { width: 10px; height: 10px; border-radius: 99px; background: #5a6a8a; transition: background .2s, box-shadow .2s; }
.tg.on .dot { background: var(--lime); box-shadow: 0 0 10px var(--lime); }

/* ------------------------------------------------------------------- help */
.help { text-align: start; font-size: clamp(13px, 1.9vmin, 17px); line-height: 1.85; font-weight: 600; }
.help li { margin-bottom: var(--s1); }
/* .85em of the surrounding 13px would be 11px — under the floor. Pin it instead. */
.kbd { font-family: var(--fd); font-size: 12px; padding: 2px 6px; border-radius: 6px; background: rgba(255, 255, 255, .16); border: 1px solid var(--line); }

/* --------------------------------------------------------- results screen */
.stars-big { font-size: clamp(38px, 8.5vmin, 76px); letter-spacing: .15em; margin: .1em 0; }
.stars-big i { display: inline-block; font-style: normal; opacity: .22; transform: scale(.8); }
.stars-big i.on { opacity: 1; color: var(--gold); text-shadow: 0 0 26px rgba(255, 198, 61, .85); animation: starIn .5s cubic-bezier(.2, 1.7, .4, 1) both; }
.stars-big i.on:nth-child(2) { animation-delay: .16s; }
.stars-big i.on:nth-child(3) { animation-delay: .32s; }
@keyframes starIn { 0% { transform: scale(2.4) rotate(-40deg); opacity: 0 } 100% { transform: scale(1) rotate(0); opacity: 1 } }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s3); margin: var(--s5) 0 var(--s1); }
@media (max-width: 520px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { padding: var(--s3) var(--s2); border-radius: 16px; background: rgba(255, 255, 255, .08); border: 1px solid var(--line); }
.stat b { display: block; font-family: var(--fd); font-size: clamp(17px, 3.2vmin, 28px); color: #8ef7ff; }
.stat small { font-size: 12px; opacity: .78; font-weight: 700; }

.rtitle { font-family: var(--f); font-weight: 900; font-size: clamp(26px, 6vmin, 54px); margin: .1em 0 0; }
.rtitle.win { background: linear-gradient(90deg, #b6ff3c, #00e5ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.rtitle.lose { background: linear-gradient(90deg, #ffc63d, #ff2d78); -webkit-background-clip: text; background-clip: text; color: transparent; }

.conf { position: absolute; top: -20px; width: 9px; height: 14px; border-radius: 2px; animation: confF linear forwards; pointer-events: none; }
@keyframes confF { to { transform: translateY(115vh) rotate(720deg) } }

/* --------------------------------------------------- loading / empty / error */
.state {
  display: flex; flex-direction: column; align-items: center; gap: var(--s3);
  padding: var(--s8) var(--s4); text-align: center;
}
.state .ico { font-size: clamp(38px, 8vmin, 64px); line-height: 1; filter: drop-shadow(0 6px 18px rgba(0, 0, 0, .5)); }
.state h3 { margin: 0; font-size: clamp(18px, 3vmin, 24px); font-weight: 900; }
.state p { margin: 0; opacity: .75; font-size: clamp(13px, 2vmin, 16px); font-weight: 600; max-width: 42ch; line-height: 1.6; }

.inline-error {
  display: flex; align-items: center; gap: var(--s2); justify-content: center; flex-wrap: wrap;
  margin-top: var(--s3); padding: var(--s3) var(--s4); border-radius: 14px;
  background: rgba(255, 77, 94, .14); border: 1px solid rgba(255, 77, 94, .45);
  color: #ffd7dc; font-size: 14px; font-weight: 700; text-align: start;
}
.inline-ok {
  margin-top: var(--s3); padding: var(--s3) var(--s4); border-radius: 14px;
  background: rgba(37, 224, 138, .14); border: 1px solid rgba(37, 224, 138, .45);
  color: #cffbe4; font-size: 14px; font-weight: 700;
}

.skeleton {
  border-radius: 14px;
  background: linear-gradient(100deg, rgba(255, 255, 255, .06) 30%, rgba(255, 255, 255, .16) 50%, rgba(255, 255, 255, .06) 70%);
  background-size: 300% 100%;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0 } to { background-position: -100% 0 } }

.spinner {
  width: 28px; height: 28px; border-radius: 99px;
  border: 3px solid rgba(255, 255, 255, .18);
  border-top-color: var(--neon);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* -------------------------------------------------------------- toasts */
#toasts {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--s6));
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  align-items: center;
  pointer-events: none;
  width: min(420px, 92vw);
}
.toast {
  padding: var(--s3) var(--s5);
  border-radius: 16px;
  background: rgba(10, 18, 42, .92);
  border: 1px solid var(--line);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .6);
  font-weight: 800;
  font-size: 14px;
  text-align: center;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .28s ease, transform .28s cubic-bezier(.2, 1.3, .4, 1);
}
.toast.in { opacity: 1; transform: translateY(0); }
.toast.win { border-color: rgba(182, 255, 60, .55); color: #e7ffc6; }
.toast.warn { border-color: rgba(255, 198, 61, .55); color: #ffeec2; }
.toast.bad { border-color: rgba(255, 77, 94, .55); color: #ffd7dc; }

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