@font-face {
  font-family: 'Bricolage Grotesque';
  src: url('./bricolage-grotesque-wght.woff2') format('woff2-variations');
  font-weight: 200 800;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('./ibm-plex-mono-500.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}

:root {
  --ink: #05070a;
  --paper: #eaf0f6;
  --muted: #8a97a6;
  --line: rgba(234, 240, 246, 0.14);
  --amber: #f2b138;
  --right: #4bd07f;
  --wrong: #e2564a;
  --display: 'Bricolage Grotesque', ui-sans-serif, system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--display);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

#stage {
  position: fixed;
  inset: 0;
  cursor: pointer;
}
body[data-phase='playing'] #stage,
body[data-phase='done'] #stage { cursor: default; }

#bricks { display: block; width: 100%; height: 100%; }

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 50% 40%, transparent 40%, rgba(3, 5, 8, 0.55) 100%),
    linear-gradient(to bottom, rgba(3, 5, 8, 0.62) 0%, rgba(3, 5, 8, 0.28) 16%, transparent 34%, transparent 62%, rgba(3, 5, 8, 0.45) 82%, rgba(3, 5, 8, 0.78) 100%);
}

/* ------------------------------------------------------------------ the clock */
#hud {
  position: absolute;
  top: clamp(14px, 3vh, 34px);
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
}
#timer {
  font-family: var(--mono);
  font-weight: 500;
  font-size: clamp(44px, 9vw, 104px);
  line-height: 0.94;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--paper);
  text-shadow: 0 2px 30px rgba(5, 7, 10, 0.8);
  transition: color 200ms ease, opacity 200ms ease;
}
body[data-phase='sign'] #timer,
body[data-phase='breaking'] #timer,
body[data-phase='done'] #timer { opacity: 0.22; }
body[data-phase='held'] #timer { color: var(--amber); }

#round {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 10px;
}

#dots { display: flex; gap: 7px; justify-content: center; margin-top: 12px; }
#dots i {
  width: 26px; height: 3px;
  background: rgba(234, 240, 246, 0.16);
  border-radius: 2px;
  transition: background 240ms ease;
}
#dots i[data-done] { background: var(--amber); }
#dots i[data-now] { background: rgba(234, 240, 246, 0.5); }
body[data-phase='sign'] #dots, body[data-phase='done'] #dots { opacity: 0; }

/* ------------------------------------------------------------------ count in */
#count {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(120px, 26vw, 320px);
  color: var(--paper);
  pointer-events: none;
  text-shadow: 0 8px 60px rgba(5, 7, 10, 0.9);
}
#count:empty { display: none; }

/* ------------------------------------------------------------------ the answer */
#foot {
  position: absolute;
  left: 0; right: 0;
  bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
}
#reveal {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--right);
}
#reveal[data-missed='1'] { color: var(--muted); }

#answer {
  width: min(460px, 92vw);
  height: 62px;
  padding: 0 20px;
  font-family: var(--display);
  font-weight: 500;
  font-size: 24px;
  text-align: center;
  color: var(--paper);
  background: rgba(10, 14, 20, 0.72);
  border: 2px solid var(--line);
  border-radius: 4px;
  outline: none;
  backdrop-filter: blur(8px);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
#answer::placeholder { color: rgba(138, 151, 166, 0.7); font-size: 17px; }
#answer:focus { border-color: rgba(234, 240, 246, 0.42); }
#answer[data-right='1'] { border-color: var(--right); box-shadow: 0 0 0 4px rgba(75, 208, 127, 0.18); }
#answer[data-wrong='1'] { border-color: var(--wrong); animation: shake 380ms cubic-bezier(0.36, 0.07, 0.19, 0.97); }

@keyframes shake {
  10%, 90% { transform: translateX(-3px); }
  20%, 80% { transform: translateX(5px); }
  30%, 50%, 70% { transform: translateX(-9px); }
  40%, 60% { transform: translateX(9px); }
}

#tip {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--muted);
}
body[data-phase='sign'] #foot,
body[data-phase='breaking'] #foot,
body[data-phase='done'] #foot { opacity: 0; pointer-events: none; }
#foot { transition: opacity 260ms ease; }

/* ------------------------------------------------------------------ the card at the end */
#end {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
  padding: 24px;
  background: rgba(5, 7, 10, 0.82);
  backdrop-filter: blur(10px);
}
#end[hidden] { display: none; }
#end h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 46px);
  font-weight: 800;
  letter-spacing: -0.03em;
}
#end table { border-collapse: collapse; font-family: var(--mono); font-size: 15px; }
#end td { padding: 5px 14px; border-bottom: 1px solid var(--line); }
#end td:first-child { color: var(--muted); }
#end td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
#totalline {
  margin: 6px 0 0;
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
#totalline strong { color: var(--amber); font-size: 30px; letter-spacing: -0.02em; margin-left: 10px; }
#best { margin: 0; font-family: var(--mono); font-size: 12px; color: var(--muted); letter-spacing: 0.1em; }
#again {
  margin-top: 6px;
  height: 52px;
  padding: 0 30px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 17px;
  color: var(--ink);
  background: var(--amber);
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  transition: filter 160ms ease, transform 120ms ease;
}
#again:hover { filter: brightness(1.08); }
#again:active { transform: translateY(1px); }
#note { margin: 4px 0 0; max-width: 34ch; text-align: center; font-family: var(--mono); font-size: 11px; line-height: 1.6; color: var(--muted); }

.fallback { position: absolute; inset: auto 0 40% 0; text-align: center; color: var(--muted); font-family: var(--mono); }

@media (prefers-reduced-motion: reduce) {
  #answer[data-wrong='1'] { animation: none; }
  * { transition-duration: 1ms !important; }
}

@media (max-width: 860px) {
  #timer { font-size: clamp(40px, 13vw, 72px); }
  #answer { height: 56px; font-size: 20px; }
  #tip { display: none; }
}
