* { box-sizing: border-box; }

:root {
  --bg: #0b1026;
  --panel: rgba(11, 16, 38, 0.9);
  --ink: #ffffff;
  --dim: #9aa6d0;
  --accent: #ff4d6d;
  --accent2: #ffd23f;
  --good: #5cf08a;
  --gold: #ffd23f;
  --silver: #cfd8e6;
  --bronze: #e0935a;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px;
}

/* ------------------------------------------------------------ top bar */
#hud {
  width: min(100%, calc((100dvh - 70px) * 16 / 9));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  min-height: 34px;
  font-weight: 800;
  letter-spacing: 0.04em;
  font-size: clamp(12px, 2.2vmin, 18px);
}

#dots { display: flex; gap: 6px; }

#dots i {
  width: 1.1em;
  height: 1.1em;
  border-radius: 50%;
  border: 2px solid #3a4680;
  background: transparent;
}

#dots i.now { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.15); }
#dots i.gold { background: var(--gold); border-color: var(--gold); }
#dots i.silver { background: var(--silver); border-color: var(--silver); }
#dots i.bronze { background: var(--bronze); border-color: var(--bronze); }
#dots i.none { background: #3a4680; }

#event-name { text-transform: uppercase; text-align: center; white-space: nowrap; }
#live { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--accent2); }

/* ------------------------------------------------------------ stage */
#stage {
  position: relative;
  flex: none;
  /* as wide as possible while the 16:9 picture still fits under the top bar */
  width: min(100%, calc((100dvh - 70px) * 16 / 9));
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #123;
}

#race {
  position: absolute;
  left: 4%;
  right: 4%;
  top: 3%;
  height: 6px;
  border-radius: 3px;
  background: rgba(11, 16, 38, 0.55);
}

#race[hidden] { display: none; }

#race i {
  position: absolute;
  top: -4px;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  border-radius: 50%;
  border: 2px solid #fff;
}

#race-me { background: var(--accent); }
#race-rival { background: #50c8ff; opacity: 0.85; }

#chips {
  position: absolute;
  left: 3%;
  top: 7%;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  pointer-events: none;
}

.chip {
  padding: 0.25em 0.7em;
  border-radius: 999px;
  background: rgba(11, 16, 38, 0.78);
  font-size: clamp(10px, 1.9vmin, 15px);
  font-weight: 700;
  white-space: nowrap;
}

.chip.bonus { background: var(--accent2); color: #1a1400; }
.chip.good { background: var(--good); color: #062b12; }
.chip.hot { background: var(--accent); }

#skip {
  position: absolute;
  right: 2%;
  bottom: 4%;
  padding: 0.3em 0.6em;
  font-size: clamp(12px, 2.4vmin, 18px);
  background: rgba(11, 16, 38, 0.6);
  opacity: 0.75;
}

#skip[hidden] { display: none; }

#cue {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-size: clamp(28px, 9vmin, 84px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.02em;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45), 0 0 24px rgba(0, 0, 0, 0.5);
  opacity: 0;
}

#cue.show { animation: cue 0.75s ease-out forwards; }
#cue.bad { color: #ff6b6b; }
#cue.great { color: var(--accent2); }

@keyframes cue {
  0% { opacity: 0; transform: scale(1.6); }
  15% { opacity: 1; transform: scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-12%); }
}

/* ------------------------------------------------------------ cards */
#card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55em;
  padding: 3%;
  text-align: center;
  background: var(--panel);
  font-size: clamp(11px, 2.6vmin, 22px);
  animation: pop 0.18s ease-out;
}

#card[hidden] { display: none; }
#card.glass { background: rgba(11, 16, 38, 0.8); }

@keyframes pop {
  from { opacity: 0; transform: scale(1.04); }
  to { opacity: 1; transform: none; }
}

