/* =====================================================================
   HILL RUSH — style.css
   ===================================================================== */
:root {
  --bg: #0b1726;
  --panel: rgba(10, 20, 34, 0.86);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #f3f6fb;
  --muted: #9fb0c6;
  --accent: #ffd23f;
  --accent2: #ff6a3d;
  --good: #2ed573;
  --bad: #ff4757;
  --blue: #2f8cff;
  --radius: 14px;
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; width: 100%; overflow: hidden;
  background: var(--bg); color: var(--text); font-family: var(--font);
  overscroll-behavior: none; -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
}
body { position: fixed; inset: 0; }
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; outline: none; }
.hidden { display: none !important; }
button { font-family: inherit; }

/* ---------------- screens / panels ---------------- */
.screen {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at center, rgba(5, 12, 22, 0.25), rgba(5, 12, 22, 0.7));
  z-index: 10; overflow-y: auto;
}
.screen.active { display: flex; }
.panel {
  width: 100%; max-width: 420px; margin: auto;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius);
  padding: 22px 22px 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; flex-direction: column; gap: 10px;
}
.panel h2 { margin: 0 0 4px; text-align: center; letter-spacing: 3px; font-size: 22px; }
.logo {
  margin: 0; text-align: center; font-size: 54px; font-weight: 900; font-style: italic; letter-spacing: 2px; line-height: 1;
  color: #fff; text-shadow: 0 4px 0 #b3261e, 0 8px 24px rgba(0, 0, 0, 0.5);
}
.logo span { color: var(--accent); margin-left: 8px; }
.tagline { margin: 2px 0 10px; text-align: center; color: var(--muted); font-size: 12px; letter-spacing: 3px; font-weight: 700; }
.field-label { font-size: 11px; letter-spacing: 2px; color: var(--muted); font-weight: 700; margin-top: 4px; }
.center { text-align: center; }
.text-input {
  width: 100%; padding: 14px 14px; font-size: 20px; font-weight: 700; color: var(--text);
  background: rgba(255, 255, 255, 0.07); border: 2px solid rgba(255, 255, 255, 0.15); border-radius: 10px; outline: none;
  -webkit-user-select: text; user-select: text; font-family: inherit;
}
.text-input:focus { border-color: var(--accent); background: rgba(255, 255, 255, 0.1); }
.text-input.invalid { border-color: var(--bad); }
.code-input { text-transform: uppercase; letter-spacing: 10px; text-align: center; font-size: 28px; font-family: ui-monospace, Consolas, monospace; }
.hint { font-size: 12px; color: var(--muted); min-height: 16px; }
.hint.error { color: var(--bad); font-weight: 700; }

.btn {
  appearance: none; border: 0; border-radius: 10px; padding: 14px 16px; font-size: 16px; font-weight: 800; letter-spacing: 2px;
  color: var(--text); background: rgba(255, 255, 255, 0.1); cursor: pointer; transition: transform 0.08s, background 0.15s, opacity 0.15s;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.18); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; filter: grayscale(1); box-shadow: none; }
