:root {
  --bg: #0b0f17;
  --bg-2: #121826;
  --bg-3: #1a2236;
  --fg: #e6ecf3;
  --fg-dim: #9aa7bd;
  --accent: #5cc8ff;
  --accent-2: #8a7dff;
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --border: #253049;
  --mono: "JetBrains Mono", "Consolas", "Menlo", monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: radial-gradient(1200px 800px at 20% 0%, #16213a 0%, var(--bg) 60%);
  color: var(--fg);
  font-family: var(--sans);
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- setup overlay ---------- */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 10, 18, 0.92);
  z-index: 10;
}
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 36px;
  width: min(560px, 92vw);
  box-shadow: 0 30px 80px rgba(0,0,0,0.45);
}
.card h1 {
  margin: 0 0 4px 0;
  font-size: 32px;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.card .sub { color: var(--fg-dim); margin: 0 0 18px 0; }
.card .desc { color: var(--fg-dim); font-size: 14px; line-height: 1.55; margin: 0 0 22px 0; }
.card label { display: block; font-size: 12px; color: var(--fg-dim); margin-bottom: 6px; letter-spacing: 0.04em; text-transform: uppercase; }
.card input {
  width: 100%; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-3); color: var(--fg); font-family: var(--mono); font-size: 14px;
  outline: none;
}
.card input:focus { border-color: var(--accent); }
.card button {
  margin-top: 16px; width: 100%; padding: 12px 14px; border-radius: 8px; border: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #0b0f17;
  font-weight: 600; font-size: 15px; cursor: pointer;
}
.card button:disabled { opacity: 0.6; cursor: wait; }
.card .status { color: var(--fg-dim); font-size: 13px; margin-top: 12px; min-height: 18px; }
.card .status.err { color: var(--bad); }
.card .status.ok { color: var(--good); }

/* ---------- main stage ---------- */
main#stage {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) 260px auto;
  height: 100vh;
  padding: 18px 28px 16px 28px;
  gap: 14px;
}

.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  color: var(--fg-dim);
  font-size: 13px;
}
.top-bar .brand {
  font-size: 18px; font-weight: 700; letter-spacing: -0.01em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.top-bar .meta { font-family: var(--mono); font-size: 12px; }
.top-bar .sep { opacity: 0.5; margin: 0 8px; }
.top-bar .hint { opacity: 0.7; }

.narrative-panel {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 22px;
  min-height: 140px;
}
.narrative-panel h2 {
  margin: 0 0 8px 0;
  font-size: 22px;
  letter-spacing: -0.01em;
  color: var(--fg);
}
.narrative-panel p {
  margin: 0;
  font-size: 15px;
  line-height: 1.55;
  color: var(--fg-dim);
}
.narrative-panel .takeaway {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  color: var(--accent);
  font-style: italic;
  opacity: 0;
  transition: opacity 0.6s ease;
}
.narrative-panel .takeaway.show { opacity: 1; }

.text-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  min-height: 0;
}
.text-box {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.text-box .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-dim);
  margin-bottom: 8px;
}
.text-box .content {
  font-size: 15px;
  line-height: 1.5;
  color: var(--fg);
  overflow: auto;
  white-space: pre-wrap;
  font-family: var(--mono);
}
.text-box.right .content.candidates {
  font-family: var(--sans);
}
.text-box.right .candidate {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--fg);
}
.text-box.right .candidate:last-child { border-bottom: 0; }
.text-box.right .candidate .cand-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  margin-bottom: 2px;
}

.viz-panel {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 14px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.score-readout {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.score-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-dim);
}
.score-value {
  font-family: var(--mono);
  font-size: 64px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
  margin: 6px 0;
  line-height: 1;
  transition: color 0.4s ease;
}
.score-band {
  font-size: 12px;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  min-height: 16px;
}
.score-value.good { color: var(--good); }
.score-value.warn { color: var(--warn); }
.score-value.bad { color: var(--bad); }

.chart-wrap {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}
.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
  max-height: 100% !important;
  display: block;
}

.progress-bar-wrap {
  position: relative;
  height: 6px;
  background: var(--bg-3);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 120ms linear;
}
.status-line {
  position: absolute;
  right: 0;
  top: 10px;
  font-size: 11px;
  color: var(--fg-dim);
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

@media (max-width: 1000px) {
  .viz-panel { grid-template-columns: 1fr; }
  .score-readout { min-height: 120px; }
}
