:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --panel: rgba(8, 18, 39, 0.82);
  --panel-strong: rgba(8, 18, 39, 0.94);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f7fbff;
  --muted: #9fb0ca;
  --blue: #3f8cff;
  --cyan: #43dcff;
  --yellow: #ffd64a;
  --green: #65e884;
  --red: #ff667a;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #0c1730; color: var(--text); }
button, input, a { font: inherit; }
button, .button-link {
  min-height: 46px; border: 1px solid var(--line); border-radius: 14px; padding: 0 18px;
  background: rgba(255, 255, 255, 0.08); color: var(--text); cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease, opacity 150ms ease;
}
button:hover, .button-link:hover { transform: translateY(-1px); border-color: rgba(255, 255, 255, 0.35); background: rgba(255, 255, 255, 0.14); }
button:active, .button-link:active { transform: translateY(0); }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
button.primary { border-color: rgba(74, 153, 255, 0.65); background: linear-gradient(135deg, #2c73ff, #35b7ff); box-shadow: 0 10px 30px rgba(36, 117, 255, 0.3); font-weight: 800; }
button.accent { border-color: rgba(255, 213, 74, 0.72); background: linear-gradient(135deg, #ff9d2f, #ffd24a); color: #1c1b16; box-shadow: 0 10px 30px rgba(255, 185, 48, 0.28); font-weight: 900; }
button.ghost { background: transparent; }
.button-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.hidden { display: none !important; }
#game { display: block; width: 100%; height: 100%; touch-action: none; }
#screen-flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; z-index: 8; }
#screen-flash { background: rgba(255, 80, 40, 0.5); transition: opacity 420ms ease; }
#boost-fx {
  position: fixed; inset: 0; pointer-events: none; z-index: 8; opacity: 0; transition: opacity 250ms ease;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 52%, rgba(255, 138, 0, 0.4) 100%);
}
#boost-fx.on { opacity: 1; }
#speed-fx {
  position: fixed; inset: -22%; pointer-events: none; z-index: 8; opacity: 0; transition: opacity 300ms ease;
  background: repeating-conic-gradient(from 0deg, rgba(255, 255, 255, 0) 0deg 5deg, rgba(255, 255, 255, 0.16) 5deg 6.5deg);
  -webkit-mask-image: radial-gradient(circle at 50% 50%, transparent 40%, #000 78%);
  mask-image: radial-gradient(circle at 50% 50%, transparent 40%, #000 78%);
  animation: speedspin 500ms linear infinite;
}
#speed-fx.on { opacity: 1; }
@keyframes speedspin { to { transform: rotate(6.5deg); } }
.glass-card, #network-bar, #item-slot, #map {
  border: 1px solid var(--line); background: linear-gradient(150deg, rgba(11, 27, 57, 0.9), rgba(7, 15, 35, 0.72));
  box-shadow: 0 15px 45px rgba(0, 0, 0, 0.22), inset 0 1px rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
#network-bar {
  position: fixed; top: max(14px, env(safe-area-inset-top)); left: 50%; z-index: 20; display: flex; align-items: center;
  gap: 16px; min-height: 42px; padding: 6px 8px 6px 14px; border-radius: 999px; transform: translateX(-50%); font-size: 13px;
}
.room-badge, .network-stat { display: flex; align-items: center; gap: 8px; }
.room-badge strong { color: var(--yellow); letter-spacing: 0.12em; }
.network-stat { color: var(--muted); }
.network-stat span + span::before { content: "·"; margin-right: 8px; color: rgba(255, 255, 255, 0.3); }
#copy-invite-mini { min-height: 30px; border-radius: 999px; padding: 0 12px; font-size: 12px; }
.connection-dot { width: 9px; height: 9px; border-radius: 50%; background: #657087; box-shadow: 0 0 0 4px rgba(101, 112, 135, 0.16); }
.connection-dot.connecting { background: var(--yellow); box-shadow: 0 0 0 4px rgba(255, 214, 74, 0.16); animation: dot-pulse 900ms ease-in-out infinite; }
.connection-dot.online { background: var(--green); box-shadow: 0 0 0 4px rgba(101, 232, 132, 0.16); }
.connection-dot.offline { background: var(--red); box-shadow: 0 0 0 4px rgba(255, 102, 122, 0.16); }
@keyframes dot-pulse { 50% { opacity: 0.45; } }
#race-stats { position: fixed; top: max(72px, calc(env(safe-area-inset-top) + 58px)); left: max(18px, env(safe-area-inset-left)); z-index: 12; display: grid; gap: 5px; min-width: 158px; padding: 14px 16px; border-radius: 18px; }
#race-stats strong { font-size: 21px; }
#race-stats span { color: var(--muted); font-variant-numeric: tabular-nums; }
#race-stats .race-environment {
  margin-top: 4px; padding-top: 7px; border-top: 1px solid rgba(255,255,255,.1);
  color: #dff6ff; font-size: 11px; letter-spacing: .02em;
}
#roster { position: fixed; top: max(72px, calc(env(safe-area-inset-top) + 58px)); right: max(18px, env(safe-area-inset-right)); z-index: 12; width: min(250px, 31vw); padding: 9px; border-radius: 18px; }
.roster-row { display: grid; grid-template-columns: 28px 12px 1fr auto; align-items: center; gap: 8px; min-height: 34px; padding: 4px 7px; border-radius: 11px; color: var(--muted); font-size: 13px; }
.roster-row + .roster-row { border-top: 1px solid rgba(255, 255, 255, 0.06); }
.roster-row.self { color: #fff; background: rgba(63, 140, 255, 0.13); }
.roster-place { color: var(--yellow); font-weight: 900; }
.roster-color, .player-color { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 12px currentColor; }
.roster-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-gap { color: #dbe8fb; font-variant-numeric: tabular-nums; }
#map { position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); z-index: 11; width: 170px; height: 170px; border-radius: 50%; }
#speed-panel { position: fixed; left: max(18px, env(safe-area-inset-left)); bottom: max(20px, env(safe-area-inset-bottom)); z-index: 12; width: min(420px, calc(100vw - 230px)); text-shadow: 0 3px 14px rgba(0, 0, 0, 0.6); }
#speed { display: flex; align-items: baseline; gap: 8px; }
#speed strong { font-size: clamp(52px, 7vw, 88px); line-height: 0.85; font-style: italic; font-variant-numeric: tabular-nums; letter-spacing: -0.06em; }
#speed span { color: var(--muted); font-weight: 800; }
#nitro-gauge { width: min(360px, 100%); height: 12px; margin-top: 12px; overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 999px; background: rgba(4, 10, 24, 0.7); box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.45); }
#nitro-fill { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #25b7ff, #5af4ff, #fff3a5); box-shadow: 0 0 16px #46ddff; transition: width 80ms linear; }
.control-hint { margin-top: 9px; color: rgba(255, 255, 255, 0.7); font-size: 12px; }
#item-slot { position: fixed; left: max(18px, env(safe-area-inset-left)); bottom: max(154px, calc(env(safe-area-inset-bottom) + 134px)); z-index: 12; display: flex; align-items: center; gap: 12px; min-width: 205px; padding: 9px 13px 9px 9px; border-radius: 18px; }
#item-slot.empty { opacity: 0.66; }
#item-slot.empty-fire-ready { border-color: rgba(255, 138, 93, 0.95); box-shadow: 0 0 24px rgba(255, 101, 64, 0.32), 0 15px 45px rgba(0, 0, 0, 0.28); }
#item-slot.empty-fire-ready #item-action { color: #ffb08f; font-weight: 900; }
.item-icon-wrap { display: grid; place-items: center; width: 58px; height: 58px; overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.15); border-radius: 14px; background: radial-gradient(circle, rgba(74, 204, 255, 0.2), rgba(0, 0, 0, 0.15)); }
#item-icon { width: 52px; height: 52px; object-fit: contain; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35)); }
#item-question { color: rgba(255, 255, 255, 0.25); font-size: 31px; font-weight: 900; }
#item-slot.rolling .item-icon-wrap { animation: item-roll 120ms linear infinite; }
@keyframes item-roll { 50% { transform: scale(0.9) rotate(7deg); } }
#item-slot > div:last-child { display: grid; gap: 4px; }
#item-slot strong { font-size: 14px; }
#item-slot span { color: var(--muted); font-size: 12px; }
kbd { min-width: 22px; display: inline-grid; place-items: center; padding: 2px 5px; border: 1px solid rgba(255, 255, 255, 0.2); border-bottom-width: 2px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); color: #fff; font-size: 11px; font-family: inherit; }
#center-message { position: fixed; top: 45%; left: 50%; z-index: 30; pointer-events: none; transform: translate(-50%, -50%); color: #fff; font-size: clamp(64px, 12vw, 152px); font-weight: 1000; font-style: italic; letter-spacing: -0.08em; text-shadow: 0 7px 0 rgba(0, 0, 0, 0.18), 0 0 40px rgba(71, 187, 255, 0.7); }
#center-message.pop { animation: center-pop 260ms cubic-bezier(0.18, 0.9, 0.25, 1.25); }
@keyframes center-pop { from { transform: translate(-50%, -50%) scale(1.55); opacity: 0; } }
#toast { position: fixed; left: 50%; bottom: 23%; z-index: 40; max-width: min(560px, 86vw); padding: 12px 18px; border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 999px; background: rgba(5, 12, 29, 0.8); box-shadow: 0 16px 42px rgba(0, 0, 0, 0.32); transform: translate(-50%, 14px); opacity: 0; pointer-events: none; transition: opacity 180ms ease, transform 180ms ease; font-weight: 800; }
#toast.show { transform: translate(-50%, 0); opacity: 1; }
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); overflow: auto; background: radial-gradient(circle at 50% 35%, rgba(49, 127, 255, 0.2), transparent 40%), rgba(3, 8, 20, 0.56); backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px); }
.dialog { width: min(620px, 100%); border: 1px solid rgba(255, 255, 255, 0.17); border-radius: 28px; padding: clamp(23px, 4vw, 38px); background: linear-gradient(155deg, rgba(17, 38, 78, 0.96), rgba(5, 14, 34, 0.97)), var(--panel-strong); box-shadow: 0 32px 90px rgba(0, 0, 0, 0.48), inset 0 1px rgba(255, 255, 255, 0.09); }
.eyebrow { color: var(--cyan); font-size: 12px; font-weight: 900; letter-spacing: 0.18em; text-transform: uppercase; }
.dialog h1, .dialog h2 { margin: 8px 0 10px; line-height: 1; letter-spacing: -0.045em; }
.dialog h1 { font-size: clamp(36px, 7vw, 62px); }
.dialog h1 em { display: inline-block; color: var(--yellow); font-size: 0.42em; font-style: normal; letter-spacing: 0.08em; transform: translateY(-0.55em); }
.dialog h2 { font-size: clamp(32px, 5vw, 48px); }
.lead { margin: 0 0 25px; color: var(--muted); line-height: 1.65; }
.lobby-environment {
  width: fit-content; margin: -13px 0 22px; padding: 7px 12px;
  border: 1px solid rgba(67,220,255,.3); border-radius: 999px;
  background: rgba(35,124,176,.18); color: #dff7ff;
  font-size: 12px; font-weight: 800; letter-spacing: .025em;
}
label { display: grid; gap: 8px; margin-top: 15px; }
label span { color: #c7d5e9; font-size: 13px; font-weight: 750; }
input { width: 100%; min-height: 52px; border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 14px; outline: none; padding: 0 15px; background: rgba(0, 0, 0, 0.22); color: #fff; text-transform: none; transition: border-color 150ms ease, box-shadow 150ms ease; }
#room-code { text-transform: uppercase; letter-spacing: 0.18em; font-weight: 900; }
input:focus { border-color: var(--cyan); box-shadow: 0 0 0 4px rgba(67, 220, 255, 0.12); }
.button-row { display: flex; gap: 10px; margin-top: 20px; }
.button-row > * { flex: 1; }
.form-error { min-height: 20px; margin: 10px 0 0; color: #ff8d9c; font-size: 13px; }
.join-foot { display: flex; justify-content: space-between; gap: 16px; margin-top: 20px; padding-top: 17px; border-top: 1px solid rgba(255, 255, 255, 0.08); color: var(--muted); font-size: 12px; }
.join-foot a { color: #d8e8ff; }
.room-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 18px 0; padding: 13px 15px; border: 1px solid rgba(255, 255, 255, 0.11); border-radius: 16px; background: rgba(0, 0, 0, 0.16); }
.room-heading > div { display: grid; gap: 3px; }
.room-heading span { color: var(--muted); font-size: 12px; }
.room-heading strong { color: var(--yellow); font-size: 27px; letter-spacing: 0.14em; }
.room-heading button { min-height: 38px; font-size: 12px; }
.player-list { display: grid; gap: 8px; }
.player-card { display: grid; grid-template-columns: 13px 1fr auto; align-items: center; gap: 12px; min-height: 54px; padding: 9px 13px; border: 1px solid rgba(255, 255, 255, 0.09); border-radius: 15px; background: rgba(255, 255, 255, 0.045); }
.player-card.self { border-color: rgba(66, 150, 255, 0.45); background: rgba(63, 140, 255, 0.1); }
.player-card.offline { opacity: 0.48; }
.player-card strong { display: block; }
.player-meta { margin-top: 3px; color: var(--muted); font-size: 11px; }
.player-state { padding: 4px 9px; border-radius: 999px; background: rgba(255, 255, 255, 0.07); color: var(--muted); font-size: 11px; font-weight: 800; }
.player-state.ready { background: rgba(101, 232, 132, 0.13); color: var(--green); }
.room-note { margin: 13px 2px 0; color: var(--muted); font-size: 12px; text-align: center; }
.controls { margin-top: 22px; border-top: 1px solid rgba(255, 255, 255, 0.08); padding-top: 15px; color: var(--muted); font-size: 12px; }
.controls summary { cursor: pointer; color: #d9e7fa; }
.controls > div { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px 15px; margin-top: 13px; }
.controls b { color: #fff; }
.result-list { display: grid; gap: 9px; margin: 22px 0; }
.result-row { display: grid; grid-template-columns: 42px 12px 1fr auto; align-items: center; gap: 11px; min-height: 58px; padding: 10px 14px; border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 16px; background: rgba(255, 255, 255, 0.045); }
.result-row:first-child { border-color: rgba(255, 214, 74, 0.5); background: linear-gradient(90deg, rgba(255, 191, 46, 0.18), rgba(255, 255, 255, 0.035)); }
.result-place { color: var(--yellow); font-size: 22px; font-weight: 1000; }
.result-time { font-variant-numeric: tabular-nums; font-weight: 800; }
#reconnect-banner { position: fixed; top: max(72px, calc(env(safe-area-inset-top) + 58px)); left: 50%; z-index: 65; padding: 9px 14px; border: 1px solid rgba(255, 214, 74, 0.4); border-radius: 999px; background: rgba(31, 25, 6, 0.9); color: #ffe27c; transform: translateX(-50%); font-size: 12px; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3); }
@media (max-width: 720px) {
  #network-bar { top: max(8px, env(safe-area-inset-top)); width: calc(100% - 18px); justify-content: space-between; gap: 7px; padding-left: 10px; }
  .network-stat { display: none; }
  #race-stats { top: max(62px, calc(env(safe-area-inset-top) + 52px)); left: 10px; min-width: 132px; padding: 10px 12px; }
  #race-stats strong { font-size: 17px; }
  #roster { top: max(62px, calc(env(safe-area-inset-top) + 52px)); right: 10px; width: 45vw; }
  .roster-row { grid-template-columns: 22px 9px 1fr; gap: 5px; font-size: 11px; }
  .roster-gap { display: none; }
  #map { right: 9px; bottom: max(12px, env(safe-area-inset-bottom)); width: 112px; height: 112px; }
  #speed-panel { left: 11px; bottom: max(14px, env(safe-area-inset-bottom)); width: calc(100vw - 140px); }
  #speed strong { font-size: 50px; }
  .control-hint { display: none; }
  #item-slot { left: 10px; bottom: max(108px, calc(env(safe-area-inset-bottom) + 92px)); min-width: 160px; transform: scale(0.86); transform-origin: left bottom; }
  .dialog { border-radius: 22px; padding: 23px 18px; }
  .button-row { flex-direction: column; }
  .join-foot { flex-direction: column; gap: 7px; }
  .controls > div { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
