/* Bricolage Grotesque (SIL Open Font License, see /fonts/OFL.txt), served from our own
   domain so no visitor data goes to Google. Variable: weight 300-800, width 75-100%. */
@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 300 800;
  font-stretch: 75% 100%;
  font-display: swap;
  src: url("/fonts/bricolage-grotesque-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 300 800;
  font-stretch: 75% 100%;
  font-display: swap;
  src: url("/fonts/bricolage-grotesque-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --carmine: #9e3039;
  --carmine-deep: #7a2129;
  --on-carmine: #fff7f6;
  --band: #ffffff;
  --ink: #2a1a1e;
  --muted: #74626a;
  --line: #eadfe0;
  --soft: #f7f0f0;
  --ok: #2e7a4e;
  --accent-text: #9e3039;
  --pattern-a: var(--carmine);
  --font: "Bricolage Grotesque", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --carmine: #7e2730;
    --carmine-deep: #5c1a21;
    --band: #1b1315;
    --ink: #f4eced;
    --muted: #b8a6aa;
    --line: #3a2a2e;
    --soft: #261b1e;
    --ok: #63c08b;
    --accent-text: #ec8a92;
    --pattern-a: #d0525d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--carmine);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--pattern-a); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- carmine header ---------- */
.top {
  color: var(--on-carmine);
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 20px 0;
}
.top-inner, .modes, .band-inner, .bottom p { max-width: 520px; margin: 0 auto; }
.top-inner { display: flex; align-items: center; justify-content: space-between; }
.logo {
  margin: 0;
  font-size: clamp(40px, 11vw, 56px);
  font-weight: 800;
  font-stretch: 75%;
  font-variation-settings: "wdth" 75, "opsz" 96;
  letter-spacing: -0.01em;
  line-height: 1;
}
.tools { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--on-carmine) 55%, transparent);
  background: transparent;
  color: var(--on-carmine);
  font-weight: 700;
  display: grid; place-items: center;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.icon-btn:hover { background: color-mix(in srgb, var(--on-carmine) 14%, transparent); }

.modes { display: flex; gap: 4px; margin-top: 22px; }
.modes button {
  border: 0;
  background: transparent;
  color: color-mix(in srgb, var(--on-carmine) 75%, transparent);
  padding: 10px 16px 12px;
  border-radius: 12px 12px 0 0;
  font-weight: 600;
}
.modes button[aria-selected="true"] { background: var(--band); color: var(--ink); }

/* ---------- white band ---------- */
.band { background: var(--band); flex: 1 0 auto; padding: 22px 20px 34px; }
.meta { margin: 0; color: var(--muted); font-size: 15px; }
.meta:empty { display: none; }
.special {
  margin: 10px 0 0;
  padding: 8px 12px;
  border-left: 4px solid var(--carmine);
  background: var(--soft);
  font-weight: 600;
}

.eras { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.eras button {
  border: 1.5px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 15px;
}
.eras button[aria-checked="true"] { border-color: var(--carmine); background: var(--carmine); color: var(--on-carmine); }
.eras button:disabled { opacity: 0.4; cursor: default; }

/* ---------- player ---------- */
.player {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 16px;
  align-items: center;
  margin: 22px 0 18px;
}
.play {
  grid-row: span 2;
  width: 76px; height: 76px;
  border-radius: 50%;
  border: 0;
  background: var(--carmine);
  color: var(--on-carmine);
  display: grid; place-items: center;
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--carmine) 18%, transparent);
  transition: transform 0.12s ease;
}
.play:active { transform: scale(0.95); }
.play:disabled { opacity: 0.45; cursor: default; }
.play svg { width: 34px; height: 34px; fill: currentColor; }
.play .i-stop, .play.playing .i-play { display: none; }
.play.playing .i-stop { display: block; }

