/* Clogged — mobile-first, no framework, no webfonts (works offline).
   The canvas fills the viewport; everything else floats on top of it. */

:root {
  --bg: #0b0e1a;
  --panel: #161d33;
  --line: #2a3556;
  --text: #e9edfb;
  --muted: #8b95b4;
  --accent: #2dd4bf;
  --bad: #fb7185;
  /* Chart surface and series colour, validated together for dark mode:
     node scripts/validate_palette.js "#12a594" --mode dark --surface "#121a2e" */
  --chart-surface: #121a2e;
  --chart-series: #12a594;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
}

/* The playfield is the whole screen. touch-action must be none or the browser
   pans the page instead of handing us the drag. */
#board {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ----------------------------------------------------------------- HUD */

#hud {
  position: fixed;
  z-index: 2;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-top) + 4px) 11px 5px;
  background: linear-gradient(180deg, rgba(9, 12, 24, 0.94) 60%, rgba(9, 12, 24, 0));
  pointer-events: none; /* the pause button re-enables it for itself */
}

.hud-block { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.hud-next { flex: 1 1 auto; align-items: center; }
.hud-end { align-items: flex-end; }

.hud-score {
  font-size: 19px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.hud-sub {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.hud-sub b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

#next { display: block; width: 48px; height: 24px; }

.icon-btn {
  pointer-events: auto;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  font-size: 11px;
  letter-spacing: 1px;
  line-height: 1;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
}

.icon-btn:active { background: rgba(255, 255, 255, 0.16); }
.icon-btn svg { display: block; width: 17px; height: 17px; margin: 0 auto; fill: currentColor; }

/* ------------------------------------------------------------ overlays */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 16px) 18px calc(var(--safe-bottom) + 16px);
  background: rgba(7, 10, 20, 0.8);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  animation: fade 0.18s ease-out;
}

/* Win and loss panels sit over a full-screen canvas effect, so they stay
   mostly transparent and skip the blur that would smear it. */
.fx-panel {
  background: rgba(7, 10, 20, 0.22);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.overlay.hidden { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: 100%;
  max-width: 330px;
  padding: 24px 22px;
  text-align: center;
  background: linear-gradient(180deg, #1a2340, var(--panel));
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.title {
  margin: 0 0 6px;
  font-size: clamp(34px, 11vw, 46px);
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--accent);
  text-shadow: 0 0 26px rgba(45, 212, 191, 0.35);
}

.subtitle { margin: 0 0 14px; font-size: 24px; font-weight: 700; }
.subtitle.good { color: var(--accent); }
.subtitle.bad { color: var(--bad); }

.tagline { margin: 0 0 16px; font-size: 14px; line-height: 1.55; color: var(--muted); }
.result-line { margin: 0 0 4px; font-size: 17px; font-weight: 600; }
.best-line { margin: 0 0 16px; font-size: 13px; color: var(--muted); }
.next-line {
  margin: 14px 0 6px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.story { margin: 0 0 18px; font-size: 14px; line-height: 1.55; font-style: italic; }

.howto {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  font-size: 12.5px;
  line-height: 1.9;
  color: var(--muted);
}

.howto b { color: var(--text); font-weight: 700; }

.level-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 18px;
}

.mini-btn {
  width: 46px;
  height: 46px;
  font-size: 24px;
  line-height: 1;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}

.mini-btn:active { background: rgba(255, 255, 255, 0.16); }

.pause-line { margin: -6px 0 16px; font-size: 13px; color: var(--muted); }

.level-readout { display: flex; flex-direction: column; gap: 2px; min-width: 104px; }
#lv-num { font-size: 17px; font-weight: 700; }
#lv-clogs { font-size: 11px; color: var(--muted); }

.big-btn {
  display: block;
  width: 100%;
  padding: 16px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #04241f;
  background: linear-gradient(180deg, #4fe3cd, var(--accent));
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(45, 212, 191, 0.28);
  cursor: pointer;
}

.big-btn:active { transform: translateY(1px); filter: brightness(0.94); }

.ghost-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 13px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.ghost-btn:active { color: var(--text); background: rgba(255, 255, 255, 0.06); }

@media (prefers-reduced-motion: reduce) {
  .overlay { animation: none; }
  .big-btn:active { transform: none; }
}

/* While the flush or the sludge owns the screen, the HUD gets out of the way. */
#hud { transition: opacity 0.35s ease; }
body.fx-active #hud { opacity: 0; pointer-events: none; }

/* ---------------------------------------------------------- score screen */

/* The scores panel is taller than the rest; let it scroll rather than clip. */
#ov-scores { align-items: flex-start; overflow-y: auto; }

.panel-wide { max-width: 360px; margin: auto; }

.score-section { margin-bottom: 18px; text-align: left; }

.score-heading {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Chart surface — the colour the marks were validated against. */
.chart-wrap {
  position: relative;
  padding: 8px 6px 4px;
  background: var(--chart-surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.chart-plot { position: relative; }
.chart-plot:empty { display: none; }
.chart-wrap svg { display: block; width: 100%; height: auto; touch-action: none; }

.chart-empty, .score-empty {
  margin: 0;
  padding: 18px 4px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}

.chart-empty.hidden, .score-empty.hidden { display: none; }

/* Tooltip: follows the touched point, never covers it. */
.chart-tip {
  position: absolute;
  z-index: 2;
  transform: translate(-50%, -120%);
  padding: 5px 9px;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
  background: #0c1222;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.chart-tip.on { opacity: 1; }
.chart-tip .tip-date { display: block; font-weight: 500; color: var(--muted); }

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.score-table th {
  padding: 0 0 6px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: right;
  border-bottom: 1px solid var(--line);
}

.score-table th:first-child, .score-table td:first-child { text-align: left; width: 22px; }
.score-table th:last-child, .score-table td:last-child { text-align: right; }

.score-table td {
  padding: 6px 0;
  font-variant-numeric: tabular-nums;
  text-align: right;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.score-table tbody tr:last-child td { border-bottom: 0; }
.score-table .rank { color: var(--muted); font-weight: 700; }
.score-table .score { font-weight: 800; }
.score-table .when { color: var(--muted); font-size: 12px; }

/* The current run, highlighted in the table it just entered. */
.score-table tr.is-latest .score { color: var(--accent); }

/* Screen-reader table view of the timeline; the chart itself is aria-hidden. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Chart text wears text tokens — never the series colour. */
.chart-wrap .ax { fill: var(--muted); font-size: 9px; font-variant-numeric: tabular-nums; }
.chart-wrap .pt {
  fill: var(--text);
  font-size: 10px;
  font-weight: 700;
  /* A surface-coloured outline behind the glyphs, so a value label stays
     readable wherever the line happens to run under it. */
  paint-order: stroke;
  stroke: var(--chart-surface);
  stroke-width: 3px;
  stroke-linejoin: round;
}

/* The resume button carries its own subtitle, so it can say what it resumes. */
.btn-sub {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  opacity: 0.72;
}

#btn-resume-saved { margin-bottom: 10px; }
#btn-resume-saved.hidden { display: none; }

/* The prize for flushing the last level: a plunger on a plinth, in a metal set
   by the final score. game.js carries the same colours for the canvas one. */
[data-trophy="bronze"] { --t-light: #f6d2a8; --t-main: #c4803f; --t-dark: #6f4118; }
[data-trophy="silver"] { --t-light: #ffffff; --t-main: #c3cad6; --t-dark: #5f6778; }
[data-trophy="gold"] { --t-light: #fff3b0; --t-main: #f5c518; --t-dark: #8f6503; }
[data-trophy="platinum"] { --t-light: #f4fdff; --t-main: #aee3f0; --t-dark: #4d8397; }

.trophy {
  display: block;
  width: 140px;
  height: 205px;
  margin: 0 auto 10px;
  filter: drop-shadow(0 0 18px color-mix(in srgb, var(--t-main) 45%, transparent));
}
.trophy .t-light { stop-color: var(--t-light); }
.trophy .t-main { stop-color: var(--t-main); }
.trophy .t-dark { stop-color: var(--t-dark); }
.trophy .t-rim { fill: var(--t-dark); }
.trophy .plinth { fill: #3a2718; stroke: #1d130b; stroke-width: 1.5; }
.trophy .sparkle { fill: var(--t-light); animation: twinkle 1.6s ease-in-out infinite alternate; }

@keyframes twinkle { from { opacity: 0.25; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .trophy .sparkle { animation: none; } }

#ov-win #win-metal { color: var(--t-main); }

/* A won run in the top table carries a small plunger in its metal. */
.score-table .badge { width: 9px; height: 12px; vertical-align: -1px; fill: var(--t-main); }
