/* Chartflip interface: chunky casual "sticker" style.
 * Every surface has a thick navy outline and a hard drop shadow; buttons press down into their shadow;
 * big numbers are white with a navy outline so they read over any sky. */
:root {
  --ink: #10132b;
  --line: #1b1f46;
  --paper: #fffaf0;
  --card: #ffffff;
  --sunk: #eef1fb;
  --text: #1b1f46;
  --muted: #6b7196;
  --up: #ff4d5e;
  --down: #3d7bff;
  --gold: #ffd23f;
  --gold-deep: #f0a800;
  --silver: #d7dde8;
  --bronze: #e39a5f;
  --mint: #46d9a4;
  --orange: #ff8a1c;
  --edge: 3px solid var(--line);
  --drop: 0 5px 0 var(--line);
  --radius: 20px;
  --font: system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font);
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
  cursor: pointer;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 4px;
}

[hidden] { display: none !important; }

/* Outlined display text: white fill, navy outline (half of it hidden under the fill), hard shadow. */
.outlined, #timer, .logo, .time {
  color: #fff;
  -webkit-text-stroke: 0.1em var(--line);
  paint-order: stroke fill;
  text-shadow: 0 0.055em 0 var(--line);
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  border-radius: 8px;
  background: var(--line);
  color: #fff;
  box-shadow: 0 3px 0 rgba(27, 31, 70, 0.35);
  font: 900 12px/1 var(--font);
  letter-spacing: 0.2px;
}

svg .fill { fill: currentColor; stroke: none; }
svg .off { display: none; }
.muted svg .on { display: none; }
.muted svg .off { display: inline; }

/* Chunky press-in buttons: they sink into their own shadow. */
.icon, .round, .primary, .secondary, .course {
  border: var(--edge);
  box-shadow: var(--drop);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.icon:active, .round:active, .primary:active, .secondary:active, .course:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--line);
}

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  inset: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  pointer-events: none;
}

.hud button { pointer-events: auto; }

.icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--card);
  color: var(--line);
}

.icon svg, .round svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.clock {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

#timer {
  contain: layout style;
  font-size: 42px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  line-height: 1.1;
}

/* Ghost split: a small pill beside the timer, mint when ahead. */
.delta {
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%) rotate(-3deg);
  padding: 3px 9px;
  border: 2.5px solid var(--line);
  border-radius: 999px;
  background: #ffb3b3;
  box-shadow: 0 3px 0 var(--line);
  color: var(--line);
  font-size: 14px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.delta.ahead { background: var(--mint); }
.delta:empty { display: none; }

#minimap {
  width: min(260px, 44vw);
  height: 28px;
  border: 2.5px solid var(--line);
  border-radius: 12px;
  background: rgba(27, 31, 70, 0.72);
  box-shadow: 0 3px 0 var(--line);
}

.hud-right {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

/* ---------- bottom dock: cash wallet (left) and key guide (centre) ---------- */
/* The wallet is the boost fuel: coin count plus a tank of twelve cells, one second of boost each. */
.wallet {
  --fill: 0;
  position: fixed;
  left: max(20px, calc(env(safe-area-inset-left) + 14px));
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 16px));
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  column-gap: 10px;
  row-gap: 5px;
  padding: 8px 14px 10px 9px;
  border: var(--edge);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--drop);
  pointer-events: none;
}

.wallet-coin {
  grid-row: 1 / 3;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 3px solid var(--line);
  background: radial-gradient(circle at 35% 32%, #fff2a8, var(--gold) 55%, #e59a00);
  box-shadow: inset 0 -4px 0 rgba(168, 101, 0, 0.35);
  color: #9a5a00;
  font-size: 21px;
  font-weight: 900;
  line-height: 1;
}

.wallet-count {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-height: 26px;
}

.wallet-count b {
  min-width: 2ch;
  color: var(--line);
  font-size: 26px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.wallet-burn {
  padding: 2px 7px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--orange);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.1;
  white-space: nowrap;
  visibility: hidden;
}

.wallet-tank {
  position: relative;
  width: 128px;
  height: 16px;
  border: 2.5px solid var(--line);
  border-radius: 6px;
  background: var(--sunk);
  overflow: hidden;
}

.wallet-tank i {
  position: absolute;
  inset: 0;
  background: linear-gradient(#ffe886, var(--gold) 55%, var(--gold-deep));
  transform: scaleX(var(--fill));
  transform-origin: left;
  will-change: transform;
}

/* Cell dividers on top of the fill. */
.wallet-tank::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 calc(100% / 12 - 2px), rgba(27, 31, 70, 0.45) calc(100% / 12 - 2px) calc(100% / 12));
}

