/* ==========================================================================
   Street Racing 3D — layout, HUD, car select, panel
   ========================================================================== */
:root {
  --bg: #050608;
  --panel: #14161f;
  --panel-border: #252a3a;
  --text: #e8eaf2;
  --muted: #8b90a6;
  --accent: #fe2c55;
  --accent-2: #25f4ee;
  --gold: #ffd84d;
  --ok: #3ddc84;
  --warn: #ffb02e;
  --err: #ff5c6c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  overflow: hidden;
}
body { display: flex; }

#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

/* HUD sizes use the viewport's smaller side (cqmin) so they scale in any shape. */
#viewport {
  position: relative;
  overflow: hidden;
  container-type: size;
  font-size: 2.2cqmin;
}
#game-canvas { display: block; width: 100%; height: 100%; }

/* ---------- Race HUD ---------- */
#race-hud, #feed, #banner, #toast { pointer-events: none; }
#race-hud { position: absolute; inset: 0; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.9); }
#race-hud[hidden] { display: none; }

.tl { position: absolute; top: 3cqmin; left: 3cqmin; line-height: 1.05; }
.pos-line { font-weight: 900; }
#pos { font-size: 9cqmin; font-style: italic; }
#pos-total { font-size: 3.6cqmin; opacity: 0.8; margin-left: 0.6cqmin; }
#lap { font-size: 3.6cqmin; font-weight: 800; color: var(--gold); margin-top: 0.6cqmin; }
#race-time { font-size: 3cqmin; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 0.4cqmin; }
#best-lap { font-size: 2cqmin; opacity: 0.75; font-variant-numeric: tabular-nums; }

#minimap {
  position: absolute;
  top: 3cqmin;
  right: 3cqmin;
  width: 24cqmin;
  height: 24cqmin;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 1.5cqmin;
}

.br {
  position: absolute;
  right: 3cqmin;
  bottom: 3cqmin;
  width: 34cqmin;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.8cqmin;
}
#chips { display: flex; gap: 0.8cqmin; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  padding: 0.4cqmin 1.2cqmin;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-weight: 800;
  font-size: 2cqmin;
}
.speedo { font-weight: 900; font-style: italic; line-height: 0.9; }
#speed { font-size: 11cqmin; font-variant-numeric: tabular-nums; }
.speedo small { font-size: 2.6cqmin; margin-left: 0.6cqmin; opacity: 0.8; }

