/* ============ Micro Machines — Tabletop Turbo ============ */
* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; }

:root {
  --red: #d43a2f;
  --yellow: #ffd23a;
  --blue: #2f6fd4;
  --dark: #10131c;
  --panel: rgba(12, 15, 24, 0.88);
}

html, body { width: 100%; height: 100%; overflow: hidden; background: #0a0c12; }

body {
  font-family: 'Trebuchet MS', 'Arial Black', Arial, sans-serif;
  color: #fff;
}

#game-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 4;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(5, 8, 16, 0.32) 100%);
}

.hidden { display: none !important; }

/* ============ checker strips ============ */
.checker-strip {
  position: absolute; left: 0; right: 0; height: 28px; z-index: 5;
  background:
    repeating-conic-gradient(#111 0% 25%, #eee 0% 50%) 0 0 / 28px 28px;
  opacity: 0.9;
}
.checker-strip.top { top: 0; }
.checker-strip.bottom { bottom: 0; }

/* ============ Title ============ */
#title-screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
}
#title-screen > * { pointer-events: auto; }

#logo { text-align: center; margin-bottom: 5vh; transform: rotate(-2.5deg); }
#logo-micro {
  font-size: clamp(38px, 7vw, 84px);
  font-weight: 900; font-style: italic; letter-spacing: 0.04em; line-height: 0.95;
  color: #fff;
  text-shadow:
    0 2px 0 #b8c4d6, 0 4px 0 #8fa1ba, 0 6px 0 #6d7f99,
    0 8px 0 #4d5c74, 0 10px 18px rgba(0,0,0,0.75);
  -webkit-text-stroke: 2px #1c2f57;
}
#logo-machines {
  font-size: clamp(46px, 9vw, 110px);
  font-weight: 900; font-style: italic; letter-spacing: 0.02em; line-height: 0.95;
  color: var(--yellow);
  text-shadow:
    0 2px 0 #d98916, 0 4px 0 #a86410, 0 6px 0 #7a440b,
    0 9px 20px rgba(0,0,0,0.8);
  -webkit-text-stroke: 2px #5c2f04;
}
#logo-sub {
  display: inline-block;
  margin-top: 14px; padding: 4px 18px;
  background: var(--red); border: 3px solid #fff; border-radius: 999px;
  font-weight: 900; font-size: clamp(12px, 1.6vw, 20px); letter-spacing: 0.35em;
  box-shadow: 0 4px 14px rgba(0,0,0,0.6);
}

#menu { display: flex; flex-direction: column; gap: 12px; width: min(340px, 80vw); }

.menu-btn {
  font-family: inherit; font-weight: 900; font-style: italic;
  font-size: clamp(15px, 1.9vw, 21px); letter-spacing: 0.06em;
  padding: 12px 22px; cursor: pointer; color: #fff;
  background: linear-gradient(180deg, #2a3350 0%, #161b2e 100%);
  border: 3px solid #4a5680; border-radius: 12px;
  text-shadow: 0 2px 3px rgba(0,0,0,0.8);
  box-shadow: 0 5px 0 #0a0d18, 0 8px 16px rgba(0,0,0,0.5);
  transition: transform 0.08s ease, border-color 0.12s, background 0.12s;
}
.menu-btn:hover, .menu-btn.kb-focus {
  border-color: var(--yellow); color: var(--yellow);
  transform: translateY(-2px) scale(1.02);
  background: linear-gradient(180deg, #37436b 0%, #1d2440 100%);
}
.menu-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #0a0d18; }

#title-hint {
  margin-top: 4vh; font-size: clamp(12px, 1.4vw, 17px); font-weight: 700;
  color: #9fb2d8; text-shadow: 0 2px 4px #000; letter-spacing: 0.08em;
}

/* ============ Panels ============ */
.panel {
  position: fixed; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--panel); backdrop-filter: blur(6px);
  gap: 16px; padding: 24px;
}
.panel h2 {
  font-size: clamp(26px, 4vw, 44px); font-weight: 900; font-style: italic;
  color: var(--yellow); letter-spacing: 0.05em;
  text-shadow: 0 3px 0 #a86410, 0 6px 14px rgba(0,0,0,0.7);
  margin-bottom: 8px;
}
.back-btn { margin-top: 10px; }

