:root {
  --paper: #f1ebdf;
  --paper-2: #e8e0d0;
  --ink: #1c1a16;
  --muted: #8d8575;
  --faint: #b9b09e;
  --rule: #cfc5b2;
  --sky: #0090b0;
  --sun: #ffc531;
  --red: #d2452c;
  --display: 'Geologica', 'Inter', sans-serif;
  --mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 'Inter', sans-serif;
  /* paper grain */
  background-image: radial-gradient(rgba(28, 26, 22, .05) 1px, transparent 1px);
  background-size: 3px 3px;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
mark { background: linear-gradient(transparent 55%, var(--sun) 55%, var(--sun) 92%, transparent 92%); color: inherit; padding: 0 .08em; }
kbd { font: 500 12px var(--mono); border: 1px solid var(--rule); border-bottom-width: 2px; border-radius: 3px; padding: 1px 5px; background: var(--paper); }

header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: 1180px; margin: 0 auto; padding: 20px 24px;
  border-bottom: 2px solid var(--ink);
}
#logo { font: 800 26px 'Unbounded', var(--display); color: var(--ink); text-decoration: none; letter-spacing: -.02em; white-space: nowrap; }
#logo span { color: var(--sky); }
#logo img { width: 1.4em; height: 1.4em; margin-right: .4em; vertical-align: -.36em; }
/* narrow phones: the keycap alone, the name does not fit next to the buttons */
@media (max-width: 400px) { header #logo { font-size: 0; } header #logo img { width: 36px; height: 36px; margin: 0; vertical-align: middle; } }
/* header: logo, rating, settings menu, account */
.top { display: flex; align-items: center; gap: 8px; }
.top-btn { background: none; border: 1.5px solid var(--ink); border-radius: 999px; padding: 6px 14px; font: 600 14px 'Inter', sans-serif; cursor: pointer; white-space: nowrap; }
.top-btn[aria-expanded="true"] { background: var(--ink); color: var(--paper); }
@media (hover: hover) { .top-btn:hover { background: var(--paper-2); } }
.menu { position: relative; }
.panel {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 20; width: min(320px, calc(100vw - 32px));
  background: var(--paper); border: 2px solid var(--ink); box-shadow: 6px 6px 0 var(--sky); padding: 6px 14px 10px;
}
.opt { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--rule); cursor: pointer; }
.opt b { display: block; font-size: 15px; }
.opt small { display: block; font-size: 12px; color: var(--muted); line-height: 1.35; margin-top: 2px; }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt i { width: 38px; height: 22px; border-radius: 999px; border: 1.5px solid var(--ink); position: relative; transition: background .15s; }
.opt i::after { content: ''; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: var(--ink); transition: transform .15s, background .15s; }
.opt input:checked + i { background: var(--ink); }
.opt input:checked + i::after { transform: translateX(16px); background: var(--sun); }
.opt input:focus-visible + i { outline: 2px solid var(--sky); outline-offset: 2px; }
.panel #sign-out { margin: 12px 0 2px; font-size: 14px; }

main { max-width: 1180px; margin: 0 auto; padding: 0 24px 80px; }

/* ---------- home ---------- */

