@font-face {
  font-family: 'Fredoka';
  src: url('fonts/fredoka-latin.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --ink: #0B1233;
  --panel: #131B47;
  --panel-edge: rgba(200, 210, 255, 0.16);
  --sun: #FFC24B;
  --visor: #7FE7FF;
  --suit: #F5F3FF;
  --soft: #C9CEF0;
  --ember: #FF6A3D;
  --radius: 22px;
  --font: 'Fredoka', ui-rounded, system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); }
body {
  font-family: var(--font);
  color: var(--suit);
  font-size: 18px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

canvas#game { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; touch-action: none; }

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--visor); outline-offset: 3px; border-radius: 12px; }

.btn {
  min-height: 54px;
  padding: 0 28px;
  border-radius: 999px;
  border: 2px solid transparent;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: transform 0.12s ease, background-color 0.12s ease;
}
.btn.primary { background: var(--sun); color: var(--ink); }
.btn.primary:hover { background: #FFD27A; }
.btn.ghost { background: transparent; border-color: rgba(245, 243, 255, 0.6); }
.btn.ghost:hover { background: rgba(245, 243, 255, 0.1); }
.btn:active { transform: scale(0.97); }

/* sound toggle, always reachable */
.sound {
  position: fixed;
  z-index: 30;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  display: inline-flex; align-items: center; gap: 6px;
  height: 44px; padding: 0 14px 0 10px;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  background: rgba(19, 27, 71, 0.8);
  font-size: 0.95rem; font-weight: 500;
}
.sound svg { width: 24px; height: 24px; }
.sound .waves { display: none; }
.sound.on .waves { display: inline; }
.sound.on .mute { display: none; }

/* in-game HUD */
.hud {
  position: fixed; z-index: 20; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 150px 8px max(10px, env(safe-area-inset-left));
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  background: rgba(19, 27, 71, 0.8);
}
.icon-btn svg { width: 22px; height: 22px; }
.where { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.where .on { font-size: 0.85rem; color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.where .next { font-size: 1.3rem; font-weight: 600; white-space: nowrap; }
.stats { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.score { font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.score .lbl { font-size: 0.85rem; font-weight: 500; color: var(--soft); }
.timer {
  font-size: 0.85rem; font-weight: 500; font-variant-numeric: tabular-nums;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(127, 231, 255, 0.14); color: var(--visor);
  white-space: nowrap;
}

.hint, .toast {
  position: fixed; z-index: 15; left: 50%; transform: translateX(-50%);
  margin: 0; max-width: min(92vw, 560px);
  text-align: center; font-weight: 500;
  padding: 10px 18px; border-radius: 16px;
  background: rgba(19, 27, 71, 0.88);
  border: 1px solid var(--panel-edge);
  pointer-events: none;
}
.hint { top: 72px; color: var(--sun); font-size: 1.05rem; }
.toast { top: 128px; opacity: 0; transition: opacity 0.2s ease; }
.toast.show { opacity: 1; }

/* journey strip: the whole trip, in order */
.journey {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
  padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(7, 10, 34, 0.92), rgba(7, 10, 34, 0));
}
.journey ol {
  list-style: none; margin: 0 auto; padding: 0; max-width: 760px;
  display: flex; justify-content: space-between; align-items: center; gap: 2px;
}
.stop {
  width: 40px; height: 40px; padding: 4px;
  border: 0; border-radius: 999px; background: none;
  opacity: 0.35; filter: grayscale(0.6);
}
.stop img { width: 100%; height: 100%; object-fit: contain; display: block; }
.stop.reached { opacity: 1; filter: none; }
.stop.target { opacity: 0.9; filter: none; box-shadow: 0 0 0 2px var(--sun); }
.stop:disabled { cursor: default; }

/* screens */
.screen {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 72px 20px 24px; text-align: center; overflow-y: auto;
}
.screen[hidden] { display: none; }
.title-screen h1 {
  margin: 0.2em 0 0.1em;
  font-size: clamp(3.4rem, 13vw, 7.5rem);
  font-weight: 700; line-height: 0.95; letter-spacing: -0.02em;
  color: var(--suit);
  text-shadow: 0 6px 0 rgba(255, 194, 75, 0.35);
}
.sub { margin: 0.4em auto 1.2em; max-width: 34ch; font-size: clamp(1.1rem, 3.6vw, 1.35rem); color: var(--soft); }
.actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.best { min-height: 1.4em; margin: 1em 0 0; color: var(--sun); font-weight: 500; }
.how { margin-top: 1.2em; font-size: 0.95rem; color: var(--soft); }
.how p { margin: 0.2em 0; }
.how strong { color: var(--suit); font-weight: 600; }
.foot { margin-top: 2em; display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--soft); }
.foot a { color: var(--soft); }

.lineup {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center;
  gap: 6px 10px; max-width: 760px;
}
.lineup li { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.lineup img { width: var(--s); height: auto; animation: rise 0.7s cubic-bezier(.2,.8,.3,1.2) both; }
.lineup li:nth-child(n) img { animation-delay: calc(var(--i, 0) * 40ms); }
.lineup span { font-size: 0.75rem; color: var(--soft); }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.8); } }
@media (max-width: 640px) { .lineup span { display: none; } .lineup { gap: 4px 6px; } }

.win-screen h2 { font-size: clamp(2.4rem, 9vw, 4.5rem); margin: 0; line-height: 1; }
.win-stats { display: flex; gap: 14px; margin: 0.6em 0 0; flex-wrap: wrap; justify-content: center; }
.win-stats div { padding: 12px 18px; border-radius: 18px; background: rgba(19, 27, 71, 0.85); border: 1px solid var(--panel-edge); }
.win-stats dt { font-size: 0.85rem; color: var(--soft); }
.win-stats dd { margin: 0; font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* fact card */
.card {
  width: min(94vw, 520px); max-height: 92dvh; overflow-y: auto;
  padding: 22px 22px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  color: var(--suit);
  user-select: text;
}
.card::backdrop { background: rgba(5, 8, 26, 0.6); }
.card[open] { animation: pop 0.28s cubic-bezier(.2,.8,.3,1.15); }
@keyframes pop { from { opacity: 0; transform: translateY(16px) scale(0.96); } }
.result { margin: 0 0 12px; color: var(--sun); font-weight: 600; font-size: 1.1rem; }
.card-top { display: flex; gap: 18px; align-items: center; }
.card-top img { width: 132px; height: 132px; object-fit: contain; flex: none; }
.card-top img.wide { width: 170px; }
.card h2 { margin: 0; font-size: 2.2rem; line-height: 1; }
.order { margin: 6px 0 8px; color: var(--soft); font-size: 1rem; }
.kind {
  display: inline-block; margin: 0; padding: 3px 10px; border-radius: 999px;
  font-size: 0.85rem; font-weight: 500;
  background: rgba(127, 231, 255, 0.14); color: var(--visor);
}
.kind.art { background: rgba(255, 194, 75, 0.16); color: var(--sun); }
.art-note { margin: 12px 0 0; font-size: 0.95rem; color: var(--soft); }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0 0; }
.facts div { padding: 10px 12px; border-radius: 14px; background: rgba(255, 255, 255, 0.06); }
.facts dt { font-size: 0.85rem; color: var(--soft); }
.facts dd { margin: 2px 0 0; font-size: 1.05rem; font-weight: 600; line-height: 1.25; }
.fact { margin: 16px 0 10px; font-size: 1.15rem; line-height: 1.5; }
.credit { margin: 0 0 16px; font-size: 0.82rem; color: var(--soft); }
.card .btn { width: 100%; }

@media (max-width: 480px) {
  body { font-size: 17px; }
  .hud { padding-right: 64px; }
  .sound .label { display: none; }
  .sound { padding: 0; width: 44px; justify-content: center; }
  .where .next { font-size: 1.1rem; }
  .stop { width: 30px; height: 30px; padding: 2px; }
  .card { padding: 18px 16px 16px; }
  .card-top img { width: 96px; height: 96px; }
  .card-top img.wide { width: 130px; }
  .card h2 { font-size: 1.8rem; }
  .toast { top: 118px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 480px) {
  .stats { flex-direction: column-reverse; align-items: flex-end; gap: 2px; }
  .timer { font-size: 0.75rem; padding: 2px 8px; }
}
