:root {
  --now: #ff453a;
  --next: #3d9bff;
  --never: #37d67a;
  --gold: #ffcb2e;
  --ink: #eaf0ff;
  --dim: #93a2c4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #070a12;
  color: var(--ink);
  font-family: "Trebuchet MS", "Avenir Next", system-ui, -apple-system, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#scene { position: fixed; inset: 0; display: block; }

#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 2;
  background:
    radial-gradient(120% 90% at 50% 42%, transparent 45%, rgba(2, 4, 10, .78) 100%),
    repeating-linear-gradient(to bottom, rgba(255,255,255,.022) 0 1px, transparent 1px 3px);
}

#ui { position: fixed; inset: 0; z-index: 3; pointer-events: none; }

/* ------------------------------- hud */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: flex-start; gap: 18px;
  padding: calc(14px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right)) 14px calc(18px + env(safe-area-inset-left));
  text-shadow: 0 2px 10px rgba(0,0,0,.9);
}

/* Ticket key: a chip's colour is the colour of the column it belongs to. */
#legend {
  position: absolute; top: calc(82px + env(safe-area-inset-top)); left: 0; right: 0;
  display: flex; justify-content: center; gap: 9px;
  pointer-events: none; text-shadow: 0 1px 6px rgba(0,0,0,.8);
}
#legend .lg {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 9px; border-radius: 11px;
  background: rgba(5, 9, 18, .58); border: 1px solid rgba(255,255,255,.1);
  font-size: 11px; font-weight: 700; letter-spacing: .05em;
  transition: background .12s ease, border-color .12s ease;
}
#legend .lg b { font-size: 12.5px; letter-spacing: .1em; }
#legend .lg.c0 { --c: var(--now); }
#legend .lg.c1 { --c: var(--next); }
#legend .lg.c2 { --c: var(--never); }
#legend .lg { color: var(--c, #cfe0ff); }
#legend .lg i {
  font-style: normal; font-weight: 800; color: #06101c;
  background: var(--c, #cfe0ff); padding: 2px 6px; border-radius: 6px;
}
#legend .lg.on { background: rgba(255,255,255,.16); border-color: var(--c, #cfe0ff); }
.stat .label, #sprintBox .label {
  font-size: 10px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--dim); font-weight: 700;
}
.stat .val { font-size: 34px; font-weight: 800; line-height: 1.05; letter-spacing: -.01em; }
.stat.right { margin-left: auto; text-align: right; }
#combo { color: var(--gold); transition: transform .08s ease; }
#combo.pop { transform: scale(1.35); }
.cups { letter-spacing: .12em; font-size: 26px !important; color: var(--now); }

#sprintBox { width: 168px; }
#sprintBox .bar {
  margin-top: 6px; height: 9px; border-radius: 6px;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.16);
  overflow: hidden;
}
#sprintFill {
  height: 100%; width: 100%;
  transform: scaleX(0); transform-origin: left center;
  background: linear-gradient(90deg, var(--next), #9be7ff);
  border-radius: 6px; transition: transform .18s ease;
}

/* ------------------------------- feedback */
#flash {
  position: absolute; inset: 0; opacity: 0;
  background: radial-gradient(120% 90% at 50% 60%, rgba(255,60,50,.42), transparent 70%);
  transition: opacity .18s ease;
}
#flash.on { opacity: 1; transition: none; }

#banner {
  position: absolute; top: 34%; left: 0; right: 0; text-align: center;
  font-size: clamp(26px, 6vw, 64px); font-weight: 800; letter-spacing: .02em;
  opacity: 0; transform: scale(.86);
  text-shadow: 0 6px 28px rgba(0,0,0,.95);
}
#banner.show { animation: bpop 1.15s ease forwards; }
@keyframes bpop {
  0% { opacity: 0; transform: scale(.8); }
  16% { opacity: 1; transform: scale(1.04); }
  72% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.06); }
}

#quip {
  position: absolute; bottom: 84px; left: 0; right: 0; text-align: center;
  font-size: 17px; font-style: italic; color: #c7d3ea; opacity: 0;
  text-shadow: 0 2px 12px rgba(0,0,0,.9);
}
#quip.show { animation: qfade 2.1s ease forwards; }
@keyframes qfade {
  0% { opacity: 0; transform: translateY(8px); }
  18% { opacity: .95; transform: translateY(0); }
  75% { opacity: .95; }
  100% { opacity: 0; }
}

#hint {
  position: absolute; bottom: 16px; left: 0; right: 0; text-align: center;
  font-size: 12px; letter-spacing: .09em; color: #7d8bab; text-transform: uppercase;
}
#hint b { color: #cfdaef; }

/* ------------------------------- touch pad
   Thumb zones: lane buttons hug the edges, SLAM sits centre so a thumb can reach
   either without covering the play view. All offsets clear the device safe area. */
#pad {
  position: absolute; bottom: 40px; left: 0; right: 0;
  display: none; justify-content: center; gap: 12px;
  padding: 0 max(14px, env(safe-area-inset-left)) 0 max(14px, env(safe-area-inset-right));
  pointer-events: auto;
}
#pad button {
  pointer-events: auto; font: inherit; font-weight: 800;
  min-width: 84px; height: 56px; padding: 0 18px;
  color: #08111f; background: rgba(235,242,255,.9);
  border: 0; border-radius: 14px; font-size: 20px; letter-spacing: .04em;
  box-shadow: 0 6px 0 rgba(0,0,0,.45);
  touch-action: manipulation;
}
#padS { background: var(--gold) !important; }
#pad button:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.45); }
@media (pointer: coarse) {
  #pad {
    display: flex; justify-content: space-between; align-items: flex-end;
    bottom: max(26px, env(safe-area-inset-bottom));
  }
  #pad button { width: 26vw; max-width: 116px; min-width: 74px; height: 60px; }
  #padS { width: auto; flex: 1; max-width: 250px; margin: 0 10px; }
  #hint { display: none; }
}