.hero { padding: 56px 0 40px; display: grid; grid-template-columns: 1.3fr 1fr; gap: 40px; align-items: end; }
h1 { font: 800 clamp(44px, 8vw, 104px)/.92 var(--display); letter-spacing: -.045em; margin: 0; }
h2 { font: 800 clamp(28px, 4vw, 44px)/1 var(--display); letter-spacing: -.03em; margin: 40px 0 16px; }
.sub { color: #4a463e; max-width: 420px; margin: 0; }
.sub mark { font-family: var(--mono); font-size: 14px; letter-spacing: .1em; }

#filter {
  flex: 0 1 280px; min-width: 0; background: transparent; border: 0; border-bottom: 1.5px solid var(--rule);
  padding: 4px 0; font: 500 14px var(--mono); text-transform: none; letter-spacing: 0; color: var(--ink); border-radius: 0;
}
.list-head span { white-space: nowrap; }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.tab { background: none; border: 1.5px solid var(--ink); border-radius: 999px; padding: 7px 16px; font: 600 14px 'Inter', sans-serif; cursor: pointer; }
.tab:hover { background: var(--paper-2); }
.tab.on { background: var(--ink); color: var(--paper); }
#filter:focus { outline: none; border-color: var(--ink); }
.list-head {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding: 0 0 8px;
  font: 500 12px var(--mono); text-transform: uppercase; letter-spacing: .12em; color: var(--muted);
  border-bottom: 2px solid var(--ink);
}
.track {
  display: grid; grid-template-columns: 44px 96px 1fr auto auto; align-items: center; gap: 18px;
  padding: 12px 8px 12px 0; border-bottom: 1px solid var(--rule); cursor: pointer;
  transition: background .12s, color .12s, padding .12s;
}
.track:hover, .track:focus-visible { background: var(--ink); color: var(--paper); padding-left: 12px; outline: none; }
.track .num { font: 500 14px var(--mono); color: var(--muted); }
.track img { width: 96px; aspect-ratio: 16/9; object-fit: cover; display: block; filter: grayscale(1) contrast(1.1); transition: filter .2s; }
.track:hover img { filter: none; }
.track .name { font: 500 clamp(18px, 2.2vw, 24px)/1.15 var(--display); letter-spacing: -.02em; }
.track small { display: block; font: 13px 'Inter', sans-serif; letter-spacing: 0; color: var(--muted); margin-top: 4px; }
.track .best { font: 500 14px var(--mono); }
.del { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.del:hover { color: var(--red); }

.link { background: none; border: 0; padding: 0; margin-top: 24px; cursor: pointer; font-weight: 500; text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1.5px; }
.link:hover { color: var(--sky); }

/* ---------- buttons & inputs ---------- */

button:not(.link):not(.del):not(.track):not(.result):not(.mini):not(.tab):not(.top-btn) {
  background: var(--ink); color: var(--paper); border: 2px solid var(--ink);
  padding: 11px 22px; font-weight: 600; cursor: pointer; border-radius: 0;
  box-shadow: 4px 4px 0 var(--sun); transition: transform .08s, box-shadow .08s;
}
button:not(.link):not(.del):not(.track):not(.result):not(.mini):not(.tab):not(.top-btn):active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--sun); }
button.ghost { background: transparent !important; color: var(--ink) !important; box-shadow: none !important; }
input:not([type]) {
  background: var(--paper); border: 2px solid var(--ink); padding: 10px 12px; border-radius: 0; min-width: 0; flex: 1;
}
input:not([type]):focus { outline: none; box-shadow: 4px 4px 0 var(--sky); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

/* ---------- game ---------- */

#game { display: grid; grid-template-columns: minmax(300px, 460px) minmax(0, 1fr); gap: 48px; padding-top: 32px; }
aside { display: flex; flex-direction: column; gap: 18px; }
.video { position: relative; aspect-ratio: 16/9; background: var(--ink); border: 2px solid var(--ink); box-shadow: 6px 6px 0 var(--sky); }
.video iframe, .video #player { position: absolute; inset: 0; width: 100%; height: 100%; }
.video { overflow: hidden; }
.video::after { content: ''; position: absolute; inset: 0; z-index: 2; cursor: pointer; } /* keeps focus away from the iframe */
/* clips often burn subtitles into the bottom of the frame */
.video::before { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 26%; z-index: 1; display: none; pointer-events: none; backdrop-filter: blur(16px); background: rgba(28, 26, 22, .25); }
.hide-words .video::before { display: block; }
/* the page could not start the video (iPhone): let the tap reach the YouTube player */
.tap-video #game .video::after, .tap-video #game .video::before { display: none; }
/* lyric videos burn the words in */
.hide-words.lyric-video .video iframe { filter: blur(18px) saturate(1.3); transform: scale(1.15); }
.now b { display: block; font: 800 22px/1.1 var(--display); letter-spacing: -.02em; }
.now span { color: var(--muted); font-size: 14px; }
.hud { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 2px solid var(--ink); border-bottom: 1px solid var(--rule); }
.hud div { padding: 10px 0; }
.hud div + div { border-left: 1px solid var(--rule); padding-left: 12px; }
.hud b, .stats b { display: block; font: 600 22px var(--mono); }
.hud small, .stats small { font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.offset { display: flex; align-items: center; gap: 8px; font: 500 12px var(--mono); color: var(--muted); }
.offset span { text-transform: uppercase; letter-spacing: .1em; margin-right: auto; }
.offset b { color: var(--ink); min-width: 48px; text-align: center; }
.mini { background: none; border: 1.5px solid var(--ink); padding: 2px 8px; font: 500 12px var(--mono); cursor: pointer; }
/* hover only where there is a mouse, otherwise iPhones keep the last tapped button dark */
@media (hover: hover) { .mini:hover { background: var(--ink); color: var(--paper); } }
.mini:active { background: var(--ink); color: var(--paper); }
#g-back svg { width: 1em; height: 1em; vertical-align: -.12em; margin-right: 4px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
aside .link { margin-top: 0; align-self: flex-start; }

.stage { display: flex; flex-direction: column; min-width: 0; }
.progress { height: 4px; background: var(--paper-2); }
#hud-progress { height: 100%; width: 0; background: var(--ink); transition: width .3s; }
#lyrics {
  position: relative; height: min(56vh, 520px); overflow-y: auto; scrollbar-width: none; margin: 16px 0 8px;
  -webkit-mask-image: linear-gradient(transparent, #000 14%, #000 86%, transparent); mask-image: linear-gradient(transparent, #000 14%, #000 86%, transparent);
}
#lyrics::-webkit-scrollbar { display: none; }
/* room above the first and below the last line so either can sit in the middle */
#lines { display: flex; flex-direction: column; gap: 18px; padding: 22vh 0; }
#intro { position: sticky; top: 30%; z-index: 1; height: 0; overflow: visible; font: 800 clamp(48px, 6vw, 80px)/1 var(--display); color: var(--faint); text-align: right; }
.line { font: 500 clamp(16px, 1.7vw, 20px)/1.35 var(--mono); white-space: pre-wrap; color: var(--faint); min-height: 1.35em; cursor: pointer; border-radius: 4px; transition: font-size .15s; }
.line.cur { font-size: clamp(24px, 3.3vw, 40px); cursor: text; }
.line.past { opacity: .7; }
.line:not(.cur):hover { background: var(--paper-2); }
.line span.kz { background: rgba(255, 197, 49, .45); border-radius: 2px; }
.line span.ok { color: var(--ink); }
.line span.ok.kz { background: var(--sun); }
.line span.miss { color: var(--red); text-decoration: line-through; text-decoration-thickness: 2px; }
.line span.hinted { color: var(--sky); }
/* hidden letters: blank slot with a short underline, Kazakh letters keep the yellow hint */
.line span.h { color: transparent; background: linear-gradient(var(--faint), var(--faint)) no-repeat center 90% / 70% 2px; }
.line span.h.kz { background: linear-gradient(var(--muted), var(--muted)) no-repeat center 90% / 70% 2px, rgba(255, 197, 49, .5); }
.line span.cursor { color: var(--muted); box-shadow: inset 0 -4px 0 var(--sky); animation: blink 1s steps(1) infinite; }
.line.err span.cursor { animation: err .35s; }
.line span.h.cursor { color: transparent; }
.line.past span, .line.future span { color: inherit; box-shadow: none; }
.line.past span.kz, .line.future span.kz { background: rgba(255, 197, 49, .3); }
.line.past span.ok { color: var(--muted); }
.line.past span.miss { color: var(--red); }
.line.past span.hinted { color: var(--sky); }
.line.future span.h { color: transparent; }
.line.future span.h.kz { background: linear-gradient(var(--faint), var(--faint)) no-repeat center 90% / 70% 2px, rgba(255, 197, 49, .3); }

@keyframes blink { 50% { box-shadow: inset 0 -4px 0 transparent; } }
@keyframes err { 0%, 60% { background: rgba(210, 69, 44, .35); } }

.hint-row { display: flex; align-items: center; gap: 20px; min-height: 48px; }
#modes { display: grid; gap: 8px; margin: 10px 0 4px; }
.mode-row { display: flex; flex-wrap: wrap; gap: 8px; }
#mode-note { font-size: 13px; }
.hint { color: var(--muted); font-size: 14px; margin: 0; }
/* at the top so iOS does not scroll to it; 16px stops the zoom on focus */
#typer { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; font-size: 16px; border: 0; padding: 0; }
.touch-keys { display: none; gap: 8px; }

/* ---------- result ---------- */

#result { padding-top: 64px; }
.kicker { font: 500 13px var(--mono); text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 0; }
.big { font: 800 clamp(96px, 20vw, 220px)/.85 var(--display); letter-spacing: -.06em; margin: 12px 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 2px solid var(--ink); margin: 40px 0 32px; max-width: 760px; }
.stats div { padding: 14px 0; }
.stats div + div { border-left: 1px solid var(--rule); padding-left: 16px; }
.stats b { font-size: 30px; }

#res-break { text-transform: none; letter-spacing: 0; margin-top: 10px; }
#board { max-width: 760px; margin-bottom: 32px; }
.board-list { list-style: none; margin: 10px 0 0; padding: 0; counter-reset: r; border-top: 2px solid var(--ink); }
.board-list li { counter-increment: r; display: grid; grid-template-columns: 28px 28px 1fr auto auto; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.board-list li::before { content: counter(r); font: 500 13px var(--mono); color: var(--muted); }
.board-list li img { width: 28px; height: 28px; border-radius: 50%; background: var(--paper-2); }
.board-list li span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list li small { font: 500 13px var(--mono); color: var(--muted); }
.board-list li b { font: 600 16px var(--mono); min-width: 64px; text-align: right; }
.board-list li.me { background: var(--sun); }
#board-login { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin: 0 0 32px; }
#board-login .hint { margin: 0; }
#auth { display: flex; align-items: center; gap: 8px; font: 600 14px 'Inter', sans-serif; white-space: nowrap; }
#auth img { width: 32px; height: 32px; border-radius: 50%; border: 1.5px solid var(--ink); }
#rating .board-list { max-width: 760px; margin-top: 20px; }
#rating-hint { margin: 16px 0; }

/* ---------- add ---------- */

#add .sub { max-width: 560px; margin: 24px 0 12px; }
#add form { max-width: 560px; }
#add-results { max-width: 560px; margin-top: 12px; }
.result {
  display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--rule); padding: 10px 4px; cursor: pointer;
  font: 500 15px var(--mono);
}
.result small { display: block; font: 13px 'Inter', sans-serif; color: var(--muted); }
.result:hover { background: var(--paper-2); }
.result.picked { background: var(--sun); }

/* ---------- timing by hand ---------- */

#add textarea { width: 100%; max-width: 560px; font: 15px/1.5 var(--mono); background: var(--paper); border: 2px solid var(--ink); padding: 10px 12px; color: var(--ink); resize: vertical; }
#add textarea:focus { outline: none; box-shadow: 4px 4px 0 var(--sky); }
.sync-grid { display: grid; grid-template-columns: minmax(300px, 460px) minmax(0, 1fr); gap: 48px; padding-top: 16px; align-items: start; }
.sync-keys { display: flex; gap: 12px; margin-top: 18px; }
.sync-keys #sync-tap { flex: 1; padding: 16px 22px; font-size: 18px; }
#sync-hint { margin: 14px 0; }
#sync .video::before { display: none; }
#sync-lines { position: relative; list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow-y: auto; font: 500 17px/1.4 var(--mono); color: var(--faint); }
#sync-lines li { display: grid; grid-template-columns: 80px 1fr; gap: 12px; padding: 6px 8px; }
#sync-lines li small { font-size: 13px; color: var(--muted); }
#sync-lines li.done { color: var(--muted); }
#sync-lines li.cur { color: var(--ink); background: var(--sun); font-size: 20px; }
#sync .link { margin-top: 24px; }

/* ---------- mobile ---------- */

#g-report { display: block; margin-top: 6px; font: 500 12px var(--mono); color: var(--muted); text-decoration-thickness: 1px; }
#report { position: fixed; inset: 0; z-index: 50; background: rgb(28 26 22 / .35); display: grid; place-items: start center; padding: 12vh 16px 16px; }
.sheet { width: min(400px, 100%); background: var(--paper); border: 2px solid var(--ink); box-shadow: 6px 6px 0 var(--sun); padding: 18px 18px 14px; display: grid; gap: 12px; }
.sheet > b { font: 800 20px/1.15 var(--display); letter-spacing: -.01em; }
.sheet .sub { margin: -8px 0 0; font-size: 13px; color: var(--muted); }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices input { position: absolute; opacity: 0; pointer-events: none; }
.choices span { display: block; border: 1.5px solid var(--ink); border-radius: 999px; padding: 6px 12px; font: 600 14px 'Inter', sans-serif; cursor: pointer; }
.choices input:checked + span { background: var(--ink); color: var(--paper); }
.choices input:focus-visible + span { outline: 2px solid var(--sky); outline-offset: 2px; }
.sheet textarea { width: 100%; font: 15px/1.4 'Inter', sans-serif; color: var(--ink); background: var(--paper); border: 1.5px solid var(--ink); padding: 8px 10px; resize: vertical; }
.sheet .hint { margin: 0; color: var(--red); }
.sheet .row { margin: 0; }

@media (max-width: 860px) {
  header { padding: 14px 16px; }
  main { padding: 0 16px 60px; }
  .hero { grid-template-columns: 1fr; gap: 20px; padding: 36px 0 28px; }
  #logo { font-size: 22px; }
  .top { gap: 6px; }
  .top-btn { padding: 6px 11px; font-size: 13px; }
  .panel { position: fixed; left: 16px; right: 16px; top: 62px; width: auto; }
  #auth span { display: none; }
  .mini { padding: 8px 12px; font-size: 13px; }
  /* phone game: one screen that fits the space above the keyboard (--vvh / --vvtop from visualViewport):
     top bar (back, song, score), video centred, lyrics, then the four help buttons right above the keys */
  .playing header { display: none; }
  #game {
    position: fixed; z-index: 5; left: 0; right: 0; top: var(--vvtop, 0px); height: var(--vvh, 100dvh);
    grid-template-columns: auto minmax(0, 1fr) auto; grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "back now hud" "video video video" "stage stage stage";
    gap: 10px 12px; background: var(--paper);
    padding: max(10px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px));
  }
  #game aside { display: contents; }
  #game .video { grid-area: video; justify-self: center; width: min(100%, calc(var(--vvh, 100dvh) * .3 * 16 / 9)); }
  .video { box-shadow: 4px 4px 0 var(--sky); }
  #g-back { grid-area: back; align-self: center; margin: 0; text-decoration: none; width: 40px; height: 40px; border: 1.5px solid var(--ink); display: grid; place-items: center; box-shadow: 3px 3px 0 var(--sun); }
  #g-back span { display: none; }
  #g-back svg { width: 22px; height: 22px; margin: 0; }
  .now { grid-area: now; min-width: 0; align-self: center; }
  .now b, .now span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .now b { font-size: 16px; }
  .now span { font-size: 12px; }
  .now { display: grid; grid-template-columns: minmax(0, max-content) auto; justify-content: start; column-gap: 8px; align-items: baseline; }
  .now b { grid-column: 1 / -1; }
  #g-report { margin: 0; font-size: 11px; white-space: nowrap; }
  #report { padding-top: calc(var(--vvtop, 0px) + 16px); }
  .hud { grid-area: hud; align-self: center; display: flex; gap: 12px; border: 0; }
  .hud div, .hud div + div { padding: 0; border: 0; text-align: right; }
  .hud b { font-size: 15px; }
  .hud small { font-size: 9px; letter-spacing: .04em; }
  .hud div:last-child { display: none; }
  .offset { display: none; }
  .stage { grid-area: stage; min-height: 0; }
  #lyrics { flex: 1; height: auto; min-height: 0; margin: 4px 0; }
  #lines { gap: 10px; padding: 18vh 0; }
  .line { font-size: 14px; }
  .line.cur { font-size: 21px; }
  .hint-row { min-height: 0; gap: 12px; justify-content: center; text-align: center; }
  #modes { margin: 6px 0 0; gap: 6px; text-align: center; }
  .mode-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  .mode-row .tab { padding: 8px 0; font-size: 12.5px; }
  #mode-note { font-size: 12px; }
  /* before the start the play keys are useless, give their room to the lyrics */
  #modes:not([hidden]) ~ .touch-keys { display: none; }
  .hint { font-size: 13px; }
  .hint-row #g-start { margin: 4px 0; }
  .touch-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
  .touch-keys .mini { padding: 11px 0; font-size: 14px; }
  /* phone: video, then the lines, and the tap buttons pinned to the bottom of the screen */
  .sync-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .sync-grid > div { display: contents; }
  #sync-lines { order: 1; max-height: 32vh; }
  #sync-hint, #sync-done { order: 2; margin: 0; }
  .sync-keys { order: 3; position: sticky; bottom: 0; margin: 0; padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--paper); z-index: 3; }
  .track { grid-template-columns: 28px 64px 1fr auto auto; gap: 12px; }
  .track img { width: 64px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats div:nth-child(3) { border-left: 0; padding-left: 0; }
}
