/* style.css — Mario-ish HUD, menus and overlays */
:root {
  --ink: #10121c;
  --paper: #fffdf6;
  --red: #e52521;
  --blue: #2b56c9;
  --yellow: #ffd429;
  --green: #35c759;
  --panel: rgba(12, 16, 32, 0.72);
  --stroke: rgba(255, 255, 255, 0.16);
  --font: "Baloo 2", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #0a0d18;
  font-family: var(--font);
  color: var(--paper);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 90ms linear;
  mix-blend-mode: screen;
  z-index: 5;
}

/* ------------------------------------------------------------------ HUD */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transition: opacity 260ms ease;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}
#hud.show { opacity: 1; }

.hud-tl, .hud-tr, .hud-bl, .hud-br { position: absolute; display: flex; gap: 10px; }
.hud-tl { top: 16px; left: 16px; flex-direction: row; flex-wrap: wrap; max-width: 46vw; }
.hud-tr { top: 16px; right: 16px; flex-direction: column; align-items: flex-end; }
.hud-bl { bottom: 18px; left: 16px; flex-direction: column; align-items: flex-start; }
.hud-br { bottom: 18px; right: 16px; flex-direction: column; align-items: flex-end; }

.pill {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 2px solid var(--stroke);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  font-weight: 800;
  letter-spacing: 0.02em;
  font-size: 20px;
  line-height: 1;
}
.pill.big span:first-child.lbl { font-size: 12px; opacity: 0.75; letter-spacing: 0.16em; }
.pill .sep { opacity: 0.45; }
.pill.big span:not(.lbl):not(.sep) { font-size: 26px; }
.pill.coins { font-size: 18px; gap: 8px; }
.coin {
  width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0, #ffcf22 60%, #c98f00);
  box-shadow: 0 0 8px rgba(255, 205, 40, 0.6);
}

#minimap {
  border-radius: 50%;
  border: 2px solid var(--stroke);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  background: rgba(8, 11, 22, 0.5);
}

.times {
  margin-top: 4px;
  min-width: 168px;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--panel);
  border: 2px solid var(--stroke);
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.trow { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; letter-spacing: 0.12em; opacity: 0.8; }
.trow b { font-family: var(--mono); font-size: 14px; letter-spacing: 0; opacity: 1; }
.trow.best b { color: var(--yellow); }

.speedo {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 16px 8px;
  border-radius: 18px;
  background: var(--panel);
  border: 2px solid var(--stroke);
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.speedo #speedValue { font-size: 44px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.speedo span { font-size: 11px; letter-spacing: 0.18em; opacity: 0.7; }

.charge {
  margin-top: 6px;
  width: 190px;
  height: 9px;
  border-radius: 999px;
  background: rgba(10, 14, 28, 0.6);
  border: 2px solid var(--stroke);
  overflow: hidden;
  opacity: 0.35;
  transition: opacity 150ms ease;
}
.charge.on { opacity: 1; }
.charge #chargeFill {
  height: 100%;
  width: 0%;
  background: #7fd4ff;
  transition: width 60ms linear, background 120ms ease;
}
.charge #chargeFill[data-tier="1"] { background: linear-gradient(90deg, #ffd429, #ff9f1a); }
.charge #chargeFill[data-tier="2"] { background: linear-gradient(90deg, #ff9f1a, #ff5a3c); }
.charge #chargeFill[data-tier="3"] { background: linear-gradient(90deg, #ff5a3c, #c724b1, #7a5cff); }

.item-slot {
  width: 96px;
  height: 96px;
  border-radius: 22px;
  background: rgba(12, 16, 32, 0.55);
  border: 3px solid var(--stroke);
  background-size: 78%;
  background-position: center;
  background-repeat: no-repeat;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4), inset 0 0 0 4px rgba(255, 255, 255, 0.05);
  display: grid;
  place-items: center;
}
.item-slot.has { border-color: rgba(255, 212, 41, 0.75); box-shadow: 0 0 26px rgba(255, 212, 41, 0.35), inset 0 0 0 4px rgba(255, 255, 255, 0.08); }
.item-slot.roulette { animation: spin-slot 160ms linear infinite; }
@keyframes spin-slot { 0% { transform: rotate(-4deg) scale(0.94); } 50% { transform: rotate(4deg) scale(1.04); } 100% { transform: rotate(-4deg) scale(0.94); } }
.item-label { margin-top: 6px; font-size: 11px; letter-spacing: 0.16em; opacity: 0.85; text-shadow: 0 2px 6px #000; }

#countdown {
  position: absolute;
  top: 26%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.4);
  font-size: clamp(64px, 13vw, 150px);
  font-weight: 900;
  letter-spacing: 0.04em;
  opacity: 0;
  color: #fff;
  text-shadow: 0 8px 0 var(--red), 0 14px 26px rgba(0, 0, 0, 0.6);
}
#countdown.show { animation: pop 700ms cubic-bezier(0.22, 1.4, 0.4, 1) forwards; }
#countdown.go { color: var(--yellow); text-shadow: 0 8px 0 #b8860b, 0 14px 30px rgba(0, 0, 0, 0.6); }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.35) rotate(-8deg); }
  35% { opacity: 1; transform: translate(-50%, -50%) scale(1.12) rotate(3deg); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.05) rotate(0deg); }
}

