:root {
  --bg: #080b0f;
  --bg-soft: #0d1117;
  --panel: #10161d;
  --panel-2: #141c24;
  --border: #26313d;
  --border-soft: #1c2630;
  --text: #f4f7fa;
  --muted: #93a0ad;
  --muted-2: #667380;
  --green: #29d67d;
  --green-soft: rgba(41, 214, 125, .14);
  --red: #ff4d58;
  --red-soft: rgba(255, 77, 88, .14);
  --accent: #d8e2ec;
  --shadow: 0 24px 70px rgba(0, 0, 0, .26);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 12% -10%, rgba(41, 214, 125, .07), transparent 34rem),
    radial-gradient(circle at 92% 0%, rgba(255, 77, 88, .055), transparent 30rem),
    var(--bg);
}
button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid #e6edf3;
  outline-offset: 3px;
}
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell { min-height: 100vh; }
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  min-height: 72px;
  padding: 12px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid rgba(255,255,255,.06);
  background: rgba(8, 11, 15, .88);
  backdrop-filter: blur(16px);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  justify-self: start;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.brand img { filter: drop-shadow(0 0 12px rgba(255,255,255,.06)); }
.brand strong { display: block; font-size: 15px; letter-spacing: -.01em; }
.brand small { display: block; margin-top: 2px; color: var(--muted-2); font-size: 11px; }
.top-nav {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: rgba(255,255,255,.02);
}
.nav-button {
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}
.nav-button.is-active { background: var(--panel-2); color: var(--text); }
.identity {
  justify-self: end;
  min-width: 138px;
  padding: 7px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  text-align: right;
  background: rgba(255,255,255,.02);
}
.identity-label { display: block; color: var(--muted-2); font-size: 9px; text-transform: uppercase; letter-spacing: .09em; }
.identity code { color: #cad4de; font-size: 12px; }

.main-content { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: clamp(34px, 7vw, 84px) 0 70px; }
.view { min-height: 60vh; }
.panel {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,.025), rgba(255,255,255,.008)), var(--panel);
  box-shadow: var(--shadow);
}
.hero-panel {
  width: min(760px, 100%);
  margin: 4vh auto 0;
  padding: clamp(34px, 6vw, 68px);
  text-align: center;
}
.signal-mark { display: inline-flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.signal-dot { width: 16px; height: 16px; border-radius: 50%; }
.signal-dot-green { background: var(--green); box-shadow: 0 0 20px rgba(41,214,125,.4); }
.signal-dot-red { background: var(--red); box-shadow: 0 0 20px rgba(255,77,88,.4); }
.signal-arrow { color: var(--muted-2); }
.eyebrow { margin: 0 0 10px; color: var(--muted-2); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .14em; }
h1, h2 { margin: 0; letter-spacing: -.035em; line-height: 1.05; }
h1 { font-size: clamp(38px, 7vw, 70px); }
h2 { font-size: clamp(30px, 5vw, 48px); }
.hero-copy, .muted { color: var(--muted); line-height: 1.65; }
.hero-copy { width: min(560px, 100%); margin: 22px auto 0; font-size: clamp(15px, 2vw, 18px); }
.hero-actions { margin-top: 32px; }
.button {
  min-height: 42px;
  padding: 0 17px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 750;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.button:hover { transform: translateY(-1px); border-color: #3a4856; }
.button-primary { border-color: #e4ebf1; background: #f2f5f7; color: #080b0f; }
.button-secondary { background: var(--panel-2); }
.button-ghost { background: transparent; color: var(--muted); }
.button-large { min-width: 150px; min-height: 52px; font-size: 16px; }
.button-small { min-height: 36px; padding: 0 13px; font-size: 12px; }
.mini-notes { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 18px; margin-top: 30px; color: var(--muted-2); font-size: 11px; }
.mini-notes span::before { content: "•"; margin-right: 7px; color: #475461; }

.category-panel, .results-panel { width: min(760px, 100%); margin: 2vh auto 0; padding: clamp(30px, 5vw, 54px); }
.category-panel > .muted { max-width: 610px; margin: 16px 0 0; }
.category-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 30px 0 22px; }
.category-card {
  min-height: 190px;
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--panel-2);
  cursor: pointer;
  text-align: left;
  transition: border-color .16s ease, transform .16s ease, background .16s ease;
}
.category-card:hover { transform: translateY(-2px); border-color: #465563; background: #18222c; }
.category-card strong, .category-card span { display: block; }
.category-icon { margin-bottom: 40px; color: #b8c4cf; font-size: 28px; }
.category-card strong { margin-bottom: 8px; font-size: 20px; }
.category-card > span:last-child { color: var(--muted); font-size: 13px; line-height: 1.5; }

.average-display { margin: 34px 0 26px; }
.average-display strong { display: block; font-size: clamp(60px, 12vw, 100px); letter-spacing: -.06em; line-height: .9; }
.average-display span { color: var(--muted); }
.trial-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 28px 0; }
.trial-card { padding: 14px 10px; border: 1px solid var(--border-soft); border-radius: 10px; background: var(--bg-soft); text-align: center; }
.trial-card span { display: block; color: var(--muted-2); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.trial-card strong { display: block; margin-top: 5px; font-size: 16px; }
.save-status { min-height: 44px; padding: 11px 13px; border-radius: 9px; color: var(--muted); background: rgba(255,255,255,.025); font-size: 13px; line-height: 1.55; }
.save-status.is-good { color: #9ceabc; background: var(--green-soft); }
.save-status.is-error { color: #ffafb5; background: var(--red-soft); }
.result-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 20px; }
.pending-banner { display: flex; align-items: center; justify-content: space-between; gap: 20px; width: min(760px,100%); margin: 14px auto 0; padding: 15px 18px; border: 1px solid #54452b; border-radius: 12px; background: #17150f; }
.pending-banner strong, .pending-banner span { display: block; }
.pending-banner strong { font-size: 13px; }
.pending-banner span { margin-top: 3px; color: #aa9d80; font-size: 11px; }

.database-heading { display: flex; justify-content: space-between; align-items: end; gap: 28px; margin-bottom: 28px; }
.database-heading h1 { font-size: clamp(38px, 6vw, 62px); }
.database-heading .muted { max-width: 660px; margin: 13px 0 0; }
.database-actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.sync-label { color: var(--muted-2); font-size: 11px; }
.database-loading { padding: 30px; color: var(--muted); }
.error-panel { padding: 18px; border: 1px solid #66343a; border-radius: 12px; color: #ffb1b7; background: #1a1013; line-height: 1.55; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat-card { min-width: 0; padding: 20px; border: 1px solid var(--border-soft); border-radius: 14px; background: var(--panel); }
.stat-card > span { display: block; color: var(--muted-2); font-size: 11px; }
.stat-card > strong { display: block; margin: 15px 0 6px; font-size: clamp(25px, 4vw, 38px); letter-spacing: -.04em; }
.stat-card strong small { font-size: 13px; color: var(--muted); }
.stat-card > small { color: var(--muted-2); font-size: 10px; }
.database-toolbar { display: flex; align-items: center; gap: 10px; margin-top: 18px; padding: 12px; box-shadow: none; }
.search-field { flex: 1; }
.search-field input, .database-toolbar select {
  width: 100%; min-height: 40px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg-soft); color: var(--text); padding: 0 12px;
}
.database-toolbar select { width: auto; min-width: 150px; }
.database-count { min-width: 90px; color: var(--muted-2); font-size: 11px; text-align: right; }
.table-wrap { position: relative; margin-top: 12px; overflow: hidden; box-shadow: none; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 15px; border-bottom: 1px solid var(--border-soft); text-align: left; white-space: nowrap; }
th { color: var(--muted-2); background: #0d1319; font-size: 10px; text-transform: uppercase; letter-spacing: .07em; }
td { color: #c7d0d9; font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
.group-pill { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border: 1px solid var(--border); border-radius: 999px; font-size: 10px; }
.group-pill.fps { color: #9ceabc; border-color: #265b40; background: rgba(41,214,125,.07); }
.group-pill.non-fps { color: #c9d1d9; }
.trials-inline { color: var(--muted); font-variant-numeric: tabular-nums; }
.avg-cell { color: var(--text); font-weight: 800; }
.empty-state { padding: 34px; color: var(--muted); text-align: center; }

.test-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100dvh;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: #030507;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.test-topbar { display: flex; justify-content: space-between; align-items: center; min-height: 48px; color: #63707c; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.test-topbar strong, .test-id code { color: #aab5bf; font-size: 11px; }
.test-topbar span, .test-topbar strong { display: block; }
.test-id { text-align: right; }
.reaction-surface {
  width: 100%;
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.reaction-light { width: clamp(96px, 20vw, 170px); aspect-ratio: 1; margin-bottom: 38px; border-radius: 50%; background: #303841; box-shadow: 0 0 0 1px rgba(255,255,255,.06), 0 0 60px rgba(255,255,255,.03); transition: background .08s linear, box-shadow .08s linear, transform .1s ease; }
.reaction-surface strong { font-size: clamp(30px, 7vw, 60px); letter-spacing: -.04em; }
.reaction-surface > span:not(.reaction-light) { display: block; }
#reactionInstruction { margin-top: 10px; color: #a3adb7; font-size: clamp(14px, 2vw, 18px); }
#reactionSubtext { margin-top: 9px; color: #4f5b66; font-size: 11px; }
.state-waiting .reaction-light { background: var(--green); box-shadow: 0 0 0 1px rgba(41,214,125,.5), 0 0 70px rgba(41,214,125,.35), 0 0 160px rgba(41,214,125,.09); }
.state-go .reaction-light { background: var(--red); box-shadow: 0 0 0 1px rgba(255,77,88,.55), 0 0 75px rgba(255,77,88,.42), 0 0 170px rgba(255,77,88,.12); transform: scale(1.025); }
.state-false .reaction-light { background: #ff9f43; box-shadow: 0 0 70px rgba(255,159,67,.3); }
.state-result .reaction-light { background: #dce5ec; box-shadow: 0 0 60px rgba(220,229,236,.15); }
.test-progress { display: grid; grid-template-columns: repeat(5, minmax(24px, 60px)); justify-content: center; gap: 6px; padding-top: 14px; }
.test-progress span { height: 3px; border-radius: 999px; background: #171d23; }
.test-progress span.done { background: #7f8b96; }

@media (max-width: 820px) {
  .site-header { grid-template-columns: 1fr auto; gap: 10px; padding: 10px 14px; }
  .top-nav { order: 3; grid-column: 1 / -1; width: 100%; }
  .nav-button { flex: 1; }
  .identity { min-width: 0; }
  .identity-label { display: none; }
  .main-content { width: min(100% - 24px, 1120px); padding-top: 30px; }
  .database-heading { align-items: flex-start; flex-direction: column; }
  .database-actions { width: 100%; justify-content: space-between; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .table-wrap { overflow-x: auto; }
  table { min-width: 790px; }
}

@media (max-width: 560px) {
  .brand small { display: none; }
  .identity code { font-size: 10px; }
  .hero-panel, .category-panel, .results-panel { padding: 28px 20px; }
  .hero-panel { margin-top: 0; }
  .category-grid { grid-template-columns: 1fr; }
  .category-card { min-height: 145px; }
  .category-icon { margin-bottom: 22px; }
  .trial-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
  .trial-card { padding: 10px 4px; }
  .trial-card strong { font-size: 12px; }
  .result-actions .button { flex: 1 1 45%; }
  .pending-banner { align-items: flex-start; flex-direction: column; }
  .stats-grid { grid-template-columns: 1fr; }
  .database-toolbar { align-items: stretch; flex-direction: column; }
  .database-toolbar select { width: 100%; }
  .database-count { width: 100%; text-align: left; }
  .reaction-light { margin-bottom: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