.btn.primary { background: linear-gradient(180deg, #ffd23f, #ff9f1a); color: #2b1a00; box-shadow: 0 4px 0 #b86b00; }
.btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, #ffe066, #ffb02e); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.small { padding: 10px 8px; font-size: 12px; letter-spacing: 1px; flex: 1; }
.btn.on { background: var(--good); color: #062b14; }
.row { display: flex; gap: 8px; }
.help { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.help b { color: var(--text); }
.footnote { font-size: 11px; color: var(--muted); text-align: center; margin-top: 4px; }

/* ---------------- lobby ---------------- */
.room-code {
  text-align: center; font-size: 46px; font-weight: 900; letter-spacing: 12px; color: var(--accent);
  font-family: ui-monospace, Consolas, monospace; padding-left: 12px;
}
.count { text-align: center; font-weight: 800; letter-spacing: 2px; margin-top: 4px; }
.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.player-list li {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; background: rgba(255, 255, 255, 0.06);
}
.player-list li.empty { opacity: 0.35; font-style: italic; }
.player-list .swatch { width: 26px; height: 14px; border-radius: 4px; flex: none; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3); }
.player-list .pname { font-weight: 800; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 10px; font-weight: 800; letter-spacing: 1px; padding: 3px 6px; border-radius: 5px; background: rgba(255, 255, 255, 0.12); }
.tag.host { background: var(--accent); color: #2b1a00; }
.tag.you { background: var(--blue); }
.tag.ready { background: var(--good); color: #062b14; }
.tag.waiting { background: rgba(255, 255, 255, 0.12); color: var(--muted); }
.tag.disc { background: var(--bad); }

/* ---------------- results ---------------- */
.results-list { list-style: none; margin: 4px 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.results-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: rgba(255, 255, 255, 0.06); font-weight: 700; }
.results-list li.me { outline: 2px solid var(--accent); }
.results-list .rpos { width: 26px; font-size: 20px; font-weight: 900; text-align: center; }
.results-list li:nth-child(1) .rpos { color: #ffd700; }
.results-list li:nth-child(2) .rpos { color: #cfd8e3; }
.results-list li:nth-child(3) .rpos { color: #e3a36b; }
.results-list .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.results-list .rname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results-list .rtime { font-family: ui-monospace, Consolas, monospace; }
.results-list .rtime.dnf { color: var(--bad); }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.hud-box {
  background: rgba(6, 14, 26, 0.6); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 12px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
#hud-left { position: absolute; top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); padding: 10px 14px; min-width: 150px; }
.hud-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.lbl { font-size: 10px; letter-spacing: 2px; color: var(--muted); font-weight: 800; }
.val { font-weight: 900; font-size: 18px; font-variant-numeric: tabular-nums; }
.val.big { font-size: 26px; color: var(--accent); }
.hud-room { font-size: 10px; color: var(--muted); letter-spacing: 2px; margin-top: 4px; }
.hud-room b { color: var(--text); }
#hud-right { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
#minimap { width: 180px; height: 180px; border-radius: 12px; }
#leaderboard { list-style: none; margin: 0; padding: 6px 8px; min-width: 180px; font-size: 13px; }
#leaderboard li { display: flex; align-items: center; gap: 6px; padding: 3px 2px; font-weight: 700; }
#leaderboard li.me { color: var(--accent); }
#leaderboard .lpos { width: 16px; text-align: right; font-weight: 900; }
#leaderboard .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
#leaderboard .lname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 90px; }
#leaderboard .lstat { font-size: 9px; letter-spacing: 1px; padding: 2px 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); color: var(--muted); }
#leaderboard .lstat.RACING { color: var(--good); }
#leaderboard .lstat.FINISHED { background: var(--accent); color: #2b1a00; }
#leaderboard .lstat.DISCONNECTED, #leaderboard .lstat.DNF { background: var(--bad); color: #fff; }

#hud-bottom {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: max(14px, env(safe-area-inset-bottom));
  padding: 8px 18px; display: flex; align-items: center; gap: 18px;
}
.speed { font-size: 36px; font-weight: 900; font-style: italic; font-variant-numeric: tabular-nums; min-width: 110px; text-align: right; }
.speed small { font-size: 12px; color: var(--muted); margin-left: 4px; font-style: normal; }
.boost-wrap { display: flex; flex-direction: column; gap: 4px; }
.boost-bar { width: 160px; height: 14px; border-radius: 7px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
#hud-boost { height: 100%; width: 50%; background: linear-gradient(90deg, #00c6ff, #7cf3ff); border-radius: 7px; transition: width 0.1s linear; }
#hud-boost.active { background: linear-gradient(90deg, #ff6a00, #ffd23f); }

#hud-buttons { position: absolute; left: max(12px, env(safe-area-inset-left)); top: calc(max(12px, env(safe-area-inset-top)) + 118px); display: flex; gap: 6px; pointer-events: auto; }
.hud-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(6, 14, 26, 0.6); color: #fff; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.hud-btn:active { transform: scale(0.94); }

#countdown {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%);
  font-size: 140px; font-weight: 900; font-style: italic; color: #fff; text-shadow: 0 6px 0 #b3261e, 0 12px 40px rgba(0, 0, 0, 0.6);
  pointer-events: none; white-space: nowrap;
}
#countdown.small { font-size: 44px; letter-spacing: 4px; }
#countdown.pop { animation: pop 0.5s ease-out; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(1.6); opacity: 0.2; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
#wrongway {
  position: absolute; top: 22%; left: 50%; transform: translateX(-50%); padding: 8px 18px; border-radius: 10px;
  background: var(--bad); font-weight: 900; letter-spacing: 4px; font-size: 22px; animation: blink 0.8s infinite;
}
@keyframes blink { 50% { opacity: 0.3; } }
#race-notice {
  position: absolute; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  padding: 6px 14px; border-radius: 10px; background: rgba(6, 14, 26, 0.7); font-weight: 800; letter-spacing: 1px; font-size: 14px;
}
#finish-banner {
  position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); text-align: center;
  background: rgba(6, 14, 26, 0.85); border: 2px solid var(--accent); border-radius: 16px; padding: 18px 34px;
  animation: pop 0.5s ease-out;
}
#finish-banner h3 { margin: 0 0 8px; font-size: 34px; letter-spacing: 3px; }
#finish-banner div { font-size: 18px; font-weight: 800; letter-spacing: 2px; }
#finish-banner .sub { font-size: 12px; color: var(--muted); margin-top: 8px; letter-spacing: 1px; font-weight: 600; }

#boost-fx {
  position: fixed; inset: 0; pointer-events: none; z-index: 4; opacity: 0; transition: opacity 0.25s;
  background:
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 55%, rgba(255, 140, 30, 0.28) 100%),
    repeating-conic-gradient(from 0deg at 50% 50%, rgba(255, 255, 255, 0) 0deg 5deg, rgba(255, 255, 255, 0.06) 5deg 6deg);
  -webkit-mask-image: radial-gradient(ellipse at center, transparent 35%, #000 80%);
  mask-image: radial-gradient(ellipse at center, transparent 35%, #000 80%);
}
#boost-fx.on { opacity: 1; }

/* ---------------- touch controls ---------------- */
#touch-controls {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  pointer-events: none; touch-action: none;
}
.tc-side { display: flex; gap: 12px; align-items: flex-end; pointer-events: auto; }
.tc-col { display: flex; flex-direction: column; gap: 10px; }
.tc-btn {
  width: 84px; height: 84px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(10, 20, 34, 0.45); color: #fff; font-size: 30px; font-weight: 900; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  display: flex; align-items: center; justify-content: center;
}
.tc-btn.on { background: rgba(255, 210, 63, 0.55); border-color: var(--accent); }
.tc-gas { background: rgba(46, 213, 115, 0.35); }
.tc-brake { width: 72px; height: 72px; background: rgba(255, 71, 87, 0.35); font-size: 24px; }
.tc-boost { width: 78px; height: 78px; font-size: 13px; letter-spacing: 1px; background: rgba(0, 170, 255, 0.4); margin-bottom: 30px; }

/* ---------------- overlays ---------------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; background: rgba(5, 12, 22, 0.78); padding: 16px; text-align: center; }
#overlay-loading { font-weight: 700; letter-spacing: 1px; line-height: 1.5; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 5px solid rgba(255, 255, 255, 0.15); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-panel { text-align: center; border-color: rgba(255, 71, 87, 0.5); }
.error-panel h2 { color: var(--bad); }
.error-panel p { margin: 0 0 8px; color: var(--text); line-height: 1.5; }
.banner {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 40;
  padding: 10px 20px; border-radius: 10px; background: var(--bad); font-weight: 900; letter-spacing: 3px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  animation: blink 1.2s infinite;
}
.toast {
  position: fixed; bottom: 30%; left: 50%; transform: translateX(-50%) translateY(20px); z-index: 45;
  background: rgba(6, 14, 26, 0.92); border: 1px solid var(--accent); padding: 10px 18px; border-radius: 10px; font-weight: 800;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- responsive ---------------- */
@media (max-width: 760px), (max-height: 520px) {
  #minimap { width: 120px; height: 120px; }
  #leaderboard { min-width: 120px; font-size: 11px; padding: 4px 6px; }
  #leaderboard .lname { max-width: 60px; }
  #leaderboard .lstat { display: none; }
  #hud-left { padding: 6px 10px; min-width: 110px; }
  .val { font-size: 15px; } .val.big { font-size: 20px; }
  #hud-buttons { top: calc(max(12px, env(safe-area-inset-top)) + 92px); }
  .hud-btn { width: 34px; height: 34px; font-size: 15px; }
  #countdown { font-size: 96px; }
  #countdown.small { font-size: 30px; }
  .logo { font-size: 44px; }
  .room-code { font-size: 38px; }
}
body.touch #hud-bottom { bottom: auto; top: max(12px, env(safe-area-inset-top)); padding: 4px 12px; gap: 10px; }
body.touch .speed { font-size: 24px; min-width: 70px; }
body.touch .boost-bar { width: 90px; height: 10px; }
body.touch #race-notice { top: calc(max(12px, env(safe-area-inset-top)) + 56px); }
@media (max-height: 520px) {
  .tc-btn { width: 70px; height: 70px; font-size: 24px; }
  .tc-brake { width: 60px; height: 60px; }
  .tc-boost { width: 64px; height: 64px; margin-bottom: 20px; font-size: 11px; }
  .panel { padding: 14px 16px; gap: 6px; }
  .screen { align-items: flex-start; }
}
@media (max-width: 400px) { body.touch #hud-bottom { top: auto; bottom: 110px; } }