/* Portrait on a phone: a short nudge to landscape, parked in the letterbox band
   above the pads so it never covers the play view. */
#rotate {
  display: none;
  position: absolute; z-index: 40;
  bottom: calc(104px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  max-width: min(88vw, 330px); padding: 10px 15px; border-radius: 12px;
  background: rgba(26, 21, 4, .94); box-shadow: 0 6px 24px rgba(0,0,0,.5);
  color: var(--gold); font-size: 12px; letter-spacing: .08em; text-transform: uppercase;
  text-align: center; pointer-events: none;
}
#rotate b { font-size: 18px; margin-right: 8px; }
#rotate.on { display: block; }

/* ------------------------------- screens */
.screen {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
           max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: rgba(4, 7, 15, .74); backdrop-filter: blur(7px);
  pointer-events: auto; overflow: auto;
  touch-action: pan-y; -webkit-overflow-scrolling: touch;
}
.screen.hidden { display: none; }

.card {
  width: min(680px, 96vw); max-height: 94vh; overflow: auto;
  padding: 26px 28px 24px; border-radius: 20px;
  background: linear-gradient(170deg, #131b2e, #0a1120);
  border: 1px solid rgba(140,170,220,.22);
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.kicker {
  font-size: 11px; letter-spacing: .28em; text-transform: uppercase;
  color: var(--next); font-weight: 800;
}
.kicker.bad { color: var(--now); }
h1 {
  margin: 4px 0 6px; font-size: clamp(38px, 8vw, 60px); line-height: .92;
  letter-spacing: -.02em; font-weight: 800;
}
h1 span { color: var(--gold); }
h1.sm { font-size: clamp(28px, 5.5vw, 42px); }
.tag { margin: 0 0 18px; color: #b6c4de; font-size: 15px; }

.cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.col {
  padding: 14px 12px 10px; border-radius: 13px;
  background: rgba(255,255,255,.045);
}
.col ul { margin: 8px 0 0; padding-left: 16px; color: #aebbd6; font-size: 12.5px; }
.col li { margin: 3px 0; }
.colName { font-size: 21px; font-weight: 800; letter-spacing: .01em; }
.colSub { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: #8fa0be; }
.col.now { box-shadow: inset 0 3px 0 var(--now); } .col.now .colName { color: var(--now); }
.col.next { box-shadow: inset 0 3px 0 var(--next); } .col.next .colName { color: var(--next); }
.col.never { box-shadow: inset 0 3px 0 var(--never); } .col.never .colName { color: var(--never); }
.colTags { margin-top: 7px; font-size: 11px; font-weight: 800; letter-spacing: .09em; }
.colTags:empty { display: none; }
.col.now .colTags { color: var(--now); } .col.next .colTags { color: var(--next); } .col.never .colTags { color: var(--never); }

.rules { font-size: 13.5px; color: #c2cee6; line-height: 1.5; }
.rules > div { margin: 6px 0; padding-left: 30px; position: relative; }
.rules b { color: #fff; }
.rules > div::before {
  content: ""; position: absolute; left: 0; top: 3px; width: 20px; height: 20px;
}
.rules .warn {
  margin-top: 12px; padding: 10px 12px; border-radius: 10px;
  background: rgba(255,203,46,.1); border: 1px solid rgba(255,203,46,.28);
  color: #f4dfae;
}

button.big {
  margin-top: 18px; width: 100%; padding: 15px 20px; font: inherit;
  font-size: 20px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase;
  color: #0a0f1a; background: linear-gradient(180deg, #ffd752, #ffb42a);
  border: 0; border-radius: 14px; cursor: pointer;
  box-shadow: 0 8px 0 #a56b0d, 0 16px 30px rgba(0,0,0,.45);
}
button.big:active { transform: translateY(5px); box-shadow: 0 3px 0 #a56b0d; }
button.big:hover { filter: brightness(1.06); }

.best { margin-top: 12px; text-align: center; font-size: 12px; letter-spacing: .16em; text-transform: uppercase; color: #8fa0be; }
.touchNote { display: none; margin-top: 14px; font-size: 13px; color: #b6c3dc; text-align: center; }
.touchNote b { color: #fff; }
@media (pointer: coarse) { .touchNote { display: block; } }

.scoreBig { text-align: center; margin: 6px 0 16px; }
.scoreBig span { font-size: 11px; letter-spacing: .28em; color: var(--dim); }
#finalScore { font-size: clamp(46px, 11vw, 78px); font-weight: 800; color: var(--gold); line-height: 1; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stats > div { padding: 10px 4px; border-radius: 12px; background: rgba(255,255,255,.05); }
.stats b { display: block; font-size: 24px; }
.stats span { font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; color: #8fa0be; }
.title2 { margin-top: 14px; text-align: center; font-style: italic; color: #a8b8d4; font-size: 14px; }

@media (max-width: 560px) {
  .cols { grid-template-columns: 1fr; }
  .stat .val { font-size: 26px; }
  #sprintBox { width: 110px; }
}