.wallet-note {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%) rotate(-4deg);
  padding: 4px 12px;
  border: 2.5px solid var(--line);
  border-radius: 999px;
  background: var(--gold);
  box-shadow: 0 3px 0 var(--line);
  color: var(--line);
  font-size: 15px;
  font-weight: 900;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.wallet-note.show { opacity: 1; transition-duration: 0.08s; }

/* Burning: the fuel turns to flame and the burn rate shows. */
.wallet.on .wallet-tank i { background: linear-gradient(#fff3b0, var(--orange) 55%, #e2560f); }
.wallet.on .wallet-burn { visibility: visible; }
.wallet.full .wallet-tank { box-shadow: 0 0 10px 2px rgba(255, 210, 63, 0.85); }
.wallet.full .wallet-coin { animation: ready 1s ease-in-out infinite; }
.wallet.empty .wallet-coin { filter: grayscale(1); opacity: 0.55; }
.wallet.empty .wallet-count b { color: var(--muted); }
/* Holding boost with nothing to burn. */
.wallet.dry { animation: dry 0.32s ease-in-out infinite; }
.wallet.dry .wallet-count b { color: var(--up); }

@keyframes ready { 50% { scale: 1.08; } }
@keyframes dry { 25% { translate: -3px 0; } 75% { translate: 3px 0; } }

/* Keycaps: light grey caps with a visible skirt; a held key sinks into its shadow. */
.keys {
  position: fixed;
  left: 50%;
  bottom: max(16px, calc(env(safe-area-inset-bottom) + 10px));
  transform: translateX(-50%);
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.key {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0;
  background: none;
  touch-action: none;
}

.key kbd {
  height: 50px;
  min-width: 58px;
  padding: 0 16px 6px;
  border: 3px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(#fbfcff, #dfe3ee);
  box-shadow: inset 0 -7px 0 #b1b8cf, 0 5px 0 var(--line);
  color: var(--line);
  font: 900 17px/1 var(--font);
  letter-spacing: 0.1em;
  transition: transform 0.05s ease, box-shadow 0.05s ease;
}

.key-space kbd { width: 216px; }

.key.down kbd {
  transform: translateY(5px);
  padding-bottom: 2px;
  background: linear-gradient(#e6e9f2, #d4d9e6);
  box-shadow: inset 0 -2px 0 #b1b8cf, inset 0 3px 0 rgba(27, 31, 70, 0.12), 0 0 0 var(--line);
}

/* X while cash burns: the cap glows like the flame. */
.key.on kbd {
  background: linear-gradient(#ffe0a6, var(--orange));
  box-shadow: inset 0 -2px 0 #d9570f, inset 0 3px 0 rgba(255, 255, 255, 0.35), 0 0 0 var(--line), 0 0 14px 3px rgba(255, 138, 28, 0.6);
}

.key em {
  color: #fff;
  font-size: 13px;
  font-style: normal;
  font-weight: 900;
  white-space: nowrap;
  -webkit-text-stroke: 4px var(--line);
  paint-order: stroke fill;
}

.touch-face { display: none; }

/* ---------- ready card and hint ---------- */
.prompt {
  position: fixed;
  left: 50%;
  /* Above the key guide. */
  bottom: max(122px, calc(env(safe-area-inset-bottom) + 116px));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 24px 16px;
  border: var(--edge);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 6px 0 var(--line);
  text-align: center;
  cursor: pointer;
  touch-action: none;
}

/* Course name on a ribbon that sits across the card's top edge. */
.prompt strong {
  margin-top: -15px;
  padding: 4px 14px;
  border: 2.5px solid var(--line);
  border-radius: 999px;
  background: var(--line);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.prompt-go {
  font-size: 26px;
  font-weight: 900;
  color: var(--line);
  animation: bob 1.1s ease-in-out infinite;
}

.hint {
  position: fixed;
  left: 50%;
  bottom: max(122px, calc(env(safe-area-inset-bottom) + 116px));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 150px);
  padding: 11px 20px;
  border: var(--edge);
  border-radius: 999px;
  background: var(--gold);
  box-shadow: var(--drop);
  color: var(--line);
  font-weight: 900;
  font-size: 17px;
  cursor: pointer;
  touch-action: none;
  animation: nudge 0.8s ease-in-out infinite;
}

@keyframes bob { 50% { transform: translateY(-3px) scale(1.04); } }
@keyframes nudge { 50% { translate: 0 -6px; } }

/* A portrait phone cannot fit the chart and both thumb controls during a race. */
.rotate-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(16, 19, 43, 0.94);
  color: #fff;
  text-align: center;
}
.rotate-card { display: flex; flex-direction: column; align-items: center; gap: 15px; max-width: 320px; }
.rotate-card svg { width: 80px; height: 80px; fill: none; stroke: #fff; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.rotate-card strong { font-size: 24px; font-weight: 900; }
.rotate-card p { margin: 0; color: #d7dde8; font-size: 15px; font-weight: 700; }
.rotate-card button { margin-top: 12px; padding: 9px 20px; border: 2px solid #fff; border-radius: 12px; background: transparent; color: #fff; font-weight: 800; }
.rotate-card button:focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; }

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.screen.dim {
  display: grid;
  padding: 20px;
  background: rgba(16, 19, 43, 0.55);
}

/* Auto margins centre a panel but fall back to the top when it is taller than the screen, so it scrolls. */
.screen.dim > .panel { margin: auto; }

.menu {
  background: linear-gradient(180deg, rgba(16, 19, 43, 0) 0%, rgba(16, 19, 43, 0.25) 40%, rgba(16, 19, 43, 0.75) 100%);
}

.menu-inner {
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 100%;
  justify-content: center;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.logo {
  margin: 0;
  font-size: clamp(54px, 10vw, 100px);
  font-weight: 900;
  letter-spacing: -1px;
  line-height: 1;
  -webkit-text-stroke-width: 0.075em;
  text-shadow: 0 0.045em 0 var(--line);
  transform: rotate(-2deg);
}

.logo .flip {
  display: inline-block;
  color: var(--down);
  transform: scaleY(-1);
  animation: flipword 3.2s ease-in-out infinite;
}

@keyframes flipword {
  0%, 38% { transform: scaleY(-1); color: var(--down); }
  50%, 88% { transform: scaleY(1); color: var(--up); }
  100% { transform: scaleY(-1); color: var(--down); }
}

/* Tagline on a gold ribbon. */
.tagline {
  margin: 14px 0 0;
  padding: 5px 18px;
  border: 2.5px solid var(--line);
  border-radius: 12px;
  background: var(--gold);
  box-shadow: 0 3px 0 var(--line);
  color: var(--line);
  font-size: clamp(17px, 2.6vw, 22px);
  font-weight: 900;
  transform: rotate(-2deg);
}

.tally {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 16px 0 0;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.tally span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 11px 3px 6px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  box-shadow: 0 2px 0 var(--line);
}

.courses {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px 12px;
}

.course {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px 12px;
  border-width: 2.5px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 4px 0 var(--line);
  color: var(--text);
  text-align: left;
}

.course:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--line); }
.course:focus-visible { outline-offset: 3px; }

.spark {
  display: block;
  width: 100%;
  height: 46px;
}

.spark polyline {
  fill: none;
  stroke: var(--up);
  stroke-width: 2.6;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.spark polygon { fill: rgba(255, 77, 94, 0.1); stroke: none; }

.course-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 0 2px;
}

/* Course number in a round navy badge. */
.num {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--line);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.course b {
  font-size: 17px;
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


.course-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.best {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text);
  font-weight: 900;
}
.best.empty { color: var(--muted); font-weight: 700; }

.goal { display: flex; align-items: center; gap: 5px; white-space: nowrap; }

.tag {
  position: absolute;
  top: -10px;
  right: 10px;
  padding: 3px 10px;
  border: 2.5px solid var(--line);
  border-radius: 999px;
  background: var(--gold);
  box-shadow: 0 3px 0 var(--line);
  color: var(--line);
  font-size: 12px;
  font-weight: 900;
  transform: rotate(4deg);
}

.dot {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(27, 31, 70, 0.25);
}

.dot.gold { background: var(--gold); border-color: var(--line); }
.dot.silver { background: var(--silver); border-color: var(--line); }
.dot.bronze { background: var(--bronze); border-color: var(--line); }

.menu-footer {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.round {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--card);
  color: var(--line);
  font-size: 19px;
  font-weight: 900;
}

.round[aria-pressed="true"] { background: var(--gold); }
.round.small { width: 44px; height: 44px; margin: 6px auto 0; background: var(--sunk); border-width: 2.5px; box-shadow: 0 3px 0 var(--line); }
/* Secondary panel actions (copy, sound) sit in the top-right corner instead of adding a row. */
.round.corner { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; margin: 0; background: var(--card); border-width: 2.5px; box-shadow: 0 3px 0 var(--line); }
.round.corner:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.round.corner svg { width: 20px; height: 20px; }
/* The pause title ribbon owns the top edge, so its sound button hangs over the corner like a badge. */
.panel.pause .round.corner { top: -20px; right: 16px; }

.fine {
  margin: 0;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

/* ---------- panels ---------- */
.panel {
  position: relative;
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 26px 22px 20px;
  border: var(--edge);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: 0 7px 0 var(--line), 0 24px 50px rgba(0, 0, 0, 0.3);
  text-align: center;
  animation: enter 0.32s cubic-bezier(0.2, 1.5, 0.4, 1);
}

/* Panel titles sit on a ribbon across the top edge. */
.panel h2 {
  align-self: center;
  margin: -46px 0 6px;
  padding: 7px 24px;
  border: var(--edge);
  border-radius: 14px;
  background: var(--down);
  box-shadow: 0 4px 0 var(--line);
  color: #fff;
  font-size: 21px;
  font-weight: 900;
  transform: rotate(-2deg);
}

.primary, .secondary {
  min-height: 54px;
  border-radius: 18px;
  font-size: 18px;
  font-weight: 900;
}

.primary { background: var(--gold); color: var(--line); }
.secondary { background: var(--card); color: var(--line); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row > [hidden] + *, .row > *:only-child { grid-column: 1 / -1; }

/* Medal disc on a slow sunburst: the element holds the number, ::after the disc, ::before the rays. */
.medal {
  --disc: var(--sunk);
  position: relative;
  isolation: isolate;
  width: 84px;
  height: 84px;
  margin: 0 auto 2px;
  display: grid;
  place-items: center;
  font-size: 36px;
  font-weight: 900;
  color: var(--line);
  animation: pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.medal::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  border-radius: 50%;
  background: var(--disc);
  border: var(--edge);
  box-shadow: 0 4px 0 var(--line);
}

.medal::before {
  content: "";
  position: absolute;
  z-index: -2;
  inset: -34px;
  border-radius: 50%;
  background: repeating-conic-gradient(rgba(255, 210, 63, 0.45) 0 12deg, transparent 12deg 30deg);
  -webkit-mask: radial-gradient(circle, #000 35%, transparent 70%);
  mask: radial-gradient(circle, #000 35%, transparent 70%);
  animation: spin 12s linear infinite;
}

.medal.none::before { display: none; }
.medal.gold { --disc: radial-gradient(circle at 35% 30%, #fff6c8, var(--gold) 55%, #e0a400); }
.medal.silver { --disc: radial-gradient(circle at 35% 30%, #ffffff, var(--silver) 55%, #a7b0c2); }
.medal.silver::before { background: repeating-conic-gradient(rgba(215, 221, 232, 0.55) 0 12deg, transparent 12deg 30deg); }
.medal.bronze { --disc: radial-gradient(circle at 35% 30%, #ffe2c7, var(--bronze) 55%, #b06a38); }
.medal.bronze::before { background: repeating-conic-gradient(rgba(227, 154, 95, 0.45) 0 12deg, transparent 12deg 30deg); }
.medal.none { color: var(--muted); }

@keyframes pop { from { transform: scale(0.3); opacity: 0; } }
@keyframes enter { from { transform: translateY(24px) scale(0.92); opacity: 0; } }
@keyframes spin { to { transform: rotate(1turn); } }

.verdict { margin: 0; font-size: 19px; font-weight: 900; color: var(--line); }

.time {
  font-size: 60px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
  line-height: 1.05;
}

.compare {
  align-self: center;
  margin: 2px 0 0;
  padding: 3px 12px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #ffb3b3;
  color: var(--line);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.compare.good { background: var(--mint); }
.target { margin: 0; color: var(--muted); font-size: 14px; font-weight: 800; }
.target:empty { display: none; }

/* Result recap: icon + number chips, no labels. */
.recap {
  margin: 4px 0 8px;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.recap li {
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 8px;
  border-radius: 14px;
  background: var(--sunk);
  font-size: 16px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.recap canvas { width: 24px; height: 24px; }
.recap .flipmark { font-size: 19px; color: var(--gold-deep); }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- help ---------- */
.panel.help { width: min(440px, 100%); gap: 14px; }

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 16px;
  text-align: left;
}

.steps li {
  display: grid;
  grid-template-columns: 44px 1fr;
  column-gap: 14px;
  align-items: center;
}

.steps .num {
  grid-row: span 2;
  width: 44px;
  height: 44px;
  border: 2.5px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 3px 0 var(--line);
  background: var(--gold);
  color: var(--line);
  font-size: 22px;
}

.steps li:nth-child(1) .num { background: var(--down); color: #fff; }
.steps li:nth-child(3) .num { background: var(--orange); }
.steps b { font-size: 16px; font-weight: 900; }
.steps span { font-size: 13.5px; line-height: 1.4; color: var(--muted); font-weight: 600; }

.panel.help, .panel.result { max-height: calc(100vh - 40px); overflow-y: auto; overflow-x: hidden; }
/* Scrolling panels cannot let the title ribbon hang outside, so it sits inside the top edge. */
.panel.help h2 { margin-top: -6px; }

.toast {
  position: fixed;
  left: 50%;
  top: max(24px, env(safe-area-inset-top));
  transform: translate(-50%, -20px);
  padding: 10px 18px;
  border: var(--edge);
  border-radius: 999px;
  background: var(--card);
  box-shadow: 0 4px 0 var(--line);
  color: var(--line);
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  .hud { gap: 8px; }
  #timer { font-size: 32px; }
  .delta { left: 50%; top: calc(100% + 40px); transform: translateX(-50%) rotate(-3deg); }
  #minimap { width: 40vw; height: 24px; }
  .courses { grid-template-columns: repeat(2, 1fr); gap: 14px 10px; }
  .course { padding: 8px 10px 10px; gap: 5px; }
  .course b { font-size: 15px; }
  .num { width: 20px; height: 20px; font-size: 11px; }
  .course-title { gap: 6px; }
  .spark { height: 36px; }
  .course-foot { font-size: 12px; }
  .round.corner { top: 10px; right: 10px; }
  .time { font-size: 52px; }
  .wallet { column-gap: 8px; padding: 6px 11px 8px 7px; border-radius: 15px; }
  .wallet-coin { width: 38px; height: 38px; font-size: 17px; }
  .wallet-count { min-height: 22px; }
  .wallet-count b { font-size: 22px; }
  .wallet-tank { width: 84px; height: 14px; }
  /* Sit above the boost key. */
  .prompt { padding: 0 18px 14px; bottom: max(134px, calc(env(safe-area-inset-bottom) + 128px)); }
  .hint { bottom: max(134px, calc(env(safe-area-inset-bottom) + 128px)); max-width: calc(100vw - 32px); }
}

@media (max-height: 480px) and (orientation: landscape) {
  .menu-inner { justify-content: flex-start; gap: 14px; padding-top: 14px; }
  .logo { font-size: 44px; }
  .tagline { font-size: 15px; margin-top: 8px; padding: 4px 14px; }
  .tally { margin-top: 8px; }
  .courses { grid-template-columns: repeat(4, 1fr); }
  .spark { height: 32px; }
  .panel { padding: 16px; gap: 6px; }
  .medal { width: 56px; height: 56px; font-size: 24px; }
  .medal::before { inset: -22px; }
  .time { font-size: 40px; }
  .recap { margin: 2px 0 4px; }
  .primary, .secondary { min-height: 44px; }
  #timer { font-size: 30px; }
  .panel.result {
    width: min(680px, 100%);
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "medal recap" "verdict retry" "time row" "compare ." "target .";
    column-gap: 24px;
    align-content: center;
  }
  #resultMedal { grid-area: medal; }
  #resultVerdict { grid-area: verdict; }
  #resultTime { grid-area: time; }
  #resultCompare { grid-area: compare; justify-self: center; }
  #resultTarget { grid-area: target; }
  #resultRecap { grid-area: recap; align-self: center; }
  #retryButton { grid-area: retry; }
  .panel.result > .row { grid-area: row; }
  /* The recap chips take the top of the right column; copy moves to its empty bottom corner. */
  .panel.result .round.corner { top: auto; bottom: 14px; }
  .wallet { bottom: max(14px, calc(env(safe-area-inset-bottom) + 8px)); column-gap: 8px; padding: 6px 11px 8px 7px; border-radius: 15px; }
  .wallet-coin { width: 38px; height: 38px; font-size: 17px; }
  .wallet-count { min-height: 22px; }
  .wallet-count b { font-size: 22px; }
  .wallet-tank { width: 96px; height: 14px; }
  .keys { bottom: max(10px, calc(env(safe-area-inset-bottom) + 4px)); }
  .prompt, .hint { bottom: 108px; }
}

/* Narrow keyboard windows: the keys move right of the wallet. */
@media (max-width: 640px) and (hover: hover) {
  .keys { left: auto; right: max(16px, calc(env(safe-area-inset-right) + 10px)); transform: none; gap: 12px; }
  .key-space kbd { width: 132px; }
}

/* Landscape touch play: two thumb buttons and a compact fuel strip above the chart. */
@media (hover: none) {
  .wallet {
    top: max(14px, env(safe-area-inset-top));
    bottom: auto;
    left: max(70px, calc(env(safe-area-inset-left) + 66px));
    display: flex;
    gap: 6px;
    min-height: 44px;
    padding: 4px 8px;
    border-width: 2.5px;
    border-radius: 14px;
  }
  .wallet-coin { grid-row: auto; width: 28px; height: 28px; border-width: 2px; font-size: 14px; }
  .wallet-count { min-height: 0; }
  .wallet-count b { min-width: 1ch; font-size: 20px; }
  .wallet-burn { display: none; }
  .wallet-tank { width: 88px; height: 12px; border-width: 2px; }
  .wallet-note { top: calc(100% + 7px); bottom: auto; font-size: 12px; }
  .keys {
    left: 0;
    right: 0;
    bottom: max(10px, calc(env(safe-area-inset-bottom) + 5px));
    width: 100%;
    padding: 0 max(20px, calc(env(safe-area-inset-right) + 14px)) 0 max(20px, calc(env(safe-area-inset-left) + 14px));
    justify-content: space-between;
    transform: none;
    pointer-events: none;
  }
  .key { min-width: 76px; gap: 4px; pointer-events: auto; }
  .key kbd { display: none; }
  .touch-face {
    display: grid;
    place-items: center;
    width: 76px;
    height: 76px;
    border: 3px solid #fffaf0;
    border-radius: 50%;
    background: rgba(27, 31, 70, 0.9);
    box-shadow: 0 5px 0 var(--line);
    transition: transform 0.05s ease, box-shadow 0.05s ease, background 0.12s ease;
  }
  .touch-face svg { width: 42px; height: 42px; fill: none; stroke: #fff; stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
  .key-x .touch-face svg { stroke: none; }
  .key-x .flame { fill: #ff8a1c; }
  .key-x .flame-core { fill: #ffd23f; }
  .key.down .touch-face { transform: translateY(4px); box-shadow: 0 1px 0 var(--line); background: #343960; }
  .key.on .touch-face { border-color: #ffd23f; box-shadow: 0 0 12px 2px rgba(255, 138, 28, 0.7); }
  .key em { font-size: 14px; }
  .hint { pointer-events: none; }
}
@media (hover: none) and (max-width: 720px) and (orientation: landscape) {
  .wallet { top: max(86px, calc(env(safe-area-inset-top) + 70px)); }
}
@media (hover: none) and (max-height: 480px) and (orientation: landscape) {
  .prompt { bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .logo .flip, .prompt-go, .hint, .medal, .medal::before, .wallet.full .wallet-coin, .wallet.dry, .panel { animation: none; }
  .course, .wallet-note, .icon, .round, .primary, .secondary, .key kbd { transition: none; }
  .touch-face { transition: none; }
}

/* Keep upright one- and two-digit course numbers optically centered. */
.num { font-style: normal; line-height: 1; text-align: center; }

/* Map workshop: the same chart cards, ink outlines and tactile buttons as the stages. */
.workshop { width: 100%; }
.workshop svg { flex: none; }
.map-tabs { display: flex; justify-content: center; gap: 12px; }
.map-tabs button { display: flex; align-items: center; justify-content: center; gap: 9px; min-height: 50px; padding: 10px 22px; border: var(--edge); border-radius: 18px; background: var(--paper); box-shadow: 0 4px 0 var(--line); font-size: 16px; font-weight: 900; transition: transform .1s, box-shadow .1s; }
.map-tabs button[aria-pressed="true"] { background: var(--gold); transform: rotate(-2deg); }
.map-tabs button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.map-tabs svg, .map-icon svg, .map-play svg, .empty-map svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.editing-map .menu-inner { max-width: 960px; gap: 20px; }
.editing-map .logo { font-size: clamp(56px, 8vw, 90px); }
.map-editor { width: min(800px, 100%); margin: 28px auto 0; }
.map-sheet { border: var(--edge); border-radius: 26px; background: var(--card); box-shadow: 0 7px 0 var(--line); overflow: hidden; }
.map-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 20px 8px; }
.map-name { min-width: 0; flex: 1; }
.map-name input { display: block; width: 100%; min-width: 0; padding: 5px 0; border: 0; border-bottom: 2px dashed #1b1f4626; border-radius: 0; background: transparent; font: 900 24px/1.3 var(--font); color: var(--line); text-overflow: ellipsis; user-select: text; }
.map-tools, .library-tools > div { display: flex; gap: 8px; }
.map-icon { display: inline-grid; place-items: center; flex: none; width: 46px; height: 46px; padding: 0; border: var(--edge); border-radius: 50%; background: var(--card); box-shadow: 0 3px 0 var(--line); color: var(--line); cursor: pointer; transition: background .12s, transform .1s, box-shadow .1s; }
.map-icon:active { transform: translateY(3px); box-shadow: none; }
.map-icon.saved { background: var(--mint); }
.map-icon.shuffle { background: var(--gold); transform: rotate(5deg); }
.map-icon.shuffle:active { transform: rotate(5deg) translateY(3px); }
.map-icon[aria-expanded="true"] { background: var(--gold); }
.map-chart { position: relative; margin: 12px 20px 0; border-radius: 12px; overflow: hidden; background-image: linear-gradient(#1b1f4608 1px, transparent 1px), linear-gradient(90deg, #1b1f4608 1px, transparent 1px); background-size: 36px 36px; }
#mapPreview { width: 100%; height: 235px; display: block; overflow: visible; transition: opacity .15s; }
.chart-line { fill: none; stroke: var(--up); stroke-width: 3; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.chart-fill { fill: #ff4d5e12; stroke: none; }
.chart-coins { fill: var(--gold); stroke: #a07816; stroke-width: .8; }
.chart-start { fill: var(--line); stroke: white; stroke-width: 3; }
.chart-flag { fill: var(--gold); stroke: var(--line); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.map-deck { display: flex; align-items: center; justify-content: space-between; gap: 22px; padding: 18px 20px 22px; border-top: 2px solid #1b1f460c; }
.medal-fields { display: flex; gap: 10px; min-width: 0; }
.medal-chip { display: flex; align-items: center; position: relative; gap: 5px; padding: 6px 8px 6px 5px; min-width: 0; border: 2px solid var(--line); border-radius: 14px; background: var(--paper); }
.medal-mark { display: grid; place-items: center; flex: none; width: 30px; height: 30px; border: 2px solid var(--line); border-radius: 50%; background: var(--disc); font-size: 14px; font-weight: 950; box-shadow: inset 0 0 0 2px #ffffff80; }
.medal-chip.gold { --disc: var(--gold); }
.medal-chip.silver { --disc: var(--silver); }
.medal-chip.bronze { --disc: var(--bronze); }
.medal-chip input { width: 5ch; min-width: 0; padding: 4px 0; border: 0; border-radius: 4px; background: transparent; color: var(--line); font: 900 17px/1.2 var(--font); font-variant-numeric: tabular-nums; text-align: right; appearance: textfield; user-select: text; }
.medal-chip input::-webkit-inner-spin-button, .medal-chip input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.time-unit { font-size: 12px; font-weight: 700; color: var(--muted); }
.map-play { display: flex; align-items: center; justify-content: center; gap: 12px; flex: none; min-width: 176px; min-height: 58px; padding: 10px 22px; font-size: 21px; transform: rotate(-2deg); }
.map-play svg { width: 24px; height: 24px; }
.map-controls { display: flex; align-items: center; gap: 12px; margin: 24px 0 0; }
.difficulty-control { display: flex; align-items: center; gap: 16px; min-height: 58px; min-width: 0; flex: 1; padding: 8px 14px 8px 20px; border: var(--edge); border-radius: 18px; background: var(--paper); box-shadow: 0 4px 0 var(--line); font-size: 15px; font-weight: 900; }
.difficulty-track { flex: 1; min-width: 0; }
#difficultyValue { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 10px; background: var(--line); color: white; font-size: 20px; font-weight: 900; }
.workshop input[type="range"] { --fill: 44%; display: block; width: 100%; height: 32px; margin: 0; padding: 0; appearance: none; background: transparent; cursor: pointer; }
.workshop input[type="range"]::-webkit-slider-runnable-track { height: 10px; border: 2px solid var(--line); border-radius: 10px; background: linear-gradient(to right, var(--gold) var(--fill), #dce1ef var(--fill)); }
.workshop input[type="range"]::-webkit-slider-thumb { appearance: none; width: 24px; height: 24px; margin-top: -9px; border: 3px solid var(--line); border-radius: 50%; background: var(--gold); box-shadow: 0 2px 0 var(--line); }
.workshop input[type="range"]::-moz-range-track { height: 7px; border: 2px solid var(--line); border-radius: 10px; background: #dce1ef; }
.workshop input[type="range"]::-moz-range-progress { background: var(--gold); height: 7px; }
.workshop input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border: 3px solid var(--line); border-radius: 50%; background: var(--gold); }
.map-advanced { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 24px; margin: 18px 0 0; padding: 20px; border: var(--edge); border-radius: 20px; background: var(--paper); box-shadow: 0 4px 0 var(--line); }
.range-label { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px; font-size: 13px; font-weight: 800; }
.range-label input { grid-column: 1 / -1; }
.range-label output { color: var(--muted); font-variant-numeric: tabular-nums; }
.placement-control { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; font-size: 13px; font-weight: 800; }
.placement-control select { padding: 8px 12px; border: 2px solid var(--line); border-radius: 12px; background: white; color: var(--line); font: 800 14px var(--font); }
.workshop input:focus-visible, .workshop select:focus-visible, .import-label:focus-within { outline: 3px solid var(--down); outline-offset: 3px; }
.map-status:not(.sr):not(:empty) { margin: 20px 0 0; padding: 10px 14px; border: 2px solid var(--line); border-radius: 12px; background: var(--paper); font-size: 13px; font-weight: 750; }
.map-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 12px; }
.loading #mapPreview { opacity: .2; }
.map-loading output { font-size: 23px; font-weight: 900; min-width: 3.5ch; font-variant-numeric: tabular-nums; }
.map-loading .map-icon { width: 36px; height: 36px; box-shadow: 0 2px 0 var(--line); }
.map-loading .map-icon svg { width: 16px; height: 16px; }
.map-spinner { width: 24px; height: 24px; border: 4px solid #1b1f4626; border-top-color: var(--line); border-radius: 50%; animation: map-spin .8s linear infinite; }
@keyframes map-spin { to { transform: rotate(360deg); } }
.workshop button:disabled, .workshop input:disabled, .workshop select:disabled { opacity: .42; cursor: default; }
.map-library { margin: 24px auto 0; width: min(800px, 100%); }
.library-tools { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-bottom: 20px; }
.import-label { position: relative; overflow: hidden; }
.import-label input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.saved-map { min-width: 0; border: var(--edge); border-radius: 22px; background: var(--card); box-shadow: var(--drop); overflow: hidden; }
.saved-map .course { border: 0; border-radius: 0; box-shadow: none; width: 100%; padding: 14px 14px 10px; min-height: 0; gap: 10px; }
.saved-map .course:active { box-shadow: none; }
.saved-map .course > svg { width: 100%; height: 70px; }
.saved-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 12px 12px; background: var(--paper); border-top: 2px solid #1b1f460c; }
.saved-actions .map-icon { width: 36px; height: 36px; border-width: 2px; box-shadow: 0 2px 0 var(--line); }
.saved-actions .map-icon svg { width: 17px; height: 17px; }
.saved-actions .map-icon:last-child { margin-left: auto; }
.empty-map { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; width: min(300px, 100%); min-height: 210px; margin: 20px auto; border: 3px dashed var(--line); border-radius: 24px; background: #fffaf0e8; font-size: 18px; font-weight: 900; }
.empty-map svg { width: 42px; height: 42px; padding: 6px; border: var(--edge); border-radius: 50%; background: var(--gold); }
@media (max-width: 640px) {
  .map-tabs { gap: 8px; }
  .map-tabs button { min-height: 46px; padding: 9px 12px; gap: 6px; border-radius: 15px; font-size: 13px; }
  .map-tabs svg { width: 17px; height: 17px; }
  .editing-map .logo { font-size: 56px; }
  .editing-map .menu-inner { gap: 18px; }
  .map-editor { margin-top: 22px; }
  .map-sheet { border-radius: 22px; }
  .map-sheet-head { padding: 12px 12px 6px; gap: 10px; }
  .map-name input { font-size: 20px; }
  .map-tools { gap: 6px; }
  .map-tools .map-icon { width: 38px; height: 38px; border-width: 2.5px; }
  .map-tools svg { width: 19px; height: 19px; }
  .map-chart { margin: 8px 10px 0; background-size: 28px 28px; }
  #mapPreview { height: 165px; }
  .map-deck { flex-direction: column; gap: 14px; padding: 12px 12px 18px; }
  .medal-fields { width: 100%; gap: 7px; }
  .medal-chip { flex: 1; padding: 4px; gap: 3px; border-radius: 12px; }
  .medal-mark { width: 24px; height: 24px; font-size: 11px; }
  .medal-chip input { width: 100%; font-size: 15px; }
  .time-unit { font-size: 10px; }
  .map-play { width: 100%; min-height: 50px; font-size: 19px; transform: none; }
  .map-controls { gap: 10px; margin-top: 20px; }
  .difficulty-control { gap: 9px; padding: 7px 8px 7px 12px; min-height: 50px; font-size: 12px; }
  #difficultyValue { width: 28px; height: 28px; font-size: 17px; }
  .map-controls > .map-icon { width: 42px; height: 42px; }
  .map-advanced { gap: 12px; padding: 16px; }
  #savedMaps { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 10px; }
  .saved-map .course { padding: 10px 8px; gap: 8px; }
  .saved-map .course > svg { height: 50px; }
  .saved-map .course-title { gap: 5px; padding: 0; }
  .saved-map .course b { font-size: 14px; }
  .saved-map .num { width: 20px; height: 20px; font-size: 11px; }
  .saved-map .course-foot { font-size: 11px; gap: 4px; }
  .saved-map .dot { width: 11px; height: 11px; }
  .saved-actions { padding: 8px 5px 10px; gap: 5px; }
  .saved-actions .map-icon { width: 36px; height: 36px; }
}
@media (max-width: 360px) {
  .map-tabs button { padding: 9px 10px; }
  .map-tabs svg { display: none; }
  #savedMaps { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .map-spinner { animation: none; }
  #mapPreview, .map-tabs button, .map-icon { transition: none; }
}
