:root {
  --bg: #f4f6fa;
  --bg-accent: radial-gradient(circle at 20% 0%, rgba(0, 102, 179, 0.08), transparent 48%),
               radial-gradient(circle at 85% 15%, rgba(237, 28, 36, 0.06), transparent 42%);
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --text: #111827;
  --text-muted: #5b6475;
  --border: #dde3ee;
  --primary: #0066b3;
  --primary-hover: #005494;
  --primary-soft: rgba(0, 102, 179, 0.11);
  --danger: #d92d20;
  --danger-soft: rgba(217, 45, 32, 0.1);
  --success: #0e9f6e;
  --success-soft: rgba(14, 159, 110, 0.12);
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, 0.12);
  --shadow: 0 10px 30px rgba(17, 24, 39, 0.07);
  --radius: 18px;
  --radius-sm: 12px;
}

[data-theme="dark"] {
  --bg: #0c111b;
  --bg-accent: radial-gradient(circle at 20% 0%, rgba(56, 152, 236, 0.14), transparent 48%),
               radial-gradient(circle at 85% 15%, rgba(239, 68, 68, 0.09), transparent 42%);
  --surface: #151c2c;
  --surface-2: #1d263b;
  --text: #f3f6fc;
  --text-muted: #98a4bc;
  --border: #2a354d;
  --primary: #3b9eff;
  --primary-hover: #58adff;
  --primary-soft: rgba(59, 158, 255, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.14);
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.42);
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  background-image: var(--bg-accent);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 16px 32px;
}

.topbar {
  width: 100%;
  max-width: 560px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}

.topbar.admin-wide {
  max-width: 1120px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 750;
  font-size: 1rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 0.85rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  height: 38px;
  padding: 0 12px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-2);
}

.card {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 20px;
  animation: fadeUp 0.2s ease-out;
}

.card.admin-wide {
  max-width: 1120px;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hidden {
  display: none !important;
}

h1, h2, h3 {
  margin: 0 0 10px;
  line-height: 1.22;
  letter-spacing: -0.02em;
}

.hero-title {
  font-size: clamp(1.75rem, 5vw, 2.25rem);
  font-weight: 800;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.02rem;
  margin: 0 0 22px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--primary-soft);
  color: var(--primary);
}

.pill.success {
  background: var(--success-soft);
  color: var(--success);
}

.pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  min-height: 52px;
  padding: 12px 16px;
  font: inherit;
  font-size: 1.02rem;
  font-weight: 650;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  transition: transform 0.08s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  min-height: 40px;
  padding: 8px 12px;
  font-size: 0.92rem;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: transparent;
  color: var(--text);
}

.btn-choice {
  justify-content: space-between;
  text-align: left;
  padding: 14px 18px;
}

.btn-choice .sub {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.btn-choice .kbd {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 7px;
  background: var(--surface);
}

@media (hover: none) and (pointer: coarse) {
  .btn-choice .kbd {
    display: none;
  }
}

.q-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.q-meta {
  font-size: 0.86rem;
  font-weight: 650;
  color: var(--text-muted);
}

.progress-track {
  width: 100%;
  height: 7px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 18px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), #18a0fb);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.question-text {
  font-size: clamp(1.2rem, 3.8vw, 1.45rem);
  font-weight: 720;
  line-height: 1.32;
  margin: 12px 0 20px;
}

.q-footer {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.link-btn {
  appearance: none;
  background: none;
  border: none;
  padding: 6px 4px;
  font: inherit;
  font-size: 0.86rem;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-btn:hover {
  color: var(--danger);
}

.toast {
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
}

.toast.error {
  background: var(--danger-soft);
  color: var(--danger);
}

/* Guess screen & chart */
.guess-headline {
  font-size: clamp(1.6rem, 4.8vw, 2.05rem);
  font-weight: 800;
  margin: 10px 0 6px;
}

.chart-wrap {
  margin: 18px 0 22px;
  padding: 14px 12px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.chart-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

.posterior-bars {
  display: grid;
  grid-template-columns: repeat(19, 1fr);
  gap: 3px;
  align-items: end;
  height: 92px;
}

.p-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 4px;
}

.p-bar {
  width: 100%;
  min-height: 3px;
  border-radius: 4px 4px 2px 2px;
  background: var(--text-muted);
  opacity: 0.35;
  transition: height 0.25s ease;
}

.p-bar.in-window {
  background: var(--primary);
  opacity: 1;
}

.p-lbl {
  font-size: 0.62rem;
  color: var(--text-muted);
  line-height: 1;
  user-select: none;
}

.year-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.year-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  min-height: 44px;
  padding: 8px 6px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 650;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.year-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.year-btn.wide {
  grid-column: 1 / -1;
}

/* Results screen */
.result-banner {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 18px;
}

.result-banner.hit {
  background: var(--success-soft);
  border-color: rgba(14, 159, 110, 0.35);
}

.result-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px 0 22px;
}

.result-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  background: var(--surface-2);
}

.result-q-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.result-q {
  font-weight: 680;
  font-size: 0.96rem;
}

.ans-chip {
  flex-shrink: 0;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
}

.result-exp {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.sources-wrap {
  margin-top: 8px;
  font-size: 0.8rem;
}

.sources-wrap summary {
  cursor: pointer;
  color: var(--primary);
  font-weight: 600;
}

.sources-wrap ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.sources-wrap a {
  color: var(--primary);
  word-break: break-all;
}

/* Admin dashboard */
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.55rem;
  font-weight: 800;
  margin-top: 4px;
}

.admin-section {
  margin-top: 24px;
}

.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.input,
.select {
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  background: var(--surface-2);
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: none;
}

.btn-sm {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 0.82rem;
  border-radius: 8px;
}

.dist-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.dist-chip {
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.split-tables {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

@media (min-width: 600px) {
  .card {
    padding: 28px 28px;
  }
}
