/* ==========================================================================
   Kart DRL Arena — interface layout.  Frosted panels floating over the 3D
   scene; hand-set spacing; serif display type for a calm, editorial feel.
   ========================================================================== */

#scene { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; display: block; }

.hidden { display: none !important; }

.panel {
  background: var(--panel);
  -webkit-backdrop-filter: blur(var(--blur));
  backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

/* thin, quiet scrollbars */
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* ---- top chrome ---------------------------------------------------------- */
#home-btn {
  position: fixed; top: 14px; left: 16px; z-index: 30;
  font-size: 13px; color: var(--dim); text-decoration: none;
  padding: 6px 10px; border-radius: var(--r-sm);
}
#home-btn:hover { color: var(--text); background: var(--panel); }

#top-tools { position: fixed; bottom: 16px; right: 16px; z-index: 30; display: flex; gap: 8px; }
.tool-btn {
  background: var(--panel);
  -webkit-backdrop-filter: blur(var(--blur)); backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border); border-radius: var(--r-sm);
  color: var(--dim); font-family: var(--sans); font-size: 13px;
  padding: 8px 10px; cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.tool-btn:hover { color: var(--text); }
select.tool-btn { appearance: none; -webkit-appearance: none; }

/* ---- overlay ------------------------------------------------------------- */
#overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); transition: opacity .5s ease;
}
#overlay.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.overlay-card { text-align: center; max-width: 560px; padding: 0 24px; }
.brand { color: var(--accent); margin-bottom: 12px; }
.overlay-card h1 {
  font-family: var(--serif); font-weight: 900;
  font-size: clamp(34px, 6vw, 58px); letter-spacing: -0.02em; line-height: 1.02;
}
.tagline {
  font-family: var(--serif); font-style: italic; color: var(--dim);
  font-size: clamp(15px, 2.4vw, 20px); margin-top: 8px;
}
.subtitle { color: var(--dim); max-width: 440px; margin: 16px auto 0; line-height: 1.6; font-size: 15px; }
.field-label {
  margin-top: 26px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.16em; color: var(--faint);
}
.segmented { display: inline-flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; justify-content: center; }
.seg {
  padding: 9px 16px; border: 1px solid var(--border); background: var(--panel);
  border-radius: var(--r-md); font-family: var(--sans); font-size: 14px;
  color: var(--dim); cursor: pointer; transition: .2s;
}
.seg:hover { color: var(--text); }
.seg.active { background: var(--accent-soft); color: var(--text); border-color: var(--accent); }
.overlay-modes { margin-top: 28px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn-primary {
  padding: 14px 28px; border: none; border-radius: var(--r-md);
  background: var(--accent); color: var(--accent-ink);
  font-family: var(--sans); font-weight: 600; font-size: 15px;
  cursor: pointer; box-shadow: var(--shadow-sm); transition: .2s;
}
.btn-primary:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn-ghost {
  padding: 14px 26px; border: 1px solid var(--border-strong); background: transparent;
  color: var(--text); border-radius: var(--r-md); font-weight: 600; font-size: 15px;
  cursor: pointer; transition: .2s; font-family: var(--sans);
}
.btn-ghost:hover { background: var(--panel); }
.btn-primary:disabled, .btn-ghost:disabled { opacity: .45; cursor: default; transform: none; filter: none; }
.boot-status { margin-top: 22px; font-family: var(--mono); font-size: 12px; color: var(--faint); }
.boot-status.ready { color: var(--good); }
.boot-status.ready::before { content: '\25CF  '; }

/* ---- race pill ----------------------------------------------------------- */
#race-pill {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 12px; padding: 9px 18px; font-family: var(--mono);
}
.rp-pos { font-size: 20px; font-weight: 700; }
.rp-pos small { color: var(--dim); font-size: 12px; }
.rp-sep { width: 1px; height: 16px; background: var(--border-strong); }
.rp-lap small { color: var(--dim); }
.rp-timer { font-weight: 700; font-size: 18px; }
.rp-money { color: var(--coin); font-weight: 700; }

