:root {
  --bg: #0a0d1e;
  --panel: #ffffff;
  --panel-solid: #ffffff;
  --chip: #ffffff;
  --chip-strong: #f2ede1;
  --border: #121212;

  --text: #121212;
  --muted: #4a4a4a;
  --ink: #121212;

  --cherry: #d6336c;
  --tangerine: #e8632c;
  --lime: #2f8a4e;
  --sky: #1f6fd6;
  --grape: #8b5fbf;
  --sun: #f2b52c;
  --red: #c62828;
  --yellow: #f2b52c;
  --hud-text: #121212;

  --font-display: "Kalam", cursive;
  --font-body: "Space Grotesk", sans-serif;

  --radius: 0px;
  --radius-sm: 0px;

  --shadow-sm: 3px 3px 0 var(--ink);
  --shadow-md: 5px 5px 0 var(--ink);
  --shadow-lg: 8px 8px 0 var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

button, input, select {
  font-family: var(--font-body);
}

::selection {
  background: var(--sun);
  color: #241a00;
}

:focus-visible {
  outline: 2px solid var(--sky);
  outline-offset: 2px;
}

h1, h2, h3 {
  margin: 0 0 8px 0;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--text);
}

h1 { font-size: 30px; letter-spacing: 0.2px; display: inline-block; transform: rotate(-1deg); }
h2 { font-size: 21px; display: inline-block; transform: rotate(-0.6deg); }
h3 {
  font-size: 12px;
  font-weight: 800;
  font-family: var(--font-body);
  color: var(--muted);
  margin: 16px 0 9px 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

p { margin: 4px 0; line-height: 1.5; }

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
  font-weight: 700;
}

.center-text { text-align: center; }
.hint-text { color: var(--muted); font-size: 12.5px; font-weight: 600; }

button {
  background: var(--chip);
  color: var(--text);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 10px 18px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, opacity 0.12s ease;
}

button:hover:not(:disabled) {
  background: var(--chip-strong);
  transform: translate(-2px, -2px);
  box-shadow: var(--shadow-md);
}

button:active:not(:disabled) { transform: translate(0, 0); box-shadow: 1px 1px 0 var(--ink); }

button:disabled { opacity: 0.45; cursor: default; box-shadow: 2px 2px 0 var(--ink); }

button.small { padding: 6px 12px; font-size: 12.5px; box-shadow: 2px 2px 0 var(--ink); }
button.block { width: 100%; }
button.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }
button.ghost:hover:not(:disabled) { background: var(--chip-strong); border-color: var(--ink); box-shadow: var(--shadow-sm); color: var(--text); transform: none; }

button.primary {
  background: var(--sky);
  border-color: var(--ink);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.2px;
  padding: 12px 22px;
  box-shadow: var(--shadow-md);
}

button.primary:hover:not(:disabled) {
  background: #2b7ce8;
  transform: translate(-2px, -2px);
  box-shadow: 7px 7px 0 var(--ink);
}

button.danger {
  color: #fff;
  background: var(--red);
  border-color: var(--ink);
}

button.danger:hover:not(:disabled) {
  background: #d94040;
}

input, select {
  background: #fff;
  color: var(--text);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: 14px;
  font-weight: 600;
  width: 100%;
}

input:focus, select:focus { outline: none; border-color: var(--sky); box-shadow: 3px 3px 0 rgba(31, 111, 214, 0.35); }

input::placeholder { color: rgba(18, 18, 18, 0.35); font-weight: 500; }

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%),
                     linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

select:disabled { opacity: 0.5; }
select option { color: #000; }

.field { margin-bottom: 14px; }
.row { display: flex; gap: 8px; }
.section-block { margin: 14px 0; }

.error-text {
  color: var(--red);
  font-size: 12.5px;
  min-height: 14px;
  margin-top: 8px;
  font-weight: 700;
}

.error-text.success-text { color: #2f9e44; }

#app {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.site-nav {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 12px 24px;
  background: var(--panel-solid);
  border-bottom: 2px solid var(--ink);
}

.site-nav-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text);
}