#toast, #warn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 20px;
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: 0.08em;
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
  white-space: nowrap;
}
#toast { top: 46%; background: rgba(12, 16, 32, 0.72); border: 2px solid var(--stroke); }
#warn { top: 56%; background: rgba(229, 37, 33, 0.85); border: 2px solid rgba(255, 255, 255, 0.35); }
#toast.show, #warn.show { opacity: 1; transform: translateX(-50%) translateY(4px); }

/* ------------------------------------------------------------------ screens */
.screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(120% 100% at 50% 0%, rgba(20, 26, 56, 0.72), rgba(6, 8, 18, 0.92));
  backdrop-filter: blur(9px);
  overflow: auto;
}
.screen.show { display: flex; }

.menu-inner {
  width: min(1000px, 96vw);
  background: linear-gradient(180deg, rgba(20, 25, 52, 0.92), rgba(11, 14, 30, 0.95));
  border: 2px solid var(--stroke);
  border-radius: 26px;
  padding: 26px clamp(18px, 3vw, 34px) 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.menu-inner.narrow { width: min(420px, 92vw); text-align: center; }

.title {
  margin: 0 0 4px;
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  font-size: clamp(34px, 6vw, 58px);
  font-weight: 900;
  letter-spacing: 0.01em;
}
.title .t1 { color: #ff5a4a; text-shadow: 0 5px 0 #8f1512; }
.title .t2 { color: #fff; text-shadow: 0 5px 0 #2b56c9; }
.title .t3 { color: var(--yellow); text-shadow: 0 5px 0 #a37b00; font-size: 0.6em; }
.tagline { margin: 0 0 18px; opacity: 0.75; font-size: 14px; letter-spacing: 0.04em; }

.menu-cols { display: grid; grid-template-columns: 1.35fr 1fr; gap: 22px; }
@media (max-width: 780px) { .menu-cols { grid-template-columns: 1fr; } }

h2 { font-size: 13px; letter-spacing: 0.2em; opacity: 0.7; margin: 0 0 10px; font-weight: 800; }

.track-list { display: flex; flex-direction: column; gap: 9px; }
.card {
  text-align: left;
  cursor: pointer;
  font-family: var(--font);
  color: var(--paper);
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid transparent;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}
.card:hover { background: rgba(255, 255, 255, 0.1); transform: translateX(3px); }
.card.sel { border-color: var(--yellow); background: rgba(255, 212, 41, 0.12); }
.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.card-name { font-weight: 900; font-size: 17px; letter-spacing: 0.02em; }
.card-lap { font-size: 11px; letter-spacing: 0.14em; opacity: 0.7; }
.card-sub { font-size: 12.5px; opacity: 0.72; margin-top: 3px; }
.card-stats { display: flex; gap: 14px; margin-top: 7px; font-size: 11px; letter-spacing: 0.1em; opacity: 0.6; font-family: var(--mono); }

.row-btns { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.row-btns h2 { margin: 0; }
.row-btns.center { justify-content: center; margin-top: 20px; }
.row-btns.col { flex-direction: column; }
.row-btns.col button { width: 100%; }

.lap-opts { display: flex; gap: 7px; }
.chipbtn, .small-btn {
  font-family: var(--font);
  color: var(--paper);
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid transparent;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  transition: all 120ms ease;
}
.chipbtn:hover, .small-btn:hover { background: rgba(255, 255, 255, 0.14); }
.chipbtn.sel { border-color: var(--yellow); color: var(--yellow); }
.small-btn small { opacity: 0.5; font-size: 10px; margin-left: 5px; }

.big-btn {
  margin-top: 18px;
  font-family: var(--font);
  cursor: pointer;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #fff;
  padding: 14px 34px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff6a52, var(--red));
  box-shadow: 0 6px 0 #8f1512, 0 14px 30px rgba(229, 37, 33, 0.35);
  transition: transform 90ms ease, box-shadow 90ms ease;
}
.big-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #8f1512, 0 18px 34px rgba(229, 37, 33, 0.4); }
.big-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 #8f1512; }
.big-btn small { font-size: 11px; opacity: 0.75; margin-left: 8px; letter-spacing: 0.16em; }

.keys { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.keys li { display: flex; gap: 12px; align-items: baseline; font-size: 12.5px; }
.keys b {
  font-family: var(--mono);
  font-size: 11px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--stroke);
  border-radius: 7px;
  padding: 3px 7px;
  min-width: 92px;
  text-align: center;
  flex: none;
}
.keys span { opacity: 0.75; }
.hint { font-size: 11.5px; line-height: 1.6; opacity: 0.55; margin: 14px 0 10px; }
.credit { margin-top: 18px; text-align: center; font-size: 10.5px; letter-spacing: 0.14em; opacity: 0.35; }

/* ------------------------------------------------------------------ results */
.res-title { font-size: 15px; letter-spacing: 0.24em; text-align: center; margin: 0 0 6px; }
.final-pos {
  text-align: center;
  font-size: clamp(46px, 9vw, 82px);
  font-weight: 900;
  line-height: 1;
  color: var(--yellow);
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
  margin-bottom: 4px;
}
.final-pos.p1 { color: #ffd429; }
.final-pos.p2 { color: #d8dee9; }
.final-pos.p3 { color: #e09a52; }
.res-sub { text-align: center; font-size: 12px; letter-spacing: 0.12em; opacity: 0.65; margin-bottom: 16px; font-family: var(--mono); }

.res-table { display: flex; flex-direction: column; gap: 5px; }
.res-table .row {
  display: grid;
  grid-template-columns: 54px 18px 1fr 110px 110px;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 13.5px;
}
.res-table .row.head { background: none; font-size: 10.5px; letter-spacing: 0.16em; opacity: 0.5; padding-bottom: 2px; }
.res-table .row.me { background: rgba(255, 212, 41, 0.16); box-shadow: inset 0 0 0 2px rgba(255, 212, 41, 0.4); }
.res-table .pos { font-weight: 900; font-size: 15px; }
.res-table .chip { width: 14px; height: 14px; border-radius: 4px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4) inset; }
.res-table .nm { font-weight: 800; letter-spacing: 0.06em; }
.res-table .t, .res-table .bl { font-family: var(--mono); text-align: right; font-size: 12.5px; opacity: 0.9; }

/* ------------------------------------------------------------------ touch */
#touch { position: fixed; inset: 0; z-index: 20; display: none; pointer-events: none; }
#touch.on { display: block; }
.tpad { position: absolute; bottom: 18px; display: flex; gap: 10px; pointer-events: auto; }
.tpad.left { left: 16px; }
.tpad.right { right: 16px; align-items: flex-end; }
.tbtn {
  width: 74px; height: 74px;
  border-radius: 50%;
  border: 2px solid var(--stroke);
  background: rgba(14, 18, 36, 0.55);
  color: #fff;
  font-size: 24px;
  font-weight: 900;
  backdrop-filter: blur(6px);
  font-family: var(--font);
}
.tbtn.small { width: 62px; height: 62px; font-size: 11px; letter-spacing: 0.06em; }
.tbtn.gas { width: 92px; height: 92px; background: rgba(53, 199, 89, 0.45); font-size: 18px; }
.tbtn.drift { background: rgba(43, 86, 201, 0.5); }
.tbtn.item { background: rgba(229, 37, 33, 0.45); }
.tbtn.down { transform: scale(0.93); filter: brightness(1.35); }

/* ------------------------------------------------------------------ loading / fatal */
#loading {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: #0a0d18;
  font-size: 12px;
  letter-spacing: 0.24em;
  opacity: 1;
  transition: opacity 400ms ease;
}
#loading.hide { opacity: 0; pointer-events: none; }
.spin { width: 46px; height: 46px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, 0.15); border-top-color: var(--yellow); animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#fatal { position: fixed; inset: 0; z-index: 90; display: none; align-items: center; justify-content: center; background: rgba(6, 8, 18, 0.9); padding: 20px; }
#fatal.show { display: flex; }
#fatal .box { max-width: 620px; background: rgba(20, 25, 52, 0.95); border: 2px solid rgba(229, 37, 33, 0.5); border-radius: 20px; padding: 24px 26px; }
#fatal h3 { margin: 0 0 10px; color: #ff8a7a; }
#fatal .msg { font-family: var(--mono); font-size: 13px; line-height: 1.6; white-space: pre-wrap; }
#fatal .small { font-size: 12px; opacity: 0.6; margin-bottom: 0; }
