/*
 * BLACKTOP 的基础层：设计令牌 + 控件 + 弹窗 + 结算页。
 *
 * 三张样式表的分工：
 *   game.css  这里——全局令牌、按钮、遮罩弹窗、结算页；
 *   net.css   大厅与候场（房间浏览器、名册、选车）；
 *   hud.css   赛道（伪 3D 画面上的仪表盘、名次、触屏控件）。
 *
 * 配色只在这一个地方定义。别的文件一律引用变量，这样"把整辆车换个颜色"
 * 就真的只需要改一处。
 */

:root {
  --bg: #080b12;
  --bg2: #0d121c;
  --panel: #131b28;
  --panel2: #1a2534;
  --line: #ffffff16;
  --line2: #ffffff26;
  --text: #edf4ff;
  --muted: #8ea2ba;
  --amber: #ffb03a;
  --amber2: #ff8a3d;
  --cyan: #5ce1ff;
  --ok: #7cf7a0;
  --danger: #ff6a7a;
  --shadow: 0 18px 44px #00000066;
  --font: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
  color-scheme: dark;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body { overflow-x: hidden; }

button, input, select, a { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
button { border: 0; background: none; cursor: pointer; user-select: none; touch-action: manipulation; }
button:disabled { cursor: default; }
a { text-decoration: none; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
canvas:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }

.hidden { display: none !important; }
.screen { width: 100%; }

/* 无障碍：屏幕上不显示，但读屏软件会读。断线、冲线名次都从这里播报。 */
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; border: 0; clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

/* ------------------------------------------------------------------ 品牌 */
.brand { display: flex; align-items: center; gap: 12px; font-weight: 900; letter-spacing: .5px; }
.brand > span:last-child { display: block; font-size: 18px; line-height: 1.1; }
.brand small {
  display: block; margin-top: 4px;
  font-size: 9px; font-weight: 600; letter-spacing: 1.8px; color: var(--muted);
}
.brand-mark {
  display: grid; place-items: center;
  width: 44px; height: 42px; flex: 0 0 auto;
  border-radius: 11px 4px 11px 4px;
  background: linear-gradient(150deg, var(--amber), var(--amber2));
  color: #201203; font-size: 27px; font-weight: 900; font-style: italic;
  box-shadow: 0 0 26px #ffb03a3d;
}

/* ------------------------------------------------------------------ 控件 */
.primary-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  height: 42px; padding: 0 20px; border-radius: 10px;
  background: linear-gradient(115deg, var(--amber), var(--amber2));
  color: #201203; font-size: 14px; font-weight: 900; letter-spacing: .3px;
  box-shadow: 0 4px 0 #a3560f, 0 12px 26px #ff9a3d1f;
  transition: transform .16s, filter .16s, box-shadow .16s;
}
.primary-button:hover { filter: brightness(1.07); transform: translateY(-1px); }
.primary-button:active { transform: translateY(2px); box-shadow: 0 1px 0 #a3560f; }
.primary-button:disabled { filter: saturate(.3) brightness(.7); box-shadow: none; transform: none; }

.secondary-button {
  display: inline-flex; align-items: center; justify-content: center;
  height: 42px; padding: 0 18px; border-radius: 10px;
  background: var(--panel2); border: 1px solid var(--line);
  color: var(--text); font-size: 13px; font-weight: 800;
}
.secondary-button:hover { border-color: var(--line2); background: #22303f; }

.text-button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 2px; font-size: 12px; color: var(--muted);
  border-bottom: 1px solid transparent;
}
.text-button:hover { color: var(--cyan); border-color: #5ce1ff66; }

.icon-button {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 10px;
  background: #ffffff08; border: 1px solid var(--line);
  color: #cfdcea; font-size: 17px; font-weight: 700;
  transition: background .16s, border-color .16s, color .16s;
}
.icon-button:hover { background: #ffffff14; border-color: var(--line2); color: #fff; }
.icon-button.off { color: var(--muted); }

kbd {
  display: inline-block; min-width: 22px; padding: 2px 6px; margin-right: 3px;
  border: 1px solid var(--line2); border-bottom-width: 2px; border-radius: 5px;
  background: #0b1220; color: #cfe0ee;
  font: 700 11px var(--mono); text-align: center;
}

/* ------------------------------------------------------------------ 弹窗 */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center; padding: 22px;
  background: #04070ccc; backdrop-filter: blur(9px);
}
.modal {
  width: min(520px, 100%);
  padding: 26px 28px;
  border: 1px solid var(--line2); border-radius: 18px;
  background: linear-gradient(165deg, #1a2433, #101825);
  box-shadow: var(--shadow); text-align: center;
}
.modal h2 { margin: 0 0 10px; font-size: 26px; letter-spacing: -.5px; }
.modal p { margin: 0 0 18px; font-size: 12px; line-height: 1.85; color: var(--muted); }
.modal-actions { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.name-modal { text-align: left; }
.name-field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 10px; font-size: 10px; color: var(--muted); }
.name-field input {
  padding: 13px; border-radius: 11px; border: 1px solid var(--line);
  background: #0b1220; color: var(--text); font-size: 17px; font-weight: 700;
}
.name-field input:focus { border-color: #5ce1ff88; outline: none; }
.name-error { margin: 0 0 12px; font-size: 11px; font-weight: 700; color: var(--danger); }
.name-error.hidden { display: none; }

.help-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 9px; margin: 0 0 16px; text-align: left;
}
.help-grid > div {
  display: flex; align-items: center; gap: 4px;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: #ffffff05; font-size: 11px; color: #c6d4e2;
}
.help-grid > div > span { margin-left: 6px; color: var(--muted); }
.help-note { text-align: left; }
.help-note b { color: var(--amber); }

/* ------------------------------------------------------------------ 结算 */
#results {
  position: relative; min-height: 100dvh; display: grid; place-items: center;
  padding: 32px 16px 56px;
  background:
    radial-gradient(ellipse at 50% 0%, #2a1a1266 0, transparent 60%),
    radial-gradient(ellipse at 12% 90%, #12304344 0, transparent 55%),
    var(--bg);
}
.result-card {
  position: relative; z-index: 5; width: min(760px, 100%);
  padding: 30px 32px 26px; border-radius: 20px;
  border: 1px solid var(--line2);
  background: linear-gradient(170deg, #18212f, #0e1521);
  box-shadow: var(--shadow); text-align: center;
}
.result-eyebrow { font-size: 10px; font-weight: 800; letter-spacing: 3px; color: var(--muted); }
.result-rank {
  margin: 8px 0 6px;
  font-size: 74px; font-weight: 900; font-style: italic; line-height: 1;
  letter-spacing: -4px; font-variant-numeric: tabular-nums;
  color: var(--amber); text-shadow: 0 6px 22px #00000088;
}
.result-card h2 { margin: 6px 0 8px; font-size: 24px; }
.result-card > p { margin: 0 0 18px; font-size: 12px; line-height: 1.85; color: var(--muted); }
.result-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
  padding: 14px 0; margin: 4px 0 16px;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.result-stats strong { display: block; font-size: 21px; font-variant-numeric: tabular-nums; }
.result-stats span { display: block; margin-top: 5px; font-size: 9px; letter-spacing: 1px; color: var(--muted); }
.result-payout {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin-bottom: 10px; font-size: 12px; color: var(--muted);
}
.result-payout strong { font-size: 26px; color: var(--ok); font-variant-numeric: tabular-nums; }
.result-record { margin: 0 0 14px !important; font-size: 10px !important; letter-spacing: 1px; }

.result-head,
.result-row {
  display: grid; grid-template-columns: 34px minmax(0, 1.5fr) 76px 52px 52px 84px;
  gap: 8px; align-items: center; font-size: 11px;
}
.result-head {
  padding: 8px 10px; margin-bottom: 4px; color: var(--muted);
  font-size: 9px; letter-spacing: 1px; text-align: right;
}
.result-head span:nth-child(2) { text-align: left; }
.result-table { display: flex; flex-direction: column; gap: 3px; max-height: 236px; overflow-y: auto; }
.result-row { padding: 8px 10px; border-radius: 9px; background: #ffffff05; text-align: right; }
.result-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-row span:nth-child(2) { text-align: left; font-weight: 700; }
.result-row.me { background: #ffb03a1f; box-shadow: inset 2px 0 var(--amber); }
.result-row.bot { color: var(--muted); }
.result-actions { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 22px; flex-wrap: wrap; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 1; }
.confetti i {
  position: absolute; top: -16px; width: 8px; height: 14px; border-radius: 2px;
  animation-name: bt-fall; animation-timing-function: linear; animation-iteration-count: infinite;
}
@keyframes bt-fall {
  from { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  to { transform: translateY(105vh) rotate(540deg); opacity: .85; }
}

@media (max-width: 640px) {
  .result-card { padding: 22px 16px 20px; }
  .result-rank { font-size: 56px; }
  .result-stats { grid-template-columns: repeat(2, 1fr); }
  .result-head, .result-row { grid-template-columns: 26px minmax(0, 1.4fr) 64px 44px 44px 70px; font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .confetti { display: none; }
}