.site-nav-brand span {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
}

.site-nav-links {
  display: flex;
  gap: 6px;
  flex: 1;
}

.nav-link {
  text-decoration: none;
  color: var(--muted);
  font-weight: 700;
  font-size: 13.5px;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
}

.nav-link:hover { color: var(--text); }

.nav-link.active {
  color: #fff;
  background: var(--cherry);
}

.site-nav-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-username {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar-badge.small {
  width: 30px;
  height: 30px;
  font-size: 13px;
}

@media (max-width: 720px) {
  .site-nav { gap: 12px; padding: 9px 14px; flex-wrap: wrap; }
  .site-nav-links { gap: 2px; }
  .nav-username { display: none; }
}

.screen {
  display: none;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  position: relative;
}

.screen.active { display: flex; }

.panel {
  position: relative;
  background: var(--panel-solid);
  border: 2.5px solid var(--ink);
  border-radius: var(--radius);
  padding: 30px 26px 24px;
  width: 380px;
  box-shadow: var(--shadow-lg);
}

.panel-auth { width: 340px; }
.panel-menu { width: 360px; }
.panel-lobby { width: 600px; }
.panel-table { width: 460px; }

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 4px 0 4px;
}

.brand h1 { margin: 0; }

#screen-auth .panel { text-align: center; }
#screen-auth .field { text-align: left; }

.tab-row {
  display: flex;
  margin: 20px 0 18px 0;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 0;
  overflow: hidden;
}

.tab-row button {
  flex: 1;
  background: transparent;
  border: none;
  box-shadow: none;
  font-family: var(--font-body);
  font-weight: 700;
  color: var(--muted);
  border-radius: 0;
}

.tab-row button + button { border-left: 2px solid var(--ink); }

.tab-row button:hover:not(.active) { background: var(--chip-strong); transform: none; box-shadow: none; color: var(--text); }

.tab-row button.active {
  background: var(--ink);
  color: #fff;
  font-weight: 700;
}

.profile-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.avatar-badge {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  background: var(--tangerine);
  color: #fff;
}

.profile-summary-text { flex: 1; min-width: 0; }

.profile-summary-text h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 2px;
  max-width: 100%;
}

.cta-lobby {
  margin: 4px 0 18px;
  font-size: 18px;
  padding: 14px 22px;
}

.practice-card {
  position: relative;
  overflow: hidden;
  margin: 0 0 18px;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: #fdfbf6;
  border: 2px solid var(--ink);
}

.practice-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.practice-card h3 { margin: 0; font-size: 18px; font-family: var(--font-display); font-weight: 700; color: var(--text); text-transform: none; letter-spacing: 0; }

.eyebrow {
  display: block;
  margin-bottom: 1px;
  color: var(--sky);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.1px;
  text-transform: uppercase;
}

.practice-track-badge {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  color: #fff;
  background: var(--sky);
  border: 2px solid var(--ink);
  border-radius: 50%;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
}

.practice-card select { width: 100%; }
.practice-card .hint-text { min-height: 32px; margin: 8px 0 12px; line-height: 1.35; }
.practice-card .training-button { margin: 0 0 10px; background: #fff; }
.practice-card .bots-row { margin: 0 0 10px; }
.practice-card .bots-row select { flex: 1; width: auto; }
.practice-card .bots-button { margin: 0; color: var(--tangerine); border-color: var(--ink); }

.divider-label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 800;
  margin: 4px 0 12px;
}

.divider-label::before, .divider-label::after {
  content: "";
  flex: 1;
  height: 2px;
  background: var(--ink);
  opacity: 0.15;
}

.code-input {
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 4px;
  font-family: var(--font-display);
  font-weight: 700;
  text-align: center;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.secondary-actions {
  flex-direction: row;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 2px dashed var(--ink);
}

.secondary-actions button { flex: 1; }

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.lobby-code-block { text-align: right; }

.lobby-code {
  display: inline-block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 6px;
  color: var(--ink);
  background: var(--sun);
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  margin-top: 4px;
  border: 2px solid var(--ink);
  transform: rotate(-1.5deg);
}

.lobby-columns {
  display: flex;
  gap: 24px;
  margin-top: 6px;
}

.lobby-col { flex: 1; min-width: 0; }

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-radius: var(--radius-sm);
  max-height: 220px;
  overflow-y: auto;
  background: #fdfbf6;
  border: 2px solid var(--ink);
}