/* the timeline: one bar for the whole clip, split where each clip length ends */
.stages { --open: 0; --played: 0; position: relative; }
.stages .bar {
  position: relative;
  height: 22px;
  border-radius: 6px;
  background: var(--soft);
  border: 1.5px solid var(--line);
  overflow: hidden;
}
.stages .open, .stages .fill { position: absolute; inset: 0 auto 0 0; }
.stages .open {
  width: calc(var(--open) * 100%);
  background: var(--pattern-a);
  transition: width 0.25s ease;
}
.stages .fill {
  width: calc(var(--played) * 100%);
  background: color-mix(in srgb, var(--ink) 55%, transparent);
  mix-blend-mode: multiply;
}
@media (prefers-color-scheme: dark) { .stages .fill { background: rgba(255,255,255,.55); mix-blend-mode: normal; } }
.stages .split { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--band); opacity: 0.9; }
.stages .labs { position: relative; height: 18px; margin-top: 4px; }
/* each label sits just left of its split, so the closely spaced early ones don't collide */
.stages .lab {
  position: absolute; top: 0; transform: translateX(-100%); padding-right: 3px;
  font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.stages .lab:last-child { padding-right: 0; }
.stages .lab.passed { color: var(--ink); }
.stages .lab.current { font-weight: 700; color: var(--accent-text); }
.under-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; margin-top: 6px; }
.under-bar .clip-len { margin: 0; }
.volume { display: flex; align-items: center; gap: 6px; flex: none; color: var(--muted); cursor: pointer; }
.volume svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.volume svg path:first-child { fill: currentColor; }
.volume.muted .wave { opacity: 0.25; }
#volume {
  --v: 0.8;
  appearance: none; -webkit-appearance: none;
  width: 92px; height: 4px; margin: 0; border-radius: 2px; cursor: pointer;
  background: linear-gradient(to right, var(--carmine) calc(var(--v) * 100%), var(--line) 0);
}
#volume::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--carmine); border: 2px solid var(--band); }
#volume::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--carmine); border: 2px solid var(--band); }
.clip-len { font-size: 14px; color: var(--muted); }

/* ---------- controls ---------- */
.controls { margin-top: 4px; }
.combo { position: relative; }
#q {
  width: 100%;
  padding: 13px 14px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--band);
}
#q:focus { border-color: var(--carmine); outline: none; }
#suggest {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px);
  margin: 0; padding: 4px;
  list-style: none;
  background: var(--band);
  border: 2px solid var(--carmine);
  border-radius: 10px;
  max-height: 280px; overflow-y: auto;
  z-index: 5;
}
#suggest li { padding: 9px 10px; border-radius: 6px; cursor: pointer; }
#suggest li small { color: var(--muted); display: block; font-size: 14px; }
#suggest li[aria-selected="true"], #suggest li:hover { background: var(--soft); }

.row { display: flex; gap: 10px; margin-top: 10px; }
.row .btn { flex: 1; }
.btn {
  padding: 12px 16px;
  border-radius: 10px;
  font-weight: 700;
  border: 2px solid var(--carmine);
}
.btn.solid { background: var(--carmine); color: var(--on-carmine); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn:disabled { opacity: 0.4; cursor: default; }

/* ---------- result ---------- */
.result { margin-top: 18px; }
.answer { display: flex; gap: 16px; align-items: center; padding: 14px; border-radius: 12px; background: var(--soft); }
.answer img { border-radius: 8px; flex: none; }
.verdict { margin: 0; font-weight: 700; color: var(--accent-text); }
.result.won .verdict { color: var(--ok); }
.song-title { margin: 2px 0 0; font-size: 24px; font-weight: 800; line-height: 1.15; font-stretch: 85%; font-variation-settings: "wdth" 85; }
.song-artist { margin: 2px 0 6px; color: var(--muted); }
.listen { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 14px; }
.listen span { color: var(--muted); }
.listen a {
  color: var(--ink); text-decoration: none;
  padding: 2px 9px; border-radius: 999px; border: 1.5px solid var(--line);
}
.listen a:hover { border-color: var(--carmine); }
.countdown { margin: 12px 0 0; color: var(--muted); font-size: 15px; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- feedback ---------- */
.feedback { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; font-size: 14px; }
.feedback > span { color: var(--muted); }
.feedback button[data-kind] {
  border: 1.5px solid var(--line); background: transparent;
  border-radius: 999px; padding: 3px 10px; font-size: 14px;
}
.feedback button[data-kind]:hover:not(:disabled) { border-color: var(--carmine); }
.feedback button[aria-pressed="true"] { border-color: var(--carmine); background: var(--carmine); color: var(--on-carmine); opacity: 1; cursor: default; }
.year-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; width: 100%; margin-top: 4px; }
.year-form label { color: var(--muted); }
.year-form input { width: 7.5em; padding: 6px 10px; border-radius: 8px; border: 2px solid var(--line); background: var(--band); }
.year-form .btn { padding: 6px 14px; }

.privacy p { font-size: 15px; margin: 0 0 10px; }
.privacy a { color: var(--accent-text); }

.link-btn { border: 0; padding: 0; background: none; color: var(--on-carmine); text-decoration: underline; font: inherit; }

.suggest-form { margin-top: 12px; display: grid; gap: 10px; }
.suggest-form label { display: grid; gap: 4px; font-weight: 600; font-size: 15px; }
.suggest-form small { font-weight: 400; color: var(--muted); }
.suggest-form input, .suggest-form textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 2px solid var(--line); background: var(--band); font-weight: 400;
}
.suggest-form input:focus, .suggest-form textarea:focus { border-color: var(--carmine); outline: none; }
.suggest-form .row { margin-top: 0; }
.form-msg { margin: 0; min-height: 1.2em; font-size: 15px; color: var(--accent-text); }

