:root {
  --ink: #1b1b1b;
  --cream: #fff6e0;
  --lime: #d6f34a;
  --pink: #ff5da2;
  --sky: #8ad8ff;
  --sun: #ffe56a;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: "Bricolage Grotesque", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#frame {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage {
  position: relative;
  width: 960px;
  height: 540px;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 0 0 4px var(--ink), 8px 8px 0 rgba(27, 27, 27, .18);
  background: #d9f6ea;
  font-size: 16px;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#hud, #title, #over { position: absolute; inset: 0; }
#hud { pointer-events: none; z-index: 2; }
#title { z-index: 3; }
#over { z-index: 4; }
#title[hidden], #over[hidden], #hud[hidden], #banner[hidden], #hint[hidden] { display: none !important; }

.pill {
  position: absolute;
  top: 0.7em;
  display: flex;
  align-items: center;
  gap: 0.45em;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 0.28em 0.7em;
  box-shadow: 3px 3px 0 var(--ink);
}
.time-pill { left: 0.7em; }
.score-pill { left: 50%; transform: translateX(-50%); }
.meter-pill { right: 0.7em; flex-direction: column; align-items: flex-start; gap: 0.18em; padding: 0.28em 0.5em 0.36em; }
.pill small {
  display: block;
  font-size: 0.62em;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1;
}
.pill b {
  display: block;
  font-size: 1.35em;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
#pips { display: flex; gap: 3px; }
#pips i {
  display: block;
  width: 0.72em;
  height: 0.72em;
  border-radius: 3px;
  background: #efe7c8;
  border: 2px solid var(--ink);
}
#pips i.on { background: var(--lime); }
#meter.full #pips i.on { background: var(--sun); }

#hint {
  position: absolute;
  left: 50%;
  top: 4.3em;
  transform: translateX(-50%);
  margin: 0;
  background: rgba(255, 255, 255, .92);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 0.28em 0.75em;
  font-weight: 800;
  font-size: 0.82em;
  white-space: nowrap;
}

.banner {
  position: absolute;
  left: 50%;
  top: 4.3em;
  transform: translateX(-50%) rotate(-2deg);
  margin: 0;
  background: var(--lime);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 0.3em 0.85em;
  font-weight: 800;
  font-size: 1.05em;
  box-shadow: 3px 3px 0 var(--ink);
  white-space: nowrap;
}
.banner.bad { background: #ffd0e4; }

#mute {
  pointer-events: auto;
  position: absolute;
  right: 0.7em;
  bottom: 0.65em;
  border: 3px solid var(--ink);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  font: inherit;
  font-weight: 800;
  font-size: 0.78em;
  padding: 0.32em 0.7em;
  cursor: pointer;
}
#mute[aria-pressed="true"] { background: var(--lime); }

#title {
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}
.logo, .title-actions, #title .back, #over .sheet, #over .back { pointer-events: auto; }

.logo {
  padding: 0.85em 1em 0;
  text-align: center;
}
.eyebrow {
  margin: 0;
  font-weight: 800;
  font-size: 0.78em;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.logo h1 {
  margin: 0.08em 0 0;
  font-size: 2.5em;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 0.92;
}
.with {
  margin: 0.15em 0 0;
  display: inline-block;
  background: var(--pink);
  color: #fff;
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 0.12em 0.7em 0.16em;
  font-weight: 800;
  font-size: 1.05em;
  transform: rotate(-2deg);
  box-shadow: 3px 3px 0 var(--ink);
}

.title-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4em;
  padding: 0.7em 1em 0;
  text-align: center;
}
#title-best { margin: 0; font-weight: 800; min-height: 1.2em; }
.how { margin: 0; font-size: 0.82em; font-weight: 600; line-height: 1.35; }

.back {
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
  font-size: 0.85em;
}
#title .back {
  position: absolute;
  top: 0.7em;
  left: 0.75em;
  background: rgba(255, 255, 255, .92);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 0.28em 0.7em;
}
.back.dark { display: block; margin-top: 0.75em; }
.back:hover { text-decoration: underline; }

.btn {
  display: inline-block;
  padding: 0.7em 1.3em;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--lime);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  font-size: 1.05em;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--ink);
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }

#over {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(27, 27, 27, .28);
}
.sheet {
  width: min(34em, calc(100% - 1.6em));
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 24px;
  box-shadow: 6px 6px 0 var(--ink);
  padding: 1.1em 1.2em 1em;
  text-align: center;
}
.sheet h2 {
  margin: 0.12em 0 0.15em;
  font-size: 1.8em;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--pink);
}
.bigscore {
  margin: 0;
  font-size: 2.8em;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
}
.bestline { margin: 0.2em 0 0.55em; font-weight: 800; }
.fact { margin: 0 auto; max-width: 34em; font-size: 0.98em; font-weight: 600; }
.src { margin: 0.3em 0 0.85em; font-size: 0.75em; font-weight: 600; opacity: .7; }

#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 6;
  background: var(--cream);
  color: var(--ink);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  padding: 2em;
  font-size: 1.4em;
  font-weight: 800;
}
#rotate .how { font-weight: 600; font-size: 0.7em; opacity: .8; margin-top: 0.4em; }

@media (orientation: portrait) and (max-width: 820px) {
  #rotate { display: flex; }
}

@media (max-height: 460px) {
  .logo h1 { font-size: 1.7em; }
  .with { font-size: 0.9em; }
  .eyebrow { display: none; }
  .sheet h2 { font-size: 1.3em; }
  .bigscore { font-size: 2em; }
  .fact { font-size: 0.82em; }
  .sheet { padding: 0.7em 0.85em; }
  .pill b { font-size: 1.05em; }
}

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}