.player-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 13px;
  border-bottom: 2px solid var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.player-list li:last-child { border-bottom: none; }

.tag {
  font-size: 10.5px;
  font-weight: 800;
  color: #fff;
  padding: 3px 9px;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-sm);
  margin-left: 6px;
}

.tag.ready { background: var(--lime); color: #fff; }
.tag.not-ready { background: var(--red); }

.kart-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-bottom: 6px;
}

.kart-swatch {
  width: 30px;
  height: 30px;
  border: 2px solid var(--ink);
  cursor: pointer;
  border-radius: 50%;
  transition: transform 0.1s ease, border-color 0.1s ease;
}

.kart-swatch:hover { transform: scale(1.1); }

.kart-swatch.selected {
  box-shadow: 3px 3px 0 var(--ink);
}

.lobby-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 2px dashed var(--ink);
}

.game-screen { position: relative; background: #6fd6f2; }

.game-screen.active {
  display: block;
  width: 100vw;
  height: 100vh;
}

.game-cursor-hidden,
.game-cursor-hidden * { cursor: none !important; }

#game-canvas { display: block; width: 100%; height: 100%; }

.hud-top {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: stretch;
  gap: 10px;
  pointer-events: none;
}

.hud-cluster { display: flex; gap: 8px; }

.hud-box {
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.hud-lap, .hud-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 60px;
}

.hud-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 21px;
  font-variant-numeric: tabular-nums;
  color: var(--tangerine);
  line-height: 1.1;
}

.hud-value i {
  font-style: normal;
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}

.hud-label {
  font-size: 10px;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-top: 1px;
}

.hud-item {
  display: flex;
  align-items: center;
  font-size: 13px;
  font-weight: 800;
  border-radius: var(--radius-sm);
}

.hud-spacer { flex: 1; }

.hud-toolbar { display: flex; gap: 8px; }

.hud-btn {
  pointer-events: auto;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  border-radius: var(--radius-sm);
}

#minimap {
  position: absolute;
  bottom: 14px;
  right: 14px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: rgba(255, 255, 255, 0.85);
  box-shadow: var(--shadow-md);
}

#countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 104px;
  font-weight: 700;
  color: #fff;
  -webkit-text-stroke: 3px var(--ink);
  text-shadow: 0 6px 26px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

#wrong-way-overlay {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: none;
  font-family: var(--font-display);
  font-size: 46px;
  font-weight: 700;
  color: var(--red);
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
  letter-spacing: 1px;
  pointer-events: none;
  z-index: 5;
}

#wrong-way-overlay.visible {
  display: block;
}

#boost-overlay {
  position: absolute;
  inset: 0;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  z-index: 4;
  transition: opacity 0.15s ease-out;
}

#boost-overlay.visible {
  opacity: 1;
}

#boost-overlay .boost-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  filter: blur(0.3px);
  mask-image: radial-gradient(circle at center, transparent 30%, #000 46%);
  -webkit-mask-image: radial-gradient(circle at center, transparent 30%, #000 46%);
}

#boost-overlay .boost-lines-a,
#boost-overlay .boost-lines-b {
  transform-box: view-box;
  transform-origin: 100px 100px;
  animation: boost-burst 0.85s cubic-bezier(0.15, 0.6, 0.35, 1) infinite;
}

#boost-overlay .boost-lines-b {
  animation-delay: -0.425s;
}

#boost-overlay .boost-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255, 209, 102, 0) 62%, rgba(255, 209, 102, 0.25) 100%);
  animation: boost-pulse 0.4s ease-in-out infinite;
}

@keyframes boost-burst {
  0% { transform: scale(0.85); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: scale(1.15); opacity: 0; }
}

