:root {
  --bg-deep: #05070d;
  --bg-mid: #101a33;
  --glass-bg: rgba(10, 16, 32, 0.78);
  --glass-border: rgba(255, 255, 255, 0.12);
  --text: #e8f0ff;
  --text-dim: #9aa6bd;
  --accent: #6ee7f9;
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at center, var(--bg-mid) 0%, var(--bg-deep) 75%);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

#canvas-container {
  position: fixed;
  inset: 0;
  z-index: 0;
}
#canvas-container canvas { display: block; touch-action: none; }

/* ---------- Header ---------- */
#header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  pointer-events: none;
}
#header > * { pointer-events: auto; }

#brand { display: flex; align-items: center; gap: 10px; }
#brand img { width: 34px; height: 34px; }
#brand .titles { display: flex; flex-direction: column; }
#brand h1 {
  margin: 0; font-size: 22px; font-weight: 600; color: var(--text);
  text-shadow: 0 0 12px rgba(110, 231, 249, 0.55);
}
#brand .subtitle { font-size: 13px; color: var(--text-dim); margin-top: 2px; }

#round-select, #country-select {
  background: rgba(10, 16, 32, 0.7);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  min-height: 44px;
}

#header-right { display: flex; align-items: center; gap: 10px; }
#about-link { color: var(--text-dim); font-size: 13px; text-decoration: none; }
#about-link:hover { color: var(--text); }
#list-toggle {
  background: rgba(10, 16, 32, 0.7);
  border: 1px solid var(--glass-border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  min-height: 44px;
}
#list-toggle.active { background: rgba(110, 231, 249, 0.18); border-color: var(--accent); }

#menu-button { display: none; }

/* ---------- Scorecard badge ---------- */
#scorecard-badge {
  position: fixed;
  top: 70px; left: 20px;
  z-index: 15;
  background: rgba(10, 16, 32, 0.7);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
}
#scorecard-badge:hover { color: var(--text); border-color: var(--accent); }
#boldness-note {
  position: fixed;
  top: 112px; left: 20px;
  z-index: 15;
  max-width: 340px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-dim);
}
@media (max-width: 700px) { #boldness-note { max-width: 260px; font-size: 11px; } }

/* ---------- Legend ---------- */
#legend {
  position: fixed;
  bottom: 18px; left: 20px;
  z-index: 15;
  font-size: 12.5px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#legend .row { display: flex; align-items: center; gap: 8px; }
.ring-icon { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.ring-icon.outer { border: 2px solid #ffffff; }
.ring-icon.middle { border: 2px solid #b9c2cc; }
.ring-icon.inner { border: 2px solid #6b7078; }
.text.short { display: none; }

/* ---------- Footer ---------- */
#footer {
  position: fixed;
  bottom: 18px; right: 20px;
  z-index: 15;
  font-size: 12px;
  color: var(--text-dim);
}
#footer a { color: var(--text-dim); }

/* ---------- Hover label ---------- */
#hover-label {
  position: fixed;
  z-index: 25;
  pointer-events: none;
  background: rgba(10, 16, 32, 0.85);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text);
  transform: translate(-50%, -130%);
  opacity: 0;
  transition: opacity 0.15s ease;
  white-space: nowrap;
  max-width: 260px;
  text-overflow: ellipsis;
  overflow: hidden;
}
#hover-label.visible { opacity: 1; }

/* ---------- Loading / error screens ---------- */
#loading-screen, #error-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, var(--bg-mid) 0%, var(--bg-deep) 75%);
  gap: 20px;
  transition: opacity 0.4s ease;
}
#error-screen { display: none; }
.rings { position: relative; width: 90px; height: 90px; }
.rings span {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: pulse 1.8s ease-in-out infinite;
  opacity: 0;
}
.rings span:nth-child(1) { animation-delay: 0s; }
.rings span:nth-child(2) { animation-delay: 0.3s; }
.rings span:nth-child(3) { animation-delay: 0.6s; }
@keyframes pulse {
  0% { transform: scale(0.5); opacity: 0.8; }
  100% { transform: scale(1.4); opacity: 0; }
}
#loading-screen p, #error-screen p { color: var(--text-dim); font-size: 15px; }

/* ---------- Panel ---------- */
#panel {
  position: fixed;
  z-index: 30;
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  overflow-y: auto;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
@media (min-width: 901px) {
  #panel {
    top: 20px; right: 20px; bottom: 20px;
    width: 400px;
    transform: translateX(420px);
    opacity: 0;
  }
  #panel.open { transform: translateX(0); opacity: 1; }
}
@media (max-width: 900px) {
  #panel {
    left: 0; right: 0; bottom: 0;
    height: 55%;
    border-radius: 18px 18px 0 0;
    transform: translateY(100%);
    opacity: 0;
  }
  #panel.open { transform: translateY(0); opacity: 1; }
}
#panel.hidden { display: none; }

.panel-pad { padding: 18px 20px; }
.panel-header-row {
  display: flex; align-items: center; gap: 12px; margin-bottom: 10px;
}
.panel-header-row img.flag { width: 40px; height: 40px; }
.panel-header-row h2 { margin: 0; font-size: 24px; font-weight: 600; flex: 1; }
.pill {
  display: inline-block;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  color: var(--text-dim);
}
.close-btn {
  background: none; border: none; color: var(--text-dim);
  font-size: 22px; cursor: pointer; line-height: 1; padding: 6px;
  min-width: 44px; min-height: 44px;
}
.close-btn:hover { color: var(--text); }

.round-line { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }
.headline { font-size: 20px; font-weight: 600; color: var(--text); margin: 6px 0 12px; }
.emoji-row { display: flex; gap: 10px; margin-bottom: 6px; }
.emoji-row img { width: 48px; height: 48px; cursor: pointer; }
.emoji-reason { font-size: 13px; color: var(--text-dim); min-height: 18px; margin-bottom: 12px; }
.tldr { font-size: 16px; line-height: 1.55; margin-bottom: 16px; }