.logo {
  font-size: 4.2em;
  font-weight: 900;
  font-style: italic;
  line-height: 1;
  letter-spacing: -0.02em;
  background: linear-gradient(100deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.kicker { color: var(--accent2); font-weight: 800; letter-spacing: 0.18em; font-size: 0.8em; }
.big { font-size: 2.6em; font-weight: 900; font-style: italic; line-height: 1.05; text-transform: uppercase; }
.sub { margin: 0; color: var(--dim); font-weight: 600; }
.how { margin: 0; font-size: 1.15em; font-weight: 700; }
.row { display: flex; gap: 0.5em; flex-wrap: wrap; justify-content: center; align-items: center; }
.row .chip { font-size: 0.8em; }
.medal { font-size: 3.4em; line-height: 1; }
.value { font-size: 2.6em; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1; }
.xp { color: var(--good); font-weight: 900; font-size: 1.3em; }

kbd {
  display: inline-block;
  min-width: 1.9em;
  padding: 0.15em 0.5em;
  border-radius: 0.4em;
  border: 2px solid #5766b0;
  border-bottom-width: 4px;
  background: #1a2350;
  font: inherit;
  font-weight: 800;
}

button {
  font: inherit;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--ink);
  border: 0;
  border-radius: 0.6em;
  padding: 0.6em 1.3em;
  background: #2a3570;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

button.primary { background: var(--accent); font-size: 1.25em; font-style: italic; }
button small { font-weight: 600; opacity: 0.7; margin-left: 0.4em; }

.timer { position: absolute; left: 0; bottom: 0; height: 4px; width: 100%; background: rgba(255, 255, 255, 0.75); transform-origin: left; animation: drain linear forwards; }
.bar { width: min(70%, 22em); height: 5px; border-radius: 3px; background: #2a3570; overflow: hidden; position: relative; }
.bar .timer { height: 100%; background: var(--accent2); }

@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.level { width: min(80%, 24em); }
.level .track { height: 10px; border-radius: 5px; background: #2a3570; overflow: hidden; }
.level .fill { height: 100%; background: linear-gradient(90deg, var(--good), var(--accent2)); transition: width 0.8s ease-out; }
.level .labels { display: flex; justify-content: space-between; font-size: 0.75em; color: var(--dim); font-weight: 700; margin-top: 0.3em; }

table.results { border-collapse: collapse; font-size: 0.85em; font-weight: 700; }
table.results td { padding: 0.12em 0.7em; text-align: left; }
table.results td.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--accent2); }

/* ------------------------------------------------------------ touch pads */
#pads { display: none; width: 100%; max-width: 560px; gap: 10px; }

#pads button {
  flex: 1;
  height: 68px;
  font-size: 26px;
  background: #18214a;
  border: 2px solid #5766b0;
  border-radius: 14px;
}

#pads button.action { flex: 1.4; border-color: var(--accent); color: var(--accent); }
#pads button.down { background: #2a3570; }

@media (pointer: coarse) {
  #pads { display: flex; min-height: 68px; }
  .keys { display: none; }
}

/* Portrait screens: the picture is small, so cards use the whole area below the top bar. */
@media (orientation: portrait) {
  #app { gap: 12px; }
  #pads { margin-top: auto; margin-bottom: 4px; }
  #pads button { height: 96px; }
  #card {
    position: fixed;
    inset: 50px 8px 8px 8px;
    border-radius: 14px;
    font-size: clamp(13px, 3.9vw, 22px);
    background: rgba(11, 16, 38, 0.96);
  }
  #card.glass { background: rgba(11, 16, 38, 0.9); }
}

@media (pointer: coarse) and (orientation: landscape) {
  #app { flex-direction: row; flex-wrap: wrap; align-content: center; justify-content: center; }
  #hud { flex-basis: 100%; }
  #pads { position: fixed; left: 0; right: 0; bottom: 6px; max-width: none; padding: 0 10px; justify-content: space-between; pointer-events: none; }
  #pads button { flex: 0 0 96px; pointer-events: auto; opacity: 0.8; }
}