.help-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 34px;
  font-size: clamp(14px, 1.7vw, 19px); font-weight: 700;
}
.key {
  display: inline-block; min-width: 34px; text-align: center;
  background: #eef1f7; color: #1a1e2c; border-radius: 7px;
  padding: 3px 9px; margin-right: 10px; font-weight: 900;
  border-bottom: 3px solid #9aa3b8;
}
.help-tip { max-width: 620px; text-align: center; line-height: 1.55; color: #cdd8ee; font-size: clamp(13px, 1.5vw, 17px); }
.help-tip b { color: var(--yellow); }

/* level cards */
#level-cards { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
.level-card {
  width: 210px; padding: 14px 12px 12px; cursor: pointer;
  background: linear-gradient(180deg, #232c49, #131828);
  border: 3px solid #4a5680; border-radius: 14px; text-align: center;
  transition: transform 0.1s, border-color 0.12s;
}
.level-card:hover, .level-card.kb-focus { border-color: var(--yellow); transform: translateY(-4px) scale(1.03); }
.level-card .lc-num { font-size: 13px; color: #8fa1c8; font-weight: 800; letter-spacing: 0.25em; }
.level-card .lc-name { font-size: 20px; font-weight: 900; font-style: italic; color: #fff; margin: 4px 0 2px; }
.level-card .lc-sub { font-size: 12.5px; color: #9fb2d8; min-height: 30px; }
.level-card .lc-best { font-size: 12px; color: var(--yellow); font-weight: 800; margin-top: 6px; }

/* ============ HUD ============ */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }

#hud-topleft { position: absolute; top: 16px; left: 20px; text-shadow: 0 2px 3px #000, 0 0 12px rgba(0,0,0,0.6); }
#hud-lap { font-size: clamp(20px, 2.6vw, 32px); font-weight: 900; font-style: italic; color: var(--yellow); }
#hud-time { font-size: clamp(16px, 2vw, 24px); font-weight: 800; color: #fff; font-variant-numeric: tabular-nums; }

#hud-topright { position: absolute; top: 16px; right: 20px; text-align: right; text-shadow: 0 2px 3px #000; }
#hud-pos { font-size: clamp(30px, 4.4vw, 54px); font-weight: 900; font-style: italic; line-height: 1; }
#hud-pos.p1 { color: #ffd23a; } #hud-pos.p2 { color: #d9dee8; } #hud-pos.p3 { color: #e09145; } #hud-pos.p4 { color: #8fa1c8; }
#hud-standings { list-style: none; margin-top: 6px; font-size: clamp(11px, 1.25vw, 15px); font-weight: 800; }
#hud-standings li { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding: 1px 0; color: #cdd8ee; }
#hud-standings li.me { color: var(--yellow); }
#hud-standings .dot { width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid rgba(255,255,255,0.75); display: inline-block; }

#hud-bottomleft { position: absolute; bottom: 16px; left: 20px; font-size: clamp(13px, 1.5vw, 17px); font-weight: 800; color: #9fb2d8; text-shadow: 0 2px 3px #000; font-variant-numeric: tabular-nums; }

#hud-boost {
  position: absolute; bottom: 18px; right: 24px;
  font-size: clamp(16px, 2vw, 24px); font-weight: 900; font-style: italic; color: #6ef2ff;
  text-shadow: 0 0 14px #2fb6ff, 0 2px 3px #000;
  animation: boostPulse 0.35s infinite alternate;
}
@keyframes boostPulse { from { transform: scale(1); } to { transform: scale(1.12); } }

#hud-msg {
  position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%) scale(1);
  font-size: clamp(34px, 6vw, 72px); font-weight: 900; font-style: italic; text-align: center;
  color: #fff; text-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 8px 24px rgba(0,0,0,0.8);
  opacity: 0; pointer-events: none; white-space: nowrap;
}
#hud-msg.pop { animation: msgPop 1.5s cubic-bezier(0.16, 1.3, 0.35, 1) forwards; }
#hud-msg.gold { color: var(--yellow); }
@keyframes msgPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  20% { transform: translate(-50%, -50%) scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.05); }
}