/* ---- standings ----------------------------------------------------------- */
#standings {
  position: fixed; top: 52px; left: 14px; z-index: 18;
  width: 212px; max-height: 56vh; overflow-y: auto; padding: 11px 12px;
}
.panel-head { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--faint); margin-bottom: 8px; }
.st-row { display: flex; align-items: center; gap: 8px; padding: 3px 2px; font-family: var(--mono); font-size: 12.5px; }
.st-row.me { color: var(--accent); font-weight: 700; }
.st-row.done { opacity: .55; }
.st-pos { width: 16px; color: var(--dim); text-align: right; }
.st-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.st-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-lap { color: var(--dim); }
.st-money { color: var(--coin); min-width: 40px; text-align: right; }

/* ---- training panel ------------------------------------------------------ */
#train-panel {
  position: fixed; top: 14px; right: 14px; z-index: 22;
  width: 254px; max-height: calc(100vh - 28px); overflow-y: auto;
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.tp-row { display: flex; align-items: center; justify-content: space-between; }
.tp-key { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--faint); }
.badge { font-family: var(--mono); font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.tp-label { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--faint); margin-top: 2px; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-row.dim { opacity: .4; pointer-events: none; }
.pill {
  flex: 1; min-width: 52px; padding: 8px 10px; border: 1px solid var(--border);
  background: var(--panel); color: var(--dim); font-family: var(--sans);
  font-size: 13px; font-weight: 500; border-radius: var(--r-sm); cursor: pointer;
  transition: .15s; white-space: nowrap; text-align: center;
}
.pill:hover { color: var(--text); border-color: var(--border-strong); }
.pill.active, .pill.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pill.speed { flex: 1 1 28%; }
.pill.danger:hover { color: #c05a4a; border-color: #c05a4a; }
.stats { margin-top: 4px; display: flex; flex-direction: column; gap: 4px; border-top: 1px solid var(--border); padding-top: 10px; }
.stat { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 12.5px; }
.stat-key { color: var(--dim); }
.stat-val { font-weight: 700; }

/* ---- minimap ------------------------------------------------------------- */
#minimap { position: fixed; bottom: 14px; left: 14px; z-index: 18; width: 180px; height: 150px; padding: 6px; }

/* ---- bottom bar ---------------------------------------------------------- */
#bottom-bar {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 20;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center;
}
.hud-group {
  display: flex; align-items: center; gap: 5px; background: var(--panel);
  -webkit-backdrop-filter: blur(var(--blur)); backdrop-filter: blur(var(--blur));
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 10px; box-shadow: var(--shadow-sm);
}
.group-label { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--faint); margin-right: 2px; }
#bottom-bar .pill { flex: none; min-width: auto; }

/* ---- hint ---------------------------------------------------------------- */
#hint {
  position: fixed; bottom: 72px; left: 50%; transform: translateX(-50%); z-index: 19;
  font-family: var(--mono); font-size: 12px; color: var(--dim);
  background: var(--panel); border: 1px solid var(--border); padding: 6px 14px;
  border-radius: 999px; -webkit-backdrop-filter: blur(var(--blur)); backdrop-filter: blur(var(--blur));
}

/* ---- touch controls ------------------------------------------------------ */
#touch { position: fixed; inset: 0; z-index: 25; pointer-events: none; }
#joystick { position: fixed; bottom: 26px; left: 26px; width: 124px; height: 124px; z-index: 26; pointer-events: auto; touch-action: none; }
#joy-base {
  position: absolute; inset: 0; border-radius: 50%; background: var(--panel);
  border: 1px solid var(--border); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