@keyframes boost-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  margin-bottom: 18px;
}

table th, table td {
  border-bottom: 2px solid var(--ink);
  padding: 10px 8px;
  text-align: left;
  color: var(--text);
}

table th {
  color: var(--muted);
  font-weight: 800;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 2.5px solid var(--ink);
}

table tbody tr:hover { background: var(--chip-strong); }

table td:first-child {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
}

table tbody tr:nth-child(1) td:first-child { color: var(--sun); -webkit-text-stroke: 0.6px var(--ink); }
table tbody tr:nth-child(2) td:first-child { color: #9aa0ab; }
table tbody tr:nth-child(3) td:first-child { color: var(--tangerine); }

.you-row {
  background: rgba(214, 51, 108, 0.1);
  box-shadow: inset 3px 0 0 var(--cherry);
}

.you-row td { color: var(--text); font-weight: 800; }

.stat-line {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 10px 0;
  border-bottom: 2px solid var(--ink);
}

.stat-line:last-child { border-bottom: none; }
.stat-line span:last-child { font-weight: 700; color: var(--cherry); font-family: var(--font-display); font-size: 16px; }

.hidden { display: none !important; }

.hud-connection { padding: 8px 11px; display: flex; align-items: center; }

.connection-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid var(--ink);
  background: #ccc;
  display: inline-block;
}

.hud-connection.connection-ok .connection-dot {
  background: var(--lime);
}

.hud-connection.connection-bad .connection-dot {
  background: var(--red);
  animation: pulse-dot 1s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

#debug-overlay {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  z-index: 5;
}

#debug-overlay.visible { display: flex; }

#debug-fps, #debug-info {
  background: rgba(18, 18, 18, 0.72);
  color: #fff;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
}

#debug-fps { display: none; }
#debug-fps.visible { display: block; }
#debug-info { display: none; }
#debug-info.visible { display: block; }

#pause-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(18, 18, 18, 0.55);
  z-index: 20;
}

#pause-overlay.visible { display: flex; }

.pause-panel { width: 300px; text-align: center; }
.pause-panel .hint-text { margin-bottom: 18px; }
.pause-panel button { margin-top: 8px; }

.app-modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 18, 18, 0.55);
  z-index: 1000;
  padding: 16px;
}

.app-modal-panel {
  width: 340px;
  max-width: 100%;
  text-align: center;
}

.app-modal-panel .hint-text { margin-bottom: 18px; }
.app-modal-panel button { margin-top: 8px; }

.settings-panel { width: 380px; text-align: left; max-height: 84vh; overflow-y: auto; }
.settings-panel h2 { display: block; }

.settings-group { margin-bottom: 6px; }
.settings-group h3 { margin: 14px 0 8px; }
.settings-group:first-of-type h3 { margin-top: 4px; }

.settings-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  margin-bottom: 0;
  border-bottom: 1.5px solid rgba(18, 18, 18, 0.08);
  cursor: pointer;
}

.settings-row:last-child { border-bottom: none; }

.settings-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--sky);
  flex-shrink: 0;
}

.settings-row-text { display: flex; flex-direction: column; gap: 2px; }
.settings-row-title { font-weight: 700; font-size: 14px; color: var(--text); }
.settings-row-hint { font-size: 11.5px; }

#toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  opacity: 0;
  transform: translateX(14px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: auto;
  box-shadow: var(--shadow-md);
}

.toast.toast-in { opacity: 1; transform: translateX(0); }
.toast.toast-out { opacity: 0; transform: translateX(14px); }

.toast-error { border-color: var(--red); }
.toast-info { border-color: var(--sky); }
.toast-success { border-color: var(--lime); }

.toast-msg { flex: 1; }

.toast-close {
  background: none;
  border: none;
  box-shadow: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  padding: 0 0 0 4px;
  cursor: pointer;
}

.toast-close:hover { color: var(--text); background: none; transform: none; box-shadow: none; }

@media (prefers-reduced-motion: reduce) {
  .connection-dot, .toast, button { animation: none !important; transition: none !important; }
}

