:root {
  --lagoon: #19b6c9;
  --lagoon-d: #0e8ea0;
  --sun: #ffd23f;
  --sun-d: #e0a800;
  --coral: #ff5d5d;
  --coral-d: #d93c3c;
  --leaf: #3fbf55;
  --leaf-d: #2a9a3f;
  --ink: #12305a;
  --sand: #fff4d6;
  --sand-d: #f3dfaa;
  --font: "Arial Rounded MT Bold", "Nunito", "Varela Round", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0e8ea0; font-family: var(--font); color: var(--ink); }
body { -webkit-font-smoothing: antialiased; user-select: none; }
#view { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
#hud { position: fixed; inset: 0; pointer-events: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
input, select, button, textarea { font-family: inherit; }

.screen { position: absolute; inset: 0; display: flex; overflow: auto; padding: clamp(14px, 3vw, 36px); }
.screen.dim { background: radial-gradient(ellipse at center, rgba(14, 142, 160, 0.35), rgba(18, 48, 90, 0.75)); }

.logo { margin: 0; line-height: 0.86; font-weight: 900; font-style: italic; letter-spacing: -0.02em; transform: rotate(-6deg) skewX(-6deg); transform-origin: left bottom; }
.logo span { display: block; color: var(--sun); -webkit-text-stroke: 0.12em var(--ink); paint-order: stroke fill; text-shadow: 0 0.09em 0 var(--ink); }
.logo span + span { color: var(--coral); margin-left: 0.6em; }
.logo.big { font-size: clamp(56px, 10vw, 132px); }
.logo.small { font-size: 42px; }