#joy-knob {
  position: absolute; top: 50%; left: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px;
  border-radius: 50%; background: var(--accent-soft); border: 1px solid var(--accent);
}
#drift-btn { position: fixed; bottom: 34px; right: 26px; z-index: 26; pointer-events: auto; }
#item-btn { position: fixed; bottom: 122px; right: 40px; z-index: 26; pointer-events: auto; width: 64px; height: 64px; font-size: 12px; }
.action-btn {
  width: 78px; height: 78px; border-radius: 50%; border: 1px solid var(--border-strong);
  background: var(--panel); color: var(--text); font-family: var(--sans); font-weight: 700;
  font-size: 13px; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); touch-action: manipulation;
}
.action-btn.on { background: var(--accent); color: var(--accent-ink); }
#mobile-menu-btn {
  position: fixed; top: 14px; right: 14px; z-index: 30; padding: 9px 14px;
  border: 1px solid var(--border); background: var(--panel);
  -webkit-backdrop-filter: blur(var(--blur)); backdrop-filter: blur(var(--blur));
  color: var(--text); border-radius: var(--r-sm); font-family: var(--sans); font-size: 13px;
}

/* ---- elites + champion in standings -------------------------------------- */
.st-row.elite { position: relative; }
.st-row.elite::before {
  content: ''; position: absolute; left: -7px; top: 3px; bottom: 3px;
  width: 2px; border-radius: 2px; background: var(--accent); opacity: .45;
}
.st-row.champ::before { opacity: 1; }
.st-row.champ .st-name { color: var(--accent); font-weight: 700; }

/* ---- locked map choice --------------------------------------------------- */
.seg.locked { opacity: .5; cursor: not-allowed; }
.seg.locked:hover { color: var(--dim); }

/* ---- advanced (race-only) map ------------------------------------------- */
.seg.adv-add { border-style: dashed; color: var(--accent); border-color: var(--accent); }
.seg.adv-add:hover { background: var(--accent-soft); }
.seg-tag {
  display: inline-block; margin-left: 7px; padding: 1px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 10px; text-transform: uppercase; letter-spacing: .08em; vertical-align: 1px;
}

/* ---- unlock banner ------------------------------------------------------- */
#unlock-banner {
  position: fixed; top: 92px; left: 50%;
  transform: translateX(-50%) translateY(-16px); z-index: 120;
  opacity: 0; transition: all .5s cubic-bezier(.34, 1.56, .64, 1); pointer-events: none;
}
#unlock-banner.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.ub-card {
  background: var(--panel-solid); border: 1px solid var(--accent); border-radius: 18px;
  padding: 16px 30px; text-align: center; box-shadow: var(--shadow);
}
.ub-kicker { font-size: 11px; text-transform: uppercase; letter-spacing: .16em; color: var(--accent); }
.ub-name { font-family: var(--serif); font-weight: 900; font-size: 24px; margin-top: 4px; color: var(--text); }

/* ---- race mode ----------------------------------------------------------- */
#train-panel.race-hidden { display: none; }

#countdown {
  position: fixed; inset: 0; z-index: 60; display: flex;
  align-items: center; justify-content: center; pointer-events: none;
}
#cd-num {
  font-family: var(--serif); font-weight: 900; font-size: clamp(90px, 18vw, 190px);
  color: var(--text); text-shadow: 0 4px 30px rgba(0,0,0,.25);
  animation: cd-pop .5s ease both;
}
#cd-num.go { color: var(--good); }
@keyframes cd-pop {
  0% { transform: scale(1.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

#item-slot {
  position: fixed; top: 66px; left: 50%; transform: translateX(-50%); z-index: 21;
  width: 64px; height: 64px; padding: 7px;
}
#item-icon { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
#item-icon svg { width: 100%; height: 100%; }
#item-slot.rolling { animation: slot-shake .18s linear infinite; }
@keyframes slot-shake {
  0% { transform: translateX(-50%) rotate(-3deg); }
  50% { transform: translateX(-50%) rotate(3deg); }
  100% { transform: translateX(-50%) rotate(-3deg); }
}
#item-slot.multi::after {
  content: attr(data-count); position: absolute; right: -6px; bottom: -6px;
  background: var(--accent); color: var(--accent-ink); border-radius: 999px;
  font-family: var(--mono); font-size: 12px; font-weight: 700;
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
}

#results {
  position: fixed; inset: 0; z-index: 90; display: flex;
  align-items: center; justify-content: center; overflow: hidden;
  background: rgba(20, 18, 15, 0.35);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
#confetti-layer { position: absolute; inset: 0; pointer-events: none; }
.confetti {
  position: absolute; top: -16px; width: 8px; height: 14px;
  border-radius: 2px; opacity: .95;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(108vh) rotate(680deg); opacity: .65; }
}
.res-card {
  background: var(--panel-solid); border: 1px solid var(--border-strong);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
  padding: 26px 30px; width: min(420px, 92vw); max-height: 84vh; overflow-y: auto;
}
.res-head {
  font-family: var(--serif); font-weight: 900; font-size: 26px;
  text-align: center; margin-bottom: 16px;
}
.res-row {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--mono); font-size: 14px; padding: 5px 4px;
  border-bottom: 1px solid var(--border);
}
.res-row.me { color: var(--accent); font-weight: 700; }
.res-pos { width: 22px; text-align: right; color: var(--dim); }
.res-row.me .res-pos { color: var(--accent); }
.res-name { flex: 1; }
.res-time { color: var(--dim); }
.res-row.me .res-time { color: var(--accent); }
.res-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }

/* ---- mobile layout ------------------------------------------------------- */
@media (max-width: 820px) {
  #train-panel {
    top: 0; right: 0; height: 100%; max-height: 100%; width: min(300px, 86vw);
    border-radius: 0; transform: translateX(112%); transition: transform .3s ease;
  }
  #train-panel.mobile-open { transform: none; }
  #standings { width: 150px; top: 50px; max-height: 40vh; padding: 8px 9px; }
  #minimap { width: 132px; height: 110px; }
  #bottom-bar { bottom: 130px; }
  #top-tools { bottom: auto; top: 12px; left: 64px; right: auto; }
  #race-pill { gap: 8px; padding: 7px 12px; font-size: 13px; }
}

/* ---- generation meter ------------------------------------------------------ */
.gen-block { margin-top: 6px; border-top: 1px solid var(--border); padding-top: 10px; }
.gen-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.trend {
  font-family: var(--mono); font-size: 10.5px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px; letter-spacing: .04em;
}
.trend.up { background: rgba(95, 122, 78, .18); color: var(--good); }
.trend.flat { background: var(--accent-soft); color: var(--accent); }
.trend.down { background: rgba(185, 138, 94, .2); color: var(--warn); }
.gen-bar {
  height: 5px; border-radius: 999px; background: var(--border);
  overflow: hidden;
}
#gen-fill {
  height: 100%; width: 0%; border-radius: 999px;
  background: var(--accent); transition: width .12s linear;
}
.gen-sub {
  display: flex; justify-content: space-between; margin-top: 5px;
  font-family: var(--mono); font-size: 10.5px; color: var(--dim);
}

/* ---- fitness graph --------------------------------------------------------- */
.fit-graph {
  width: 100%; height: 74px; display: block;
  border: 1px solid var(--border); border-radius: 8px;
  background: rgba(128, 128, 128, .05);
}
.fit-legend {
  display: flex; gap: 12px; margin-top: 5px;
  font-family: var(--mono); font-size: 10.5px; color: var(--dim);
}
.lg { display: inline-flex; align-items: center; gap: 5px; }
.lg::before { content: ''; width: 10px; height: 2px; border-radius: 2px; }
.lg-best::before { background: var(--accent); }
.lg-mean::before { background: var(--dim); }

/* ---- brain inspector ------------------------------------------------------- */
/* Sits on the left, above the minimap — the right column is fully taken by the
   training panel once the fitness graph is in it. */
#brain-panel {
  position: fixed; left: 14px; bottom: 178px; z-index: 18;
  width: 232px; padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