.history-row { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; font-size: 13.5px; color: var(--text-dim); }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; flex-shrink: 0; }
.dot.inner { background: #6b7078; }
.dot.middle { background: #b9c2cc; }
.dot.outer { background: #ffffff; }
.history-row .label { font-weight: 600; color: var(--text); margin-right: 4px; }
.history-row .mini-emoji { height: 16px; vertical-align: middle; margin-right: 2px; }

.score-line {
  font-size: 13.5px; padding: 10px 12px; border-radius: 10px;
  margin: 14px 0; border: 1px solid var(--glass-border);
}
.score-line.crystal { color: var(--green); border-color: var(--green); }
.score-line.tie { color: var(--amber); border-color: var(--amber); }
.score-line.naive { color: var(--red); border-color: var(--red); }

.panel-buttons { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.btn {
  flex: 1;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: flex; align-items: center; justify-content: center;
}
.btn.primary { background: var(--accent); color: #05070d; font-weight: 600; border-color: var(--accent); }
.btn:hover { filter: brightness(1.1); }

/* ---------- Modal ("Read more") ---------- */
#modal-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 40px 16px;
}
#modal-backdrop.open { display: flex; }
#modal {
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  max-width: 760px;
  width: 100%;
  padding: 24px 26px 32px;
}
#modal h3 { font-size: 15px; color: var(--accent); margin: 26px 0 10px; }
#modal h3:first-of-type { margin-top: 16px; }
#modal p { font-size: 15px; line-height: 1.6; color: var(--text); margin: 0 0 10px; }

.statement-row { margin-bottom: 14px; }
.statement-top { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.prob-bar-track { flex: 1; height: 8px; border-radius: 4px; background: rgba(255,255,255,0.1); overflow: hidden; }
.prob-bar-fill { height: 100%; width: 0%; border-radius: 4px; transition: width 0.6s ease; }
.prob-pct { font-size: 13px; width: 42px; text-align: right; color: var(--text-dim); }
.statement-text { font-size: 14px; color: var(--text); flex: 1; }
.statement-meta { display: flex; gap: 8px; align-items: center; margin-top: 2px; }
.outcome-mark { font-size: 13px; }
.outcome-mark.yes { color: var(--green); }
.outcome-mark.no { color: var(--red); }
.evidence-text { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }

ul.bullets { margin: 6px 0; padding-left: 20px; }
ul.bullets li { font-size: 14px; margin-bottom: 4px; color: var(--text); }

.modal-close {
  display: block; margin: 20px auto 0;
}
.modal-footer { font-size: 12px; color: var(--text-dim); margin-top: 20px; border-top: 1px solid var(--glass-border); padding-top: 12px; }

/* ---------- List view ---------- */
#list-view {
  position: fixed; inset: 0; z-index: 10;
  background: radial-gradient(ellipse at center, var(--bg-mid) 0%, var(--bg-deep) 75%);
  overflow-y: auto;
  padding: 100px 20px 60px;
  display: none;
}
#list-view.active { display: block; }
.list-group-title { font-size: 14px; color: var(--accent); margin: 20px 0 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  cursor: pointer; margin-bottom: 4px;
  min-height: 44px;
}
.list-item:hover { background: rgba(255,255,255,0.06); }
.list-item img.flag { width: 32px; height: 32px; flex-shrink: 0; }
.list-item .emojis { display: flex; gap: 2px; flex-shrink: 0; }
.list-item .emojis img { width: 24px; height: 24px; }
.list-item .name { font-weight: 600; min-width: 140px; flex-shrink: 0; }
.list-item .headline-text { color: var(--text-dim); font-size: 13px; flex: 1; }

/* ---------- Scorecard modal ---------- */
#scorecard-modal-backdrop {
  position: fixed; inset: 0; z-index: 41;
  background: rgba(0,0,0,0.6);
  display: none; align-items: center; justify-content: center;
  padding: 16px;
}
#scorecard-modal-backdrop.open { display: flex; }
#scorecard-modal {
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  max-width: 420px; width: 100%;
  padding: 22px;
}
#scorecard-modal .baseline { font-size: 13px; color: var(--text-dim); margin-bottom: 14px; }
#scorecard-modal .stat-row { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 6px; }
#scorecard-modal a { color: var(--accent); font-size: 13px; }

/* ---------- Hidden utility ---------- */
.hidden { display: none !important; }

@media (max-width: 700px) {
  #brand h1 { font-size: 18px; }
  #brand .subtitle { display: none; }
  #round-select { display: none; }
  #header-right > *:not(#menu-button) { display: none; }
  #menu-button {
    display: block;
    background: rgba(10,16,32,0.7);
    border: 1px solid var(--glass-border);
    color: var(--text);
    border-radius: 10px;
    padding: 8px 12px;
    min-height: 44px;
    cursor: pointer;
  }
  #header.menu-open #round-select,
  #header.menu-open #header-right > * { display: flex; }
  #header.menu-open {
    flex-direction: column;
    align-items: stretch;
    background: rgba(10,16,32,0.92);
    gap: 10px;
    padding-bottom: 16px;
  }
  #legend { font-size: 11px; flex-direction: row; gap: 10px; bottom: 10px; }
  #legend .row span.text.full { display: none; }
  #legend .row span.text.short { display: inline; }
}

.qrow { padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.08); }
.qrow.disagree { border-left: 3px solid #fbbf24; padding-left: 8px; }
.ans-crystal { background: rgba(110,231,249,0.18); }
.ans-plain { background: rgba(255,255,255,0.10); }