.title-layout { flex-direction: column; justify-content: space-between; gap: 24px; width: 100%; }
.title-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.title-menu { display: flex; flex-direction: column; gap: 14px; width: min(380px, 100%); margin-top: 28px; }
.title-hint { color: #fff; font-weight: 800; text-shadow: 0 2px 0 var(--ink); font-size: 15px; }

.btn { --bg: var(--sun); --bd: var(--sun-d); position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 10px; border: 4px solid var(--ink); border-radius: 16px; background: var(--bg); color: var(--ink); font-weight: 900; font-size: 18px; padding: 12px 20px; cursor: pointer; box-shadow: 0 6px 0 var(--ink); transition: transform 0.06s, box-shadow 0.06s, filter 0.1s; text-decoration: none; }
.btn:hover { filter: brightness(1.06); }
.btn:active, .btn.pressed { transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible { outline: 4px solid #fff; outline-offset: 3px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: 0 6px 0 var(--ink); }
.btn.big { font-size: clamp(20px, 2.4vw, 26px); padding: 16px 24px; justify-content: flex-start; }
.btn.coral { --bg: var(--coral); color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
.btn.lagoon { --bg: var(--lagoon); color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
.btn.leaf { --bg: var(--leaf); color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
.btn.sand { --bg: var(--sand); }
.btn.small { font-size: 15px; padding: 7px 12px; border-width: 3px; border-radius: 12px; box-shadow: 0 4px 0 var(--ink); }
.btn.small:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn .key { font-size: 12px; background: rgba(18, 48, 90, 0.12); border-radius: 6px; padding: 2px 6px; margin-left: auto; font-weight: 800; }
.btn-ico { width: 30px; height: 30px; flex: none; }

.panel { background: var(--sand); border: 4px solid var(--ink); border-radius: 22px; box-shadow: 0 8px 0 var(--ink); padding: clamp(16px, 2.4vw, 26px); }
.panel h2 { margin: 0 0 14px; font-size: 28px; font-weight: 900; }
.panel h3 { margin: 18px 0 8px; font-size: 18px; font-weight: 900; }
.panel p { margin: 6px 0; line-height: 1.45; }
.muted { opacity: 0.7; font-size: 14px; }

.center-col { margin: auto; width: min(560px, 100%); display: flex; flex-direction: column; gap: 18px; }
.wide { margin: auto; width: min(1180px, 100%); display: grid; gap: 22px; }
.two-col { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; font-weight: 800; font-size: 15px; }
.input { border: 3px solid var(--ink); border-radius: 12px; padding: 11px 13px; font-size: 18px; font-weight: 800; color: var(--ink); background: #fff; width: 100%; }
.input:focus { outline: 4px solid var(--lagoon); outline-offset: 1px; }
.input.code { text-transform: uppercase; letter-spacing: 0.25em; text-align: center; font-size: 24px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 800; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--coral); }
.error { color: var(--coral-d); font-weight: 900; min-height: 1.2em; margin: 6px 0 0; }

.seg { display: inline-flex; border: 3px solid var(--ink); border-radius: 12px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 8px 12px; font-weight: 900; font-size: 15px; color: var(--ink); cursor: pointer; }
.seg button + button { border-left: 3px solid var(--ink); }
.seg button.on { background: var(--lagoon); color: #fff; }
.seg button:focus-visible { outline: 3px solid var(--coral); outline-offset: -3px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 2px dashed rgba(18, 48, 90, 0.18); flex-wrap: wrap; }
.setting-row:last-child { border-bottom: 0; }
.setting-row > span { font-weight: 900; }

.tracks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.track-card { border: 4px solid var(--ink); border-radius: 16px; background: #fff; padding: 8px; cursor: pointer; text-align: left; color: var(--ink); font-weight: 900; box-shadow: 0 4px 0 var(--ink); transition: transform 0.06s; }
.track-card canvas { width: 100%; aspect-ratio: 4/3; display: block; border-radius: 10px; }
.track-card .tname { display: block; margin-top: 6px; font-size: 16px; }
.track-card .tveh { display: block; font-size: 12px; opacity: 0.7; }
.track-card.on { background: var(--sun); transform: translateY(-3px); box-shadow: 0 7px 0 var(--ink); }
.track-card:focus-visible { outline: 4px solid var(--coral); }
.track-desc { margin-top: 10px; font-size: 15px; min-height: 2.6em; }

.chars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.char { border: 3px solid var(--ink); border-radius: 14px; background: #fff; padding: 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; font-weight: 900; font-size: 13px; color: var(--ink); }
.char img { width: 100%; aspect-ratio: 1; display: block; }
.char.on { background: var(--sun); box-shadow: 0 0 0 3px var(--coral) inset; }
.char:focus-visible { outline: 4px solid var(--coral); }
.vehicles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.veh { border: 3px solid var(--ink); border-radius: 14px; background: #fff; padding: 4px; cursor: pointer; font-weight: 900; font-size: 14px; color: var(--ink); display: flex; flex-direction: column; align-items: center; }
.veh img { width: 100%; aspect-ratio: 4/3; object-fit: contain; }
.veh.on { background: var(--lagoon); color: #fff; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: center; font-size: 13px; font-weight: 900; margin-top: 10px; }
.stats i { display: block; height: 10px; border: 2px solid var(--ink); border-radius: 8px; background: linear-gradient(90deg, var(--leaf) var(--v), #fff var(--v)); }

.slots { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
@media (max-width: 640px) { .slots { grid-template-columns: 1fr; } }
.slot { border: 4px dashed rgba(18, 48, 90, 0.35); border-radius: 18px; min-height: 230px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 12px; gap: 6px; }
.slot.joined { border-style: solid; border-color: var(--ink); background: #fff; }
.slot.ready { background: #e6ffe9; }
.slot .pname { font-size: 20px; font-weight: 900; }
.slot .dev { font-size: 13px; opacity: 0.7; font-weight: 800; }
.slot img.portrait { width: 110px; height: 110px; }
.slot .picker { display: flex; align-items: center; gap: 8px; }
.slot .arrow { width: 38px; height: 38px; border: 3px solid var(--ink); border-radius: 50%; background: var(--sun); font-weight: 900; font-size: 18px; cursor: pointer; color: var(--ink); }
.slot .vrow { display: flex; gap: 6px; }
.slot .vrow button { border: 3px solid var(--ink); border-radius: 10px; background: #fff; padding: 4px 8px; font-weight: 900; font-size: 13px; cursor: pointer; color: var(--ink); }
.slot .vrow button.on { background: var(--lagoon); color: #fff; }
.slot .hint { font-size: 14px; font-weight: 800; opacity: 0.75; line-height: 1.5; }
.kbd { display: inline-block; border: 2px solid var(--ink); border-bottom-width: 4px; border-radius: 7px; padding: 0 6px; margin: 0 2px; font-size: 13px; background: #fff; }

.code-box { font-size: clamp(40px, 6vw, 64px); font-weight: 900; letter-spacing: 0.12em; color: var(--coral); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; line-height: 1; }
.members { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.member { display: flex; align-items: center; gap: 10px; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 6px 10px; }
.member img { width: 46px; height: 46px; }
.member .mname { font-weight: 900; font-size: 17px; }
.member .msub { font-size: 12px; opacity: 0.7; font-weight: 800; }
.member .tag { margin-left: auto; font-weight: 900; font-size: 13px; padding: 3px 9px; border-radius: 999px; border: 2px solid var(--ink); background: var(--sand-d); }
.member .tag.ready { background: var(--leaf); color: #fff; }
.member .pts { font-weight: 900; min-width: 52px; text-align: right; }
.member .kick { border: 0; background: transparent; cursor: pointer; font-size: 18px; color: var(--coral-d); font-weight: 900; }
.chat { display: flex; flex-direction: column; gap: 8px; }
.chat-log { height: 130px; overflow-y: auto; background: #fff; border: 3px solid var(--ink); border-radius: 12px; padding: 8px 10px; font-size: 14px; line-height: 1.4; user-select: text; }
.chat-log .sys { opacity: 0.6; font-style: italic; }
.room-list { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow: auto; }
.room-item { display: flex; align-items: center; gap: 10px; background: #fff; border: 3px solid var(--ink); border-radius: 12px; padding: 8px 12px; font-weight: 900; }
.empty-note { opacity: 0.65; font-weight: 800; font-size: 14px; }

table.results { width: 100%; border-collapse: separate; border-spacing: 0 6px; font-weight: 900; }
table.results td, table.results th { padding: 6px 10px; text-align: left; }
table.results th { font-size: 13px; opacity: 0.65; }
table.results tr.rrow td { background: #fff; border-top: 3px solid var(--ink); border-bottom: 3px solid var(--ink); }
table.results tr.rrow td:first-child { border-left: 3px solid var(--ink); border-radius: 12px 0 0 12px; font-size: 22px; }
table.results tr.rrow td:last-child { border-right: 3px solid var(--ink); border-radius: 0 12px 12px 0; }
table.results tr.me td { background: var(--sun); }
table.results img { width: 38px; height: 38px; vertical-align: middle; }
table.results .num { text-align: right; font-variant-numeric: tabular-nums; }

.account-chip { display: flex; align-items: center; gap: 8px; background: var(--sand); border: 4px solid var(--ink); border-radius: 999px; padding: 4px 6px 4px 14px; box-shadow: 0 4px 0 var(--ink); font-weight: 900; }
.account-chip img { width: 34px; height: 34px; }

.modal-wrap { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(18, 48, 90, 0.55); padding: 16px; z-index: 20; }
.modal { width: min(460px, 100%); max-height: 100%; overflow: auto; }
.modal.wide-modal { width: min(720px, 100%); }
.controls-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.controls-grid dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; font-size: 14px; }
.controls-grid dt { font-weight: 900; }
.controls-grid dd { margin: 0; }

#toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(220%); visibility: hidden; background: var(--ink); color: #fff; font-weight: 900; padding: 12px 20px; border-radius: 14px; transition: transform 0.25s; z-index: 50; pointer-events: none; max-width: 90vw; }
#toast.show { transform: translateX(-50%) translateY(0); visibility: visible; }

.pause-menu { margin: auto; width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; }

.hud { position: absolute; container-type: size; font-weight: 900; color: #fff; overflow: hidden; }
.hud + .hud { border-left: 3px solid var(--ink); border-top: 3px solid var(--ink); }
.hud-tl { position: absolute; left: 2.2cqw; top: 2.4cqh; text-shadow: 0 0.35cqh 0 var(--ink); -webkit-text-stroke: 0.4cqh var(--ink); paint-order: stroke fill; }
.hud-lap { font-size: clamp(16px, 6cqh, 44px); line-height: 1.05; }
.hud-time { font-size: clamp(13px, 4.2cqh, 30px); font-variant-numeric: tabular-nums; color: var(--sun); }
.hud-laptime { font-size: clamp(11px, 2.8cqh, 18px); opacity: 0.95; }
.hud-tr { position: absolute; right: 2.2cqw; top: 2.4cqh; display: flex; flex-direction: column; align-items: flex-end; gap: 1cqh; }
.hud-item { width: clamp(52px, 15cqh, 104px); height: clamp(52px, 15cqh, 104px); border: 0.7cqh solid var(--ink); border-radius: 22%; background: rgba(255, 244, 214, 0.92); display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 0.8cqh 0 var(--ink); }
.hud-item.empty { background: rgba(255, 244, 214, 0.45); }
.hud-item-icon svg { width: clamp(30px, 9.5cqh, 66px); height: auto; display: block; }
.hud-item-level { display: flex; gap: 3px; margin-top: 2px; }
.hud-item-level i { width: clamp(6px, 1.6cqh, 12px); height: clamp(6px, 1.6cqh, 12px); border-radius: 50%; border: 2px solid var(--ink); background: #fff; }
.hud-item-level i.on { background: var(--coral); }
.hud-item.pop { animation: pop 0.35s ease-out; }
@keyframes pop { 0% { transform: scale(0.6) rotate(-10deg); } 70% { transform: scale(1.15) rotate(4deg); } 100% { transform: scale(1); } }
.hud-coins { display: flex; align-items: center; gap: 6px; font-size: clamp(14px, 4.4cqh, 30px); text-shadow: 0 0.35cqh 0 var(--ink); -webkit-text-stroke: 0.4cqh var(--ink); paint-order: stroke fill; }
.coin { width: clamp(16px, 4.4cqh, 30px); height: clamp(16px, 4.4cqh, 30px); border-radius: 50%; background: radial-gradient(circle at 40% 35%, #fff3a0, var(--sun) 45%, var(--sun-d)); border: 3px solid var(--ink); display: inline-block; }
.hud-place { position: absolute; left: 2.2cqw; bottom: 2cqh; display: flex; align-items: baseline; gap: 0.6cqw; }
.hud-place b { font-size: clamp(40px, 18cqh, 150px); line-height: 0.9; color: var(--sun); font-style: italic; -webkit-text-stroke: 1.1cqh var(--ink); paint-order: stroke fill; text-shadow: 0 1cqh 0 var(--ink); }
.hud-place span { font-size: clamp(12px, 3.6cqh, 26px); -webkit-text-stroke: 0.4cqh var(--ink); paint-order: stroke fill; }
.hud-speed { position: absolute; right: 2.2cqw; bottom: 3cqh; width: clamp(90px, 24cqw, 230px); }
.hud-speed-bar { height: clamp(10px, 3cqh, 20px); border: 0.6cqh solid var(--ink); border-radius: 999px; background: rgba(255, 255, 255, 0.4); overflow: hidden; }
.hud-speed-bar i { display: block; height: 100%; width: 100%; transform-origin: left; background: linear-gradient(90deg, var(--leaf), var(--sun) 70%, var(--coral)); }
.hud.boosting .hud-speed-bar i { background: linear-gradient(90deg, var(--sun), var(--coral)); }
.hud-msg { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: clamp(30px, 16cqh, 140px); font-style: italic; color: var(--sun); -webkit-text-stroke: 1cqh var(--ink); paint-order: stroke fill; text-shadow: 0 1.2cqh 0 var(--ink); opacity: 0; transform: scale(0.6); transition: opacity 0.12s, transform 0.18s cubic-bezier(.3, 1.6, .5, 1); }
.hud-msg.show { opacity: 1; transform: scale(1); }
.hud-msg.warn { color: var(--coral); font-size: clamp(22px, 9cqh, 80px); }
.hud-msg.lap { font-size: clamp(24px, 10cqh, 90px); }
.hud-msg.finish { color: var(--sun); }
.hud-msg.go { color: var(--leaf); }
.hud-sub { position: absolute; left: 0; right: 0; top: 52%; text-align: center; font-size: clamp(14px, 4.5cqh, 34px); -webkit-text-stroke: 0.5cqh var(--ink); paint-order: stroke fill; opacity: 0; transition: opacity 0.2s; }
.hud-sub.show { opacity: 1; }
.hud-name { position: absolute; left: 50%; top: 2cqh; transform: translateX(-50%); background: var(--pc); border: 3px solid var(--ink); border-radius: 999px; padding: 2px 12px; font-size: clamp(12px, 3.4cqh, 20px); text-shadow: 0 2px 0 var(--ink); }
.minimap { position: absolute; right: 1.5vw; bottom: 12vh; width: min(24vmin, 210px); height: min(24vmin, 210px); filter: drop-shadow(0 3px 0 rgba(18, 48, 90, 0.5)); }
.spectate-label { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--sand); border: 4px solid var(--ink); border-radius: 999px; padding: 6px 16px; font-weight: 900; box-shadow: 0 4px 0 var(--ink); }

.loading { margin: auto; text-align: center; color: #fff; font-size: 28px; font-weight: 900; text-shadow: 0 3px 0 var(--ink); }
.loading .spinner { width: 64px; height: 64px; border-radius: 50%; border: 8px solid var(--sand); border-top-color: var(--coral); margin: 0 auto 14px; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .hud-msg, .hud-item.pop, .btn, #toast { transition: none !important; animation: none !important; }
}
a { color: var(--coral-d); font-weight: 900; }
body.pad-nav .btn:focus, body.pad-nav .track-card:focus, body.pad-nav .char:focus, body.pad-nav .veh:focus, body.pad-nav .seg button:focus, body.pad-nav input:focus, body.pad-nav a:focus { outline: 5px solid #fff; outline-offset: 3px; box-shadow: 0 0 0 9px var(--coral); position: relative; z-index: 2; }
body.pad-nav .seg button:focus { outline-offset: -5px; box-shadow: none; outline-color: var(--coral); }
