/* Drive - the menus wear cgovind.com's clothes (paper white, xkcd Script,
   hand-drawn borders) while the game itself is a dark HUD over a bright
   low-poly world. Racing red is the accent, matching the racing tile on the
   landing page. */

@font-face {
  font-family: "xkcd Script";
  src: url("../fonts/xkcd-script.woff") format("woff");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --hand: "xkcd Script", "Comic Sans MS", cursive, sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --paper: #faf8f4;
  --ink: #1d1d1f;
  --ink-soft: #6b6b73;
  --line: #1d1d1f;
  --red: #c0182b;
  --red-soft: #e8453c;
  --blue: #3d8bfd;
  --gold: #e5b528;
  --silver: #a9b0bb;
  --bronze: #c2803f;
  --author: #17b57a;
  --hud: rgba(16, 18, 24, .74);
  --hud-line: rgba(255, 255, 255, .16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--hand);
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- nav ---------------------------------------------------------------- */
.nav {
  display: flex; align-items: center; gap: 1rem;
  padding: .7rem 1.1rem;
  border-bottom: 2px solid var(--line);
  background: var(--paper);
  position: sticky; top: 0; z-index: 40;
  flex-wrap: wrap;
}
.brand {
  font-size: 1.5rem; color: var(--ink); display: flex; align-items: center; gap: .5rem;
}
.brand:hover { text-decoration: none; }
.brand small { color: var(--ink-soft); font-size: .8rem; }
.brand-ico { width: 26px; height: 26px; }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.nav-right a { color: var(--ink); font-size: 1.05rem; }
.nav-right a.active { color: var(--red); text-decoration: underline; }
.nav-user { color: var(--ink-soft); font-size: .95rem; }
.badge, .tag {
  font-family: var(--sans); font-size: .58rem; letter-spacing: .06em;
  border: 1px solid currentColor; border-radius: 3px; padding: .1rem .25rem;
  color: var(--ink-soft); vertical-align: middle;
}
.tag.guest { color: var(--blue); }

/* --- layout ------------------------------------------------------------- */
.wrap { max-width: 1080px; margin: 0 auto; padding: 1.6rem 1.1rem 4rem; }
.wrap.narrow { max-width: 480px; }
h1 { font-size: 2.5rem; margin: .2rem 0 .3rem; }
h2 { font-size: 1.6rem; margin: 1.6rem 0 .6rem; }
h3 { font-size: 1.2rem; margin: 1.2rem 0 .4rem; }
p { line-height: 1.55; }
.muted { color: var(--ink-soft); }
.lede { font-size: 1.15rem; color: var(--ink-soft); margin-top: 0; }

.panel {
  border: 2px solid var(--line); border-radius: 12px;
  padding: 1.1rem 1.2rem; background: #fff;
  box-shadow: 3px 3px 0 rgba(29, 29, 31, .1);
}

.btn {
  font-family: var(--hand); font-size: 1.1rem;
  border: 2px solid var(--line); border-radius: 10px;
  background: var(--red); color: #fff;
  padding: .5rem 1.1rem; cursor: pointer;
  box-shadow: 2px 2px 0 rgba(29, 29, 31, .25);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translate(2px, 2px); box-shadow: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--ink); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.big { font-size: 1.3rem; padding: .7rem 1.4rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

input[type=text], input[type=password], input[type=email], input:not([type]) {
  font-family: var(--hand); font-size: 1.05rem;
  border: 2px solid var(--line); border-radius: 8px;
  padding: .45rem .6rem; width: 100%; background: #fff; color: var(--ink);
}
.field { margin-bottom: .8rem; }
.field label { display: block; font-size: .95rem; color: var(--ink-soft); margin-bottom: .2rem; }
.error {
  display: none; color: var(--red); border: 2px dashed var(--red);
  border-radius: 8px; padding: .4rem .6rem; margin-bottom: .7rem; font-size: .95rem;
}
.error.show { display: block; }

/* --- track cards -------------------------------------------------------- */
.tracks { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: 1rem; }
.tcard {
  border: 2px solid var(--line); border-radius: 12px; background: #fff;
  padding: .9rem 1rem; display: flex; flex-direction: column; gap: .4rem;
  box-shadow: 3px 3px 0 rgba(29, 29, 31, .1); color: var(--ink);
  transition: transform .08s;
}
.tcard:hover { text-decoration: none; transform: translate(-1px, -2px); }
.tcard-top { display: flex; align-items: baseline; gap: .5rem; }
.tcard h3 { margin: 0; font-size: 1.25rem; }
.tcard .blurb { color: var(--ink-soft); font-size: .92rem; line-height: 1.4; flex: 1; }
.diff { display: flex; gap: 2px; margin-left: auto; }
.pip { width: 7px; height: 7px; border-radius: 50%; border: 1px solid var(--line); }
.pip.on { background: var(--red); }
.tcard-foot {
  display: flex; align-items: center; gap: .5rem; font-family: var(--mono);
  font-size: .82rem; color: var(--ink-soft); border-top: 1px dashed #d5d2cb; padding-top: .45rem;
}

.medal {
  width: 12px; height: 12px; border-radius: 50%; display: inline-block;
  border: 1px solid rgba(0, 0, 0, .35); flex: 0 0 auto;
}
.medal.author { background: var(--author); }
.medal.gold { background: var(--gold); }
.medal.silver { background: var(--silver); }
.medal.bronze { background: var(--bronze); }
.medal.none { background: transparent; border-style: dashed; }

/* --- tables ------------------------------------------------------------- */
table.board { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: .92rem; }
table.board th, table.board td { padding: .42rem .55rem; text-align: left; border-bottom: 1px solid #e4e1da; }
table.board th { font-family: var(--hand); font-size: 1rem; color: var(--ink-soft); }
table.board td.num, table.board th.num { text-align: right; font-family: var(--mono); }
table.board tr.me { background: #fff6d9; }

/* =======================================================================
   In-game
   ======================================================================= */
body.playing { overflow: hidden; background: #9ed2f0; }
#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }

.hud { position: fixed; inset: 0; pointer-events: none; font-family: var(--sans); }
.hud > * { pointer-events: auto; }

.hud-tl { position: absolute; top: 12px; left: 14px; display: flex; flex-direction: column; gap: 8px; }
.hud-tr { position: absolute; top: 12px; right: 14px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.hud-bl { position: absolute; bottom: 14px; left: 14px; }
.hud-br { position: absolute; bottom: 14px; right: 14px; text-align: right; }

.card {
  background: var(--hud); color: #fff; border: 1px solid var(--hud-line);
  border-radius: 10px; padding: .5rem .7rem;
  backdrop-filter: blur(6px);
}

.timer { font-family: var(--mono); font-size: 2.1rem; font-weight: 700; line-height: 1.05;
         font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.timer-row { display: flex; align-items: baseline; gap: .6rem; }
.delta { font-family: var(--mono); font-size: 1.15rem; font-weight: 700; }
.delta.ahead { color: #55e08a; }
.delta.behind { color: #ff8a7a; }
.sub { font-size: .78rem; color: #b9c2d0; text-transform: uppercase; letter-spacing: .08em; }

.speedo { display: flex; align-items: flex-end; gap: .35rem; }
.speed-num { font-family: var(--mono); font-size: 2.6rem; font-weight: 700; line-height: .95;
             font-variant-numeric: tabular-nums; }
.speed-unit { font-size: .8rem; color: #b9c2d0; padding-bottom: .35rem; }
.speed-bar { height: 6px; border-radius: 3px; background: rgba(255,255,255,.18); overflow: hidden; margin-top: .35rem; }
.speed-bar i { display: block; height: 100%; width: 0; background: #fff; transition: width .06s linear; }
.speed-bar i.over { background: #8fd6ff; box-shadow: 0 0 10px #8fd6ff; }

#minimap { display: block; width: 190px; height: 150px; }

.trackname { font-family: var(--hand); font-size: 1.35rem; }
.trackblurb { font-size: .8rem; color: #b9c2d0; max-width: 240px; }

.mrow { display: flex; align-items: center; gap: .45rem; font-size: .82rem; padding: .1rem 0; }
.mrow b { margin-left: auto; font-family: var(--mono); }
.mrow.pb { border-top: 1px solid var(--hud-line); margin-top: .3rem; padding-top: .3rem; color: #ffd96b; }

.st-row { display: flex; align-items: center; gap: .45rem; font-size: .85rem; padding: .14rem 0; }
.st-row.me { color: #ffd96b; font-weight: 700; }
.st-pos { width: 1.1rem; text-align: right; font-family: var(--mono); color: #b9c2d0; }
.st-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; border: 1px solid rgba(0,0,0,.4); }
.st-name { max-width: 8.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-gap { margin-left: auto; font-family: var(--mono); font-size: .8rem; color: #cfd7e3; }
.st-elo { font-family: var(--mono); font-size: .75rem; }
.st-elo.up { color: #55e08a; }
.st-elo.down { color: #ff8a7a; }
.elo-line { margin-top: .4rem; font-size: .85rem; color: #cfd7e3; }

.position { display: flex; align-items: baseline; gap: .15rem; }
.position b { font-family: var(--mono); font-size: 2.2rem; line-height: 1; }
.position span { font-size: .95rem; color: #b9c2d0; }

#wrongWay {
  position: absolute; top: 26%; left: 50%; transform: translateX(-50%);
  background: rgba(192, 24, 43, .9); color: #fff; padding: .35rem 1rem;
  border-radius: 8px; font-weight: 700; letter-spacing: .08em;
  animation: pulse .7s ease-in-out infinite alternate;
}
@keyframes pulse { from { opacity: .55; } to { opacity: 1; } }

#toast {
  position: absolute; top: 16%; left: 50%; transform: translateX(-50%);
  background: var(--hud); color: #fff; border: 1px solid var(--hud-line);
  padding: .4rem 1rem; border-radius: 999px; font-size: .95rem;
  opacity: 0; transition: opacity .2s; white-space: nowrap;
}
#toast.show { opacity: 1; }

.countdown {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%);
  font-family: var(--hand); font-size: 8rem; color: #fff;
  text-shadow: 0 6px 24px rgba(0, 0, 0, .5); line-height: 1;
}
.countdown.go { color: #55e08a; font-size: 7rem; }
.countdown.n1 { color: #ffd96b; }

#startHint {
  position: absolute; bottom: 24%; left: 50%; transform: translateX(-50%);
  background: var(--hud); color: #fff; border: 1px solid var(--hud-line);
  padding: .45rem 1.1rem; border-radius: 999px; font-size: 1rem;
}

.overlay {
  position: fixed; inset: 0; background: rgba(12, 14, 20, .72);
  display: flex; align-items: center; justify-content: center; z-index: 60;
  backdrop-filter: blur(3px); padding: 1rem;
}
.sheet {
  background: var(--paper); border: 2px solid var(--line); border-radius: 14px;
  padding: 1.3rem 1.5rem; max-width: 460px; width: 100%;
  box-shadow: 5px 5px 0 rgba(0, 0, 0, .3); max-height: 90vh; overflow: auto;
}
.sheet h2 { margin-top: 0; }
.result-time { font-family: var(--mono); font-size: 2.8rem; font-weight: 700; }
.medal-big {
  display: inline-block; font-family: var(--sans); font-size: .8rem; letter-spacing: .12em;
  border: 2px solid var(--line); border-radius: 999px; padding: .2rem .8rem; margin-bottom: .4rem;
}
.medal-big.author { background: var(--author); color: #fff; }
.medal-big.gold { background: var(--gold); }
.medal-big.silver { background: var(--silver); }
.medal-big.bronze { background: var(--bronze); color: #fff; }
.medal-big.none { background: #fff; }
#resNote div { font-size: .95rem; color: var(--ink-soft); }
#resPending { font-size: .85rem; color: var(--ink-soft); }

/* room side panel */
.side {
  position: fixed; top: 0; right: 0; bottom: 0; width: 274px; z-index: 30;
  background: rgba(16, 18, 24, .8); border-left: 1px solid var(--hud-line);
  color: #fff; font-family: var(--sans); padding: .8rem;
  display: flex; flex-direction: column; gap: .7rem; overflow: auto;
  backdrop-filter: blur(8px);
}
.side h4 { margin: 0 0 .3rem; font-family: var(--hand); font-size: 1.15rem; font-weight: normal; }
.side .btn { font-size: 1rem; padding: .4rem .8rem; width: 100%; }
.pl { display: flex; align-items: center; gap: .4rem; font-size: .88rem; padding: .15rem 0; }
.pl.me { color: #ffd96b; }
.pl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-elo { margin-left: auto; font-family: var(--mono); font-size: .75rem; color: #b9c2d0; }
.kick { background: none; border: 0; color: #ff8a7a; cursor: pointer; font-size: 1rem; }
.tracklist { display: flex; flex-direction: column; gap: 2px; max-height: 168px; overflow: auto; }
.tpick {
  text-align: left; background: rgba(255,255,255,.06); border: 1px solid transparent;
  color: #fff; font-family: var(--sans); font-size: .82rem; border-radius: 6px;
  padding: .28rem .45rem; cursor: pointer;
}
.tpick.active { border-color: #ffd96b; color: #ffd96b; }
#chatLog { flex: 1; min-height: 70px; max-height: 190px; overflow: auto; font-size: .82rem; }
.cm { padding: .1rem 0; line-height: 1.35; word-break: break-word; }
#chatInput { font-family: var(--sans); font-size: .85rem; padding: .3rem .45rem; border-width: 1px; }

/* touch controls */
#touch { display: none; }
body.touch #touch { display: block; }
.tbtn {
  position: fixed; z-index: 35; width: 78px; height: 78px; border-radius: 50%;
  background: rgba(255, 255, 255, .16); border: 2px solid rgba(255, 255, 255, .4);
  color: #fff; font-size: 1.6rem; display: flex; align-items: center; justify-content: center;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
.tbtn.down { background: rgba(255, 255, 255, .4); }
#tLeft { left: 14px; bottom: 96px; }
#tRight { left: 104px; bottom: 96px; }
#tGas { right: 14px; bottom: 96px; }
#tBrake { right: 104px; bottom: 96px; }
#tDrift { right: 60px; bottom: 186px; width: 64px; height: 64px; font-size: .9rem; }

@media (max-width: 860px) {
  .side { width: 100%; height: 46vh; top: auto; bottom: 0; border-left: 0; border-top: 1px solid var(--hud-line); }
  .hud-br { bottom: 48vh; }
  #minimap { width: 130px; height: 104px; }
  .trackblurb { display: none; }
  .speed-num { font-size: 2rem; }
  .timer { font-size: 1.7rem; }
}
@media (max-width: 560px) {
  .hud-tr .card.medals { display: none; }
  .countdown { font-size: 5.5rem; }
}