@media (max-width: 720px) {
  html, body { font-size: 14px; }

  .panel-lobby { width: min(94vw, 420px); }
  .lobby-columns { flex-direction: column; gap: 18px; }

  .panel { padding: 24px 18px 18px; }
  .panel-auth, .panel-menu, .panel-table { width: min(92vw, 360px); }

  .hud-top { flex-wrap: wrap; }
  .hud-value { font-size: 18px; }
  #minimap { width: 110px; height: 110px; }

  #countdown-overlay { font-size: 64px; }
  #wrong-way-overlay { font-size: 32px; }
}

.training-button {
  margin: -8px 0 14px;
}

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--sky);
  outline-offset: 3px;
}

#touch-controls {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#touch-controls.visible { display: block; }

.touch-joystick {
  position: absolute;
  left: max(20px, env(safe-area-inset-left));
  bottom: max(22px, env(safe-area-inset-bottom));
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  border: 2px solid var(--ink);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  touch-action: none;
}

.touch-stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: var(--cherry);
  border: 2px solid var(--ink);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  will-change: transform;
}

.touch-action-buttons {
  position: absolute;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  width: 96px;
  height: 96px;
  pointer-events: none;
}

.touch-control {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  border: 2px solid var(--ink);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease, background 0.08s ease;
}

.touch-control:active,
.touch-control.pressed {
  transform: scale(0.94);
  background: rgba(255, 255, 255, 0.85);
}

.touch-item {
  right: 0;
  bottom: 0;
  width: 92px;
  height: 92px;
  font-size: 15px;
  background: rgba(242, 181, 44, 0.6);
}

@media (max-width: 600px), (pointer: coarse) {
  .hud-top { top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; gap: 6px; }
  .hud-box { padding: 6px 11px; }
  .hud-value { font-size: 18px; }
  .hud-label { font-size: 8px; }
  .hud-item { font-size: 11px; }
  .hud-toolbar { gap: 5px; }
  .hud-btn { font-size: 11px; }
  #minimap { width: 105px; height: 105px; right: 8px; bottom: 8px; }
  #btn-fullscreen { display: none; }
  #btn-pause-fullscreen { display: none; }
}

@media (max-width: 430px) {
  .touch-joystick { width: 105px; height: 105px; left: max(14px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom)); }
  .touch-stick { width: 48px; height: 48px; margin: -24px 0 0 -24px; }
  .touch-action-buttons { right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); transform: scale(0.9); transform-origin: bottom right; }
}

.game-screen,
.game-screen canvas { touch-action: none; }

.bg-scene-wrap {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--bg);
  overflow: hidden;
}

#bg-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.bg-scrim {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(6, 7, 18, 0.55) 0%, rgba(6, 7, 18, 0) 26%, rgba(6, 7, 18, 0) 62%, rgba(6, 7, 18, 0.6) 100%);
}

body.cinematic, html.cinematic {
  background: var(--bg);
  overflow: hidden;
}

body.cinematic #app { align-items: stretch; justify-content: stretch; }

.hud-screen {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(24px + env(safe-area-inset-top)) calc(34px + env(safe-area-inset-right)) calc(22px + env(safe-area-inset-bottom)) calc(34px + env(safe-area-inset-left));
  color: var(--text);
}

.hud-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex: 0 0 auto;
}

.hud-topbar-end { justify-content: flex-end; }

.hud-tabs {
  display: flex;
  gap: 0;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 0;
  box-shadow: var(--shadow-sm);
  transform: rotate(-1deg);
}

.hud-tab {
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--muted);
  border-radius: 0;
  padding: 9px 20px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  transform: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.hud-tab + .hud-tab { border-left: 2.5px solid var(--ink); }

.hud-tab:hover:not(.active) { color: var(--text); background: var(--chip-strong); transform: none; box-shadow: none; }

.hud-tab.active {
  background: var(--ink);
  color: #fff;
}

