* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: #14102a; overflow: hidden; font-family: 'Courier New', monospace; }
#game-canvas { display: block; width: 100vw; height: 100vh; }
.hidden { display: none !important; }

#split-divider {
  position: fixed; top: 0; left: 50%; width: 2px; height: 100%;
  background: rgba(255,255,255,0.35); z-index: 10; pointer-events: none;
}

#hud {
  position: fixed; inset: 0; pointer-events: none; user-select: none; z-index: 5;
  color: #fff; text-shadow: 0 0 6px rgba(0,0,0,0.85);
}
.player-hud { position: absolute; top: 14px; padding: 0 16px; }
#p1-hud { left: 10px; }
#p2-hud { left: calc(50% + 10px); }
.hud-label { font-size: 14px; color: #aaa; letter-spacing: 2px; }
.status { font-size: 20px; font-weight: bold; letter-spacing: 2px; }
.status.good { color: #9dffb0; }
.status.bad { color: #ff5a5a; animation: pulse 0.35s ease-in-out infinite alternate; }
.speed-display { font-size: 15px; margin-top: 2px; }
.ammo { font-size: 14px; margin-top: 4px; letter-spacing: 2px; color: #ffb3b3; min-height: 18px; }
@keyframes pulse { from { opacity: 0.55; } to { opacity: 1; } }

#top-center {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  text-align: center; background: rgba(0,0,0,0.35); padding: 6px 18px; border-radius: 6px;
}
#timer { font-size: 22px; font-weight: bold; color: #ffe27a; letter-spacing: 2px; }
#cars-left { font-size: 14px; letter-spacing: 2px; margin-top: 2px; }
#best-hud { font-size: 13px; color: #ffb3f0; letter-spacing: 2px; margin-top: 2px; }
#tiles-left { font-size: 12px; color: #9fd7ff; letter-spacing: 1px; margin-top: 2px; }
#ghost-hud { font-size: 12px; color: #a9e4ff; letter-spacing: 2px; margin-top: 2px; }

#event-feed {
  position: absolute; top: 22%; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.event-msg {
  padding: 6px 14px; border-radius: 4px; background: rgba(40,20,60,0.75);
  color: #fff; font-size: 14px; letter-spacing: 1px; white-space: nowrap;
  animation: eventFade 3s ease-out forwards;
}
@keyframes eventFade { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }

#finish-screen, #start-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; text-align: center; padding: 20px;
}
#finish-screen { background: rgba(10,6,24,0.85); }
#start-overlay { background: radial-gradient(ellipse at center, rgba(40,20,80,0.88), rgba(10,6,24,0.96)); }
#start-overlay h1, #finish-screen h1 {
  font-size: clamp(42px, 9vw, 92px); letter-spacing: 8px; margin-bottom: 14px;
  background: linear-gradient(90deg, #5ec8f2, #f2d65e, #e06c9f); -webkit-background-clip: text; background-clip: text; color: transparent;
}
#finish-screen h1 { color: #fff; background: none; -webkit-text-fill-color: #fff; font-size: clamp(34px, 7vw, 72px); }
.best-line { font-size: 15px; color: #ffb3f0; letter-spacing: 3px; margin: 8px 0 18px; }
.tagline { font-size: 16px; color: #d9d2ff; margin-bottom: 30px; letter-spacing: 1px; }
#finish-sub { font-size: 20px; color: #ffe27a; margin-bottom: 26px; letter-spacing: 2px; }
#mode-select { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; margin-bottom: 26px; }
.mode-btn, #restart-btn {
  font-family: inherit; font-size: 20px; letter-spacing: 3px; padding: 14px 30px;
  background: #241a4a; color: #fff; border: 2px solid #7f6cf0; border-radius: 6px; cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.mode-btn:hover, #restart-btn:hover { background: #3a2a7a; transform: translateY(-2px); }
.controls { font-size: 14px; color: #bbb; letter-spacing: 1px; margin-top: 6px; }
.controls.dim { color: #8a84a8; }
.select-hint { font-size: 13px; color: #888; margin-top: 14px; letter-spacing: 2px; }

#countdown {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-size: clamp(80px, 18vw, 180px); font-weight: bold; color: #fff; z-index: 50;
  text-shadow: 0 0 30px rgba(255,220,120,0.9); pointer-events: none;
}
#countdown.pop { animation: pop 0.9s ease-out forwards; }
@keyframes pop { 0% { transform: translate(-50%, -50%) scale(1.6); opacity: 0; } 20% { opacity: 1; } 100% { transform: translate(-50%, -50%) scale(0.9); opacity: 0.2; } }

/* Username / leaderboard modals */
.modal { position: fixed; inset: 0; z-index: 120; display: flex; align-items: center; justify-content: center; background: rgba(8,4,20,0.8); color: #fff; }
.modal-box { background: #1b1438; border: 2px solid #7f6cf0; border-radius: 10px; padding: 28px 30px; width: min(92vw, 420px); text-align: center; }
.modal-box.wide { width: min(94vw, 640px); max-height: 86vh; display: flex; flex-direction: column; }
.modal-box h2 { font-size: 22px; letter-spacing: 4px; margin-bottom: 12px; }
.modal-box p { font-size: 13px; color: #c9c2ee; margin-bottom: 16px; line-height: 1.5; }
.modal-box a { color: #ffb3f0; }
#name-form { display: flex; gap: 8px; }
#name-input { flex: 1; font-family: inherit; font-size: 18px; letter-spacing: 1px; padding: 10px 12px; background: #0f0b24; color: #fff; border: 2px solid #4a3d8a; border-radius: 6px; }
#name-input:focus { outline: none; border-color: #ffb3f0; }
#name-submit { font-family: inherit; font-size: 16px; letter-spacing: 2px; padding: 10px 18px; background: #3a2a7a; color: #fff; border: 2px solid #7f6cf0; border-radius: 6px; cursor: pointer; }
#name-submit:disabled { opacity: 0.6; cursor: wait; }
.modal-error { min-height: 20px; margin-top: 10px; font-size: 13px; color: #ff6b6b; letter-spacing: 1px; }
.modal-status { font-size: 13px; color: #c9c2ee; margin-bottom: 10px; min-height: 18px; }
.link-btn { font-family: inherit; font-size: 13px; letter-spacing: 2px; color: #bfb5ff; background: none; border: none; cursor: pointer; text-decoration: underline; margin-top: 10px; }
.link-btn:hover { color: #fff; }
.link-row { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; }
.who-line { font-size: 13px; color: #ffb3f0; letter-spacing: 2px; margin-top: 14px; min-height: 16px; }
#lb-list { overflow-y: auto; flex: 1; margin-bottom: 16px; text-align: left; }
.lb-row { display: grid; grid-template-columns: 34px 1fr 90px 90px 92px; gap: 8px; align-items: center; padding: 7px 8px; border-bottom: 1px solid #2d2460; font-size: 14px; }
.lb-row.me { background: rgba(255,179,240,0.12); }
.lb-rank { color: #ffe27a; font-weight: bold; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-time { color: #9dffb0; letter-spacing: 1px; }
.lb-date { color: #8a84a8; font-size: 12px; }
.lb-replay { font-family: inherit; font-size: 12px; letter-spacing: 1px; padding: 5px 8px; background: #241a4a; color: #fff; border: 1px solid #7f6cf0; border-radius: 4px; cursor: pointer; }
.lb-replay:hover { background: #3a2a7a; }
.lb-replay:disabled { opacity: 0.6; cursor: default; }
@media (max-width: 520px) { .lb-row { grid-template-columns: 28px 1fr 80px 80px; } .lb-date { display: none; } }
.finish-rank { font-size: 15px; color: #ffb3f0; letter-spacing: 2px; margin: -14px 0 22px; min-height: 18px; }
#replay-banner { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 60; background: rgba(40,20,60,0.8); color: #ffb3f0; padding: 8px 16px; border-radius: 6px; font-size: 14px; letter-spacing: 2px; display: flex; gap: 12px; align-items: center; }
#replay-stop { font-family: inherit; font-size: 12px; letter-spacing: 2px; padding: 4px 10px; background: #241a4a; color: #fff; border: 1px solid #7f6cf0; border-radius: 4px; cursor: pointer; }
.credit { margin-top: 18px; font-size: 12px; }
.credit a { color: #bfb5ff; }