.brain-meta { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.obs-strip {
  width: 100%; height: 46px; display: block;
  border: 1px solid var(--border); border-radius: 8px;
  background: rgba(128, 128, 128, .05);
}
.act-row { display: flex; gap: 6px; }
.act {
  flex: 1; display: flex; flex-direction: column; gap: 2px;
  padding: 5px 6px; border-radius: 7px; background: rgba(128, 128, 128, .08);
}
.act small {
  font-size: 9px; text-transform: uppercase; letter-spacing: .1em; color: var(--faint);
}
.act b { font-family: var(--mono); font-size: 12px; }

/* ---- floating kart labels --------------------------------------------------- */
#label-layer { position: fixed; inset: 0; z-index: 12; pointer-events: none; }
.kart-label {
  position: absolute; top: 0; left: 0; display: flex; align-items: center; gap: 5px;
  padding: 2px 7px 2px 4px; border-radius: 999px; white-space: nowrap;
  background: var(--panel-solid); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm); font-family: var(--mono); font-size: 10.5px;
  color: var(--text); will-change: transform;
}
.kl-pos {
  min-width: 15px; height: 15px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--kl-color, var(--dim)); color: #fff; font-weight: 700; font-size: 9.5px;
}
.kart-label.elite { border-color: var(--accent); }
.kart-label.elite .kl-name { color: var(--accent); font-weight: 700; }
.kart-label.me { border-color: var(--text); font-weight: 700; }

/* ---- speedometer ------------------------------------------------------------ */
#speedo {
  position: fixed; right: 16px; bottom: 74px; z-index: 18;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end; min-width: 116px;
}
.sp-num { display: flex; align-items: baseline; gap: 4px; }
#sp-val { font-family: var(--mono); font-size: 26px; font-weight: 700; line-height: 1; }
.sp-num small { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: .1em; }
.sp-meter { width: 100%; height: 5px; border-radius: 999px; background: var(--border); overflow: hidden; }
#sp-drift { height: 100%; width: 0%; border-radius: 999px; background: #4aa8ff; transition: width .08s linear; }
#sp-drift.t1 { background: #4aa8ff; }
#sp-drift.t2 { background: #ff9d3b; }
#sp-drift.t3 { background: #ff5bd6; }

/* ---- speed lines while boosting -------------------------------------------- */
#speed-lines {
  position: fixed; inset: 0; z-index: 11; pointer-events: none; opacity: 0;
  transition: opacity .18s ease;
  background:
    radial-gradient(ellipse at center, rgba(255,255,255,0) 42%, rgba(255,255,255,.32) 100%);
  mix-blend-mode: screen;
}
body[data-theme='dark'] #speed-lines {
  background: radial-gradient(ellipse at center, rgba(255,255,255,0) 42%, rgba(180,210,255,.3) 100%);
}
#speed-lines.on { opacity: 1; }

/* ---- lap split flash --------------------------------------------------------- */
#lap-flash {
  position: fixed; top: 96px; left: 50%; transform: translateX(-50%);
  z-index: 22; pointer-events: none;
}
#lap-flash span {
  display: inline-block; padding: 8px 20px; border-radius: 999px;
  background: var(--panel-solid); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow); font-family: var(--mono); font-size: 15px; font-weight: 700;
  animation: lapPop 1.6s ease forwards;
}
#lap-flash.final span { color: var(--accent); border-color: var(--accent); }
@keyframes lapPop {
  0% { opacity: 0; transform: translateY(-8px) scale(.96); }
  14% { opacity: 1; transform: none; }
  76% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-6px); }
}

/* ---- gamepad menu focus ------------------------------------------------------ */
.pad-focus {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---- race / watch mode visibility -------------------------------------------- */
#bottom-bar.race-mode .watch-only { display: none; }

@media (max-width: 820px) {
  #brain-panel { display: none !important; }
  /* the lower half of a phone screen belongs to the joystick and buttons, so
     the speedometer moves up beside the standings instead */
  #speedo {
    right: 12px; top: 96px; bottom: auto; min-width: 76px; padding: 8px 10px;
  }
  #speedo .sp-num #sp-val { font-size: 19px; }
  .kart-label { font-size: 9.5px; }
  #lap-flash { top: 150px; }
}