.hud-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  text-decoration: none;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 7px 16px;
  box-shadow: var(--shadow-sm);
  transform: rotate(2deg);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.hud-brand:hover { transform: rotate(0deg) scale(1.04); box-shadow: var(--shadow-md); }

.hud-brand svg { flex-shrink: 0; }

.hud-brand-logo {
  flex-shrink: 0;
  display: block;
  object-fit: contain;
  border-radius: 6px;
}

.hud-brand span {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.05;
  letter-spacing: 0.5px;
  text-shadow: none;
}

.menu-layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: auto;
  align-items: stretch;
  align-content: center;
  gap: 34px 28px;
  margin: 10px auto;
  width: 100%;
  max-width: 900px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
}

.menu-side { display: contents; }

.menu-tile { grid-column: 1 / 8; grid-row: 1; }
.menu-row-practice { grid-column: 8 / 13; grid-row: 1; }
.menu-row-online { grid-column: 1 / 13; grid-row: 2; }

.menu-tile, .menu-row {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 20px 18px 16px;
  border: 2.5px solid var(--ink);
  color: var(--text);
  text-decoration: none;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transform: rotate(-1.2deg);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.menu-tile:hover, .menu-tile:focus-within,
.menu-row:hover, .menu-row:focus-within {
  transform: rotate(0deg) translateY(-3px);
  box-shadow: var(--shadow-lg);
  z-index: 1;
}

.menu-row-practice { --row-accent: var(--sky); transform: rotate(1.4deg); }
.menu-row-online { --row-accent: var(--tangerine); transform: rotate(-0.8deg); }
.menu-tile { --row-accent: var(--tangerine); }

.menu-row {
  flex-direction: row;
  align-items: center;
  gap: 14px;
}

.menu-row-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--ink);
  display: grid;
  place-items: center;
  color: var(--row-accent, var(--text));
}

.menu-row-icon svg { width: 22px; height: 22px; }

.menu-row-body { flex: 1; min-width: 0; }

.menu-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.menu-row-title {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: inherit;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  text-align: left;
  cursor: pointer;
  transform: none;
}

.menu-row-title:hover:not(:disabled) { color: var(--row-accent, var(--tangerine)); background: none; transform: none; box-shadow: none; }
.menu-row-title-static { cursor: inherit; }

.menu-row-desc {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
  max-width: 96%;
}

.menu-row-tag {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--sun);
  border: 1.5px solid var(--ink);
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  color: var(--ink);
}

.menu-row-select {
  background: #fff;
  color: var(--text);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 4px 24px 4px 10px;
  font-size: 11px;
  font-weight: 700;
  width: auto;
}