#hud-wrongway {
  position: absolute; top: 42%; left: 50%; transform: translateX(-50%);
  font-size: clamp(24px, 4vw, 44px); font-weight: 900; font-style: italic; color: #ff5040;
  text-shadow: 0 0 18px rgba(255, 40, 20, 0.8), 0 3px 4px #000;
  animation: wrongBlink 0.5s infinite alternate;
}
@keyframes wrongBlink { from { opacity: 1; } to { opacity: 0.35; } }

#hud-countdown {
  position: absolute; top: 18%; left: 50%; transform: translateX(-50%);
  display: flex; gap: 20px; padding: 16px 26px;
  background: rgba(8, 10, 16, 0.78); border-radius: 999px; border: 3px solid #39415f;
}
.cd-lamp { width: clamp(34px, 4.5vw, 56px); height: clamp(34px, 4.5vw, 56px); border-radius: 50%; background: #2a2230; border: 3px solid #171320; transition: background 0.1s, box-shadow 0.1s; }
.cd-lamp.lit { background: radial-gradient(circle at 35% 35%, #ff9d8a, #e02c1c 60%, #8f130a); box-shadow: 0 0 26px 6px rgba(255, 70, 40, 0.65); }
.cd-lamp.go { background: radial-gradient(circle at 35% 35%, #b9ff9d, #27c93f 60%, #12812a); box-shadow: 0 0 30px 8px rgba(60, 255, 100, 0.7); }

/* ============ Car select ============ */
#car-stage { position: relative; display: flex; align-items: center; gap: 10px; }
#car-preview {
  width: min(560px, 72vw); height: auto; aspect-ratio: 560/340;
  background: radial-gradient(ellipse at 50% 62%, rgba(70, 90, 140, 0.35), rgba(10, 12, 20, 0) 70%);
  border-radius: 18px;
}
.car-arrow {
  font-size: 34px; font-weight: 900; color: var(--yellow);
  background: linear-gradient(180deg, #2a3350, #161b2e);
  border: 3px solid #4a5680; border-radius: 12px; cursor: pointer;
  width: 56px; height: 56px; line-height: 1;
  transition: transform 0.08s, border-color 0.12s;
}
.car-arrow:hover { border-color: var(--yellow); transform: scale(1.08); }
#car-name {
  margin-top: 6px; font-size: clamp(24px, 3.4vw, 40px); font-weight: 900; font-style: italic;
  letter-spacing: 0.04em; color: #fff;
  text-shadow: 0 3px 0 rgba(0,0,0,0.4), 0 6px 16px rgba(0,0,0,0.7);
}
#car-desc { max-width: 560px; text-align: center; color: #cdd8ee; font-size: clamp(12.5px, 1.5vw, 16.5px); min-height: 44px; }
#car-stats { display: flex; gap: 26px; margin: 4px 0 6px; }
.stat { text-align: center; }
.stat .stat-label { font-size: 11px; font-weight: 800; letter-spacing: 0.18em; color: #8fa1c8; margin-bottom: 4px; }
.stat .pips { display: flex; gap: 4px; }
.stat .pip { width: 16px; height: 8px; border-radius: 3px; background: #2c3450; border: 1px solid #454f78; }
.stat .pip.on { background: linear-gradient(180deg, #ffd23a, #e0930f); box-shadow: 0 0 6px rgba(255, 210, 58, 0.55); }

/* ============ Results ============ */
#results-table { border-collapse: collapse; min-width: min(480px, 88vw); }
#results-table td, #results-table th {
  padding: 8px 20px; font-size: clamp(14px, 1.8vw, 20px); font-weight: 800;
  border-bottom: 2px solid rgba(255,255,255,0.12); text-align: left; font-variant-numeric: tabular-nums;
}
#results-table tr.me td { color: var(--yellow); }
#results-table .r-dot { width: 13px; height: 13px; border-radius: 50%; display: inline-block; margin-right: 10px; border: 1.5px solid rgba(255,255,255,0.7); }
#results-title.won { color: #ffd23a; }
#results-best { font-size: clamp(13px, 1.5vw, 17px); color: #8ff0a4; font-weight: 800; }
.results-btns { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

@media (max-width: 640px) {
  .help-grid { grid-template-columns: 1fr; }
}
