:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2b313d;
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --accent-ink: #ffffff;
  --good: #3fbf7f;
  --bad: #e5604d;
  --warn: #dfa33c;
  --radius: 10px;
  --maxw: 44rem;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f0f2f6;
    --border: #d9dee7;
    --text: #1a1d23;
    --muted: #5c6472;
    --accent: #2563eb;
    --good: #16794c;
    --bad: #c2341f;
    --warn: #9a6400;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.5rem 16px 3rem;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--text);
}
.brand span { color: var(--accent); }

.site-footer {
  display: flex;
  gap: 1.25rem;
  justify-content: center;
  padding: 1.5rem 16px 2.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
}
.site-footer a { color: var(--muted); }

h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 0.6rem; letter-spacing: -0.02em; }
h2 { font-size: 1.2rem; margin: 2rem 0 0.75rem; letter-spacing: -0.01em; }
h3 { font-size: 1rem; margin: 1.5rem 0 0.5rem; }
p { margin: 0 0 1rem; }
a { color: var(--accent); }

.lede { color: var(--muted); font-size: 1.05rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 0 0 1rem;
}

.topic-grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 40rem) {
  .topic-grid { grid-template-columns: 1fr 1fr; }
}

.btn {
  display: inline-block;
  padding: 0.7rem 1.2rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.85rem; font-weight: 500; }
.btn-danger { background: var(--bad); }

label { display: block; font-weight: 600; margin: 1rem 0 0.35rem; font-size: 0.925rem; }
.hint { color: var(--muted); font-size: 0.85rem; font-weight: 400; }

input[type="text"], input[type="email"], input[type="tel"], input[type="password"],
input[type="date"], select, textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
textarea { min-height: 9rem; resize: vertical; line-height: 1.55; }
input:focus-visible, textarea:focus-visible, select:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.checkbox { display: flex; gap: 0.6rem; align-items: flex-start; margin: 1.25rem 0; }
.checkbox input { margin-top: 0.3rem; flex: none; }
.checkbox span { font-size: 0.9rem; color: var(--muted); }

.honeypot { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.notice {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--surface-2);
  padding: 0.85rem 1rem;
  margin: 0 0 1rem;
  font-size: 0.925rem;
}
.notice-bad { border-left-color: var(--bad); }
.notice-good { border-left-color: var(--good); }
.notice-warn { border-left-color: var(--warn); }

.rules { margin: 0; padding-left: 1.2rem; }
.rules li { margin: 0.4rem 0; }

/* Test page */
.test-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  font-variant-numeric: tabular-nums;
}
.progress-text { color: var(--muted); font-size: 0.9rem; }
.timer {
  font-size: 1.35rem;
  font-weight: 700;
  padding: 0.2rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.timer.low { color: var(--bad); border-color: var(--bad); }
.progress-track { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); }

.question {
  font-size: 1.2rem;
  line-height: 1.45;
  font-weight: 600;
  margin: 0 0 1rem;
}
.answer-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.4rem 0 1rem;
}

/* Result page */
.score {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin: 0 0 0.5rem;
}
.score strong { font-size: 2.75rem; letter-spacing: -0.03em; line-height: 1; }
.score .out-of { color: var(--muted); }

.coupon {
  display: block;
  margin: 1rem 0;
  padding: 1rem;
  border: 2px dashed var(--good);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  word-break: break-all;
}

.answer-review { border-top: 1px solid var(--border); padding: 1rem 0; }
.answer-review:last-child { border-bottom: 1px solid var(--border); }
.answer-review .q { font-weight: 600; margin: 0 0 0.4rem; }
.answer-review .a {
  white-space: pre-wrap;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  margin: 0 0 0.5rem;
  font-size: 0.925rem;
}
.answer-review .fb { font-size: 0.925rem; margin: 0; }
.mark { font-weight: 700; font-variant-numeric: tabular-nums; }
.mark-good { color: var(--good); }
.mark-mid { color: var(--warn); }
.mark-bad { color: var(--bad); }

.shake { animation: shake 0.3s; border-color: var(--bad); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
@media (prefers-reduced-motion: reduce) {
  .shake { animation: none; }
}

.spinner {
  width: 1.75rem; height: 1.75rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 1.5rem auto;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
}

/* Admin */
.stat-grid { display: grid; gap: 0.75rem; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 40rem) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}
.stat .n { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; display: block; }
.stat .k { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }

.pill {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
.pill-good { color: var(--good); border-color: var(--good); }
.pill-bad { color: var(--bad); border-color: var(--bad); }
.pill-warn { color: var(--warn); border-color: var(--warn); }

.flag-list { margin: 0.5rem 0 0; padding-left: 1.1rem; font-size: 0.85rem; color: var(--warn); }

.filters { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: flex-end; margin-bottom: 1rem; }
.filters label { margin: 0; }
.filters input, .filters select { width: auto; min-width: 9rem; }

.pager { display: flex; gap: 0.75rem; align-items: center; justify-content: center; margin-top: 1.25rem; color: var(--muted); font-size: 0.9rem; }

.row-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.inline-form { display: inline; }

.admin-nav { display: flex; flex-wrap: wrap; gap: 0.9rem; align-items: center; font-size: 0.9rem; }
.admin-nav a { color: var(--muted); text-decoration: none; }
.admin-nav a:hover { color: var(--text); }

details summary::-webkit-details-marker { color: var(--muted); }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