.menu-row .tile-join-row { margin-top: 6px; }
.menu-row .code-input { background: #fff; color: var(--text); border: 2px solid var(--ink); }
.menu-row .tile-join-btn { background: var(--sun); color: var(--ink); }
.menu-row .tile-join-btn:hover:not(:disabled) { background: #ffd965; }

.tile-media,
.tile-media-bots,
.tile-icon,
.tile-icon-right,
.tile-gradient { display: none; }

.tile-row-top {
  position: static;
  z-index: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0;
}

.tile-select {
  background: #fff;
  color: var(--text);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 5px 26px 5px 12px;
  font-size: 11.5px;
  font-weight: 700;
  width: auto;
}

.tile-select:focus { box-shadow: 2px 2px 0 var(--ink); border-color: var(--sky); }

.tile-selects { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.menu-tile.menu-mode-hidden,
.menu-row.menu-mode-hidden {
  display: none;
}

.profile-mini { display: flex; align-items: center; gap: 12px; }
.profile-mini .tile-label-btn { margin: 0; font-size: 18px; }
.profile-mini h2.tile-label-btn { display: block; }

.tile-join-row { display: flex; gap: 8px; margin-top: 4px; min-width: 0; flex-wrap: wrap; }

.tile-join-row .code-input {
  background: #fff;
  color: var(--text);
  border: 2px solid var(--ink);
  width: auto;
  min-width: 0;
  flex: 1;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}

.tile-join-btn {
  background: var(--sun);
  color: var(--ink);
  box-shadow: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 800;
  flex-shrink: 0;
  transform: none;
}

.tile-join-btn:hover:not(:disabled) { background: #ffd965; transform: none; }

.tile-public-btn {
  background: var(--tangerine, #ff8a4c);
  color: #fff;
}

.tile-public-btn:hover:not(:disabled) { background: #ff9d68; transform: none; }

.tile-body {
  position: static;
  z-index: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0;
  pointer-events: auto;
}

.tile-eyebrow {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--tangerine);
}

.tile-label-btn {
  align-self: flex-start;
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0;
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 21px;
  letter-spacing: 0.2px;
  text-align: left;
  cursor: pointer;
  transform: none;
}

.tile-label-btn:hover:not(:disabled) { color: var(--tangerine); background: none; transform: none; box-shadow: none; }
.tile-label-btn.tile-label-static { cursor: inherit; }

.tile-badge {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-right: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: var(--sun);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 800;
  vertical-align: middle;
}

.tile-desc {
  max-width: 92%;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.hud-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 10px;
}

.hud-footer:has(.hud-footer-actions:only-child) {
  justify-content: flex-end;
}

.hud-footer-status {
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 8px 16px;
  transform: rotate(-0.6deg);
}

.hud-footer-label {
  display: block;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}

.hud-footer-status h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  transform: none;
  text-transform: none;
  letter-spacing: 0;
}

.hud-footer-status .error-text { margin-top: 4px; }

.hud-footer-actions.site-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  background: none;
  border: none;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hud-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 700;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 7px 13px;
  transform: rotate(1deg);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.hud-chip:hover { color: var(--ink); background: var(--chip-strong); transform: rotate(0deg) translateY(-2px); box-shadow: var(--shadow-md); }

.hud-chip-icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--sun);
  font-size: 9px;
}

@media (max-width: 980px) {
  .hud-screen { padding: calc(18px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
  .hud-footer { flex-direction: column; align-items: stretch; gap: 10px; }
  .hud-footer-actions.site-nav { justify-content: flex-start; }
}

@media (max-width: 720px) {
  .menu-layout { grid-template-columns: 1fr; gap: 26px; }
  .menu-tile, .menu-row-practice, .menu-row-online {
    grid-column: 1 / -1;
    grid-row: auto;
  }

  html, body { overflow-y: auto; overflow-x: hidden; height: auto; min-height: 100%; -webkit-overflow-scrolling: touch; }
  html.cinematic, body.cinematic { overflow-y: auto; overflow-x: hidden; height: auto; min-height: 100%; }
  .hud-screen { height: auto; min-height: 100dvh; }
  #app { min-height: 100dvh; }
  .hud-card-shell { flex: 0 0 auto; padding: 6px 0 18px; align-items: stretch; }
  .hud-card { overflow: visible; }

  .hud-footer-status { display: none; }
}

@media (max-width: 560px) {
  .hud-tab { padding: 8px 14px; font-size: 13px; }
  .tile-label-btn { font-size: 18px; }
  .menu-row-title { font-size: 17px; }
}

.auth-shell {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
}

.auth-card {
  width: 380px;
  max-width: 92vw;
  padding: 30px 28px;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  transform: rotate(-0.8deg);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.auth-brand span {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  color: var(--text);
}

.auth-tagline { color: var(--muted); font-size: 13px; margin: 0 0 22px; font-weight: 600; }

.hud-tabs.auth-tabs { margin-bottom: 20px; background: #fff; transform: none; width: 100%; }
.hud-tabs.auth-tabs .hud-tab { flex: 1; }

#screen-auth .field label { color: var(--muted); }

#screen-auth .field input {
  background: #fff;
  color: var(--text);
  border: 2px solid var(--ink);
}

#screen-auth .field input:focus { border-color: var(--sky); box-shadow: 3px 3px 0 rgba(31, 111, 214, 0.3); }

#screen-auth button.primary {
  border-radius: var(--radius-sm);
}

@media (max-width: 560px) {
  .hud-screen.auth-hud { padding: 18px 18px 22px; }
  .auth-card { width: 100%; transform: none; }
}

.hud-card-shell {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.hud-card {
  position: relative;
  width: 400px;
  max-width: 92vw;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  box-shadow: var(--shadow-lg);
  transform: rotate(-0.6deg);
}

.hud-card-wide { width: 540px; }

.hud-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 24px 4px;
}

.hud-card-header h2 { color: var(--text); margin: 0; }

.hud-card-header-tags {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.garage-coins-badge { background: var(--sun); color: #241a00; }

.hud-card-flag { display: none; }

.hud-card-body { padding: 16px 24px 26px; }

.hud-card-tag {
  font-family: var(--font-body);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #fff;
  background: var(--grape);
  border: 1.5px solid var(--ink);
  padding: 4px 11px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.hud-card .profile-summary { margin-top: 6px; }
.hud-card .profile-summary-text h2 { font-size: 19px; color: var(--text); }
.hud-card .hint-text { color: var(--muted); }

.hud-card table { margin-bottom: 0; }
.hud-card .you-row { background: rgba(214, 51, 108, 0.1); box-shadow: inset 3px 0 0 var(--cherry); }

.rank-medal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 13px;
}

.rank-medal-gold { background: var(--sun); }
.rank-medal-silver { background: #c7c9d9; }
.rank-medal-bronze { background: var(--tangerine); }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: #fdfbf6;
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.stat-tile-wide { grid-column: 1 / 3; flex-direction: row; align-items: center; justify-content: space-between; }

.stat-tile-label {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-tile-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  color: var(--cherry);
}

.stat-tile-wide .stat-tile-value { font-size: 20px; }

@media (max-width: 560px) {
  .hud-card { padding: 0; transform: none; }
  .hud-card-wide { width: 100%; }
}

#garage-card.hud-card-wide { width: min(880px, 94vw); }

.garage-layout {
  display: flex;
  gap: 22px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

.garage-preview {
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
}

.garage-preview-canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: linear-gradient(180deg, #dff3ff 0%, #fdfbf6 72%);
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.garage-preview-canvas-wrap canvas { width: 100%; height: 100%; display: block; }

.garage-preview-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  text-align: center;
}

.garage-preview-hint { text-align: center; min-height: 16px; }

.garage-grid {
  flex: 1 1 340px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(126px, 1fr));
  gap: 12px;
  align-content: start;
  max-height: min(56vh, 480px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 3px 6px 3px 3px;
  scrollbar-width: thin;
  scrollbar-color: var(--ink) transparent;
}

.garage-grid::-webkit-scrollbar { width: 8px; }
.garage-grid::-webkit-scrollbar-track { background: transparent; }
.garage-grid::-webkit-scrollbar-thumb { background: var(--ink); border-radius: 8px; }

.car-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  background: #fdfbf6;
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 12px 12px 14px;
  cursor: pointer;
  text-align: left;
  font-family: var(--font-body);
  color: var(--text);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.car-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

.car-card.selected {
  border-color: var(--cherry);
  box-shadow: 3px 3px 0 var(--cherry);
}

.car-card.locked { background: #f3f1ea; }
.car-card.locked .car-card-swatch { opacity: 0.55; }
.car-card.busy { opacity: 0.7; cursor: default; }

.car-card-swatch {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--ink);
  background: var(--chip-strong);
  display: grid;
  place-items: center;
  font-size: 22px;
}

.car-card-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
}

.car-card-tag {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: var(--lime);
  color: #fff;
  border: 1.5px solid var(--ink);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}

.car-card-price {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: var(--sun);
  color: #241a00;
  border: 1.5px solid var(--ink);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}

@media (max-width: 640px) {
  #garage-card.hud-card-wide { width: 100%; }
  .garage-preview { flex: 1 1 100%; position: static; }
  .garage-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); max-height: none; overflow: visible; gap: 9px; }
  .car-card { padding: 9px 9px 11px; }
  .car-card-swatch { height: 36px; font-size: 18px; }
  .car-card-name { font-size: 13px; }
}