.bar {
  position: relative;
  width: 100%;
  height: 2.8cqmin;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 0.8cqmin;
  overflow: hidden;
}
.bar span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  padding-left: 1cqmin;
  font-weight: 800;
  font-size: 1.8cqmin;
}
.fill { height: 100%; transition: width 0.15s; }
#nitro-fill { background: linear-gradient(90deg, #1b6cff, #25f4ee); }
.hp-ok { background: linear-gradient(90deg, #1fa85c, #3ddc84); }
.hp-warn { background: linear-gradient(90deg, #d68910, #ffb02e); }
.hp-low { background: linear-gradient(90deg, #b3202f, #ff4d5e); }

/* ---------- Feed / banner / toast ---------- */
#feed {
  position: absolute;
  top: 26cqmin;
  left: 3cqmin;
  max-width: 55%;
  display: flex;
  flex-direction: column;
  gap: 0.6cqmin;
}
.feed-line {
  align-self: flex-start;
  padding: 0.6cqmin 1.4cqmin;
  border-radius: 0.8cqmin;
  background: rgba(0, 0, 0, 0.6);
  font-weight: 700;
  font-size: 2.3cqmin;
  text-shadow: 0 1px 3px #000;
  animation: slideIn 0.25s ease-out;
  transition: opacity 0.5s;
}
.feed-line.fade { opacity: 0; }

#banner {
  position: absolute;
  top: 30%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 7cqmin;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.3cqmin;
  opacity: 0;
  -webkit-text-stroke: 0.2cqmin #000;
  text-shadow: 0 0 3cqmin rgba(0, 0, 0, 0.6);
}
#banner.big { font-size: 14cqmin; }
#banner.show { animation: banner 1.1s ease-out forwards; }

#toast {
  position: absolute;
  top: 48%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 4cqmin;
  font-weight: 900;
  opacity: 0;
  text-shadow: 0 2px 6px #000;
}
#toast.show { animation: toast 1.4s ease-out forwards; }

/* ---------- Car select ---------- */
#select-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 4cqmin 3cqmin;
  pointer-events: none;
}
#select-screen[hidden] { display: none; }
#select-screen button { pointer-events: auto; }
.sel-title {
  font-size: 6cqmin;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.4cqmin;
  text-shadow: 0 0 3cqmin rgba(37, 244, 238, 0.5);
}
.sel-bottom { display: flex; align-items: center; gap: 3cqmin; width: 100%; justify-content: center; }
.sel-card {
  width: min(90cqw, 70cqmin);
  padding: 2.4cqmin 3cqmin;
  background: rgba(10, 12, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 2cqmin;
  backdrop-filter: blur(6px);
}
#car-name { font-size: 4.6cqmin; font-weight: 900; font-style: italic; }
#car-tagline { color: var(--accent-2); font-weight: 700; font-size: 2.3cqmin; margin-bottom: 1.6cqmin; }
.stat { display: grid; grid-template-columns: 16cqmin 1fr 12cqmin; align-items: center; gap: 1.4cqmin; margin: 0.9cqmin 0; font-size: 1.9cqmin; font-weight: 700; color: var(--muted); }
.stat .track { height: 1.3cqmin; background: rgba(255, 255, 255, 0.1); border-radius: 99px; overflow: hidden; }
.stat .fill { background: linear-gradient(90deg, var(--accent), var(--gold)); transition: width 0.35s; }
.stat b { color: #fff; text-align: right; }
#car-index { text-align: center; color: var(--muted); font-size: 1.8cqmin; margin-top: 1cqmin; }

button.arrow {
  flex: none;
  width: 9cqmin;
  height: 9cqmin;
  border-radius: 50%;
  font-size: 3.6cqmin;
  background: rgba(10, 12, 18, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.25);
}
button.go-btn {
  flex: none;
  padding: 1.6cqmin 6cqmin;
  font-size: 3.6cqmin;
  font-weight: 900;
  font-style: italic;
  border-radius: 99px;
  background: var(--accent);
  border: none;
  box-shadow: 0 0 4cqmin rgba(254, 44, 85, 0.6);
}
button.go-btn small { font-size: 1.8cqmin; opacity: 0.8; font-style: normal; }

/* ---------- Results ---------- */
#results {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.6cqmin;
  background: radial-gradient(ellipse at center, rgba(10, 14, 30, 0.75), rgba(0, 0, 0, 0.9));
  cursor: pointer;
  animation: fadeIn 0.5s;
}
#results[hidden] { display: none; }
#results-title { font-size: 7cqmin; font-weight: 900; font-style: italic; color: var(--gold); }
#results-list { list-style: none; margin: 0; padding: 0; width: min(90cqw, 60cqmin); }
#results-list li {
  display: grid;
  grid-template-columns: 8cqmin 1fr auto;
  align-items: center;
  padding: 0.9cqmin 1.6cqmin;
  margin: 0.5cqmin 0;
  border-radius: 1cqmin;
  background: rgba(255, 255, 255, 0.06);
  font-size: 2.6cqmin;
  font-weight: 700;
}
#results-list li.me { background: rgba(37, 244, 238, 0.2); border: 1px solid var(--accent-2); }
#results-list li.viewer .rn { color: #ff9ccc; }
#results-list .rp { font-weight: 900; font-style: italic; }
#results-list .rt { font-variant-numeric: tabular-nums; opacity: 0.85; }
.res-hint { color: var(--accent-2); font-size: 2.2cqmin; font-weight: 700; margin-top: 1cqmin; }
#results-countdown { color: var(--muted); font-size: 2cqmin; }

/* ---------- Loading / credits ---------- */
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2cqmin;
  background: #07080c;
}
#loading[hidden] { display: none; }
.loading-title { font-size: 7cqmin; font-weight: 900; font-style: italic; color: var(--accent); }
.loading-track { width: 50%; height: 1cqmin; background: #1c1f2a; border-radius: 99px; overflow: hidden; }
#loading-bar { width: 0; height: 100%; background: var(--accent-2); transition: width 0.3s; }
.loading-sub { color: var(--muted); font-size: 2.2cqmin; text-align: center; padding: 0 5cqmin; }

#credits {
  position: absolute;
  left: 1.2cqmin;
  bottom: 0.8cqmin;
  font-size: 1.3cqmin;
  color: rgba(255, 255, 255, 0.45);
  pointer-events: none;
}

@keyframes banner {
  0% { opacity: 0; transform: scale(1.6); }
  15% { opacity: 1; transform: scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: scale(0.9); }
}
@keyframes toast {
  0% { opacity: 0; transform: translateY(2cqmin); }
  15% { opacity: 1; transform: none; }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-3cqmin); }
}
@keyframes slideIn { from { opacity: 0; transform: translateX(-3cqmin); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ==========================================================================
   Streamer panel
   ========================================================================== */
#panel {
  width: 320px;
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  padding: 16px;
}
body.panel-hidden #panel { display: none; }
#show-panel-btn { display: none; position: absolute; top: 8px; right: 8px; opacity: 0.25; flex: none; }
#show-panel-btn:hover { opacity: 1; }
body.panel-hidden #show-panel-btn { display: block; }

.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
h1 { font-size: 17px; margin: 0; }
h2 { font-size: 14px; margin: 0 0 10px; color: var(--accent-2); }
h3 { font-size: 12px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
section { padding: 14px 0; border-top: 1px solid var(--panel-border); }
label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.at { color: var(--muted); font-weight: 600; }

input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: #0d0f16;
  color: var(--text);
  font-size: 14px;
}
input:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }

button {
  flex: 1;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: #20243a;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
button:hover:not(:disabled) { filter: brightness(1.25); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
button.small { flex: none; padding: 4px 8px; font-size: 12px; }
button.active { background: #1f6f4a; border-color: var(--ok); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid .wide { grid-column: span 2; }

.status { margin: 4px 0 0; padding: 8px 10px; border-radius: 6px; background: #0d0f16; font-size: 13px; }
.status::before { content: "● "; }
.status-idle::before, .status-disconnected::before { color: var(--muted); }
.status-connecting::before { color: var(--warn); }
.status-connected::before { color: var(--ok); }
.status-error::before { color: var(--err); }
.status-error { color: var(--err); }

.hint { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 8px 0 0; }
.hint a { color: var(--accent-2); }
.hint b { color: var(--text); }
code { background: #0d0f16; padding: 1px 4px; border-radius: 4px; font-size: 11px; }

/* Home button (panel header) */
.panel-header { gap: 8px; }
.panel-header h1 { flex: 1; }
.home-btn {
  flex: none;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--accent-2, #25f4ee);
  background: rgba(37, 244, 238, 0.12);
  color: var(--text, #e8eaf2);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.home-btn:hover { background: rgba(37, 244, 238, 0.25); }

/* Steering sensitivity slider */
.slider-label { display: flex; justify-content: space-between; margin-top: 12px; color: var(--muted); font-size: 12px; }
.slider-label b { color: var(--text); }
#steering { width: 100%; padding: 0; accent-color: var(--accent); }
#difficulty { width: 100%; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--panel-border); background: #0d0f16; color: var(--text); font-size: 14px; }
