:root {
  --blue: #1E5AA8;
  --night: #0E1A2B;
  --cream: #F4ECD8;
  --gold: #E8B33A;
  --red: #C8402F;
  --ink: #1A1A1A;
  --glass: rgba(14, 26, 43, 0.78);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--cream); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
button { font: inherit; cursor: pointer; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* loading + menus */
#loading { background: var(--night) url("assets/ui/menu-bg.svg") center / cover; display: none; place-items: center; text-align: center; }
#loading.active { display: grid; align-content: center; justify-items: center; gap: 12px; }
#loading .logo { width: min(520px, 86vw); }
#menu, #lobby { overflow-y: auto; padding: 24px 16px; background: linear-gradient(90deg, rgba(14,26,43,.86) 0%, rgba(14,26,43,.55) 55%, rgba(14,26,43,.1) 100%); }
#menu.active, #lobby.active { display: block; }
.menu-card { max-width: 560px; display: grid; gap: 14px; }
.menu-card .logo { width: min(460px, 100%); }
.menu-card h2 { margin: 0; font-family: Impact, "Arial Black", sans-serif; font-weight: 400; letter-spacing: 1px; font-size: 32px; }
.tag-line { margin: 0; font-size: 16px; }
.tag-line b { color: var(--gold); }
.field { display: grid; gap: 4px; font-size: 13px; color: #c9d4e3; }
input { font: inherit; padding: 10px 12px; border-radius: 10px; border: 2px solid #2b3d57; background: #0b1524; color: var(--cream); }
input:focus { outline: none; border-color: var(--gold); }
.stats-row { display: flex; flex-wrap: wrap; gap: 8px; }
.stats-row span { display: inline-flex; align-items: center; gap: 6px; background: var(--glass); border-radius: 999px; padding: 4px 12px 4px 6px; }
.stats-row img { height: 24px; }
.stats-row b { color: var(--gold); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.online { display: flex; gap: 6px; }
.online input { width: 92px; text-transform: uppercase; text-align: center; font-weight: 700; }
.primary, .secondary, .ghost { border-radius: 12px; padding: 12px 20px; font-weight: 800; border: 0; display: inline-flex; align-items: center; gap: 8px; }
.primary { background: var(--gold); color: var(--ink); box-shadow: 0 4px 0 #9a7417; }
.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #9a7417; }
.secondary { background: var(--blue); color: var(--cream); box-shadow: 0 4px 0 #123a6f; }
.secondary img { height: 22px; }
.ghost { background: transparent; color: var(--cream); border: 2px solid #3a4f6e; }
.msg { min-height: 20px; margin: 0; color: #ffb4a8; }
.hint { margin: 0; color: #c9d4e3; }

.stable { background: var(--glass); border-radius: 14px; padding: 10px 14px; }
.stable summary { cursor: pointer; font-weight: 700; }
#stableList { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
#stableList li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; background: rgba(255,255,255,.04); }
#stableList li.sel { outline: 2px solid var(--gold); }
#stableList .sw { display: inline-flex; }
#stableList .sw i { width: 16px; height: 22px; display: inline-block; border: 1px solid var(--ink); }
#stableList .sw i:first-child { border-radius: 6px 0 0 6px; }
#stableList .sw i:last-child { border-radius: 0 6px 6px 0; }
#stableList .nm { flex: 1; }
#stableList button { background: var(--blue); color: var(--cream); border: 0; border-radius: 8px; padding: 6px 12px; font-weight: 700; }
#stableList button:disabled { opacity: .45; cursor: not-allowed; }
#stableList .tag { color: var(--gold); font-weight: 800; }

.controls-help { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: #c9d4e3; }
kbd { display: inline-block; min-width: 22px; padding: 1px 6px; border-radius: 5px; background: var(--cream); color: var(--ink); font: 700 12px system-ui; text-align: center; margin-right: 2px; }
.credit { font-size: 11px; color: #8ea0b8; margin: 0; }

.lobby-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.lobby-list li { display: flex; align-items: center; gap: 6px; background: var(--glass); border-radius: 10px; padding: 8px 12px; }
.lobby-list i { width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--ink); }
.lobby-list em { color: var(--gold); font-style: normal; font-size: 12px; margin-left: 4px; }
.lobby-list span { margin-left: auto; color: #ffb4a8; font-weight: 700; }
.lobby-list span.ok { color: #8fe3a1; }

/* HUD */
#hud { pointer-events: none; }
#hud button, #hud .touch { pointer-events: auto; }
.hud-tl { position: absolute; top: 14px; left: 14px; display: grid; gap: 4px; }
.pos { font: 400 56px/1 Impact, "Arial Black", sans-serif; color: var(--gold); text-shadow: 0 3px 0 var(--ink); }
.pos sup { font-size: 24px; }
.pos small { font-size: 24px; color: var(--cream); }
.clock { font: 700 18px ui-monospace, Menlo, monospace; background: var(--glass); padding: 2px 10px; border-radius: 8px; justify-self: start; }
.board { list-style: none; margin: 4px 0 0; padding: 6px 8px; background: var(--glass); border-radius: 10px; font-size: 13px; min-width: 180px; }
.board li { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.board li.me { color: var(--gold); font-weight: 800; }
.board b { width: 16px; }
.board i { width: 10px; height: 10px; border-radius: 3px; border: 1px solid var(--ink); }
.board em { margin-left: auto; font-style: normal; color: #9fb0c7; font-size: 12px; }
.street { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); background: var(--cream); color: var(--ink); border: 3px solid var(--ink); border-radius: 8px; padding: 4px 16px; font-weight: 800; font-size: 18px; white-space: nowrap; }
.street:empty { display: none; }
.street.pop { animation: pop .4s ease-out; }
@keyframes pop { from { transform: translateX(-50%) scale(1.25); } }
#minimap { position: absolute; top: 60px; right: 14px; width: 190px; height: 190px; background: rgba(14,26,43,.55); border-radius: 50%; border: 3px solid rgba(232,179,58,.6); }
.hud-tr-btns { position: absolute; top: 14px; right: 14px; display: flex; gap: 6px; }
.pill { background: var(--glass); color: var(--cream); border: 0; border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 13px; }
.hud-bl { position: absolute; left: 14px; bottom: 18px; display: grid; gap: 8px; }
.speed { display: flex; align-items: baseline; gap: 6px; }
.speed img { height: 28px; align-self: center; }
.speed b { font: 400 52px/1 Impact, "Arial Black", sans-serif; text-shadow: 0 3px 0 var(--ink); }
.speed small { font-weight: 700; color: #c9d4e3; }
.stamina { display: flex; align-items: center; gap: 8px; }
.stamina img { height: 26px; }
.stamina .bar { width: 200px; height: 14px; background: var(--glass); border-radius: 8px; overflow: hidden; border: 2px solid var(--ink); }
#staminaFill { height: 100%; width: 100%; background: linear-gradient(90deg, #4cc36b, #a6e36c); transition: width .1s; }
#staminaFill.low { background: var(--red); }
.whip { display: flex; align-items: center; gap: 8px; opacity: .45; font-weight: 800; font-size: 12px; }
.whip img { height: 34px; }
.whip.ready { opacity: 1; }
.whip.boost img { animation: shake .2s infinite; }
@keyframes shake { 50% { transform: rotate(-18deg); } }
.progress { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); width: min(420px, 50vw); height: 12px; background: var(--glass); border-radius: 8px; border: 2px solid var(--ink); }
#progressFill { height: 100%; width: 0; background: var(--gold); border-radius: 6px; }
.progress span { position: absolute; left: 0; right: 0; top: -22px; text-align: center; font-weight: 700; font-size: 13px; text-shadow: 0 1px 2px #000; }
.count { position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%); font: 400 150px/1 Impact, "Arial Black", sans-serif; color: var(--gold); -webkit-text-stroke: 6px var(--ink); opacity: 0; transition: opacity .2s; }
.count.show { opacity: 1; }
.flash { position: absolute; top: 22%; left: 50%; transform: translateX(-50%); background: var(--glass); padding: 8px 18px; border-radius: 12px; font-weight: 800; font-size: 20px; opacity: 0; transition: opacity .25s; white-space: nowrap; }
.flash.show { opacity: 1; }
.flash.warn { color: #ffb4a8; }
.flash.gold { color: var(--gold); font-size: 28px; }
.wrongway { position: absolute; top: 45%; left: 50%; transform: translate(-50%, -50%); font: 400 60px Impact, sans-serif; color: var(--red); -webkit-text-stroke: 3px var(--ink); opacity: 0; }
.wrongway.show { opacity: 1; animation: blink .6s infinite; }
@keyframes blink { 50% { opacity: .3; } }

.touch { display: none; position: absolute; left: 0; right: 0; bottom: 70px; justify-content: space-between; padding: 0 16px; }
.touch button { width: 70px; height: 70px; border-radius: 50%; border: 3px solid var(--ink); background: rgba(244,236,216,.82); color: var(--ink); font-weight: 900; font-size: 18px; touch-action: none; user-select: none; -webkit-user-select: none; }
.touch button.on { background: var(--gold); }
.touch-l, .touch-r { display: flex; gap: 10px; align-items: flex-end; }
.t-gas { width: 86px !important; height: 86px !important; background: rgba(76,195,107,.9) !important; }
.t-whip { background: rgba(232,179,58,.95) !important; }
@media (pointer: coarse) {
  .touch { display: flex; }
  .hud-bl { bottom: 180px; }
  .board { display: none; }
}

/* results */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; z-index: 5; }
.modal-card { background: var(--cream); color: var(--ink); border: 4px solid var(--gold); border-radius: 18px; padding: 20px 22px; width: min(480px, 100%); text-align: center; animation: modalIn .25s ease-out; max-height: 100%; overflow: auto; }
@keyframes modalIn { from { transform: scale(.88); opacity: 0; } }
.res-medal img { height: 110px; }
.modal-card h2 { margin: 4px 0 10px; font-family: Impact, "Arial Black", sans-serif; font-weight: 400; font-size: 28px; letter-spacing: .5px; }
.res-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.res-table th { text-align: left; color: #6b6355; font-weight: 600; border-bottom: 2px solid #ddd2bb; padding: 4px; }
.res-table td { text-align: left; padding: 4px; border-bottom: 1px solid #e6dcc6; }
.res-table tr.me td { font-weight: 800; background: rgba(232,179,58,.25); }
.res-prize { font-size: 16px; }
.res-prize b { color: #9a6b00; }
.modal-card .actions { justify-content: center; }
.modal-card .ghost { color: var(--ink); border-color: #bfb39a; }

@media (max-width: 640px) {
  .pos { font-size: 40px; }
  #minimap { width: 120px; height: 120px; top: 54px; }
  .street { top: 54px; font-size: 14px; max-width: 70vw; overflow: hidden; text-overflow: ellipsis; }
  .speed b { font-size: 38px; }
  .stamina .bar { width: 130px; }
  .count { font-size: 100px; }
}
