* { box-sizing: border-box; }
:root {
  --ink: #fff;
  --navy: #0c1033;
  --panel: #171a4aee;
  --pink: #ff3d8b;
  --gold: #ffd23f;
  --mint: #5ef0d0;
  --line: #ffffff2a;
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--navy);
}
html, body { margin: 0; height: 100%; }
body { overflow: hidden; background: var(--navy); }
#app { height: 100dvh; display: flex; flex-direction: column; }
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
canvas#arena { display: block; width: 100%; height: 100%; touch-action: none; }
footer { font: 10px monospace; padding: 3px 8px; background: #070920; color: #fff8; text-align: center; }

button, .home {
  font: inherit; font-weight: 800; color: #1a1340; background: #fff;
  min-height: 56px; border: 0; border-radius: 16px; padding: 10px 18px;
  box-shadow: 0 4px 0 #00000055; cursor: pointer; touch-action: manipulation;
}
button:active { transform: translateY(2px); box-shadow: 0 2px 0 #00000055; }
button:focus-visible, .home:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; }
button small { display: block; font-size: 12px; font-weight: 650; opacity: .8; }
.primary { background: linear-gradient(180deg, #ff5fa0, var(--pink)); color: #fff; }
.big { min-height: 72px; font-size: 20px; }
.ghost { background: #ffffff1c; color: #fff; box-shadow: none; min-height: 48px; }
[hidden] { display: none !important; }

/* Overlay screens */
.screen {
  position: absolute; inset: 0; overflow-y: auto; padding: 18px 16px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  background: linear-gradient(180deg, #0c1033d9, #2a1c5cc4 60%, #0c1033ee);
  text-align: center;
}
.screen > * { flex-shrink: 0; }
.screen:focus { outline: none; }
.home { position: absolute; left: 12px; top: 12px; display: inline-flex; align-items: center; text-decoration: none; min-height: 48px; font-size: 15px; padding: 0 14px; }
.logo { margin: 46px 0 0; line-height: .9; font-style: italic; font-weight: 950; letter-spacing: -1px; text-shadow: 0 4px 0 #00000066; }
.logo span { display: block; font-size: clamp(34px, 10vw, 66px); background: linear-gradient(180deg, #fff, #c9c2ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo b { display: inline-block; margin-top: 6px; font-size: clamp(40px, 12vw, 80px); color: var(--navy); background: var(--gold); padding: 0 16px; border-radius: 14px; transform: skewX(-10deg); box-shadow: 0 6px 0 #b8860b; }
.tagline { margin: 0; color: #ffffffcc; font-weight: 700; }
.kicker { margin: 8px 0 0; font-weight: 900; letter-spacing: 3px; color: var(--mint); font-size: 14px; }
h2 { margin: 0; font-size: clamp(28px, 7vw, 40px); font-style: italic; font-weight: 950; }
.hint { margin: 0; color: #ffffffbb; font-size: 14px; }

.roster { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; width: min(560px, 100%); }
.roster button { display: flex; flex-direction: column; align-items: center; gap: 0; padding: 4px 4px 6px; background: #ffffff14; color: #fff; border: 3px solid transparent; box-shadow: none; min-height: 96px; }
.roster button[aria-checked="true"] { border-color: var(--gold); background: #ffd23f26; }
.roster button[aria-checked="true"]::after { content: "✓ YOU"; font-size: 11px; color: var(--gold); letter-spacing: 1px; }
.roster .portrait { width: 60px; height: 64px; object-fit: contain; }
.modes, .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: min(560px, 100%); }
.modes .wide { grid-column: 1 / -1; }

/* Career ladder */
.stages { display: grid; gap: 10px; width: min(560px, 100%); }
.stage { display: flex; align-items: center; gap: 12px; text-align: left; background: #fff; min-height: 88px; }
.stage-icon { font-size: 36px; }
.stage-text { display: flex; flex-direction: column; gap: 2px; }
.stage-text small { font-size: 13px; font-weight: 650; opacity: .75; }
.stage-text .new { color: #7b4dff; opacity: 1; }
.stage .status { font-size: 15px; font-weight: 900; color: #c2185b; }
.stage.current { outline: 4px solid var(--gold); background: #fff8d6; }
.stage.locked { background: #ffffff1f; color: #ffffffb3; box-shadow: none; cursor: default; }
.stage.locked .new, .stage.locked .status { color: #ffffffb3; }

/* Gym */
.gym-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: min(560px, 100%); }
.gym-tabs button { min-height: 72px; padding: 6px 4px; font-size: 15px; background: #ffffff1c; color: #fff; box-shadow: none; border: 2px solid #ffffff40; }
.gym-tabs button span { display: block; font-size: 24px; }
.gym-tabs button[aria-pressed="true"] { background: #fff; color: #1a1340; border-color: var(--gold); }
.skills { display: grid; gap: 8px; width: min(560px, 100%); }
.skill { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "lvl name stars" "tip tip tip"; align-items: center; gap: 2px 10px; text-align: left; min-height: 72px; }
.skill .lvl { grid-area: lvl; font-size: 11px; font-weight: 900; letter-spacing: 1px; background: #1a1340; color: #fff; border-radius: 999px; padding: 3px 8px; }
.skill b { grid-area: name; font-size: 18px; }
.skill .stars { grid-area: stars; font-size: 20px; color: #e8a200; letter-spacing: 1px; }
.skill small { grid-area: tip; }
.skill.current { outline: 4px solid var(--gold); background: #fff8d6; }
.skill.mastered { background: #dffbef; }
.skill:disabled { background: #ffffff1f; color: #ffffffa8; box-shadow: none; cursor: default; }
.skill:disabled .lvl { background: #ffffff33; }
.drill-stars { margin: 0; font-size: 56px; color: var(--gold); letter-spacing: 6px; }
.drill-message { margin: 0; font-size: 20px; font-weight: 900; max-width: 480px; }
.row.small { width: min(360px, 100%); }
.toggles { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.toggles button, #pause-slowmo { background: #ffffff1c; color: #fff; box-shadow: none; min-height: 52px; border: 2px solid #ffffff40; }
.toggles button[aria-pressed="true"], #pause-slowmo[aria-pressed="true"] { background: var(--mint); color: #0c1033; }
#trophies { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; font-weight: 800; color: #ffffffdd; }
#trophies span { background: #ffffff14; border-radius: 999px; padding: 6px 12px; }

.grid4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; width: min(520px, 100%); }
.grid4 button { min-height: 120px; font-size: 22px; }
.grid4 .icon { display: block; font-size: 40px; }
.tiers { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; width: min(600px, 100%); }
.tiers button { min-height: 150px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 21px; }
.tiers .stars { font-size: 24px; color: #e8a200; letter-spacing: 2px; }
.tiers button:nth-child(3) { background: #fff3c4; }
.tiers button:nth-child(4) { background: linear-gradient(180deg, #ffe066, #ffb703); }
@media (min-width: 720px) { .tiers { grid-template-columns: repeat(4, 1fr); } }

/* In-routine HUD */
#hud { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 10px; pointer-events: none; }
#bug { display: flex; align-items: stretch; border-radius: 10px; overflow: hidden; font-weight: 900; font-size: 14px; letter-spacing: 1px; box-shadow: 0 4px 12px #0007; }
#bug span { padding: 8px 10px; background: #fff; color: #120a2e; }
#bug .live { background: #e8113f; color: #fff; }
#bug.practice .live { display: none; }
#bug #bug-event { background: var(--navy); color: #fff; font-style: italic; }
#bug #bug-level { background: var(--gold); }
#dots { display: flex; gap: 5px; margin-top: 12px; }
#dots i { width: 13px; height: 13px; border-radius: 50%; background: #ffffff33; border: 2px solid #ffffff66; }
#dots i.perfect { background: var(--gold); border-color: #fff; }
#dots i.great { background: #5ef08a; }
#dots i.good { background: #7cc7ff; }
#dots i.miss { background: #ff9b52; }
#pause-btn { pointer-events: auto; min-width: 56px; min-height: 56px; padding: 0; font-size: 22px; background: #ffffff26; color: #fff; box-shadow: none; }
#tap-btn { position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(300px, 70%); min-height: 76px; font-size: 26px; font-style: italic; border-radius: 999px; background: #ffffffd9; color: #120a2e; }
#tap-btn.flash { background: var(--gold); }
#call { position: absolute; left: 12px; right: 12px; top: 74px; margin: 0 auto; width: fit-content; max-width: calc(100% - 24px); padding: 8px 14px; border-radius: 10px; background: #0c1033e6; border-left: 5px solid var(--pink); font-weight: 800; pointer-events: none; opacity: 0; transition: opacity .2s; }
#call.show { opacity: 1; }

#banner { position: absolute; left: 0; right: 0; top: 30%; display: flex; flex-direction: column; align-items: center; padding: 14px; background: linear-gradient(90deg, transparent, #e8113fee 15%, #7b1fa2ee 85%, transparent); animation: slide 1.7s ease both; pointer-events: none; }
#banner-kicker { font-weight: 900; letter-spacing: 4px; font-size: 13px; color: #ffffffcc; }
#banner-title { font-size: clamp(44px, 13vw, 80px); font-style: italic; font-weight: 950; line-height: 1; text-shadow: 0 4px 0 #0006; }
#banner-sub { font-weight: 800; color: var(--gold); }
@keyframes slide { 0% { transform: translateX(-110%); } 18%, 82% { transform: translateX(0); } 100% { transform: translateX(110%); } }

/* Scorecard */
.judges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: min(440px, 100%); }
.judge { background: #fff; color: #120a2e; border-radius: 12px; padding: 8px 4px; font-weight: 950; font-size: 20px; transform: rotateX(90deg); transition: transform .3s; }
.judge small { display: block; font-size: 10px; letter-spacing: 1px; opacity: .6; }
.judge.show { transform: none; }
.judge.ten { background: var(--gold); }
.judge.dropped { opacity: .45; text-decoration: line-through; }
.score-line { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 8px; width: min(440px, 100%); }
.score-line > div { background: #ffffff14; border-radius: 12px; padding: 8px; }
.score-line small { display: block; font-size: 12px; color: #ffffffaa; font-weight: 800; }
.score-line b { font-size: 22px; font-variant-numeric: tabular-nums; }
.score-line .total { background: var(--pink); }
.score-line .total b { font-size: 30px; }
#score-badge { margin: 0; min-height: 24px; font-weight: 950; color: var(--gold); font-size: 20px; }
.standings { list-style: none; margin: 0; padding: 0; width: min(440px, 100%); display: grid; gap: 4px; }
.standings li { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 8px; padding: 6px 12px; background: #ffffff10; border-radius: 10px; font-weight: 800; text-align: left; }
.standings li.you { background: #ffd23f30; outline: 2px solid var(--gold); }
.standings .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.standings b { font-variant-numeric: tabular-nums; }

.podium { display: grid; grid-template-columns: repeat(3, 1fr); align-items: end; gap: 8px; width: min(420px, 100%); }
.podium div { display: flex; flex-direction: column; align-items: center; }
.podium .portrait { width: 72px; height: 86px; object-fit: contain; }
.podium .block { width: 100%; border-radius: 10px 10px 0 0; font-size: 28px; font-weight: 950; padding-top: 6px; color: #120a2e; }
.podium .p1 .block { height: 96px; background: var(--gold); }
.podium .p2 .block { height: 70px; background: #dfe4ef; }
.podium .p3 .block { height: 52px; background: #e7a56b; }
.podium .name { font-weight: 900; }

dialog { border: 0; border-radius: 22px; padding: 22px; width: min(420px, calc(100% - 24px)); background: #1d1f5c; color: #fff; text-align: center; }
dialog::backdrop { background: #070920c4; }
.pause-actions { display: grid; gap: 12px; margin-top: 16px; }

/* Chromebook screens lose ~120px to browser chrome: keep the whole title,
   all eight gymnasts and the toggles on one screen. */
@media (max-height: 760px) {
  .logo { margin-top: 10px; }
  .logo span { font-size: 44px; }
  .logo b { font-size: 50px; margin-top: 2px; }
}
@media (max-height: 560px) {
  .logo { margin-top: 8px; }
  .logo span { font-size: 34px; }
  .logo b { font-size: 36px; }
  .roster button { min-height: 76px; }
  .roster .portrait { height: 48px; }
  .tiers button { min-height: 110px; }
}
@media (prefers-reduced-motion: reduce) {
  #banner { animation: none; }
  .judge { transition: none; }
}
