/* ==========================================================================
   反应速度测试 · 样式
   ========================================================================== */

:root {
  --bg-0: #070b16;
  --bg-1: #0c1226;
  --bg-2: #131a35;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #eef2ff;
  --text-dim: #a7b0d0;
  --text-mute: #6f7aa0;

  --accent: #4f8cff;
  --accent-2: #7c5cff;
  --green: #22e07a;
  --green-deep: #0f9d58;
  --red: #ff4d5e;
  --red-deep: #a3122a;
  --amber: #ffb020;

  --radius: 18px;
  --radius-sm: 11px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.5);

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-0);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  transition: background 180ms linear;
}

body.no-select { user-select: none; -webkit-user-select: none; }
body[data-phase="go"] { cursor: crosshair; }
body[data-phase="waiting"] { cursor: progress; }

/* --------------------------------------------------------------------------
   背景层（反应区颜色就在这里）
   -------------------------------------------------------------------------- */

.bg-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(1100px 700px at 12% -10%, rgba(79, 140, 255, 0.20), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(124, 92, 255, 0.18), transparent 55%),
    linear-gradient(160deg, var(--bg-0) 0%, var(--bg-1) 55%, var(--bg-0) 100%);
  transition: background 220ms var(--ease);
}

/* 等待：红 */
body[data-phase="waiting"] .bg-layer {
  background:
    radial-gradient(900px 600px at 50% 0%, rgba(255, 77, 94, 0.30), transparent 65%),
    linear-gradient(160deg, #2a0714 0%, #56101f 55%, #240610 100%);
  transition: none;
}

/* 出发：绿（全屏纯色，最容易看清） */
body[data-phase="go"] .bg-layer {
  background:
    radial-gradient(1000px 700px at 50% 20%, rgba(255, 255, 255, 0.22), transparent 70%),
    linear-gradient(160deg, #0a7a45 0%, #12b768 50%, #0a8f4f 100%);
  transition: none;
}

/* 抢跑 / 超时 */
body[data-phase="foul"] .bg-layer {
  background:
    radial-gradient(900px 600px at 50% 0%, rgba(255, 176, 32, 0.28), transparent 65%),
    linear-gradient(160deg, #2a1c05 0%, #4d3208 55%, #1d1304 100%);
  transition: none;
}

.grid-layer {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at 50% 40%, #000 0%, transparent 78%);
  -webkit-mask-image: radial-gradient(circle at 50% 40%, #000 0%, transparent 78%);
}

body[data-phase="go"] .grid-layer,
body[data-phase="waiting"] .grid-layer,
body[data-phase="foul"] .grid-layer { opacity: 0.12; }

/* --------------------------------------------------------------------------
   顶栏 / 页脚
   -------------------------------------------------------------------------- */

.topbar {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px clamp(16px, 4vw, 34px);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.4px;
  font-size: 15px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.bolt { filter: drop-shadow(0 0 10px rgba(255, 200, 60, 0.7)); }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.pill {
  font-size: 12px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-dim);
  white-space: nowrap;
}
.pill-ok { color: #86f0b6; border-color: rgba(34, 224, 122, 0.35); background: rgba(34, 224, 122, 0.10); }
.pill-warn { color: #ffd591; border-color: rgba(255, 176, 32, 0.35); background: rgba(255, 176, 32, 0.10); }

.footer {
  position: relative;
  z-index: 4;
  padding: 14px clamp(16px, 4vw, 34px) 20px;
  font-size: 12px;
  color: var(--text-mute);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.footer .dot { opacity: 0.5; }

/* --------------------------------------------------------------------------
   页面布局与面板
   -------------------------------------------------------------------------- */

.page {
  position: relative;
  z-index: 3;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2vh, 26px) clamp(14px, 4vw, 34px);
  width: 100%;
}

.screen { display: none; width: 100%; justify-content: center; }
body[data-screen="idle"] #screen-idle,
body[data-screen="summary"] #screen-summary,
body[data-screen="board"] #screen-board { display: flex; }

/* 测试进行中隐藏所有面板 */
body[data-screen="testing"] .screen { display: none; }

.screen-idle { flex-direction: column; align-items: center; gap: 16px; }

.card {
  width: min(680px, 100%);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.035));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: clamp(22px, 3.4vw, 38px);
  animation: rise 420ms var(--ease) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------------------
   开始页
   -------------------------------------------------------------------------- */

.hero-badge {
  display: inline-block;
  font-size: 12px;
  letter-spacing: 0.6px;
  padding: 6px 12px;
  border-radius: 999px;
  color: #cfe0ff;
  background: rgba(79, 140, 255, 0.14);
  border: 1px solid rgba(79, 140, 255, 0.3);
  margin-bottom: 16px;
}

.hero-title {
  margin: 0 0 10px;
  font-size: clamp(28px, 5.2vw, 42px);
  line-height: 1.14;
  letter-spacing: -0.5px;
  background: linear-gradient(100deg, #ffffff 10%, #a9c3ff 60%, #cfb6ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-sub {
  margin: 0 0 22px;
  color: var(--text-dim);
  font-size: clamp(14px, 1.7vw, 15.5px);
  line-height: 1.75;
}

.c-red { color: #ff8592; font-weight: 600; }
.c-green { color: #5ef2a4; font-weight: 600; }

.field { margin-bottom: 20px; }

.field label {
  display: block;
  font-size: 12.5px;
  color: var(--text-mute);
  margin-bottom: 8px;
  letter-spacing: 0.3px;
}

.input {
  width: 100%;
  padding: 13px 15px;
  font-size: 15px;
  color: var(--text);
  background: rgba(6, 10, 22, 0.55);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 160ms, box-shadow 160ms;
  font-family: inherit;
}
.input::placeholder { color: #5c6688; }
.input:focus {
  border-color: rgba(79, 140, 255, 0.75);
  box-shadow: 0 0 0 4px rgba(79, 140, 255, 0.16);
}

.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }

.hint-row {
  margin-top: 18px;
  font-size: 12.5px;
  color: var(--text-mute);
  line-height: 1.9;
}

.kbd {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.07);
  font-size: 11.5px;
  color: var(--text-dim);
}

/* 小统计条 */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  width: min(680px, 100%);
}
.stat-mini {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  backdrop-filter: blur(8px);
}
.stat-mini-k { font-size: 11.5px; color: var(--text-mute); }
.stat-mini-v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   按钮
   -------------------------------------------------------------------------- */

.btn {
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 120ms var(--ease), box-shadow 160ms, background 160ms, border-color 160ms;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(0.99); }

.btn-primary {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 28px rgba(79, 140, 255, 0.34);
}
.btn-primary:hover { box-shadow: 0 16px 34px rgba(79, 140, 255, 0.44); }

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--line-strong);
  color: var(--text-dim);
}
.btn-ghost:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.32); }

.btn-sm { padding: 8px 14px; font-size: 12.5px; }
.btn-lg { padding: 14px 26px; font-size: 15.5px; }

/* 点到空白处时轻推一下按钮：点击空白不启动测试，但要让人知道该点哪里 */
@keyframes nudge {
  0%, 100% { transform: none; }
  25% { transform: translateY(-2px) scale(1.045); box-shadow: 0 0 0 7px rgba(79, 140, 255, 0.20); }
  60% { transform: translateY(-1px) scale(1.015); }
}
.btn.nudge { animation: nudge 640ms var(--ease) 1; }

.btn-danger { background: rgba(255, 77, 94, 0.14); border-color: rgba(255, 77, 94, 0.4); color: #ff9aa4; }
.btn-danger:hover { background: rgba(255, 77, 94, 0.22); }

/* --------------------------------------------------------------------------
   实时计时层
   -------------------------------------------------------------------------- */

.live-layer {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
body[data-screen="testing"] .live-layer { display: flex; }
body[data-screen="testing"] { overflow: hidden; }

.live-inner { text-align: center; padding: 20px; }

.live-hint {
  font-size: clamp(30px, 7.5vw, 68px);
  font-weight: 800;
  letter-spacing: 1px;
  line-height: 1.1;
  text-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
  animation: pop 260ms var(--ease) both;
}

@keyframes pop {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: none; }
}

body[data-phase="waiting"] .live-hint { color: #ffe3e7; }
body[data-phase="go"] .live-hint { color: #ffffff; text-shadow: 0 10px 44px rgba(0, 0, 0, 0.3); }
body[data-phase="foul"] .live-hint { color: #ffe6b8; }

.live-round {
  margin-top: 14px;
  font-size: 14px;
  letter-spacing: 1.5px;
  color: rgba(255, 255, 255, 0.82);
  font-variant-numeric: tabular-nums;
}

.dots { display: flex; gap: 9px; justify-content: center; margin-top: 18px; }
.dots i {
  width: 11px; height: 11px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.35);
  transition: transform 160ms var(--ease), background 160ms;
}
.dots i.done { background: #fff; }
.dots i.now { background: var(--amber); transform: scale(1.35); border-color: #fff; }

.live-penalty {
  margin-top: 18px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.9);
  min-height: 20px;
}

/* 结果提示（复用 live 层） */
.result-num {
  font-size: clamp(56px, 15vw, 150px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -2px;
}
.result-num em { font-size: 0.3em; font-style: normal; opacity: 0.7; margin-left: 6px; }

/* --------------------------------------------------------------------------
   本轮成绩面板
   -------------------------------------------------------------------------- */

.summary-card { width: min(720px, 100%); }

.summary-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.summary-label { font-size: 12.5px; color: var(--text-mute); letter-spacing: 0.6px; }

.summary-avg {
  font-size: clamp(44px, 9vw, 68px);
  font-weight: 800;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1.5px;
}
.summary-avg em { font-size: 0.3em; font-style: normal; color: var(--text-mute); margin-left: 6px; }

.rating {
  font-size: 14px;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.07);
}

.bars { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }

.bar-row { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--text-mute); }
.bar-row .bar-idx { width: 44px; flex: none; }
.bar-track { flex: 1; height: 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.07); overflow: hidden; }
.bar-fill {
  display: block;            /* span 默认是 inline，必须转成块级 width/height 才生效 */
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  width: 0;
  transition: width 620ms var(--ease);
}
.bar-row .bar-val { width: 74px; text-align: right; flex: none; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.bar-row .bar-tag { width: 52px; flex: none; text-align: right; font-size: 11.5px; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.mini {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mini span { font-size: 11.5px; color: var(--text-mute); }
.mini strong { font-size: 17px; font-variant-numeric: tabular-nums; }

.save-state { font-size: 12.5px; color: var(--text-mute); margin-bottom: 18px; min-height: 18px; }
.save-state.ok { color: #86f0b6; }
.save-state.err { color: #ffb0b8; }

.summary-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* --------------------------------------------------------------------------
   排行榜 / 历史 / 统计
   -------------------------------------------------------------------------- */

.board-card { width: min(820px, 100%); }

.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.board-head h2 { margin: 0; font-size: 20px; letter-spacing: 0.3px; }
.board-head-actions { display: flex; gap: 8px; }

.tabs {
  display: flex;
  gap: 6px;
  padding: 5px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: 999px;
  margin-bottom: 16px;
  overflow-x: auto;
}
.tab {
  flex: 1;
  min-width: 88px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-mute);
  background: transparent;
  border: 0;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 160ms, color 160ms;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: #fff; }

.board-body { max-height: min(58vh, 520px); overflow-y: auto; padding-right: 4px; }
.board-body::-webkit-scrollbar { width: 8px; }
.board-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.16); border-radius: 8px; }

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: rgba(12, 18, 38, 0.92);
  backdrop-filter: blur(6px);
  z-index: 1;
}
.table td { padding: 10px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); font-variant-numeric: tabular-nums; }
.table tr.me td { background: rgba(79, 140, 255, 0.12); }
.table tr:hover td { background: rgba(255, 255, 255, 0.04); }

.rk { font-weight: 700; width: 46px; }
.rk-1 { color: #ffd76a; }
.rk-2 { color: #d7dce8; }
.rk-3 { color: #e0a173; }

.time-strong { font-weight: 700; }
.cell-name { max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-dim { color: var(--text-mute); font-size: 12.5px; }

.empty {
  text-align: center;
  padding: 44px 16px;
  color: var(--text-mute);
  font-size: 13.5px;
  line-height: 2;
}

.tag-fast { color: #5ef2a4; }
.tag-mid { color: #ffd76a; }
.tag-slow { color: #ff9aa4; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat-box {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.stat-box span { display: block; font-size: 11.5px; color: var(--text-mute); margin-bottom: 6px; }
.stat-box strong { font-size: 22px; font-variant-numeric: tabular-nums; }

.section-title { font-size: 13px; color: var(--text-dim); margin: 18px 0 10px; font-weight: 600; }

.spark { display: flex; align-items: flex-end; gap: 3px; height: 84px; padding: 8px 4px; background: rgba(0, 0, 0, 0.25); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.spark i { flex: 1; background: linear-gradient(180deg, var(--accent), rgba(124, 92, 255, 0.5)); border-radius: 3px 3px 0 0; min-height: 3px; }

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translate(-50%, 24px);
  z-index: 20;
  padding: 12px 20px;
  border-radius: 999px;
  background: rgba(16, 22, 42, 0.95);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 13.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms var(--ease), transform 220ms var(--ease);
  max-width: min(90vw, 520px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --------------------------------------------------------------------------
   响应式
   -------------------------------------------------------------------------- */

@media (max-width: 720px) {
  .stat-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { padding: 20px 18px; border-radius: 16px; }
  .summary-head { align-items: flex-start; }
  .table th:nth-child(5), .table td:nth-child(5) { display: none; }
  .footer { font-size: 11px; }
}

@media (max-width: 480px) {
  .hero-actions .btn, .summary-actions .btn { flex: 1; text-align: center; }
  .board-head { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