.share-to { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; margin-top: 12px; font-size: 14px; }
.share-to span { color: var(--muted); }
.share-to a {
  color: var(--ink); text-decoration: none; font-weight: 600;
  padding: 4px 12px; border-radius: 999px; border: 1.5px solid var(--line);
}
.share-to a:hover { border-color: var(--carmine); }

/* ---------- footer ---------- */
.bottom { color: color-mix(in srgb, var(--on-carmine) 82%, transparent); padding: 22px 20px calc(env(safe-area-inset-bottom, 0px) + 26px); font-size: 14px; text-align: center; }
.bottom p { margin-top: 0; margin-bottom: 0; }
.bottom a { color: var(--on-carmine); }

/* ---------- dialogs ---------- */
dialog {
  width: min(440px, calc(100vw - 32px));
  border: 0; border-radius: 16px;
  padding: 22px;
  background: var(--band); color: var(--ink);
  border-top: 10px solid var(--carmine);
}
dialog::backdrop { background: rgba(30, 8, 12, 0.55); }
dialog h2 { margin: 0 0 10px; font-size: 26px; font-stretch: 80%; font-variation-settings: "wdth" 80; }
dialog h3 { margin: 18px 0 8px; font-size: 16px; }
dialog form[method="dialog"] { margin-top: 18px; }
dialog form .btn { width: 100%; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stat-grid b { display: block; font-size: 28px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-grid span { font-size: 13px; color: var(--muted); }
.dist { display: grid; gap: 4px; }
.dist div { display: grid; grid-template-columns: 18px 1fr; gap: 8px; align-items: center; font-size: 14px; }
.dist i {
  display: block; min-width: 26px; padding: 2px 8px;
  background: var(--line); border-radius: 4px; font-style: normal; text-align: right; font-weight: 700;
}
.dist i.hi { background: var(--carmine); color: var(--on-carmine); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 18px); /* below the status bar in app mode */
  transform: translate(-50%, calc(-100% - env(safe-area-inset-top, 0px) - 24px)); /* fully above the screen edge */
  background: var(--ink); color: var(--band);
  padding: 10px 16px; border-radius: 10px;
  font-weight: 600;
  transition: transform 0.25s ease;
  z-index: 20;
}
.toast.show { transform: translate(-50%, 0); }

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

/* ---------- rounds: one per level ---------- */
.rounds { list-style: none; margin: 14px 0 0; padding: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.rounds li {
  display: grid; justify-items: center; gap: 2px;
  padding: 7px 2px 6px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  color: var(--muted);
  min-width: 0;
}
.rounds b { font-size: 17px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.rounds span { font-size: 12px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rounds li.current { border-color: var(--carmine); background: var(--carmine); color: var(--on-carmine); }
.rounds li.won { border-color: var(--ok); color: var(--ok); }
.rounds li.lost { border-style: dashed; color: var(--accent-text); }

#q.shake { animation: shake 0.35s ease; border-color: var(--accent-text); }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ---------- summary ---------- */
.summary { margin-top: 22px; text-align: center; }
.score-label { margin: 0; color: var(--muted); }
.score { margin: 0; font-size: 56px; font-weight: 800; line-height: 1.05; font-stretch: 80%; font-variation-settings: "wdth" 80; font-variant-numeric: tabular-nums; }
.recap { list-style: none; margin: 18px 0 0; padding: 0; display: grid; gap: 6px; text-align: left; }
.recap li {
  display: grid; grid-template-columns: 1fr auto; column-gap: 10px; align-items: center;
  padding: 8px 12px; border-radius: 8px; border: 1.5px solid var(--line);
}
.recap small { grid-column: 1; color: var(--muted); font-size: 13px; }
.recap span { grid-column: 1; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.recap b { grid-column: 2; grid-row: 1 / span 2; font-variant-numeric: tabular-nums; }
.recap li.won b { color: var(--ok); }
.recap li.lost b { color: var(--accent-text); }
.dist div { grid-template-columns: 96px 1fr; }
