:root {
  --bg: #0b1020;
  --panel: #121a30;
  --panel-2: #182240;
  --ink: #e8ecf6;
  --ink-dim: #8fa0c2;
  --up: #2fbf9b;
  --down: #ef5350;
  --amber: #f5b942;
  --acc: #a78bfa;          /* Epoch's signature: deep-time violet */
  --line: #223052;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

header { border-bottom: 1px solid var(--line); }
.head-inner {
  max-width: 560px; margin: 0 auto; padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between;
}
h1 { font-size: 20px; letter-spacing: 3px; font-weight: 800; }
h1 span { color: var(--acc); }
.head-right { display: flex; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  font-size: 16px; cursor: pointer;
}
.icon-btn:active { transform: scale(.95); }

main { flex: 1; width: 100%; max-width: 560px; margin: 0 auto; padding: 12px 14px 28px; }

.puzzle-meta {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--ink-dim); margin-bottom: 8px;
}
#puzzle-num { font-weight: 700; color: var(--ink); }
.chip {
  margin-left: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 99px; padding: 2px 10px; font-size: 13px;
}

#chart-wrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; height: 38vh; min-height: 230px; max-height: 360px;
}
#chart { width: 100%; height: 100%; display: block; }

/* ---- guess surface ---- */
#phase-strip { text-align: center; margin: 10px 0 6px; }
#phase-label { font-size: 13.5px; color: var(--ink-dim); }
#phase-label b { color: var(--acc); letter-spacing: 1px; }
#guess-log {
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
  margin-top: 6px; min-height: 0;
}
.log-chip {
  background: var(--panel); border: 1px solid var(--line); border-radius: 99px;
  font-size: 13px; padding: 2px 10px; color: var(--ink-dim);
}
.log-chip b { color: var(--ink); }
#corridor { font-size: 12.5px; color: var(--amber); margin-top: 5px; }

.year-row {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  margin: 8px 0 2px;
}
#year-big {
  font-size: 46px; font-weight: 800; letter-spacing: 2px; color: var(--acc);
  font-variant-numeric: tabular-nums; min-width: 140px; text-align: center;
}
.nudge {
  width: 44px; height: 44px; border-radius: 12px; font-size: 16px; font-weight: 700;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  cursor: pointer;
}
.nudge:active { transform: scale(.94); }

.rail-row { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; }
.rail-cap { font-size: 11.5px; color: var(--ink-dim); font-variant-numeric: tabular-nums; width: 34px; }
#rail { flex: 1; accent-color: var(--acc); height: 28px; cursor: pointer; }

#decades { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 12px; }
.dec-chip {
  background: var(--panel); color: var(--ink-dim); border: 1px solid var(--line);
  border-radius: 99px; padding: 5px 11px; font-size: 12.5px; cursor: pointer;
}
.dec-chip:hover { border-color: var(--acc); }
.dec-chip.on { color: var(--acc); border-color: var(--acc); }
.dec-chip:disabled { opacity: .28; cursor: default; }
.dec-chip:disabled:hover { border-color: var(--line); }

.lock-btn { display: block; margin: 0 auto; min-width: 220px; }
button.primary {
  background: var(--acc); color: #14102a; border: none; font-weight: 800;
  border-radius: 10px; padding: 11px 22px; font-size: 15px; cursor: pointer;
}
button.primary:active { transform: scale(.97); }
button.primary:disabled { opacity: .45; cursor: default; }
button.primary:disabled:active { transform: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---- confirm modal ---- */
.confirm-card { text-align: center; }
.confirm-kicker { letter-spacing: 3px; font-size: 12px; color: var(--acc); font-weight: 700; }
#confirm-year { font-size: 48px; font-weight: 800; letter-spacing: 2px; margin: 6px 0 2px; }
.confirm-warn { color: var(--amber); font-size: 14px; margin-bottom: 14px; }
.confirm-card .primary { width: 100%; margin-bottom: 8px; }
#btn-confirm-wait {
  width: 100%; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: 14px; cursor: pointer;
}

/* ---- result ---- */
#result-panel { margin-top: 14px; text-align: center; }
#result-verdict { font-size: 21px; font-weight: 800; margin-bottom: 4px; }
#result-score { font-size: 14px; color: var(--ink-dim); margin-bottom: 6px; }
#result-coach { font-size: 13px; color: var(--ink-dim); margin-bottom: 10px; }
#result-coach:empty { display: none; }
.tier-word { color: var(--acc); font-weight: 700; }
#result-score b { color: var(--acc); font-size: 16px; }
#result-reveal {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; font-size: 14.5px; color: var(--ink-dim); text-align: left;
}
#result-reveal b { color: var(--ink); }
.fact { color: var(--amber); font-size: .92em; display: inline-block; margin-top: 6px; }
.provenance { font-size: 11px; margin-top: 8px; opacity: .75; }

#tells-box {
  margin-top: 10px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); text-align: left;
}
#tells-box summary {
  cursor: pointer; padding: 11px 14px; font-size: 14px; font-weight: 700;
  color: var(--acc); list-style-position: inside;
}
#tells-learned { color: var(--ink-dim); font-weight: 400; font-size: 12px; }
#tells-list { padding: 0 16px 12px 34px; }
#tells-list li { font-size: 13.5px; color: var(--ink-dim); margin-bottom: 8px; }
#tells-list b { color: var(--ink); display: block; }
.tell-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 50%; background: var(--acc);
  color: #14102a; font-size: 11px; font-weight: 800; margin-right: 6px;
}

#handoff { margin-top: 10px; }
.handoff-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 34px 10px 14px; font-size: 13.5px; color: var(--ink-dim);
  text-align: left; position: relative;
}
.handoff-card a { color: var(--amber); font-weight: 700; text-decoration: none; }
.handoff-x {
  position: absolute; top: 6px; right: 8px; background: none; border: none;
  color: var(--ink-dim); font-size: 18px; cursor: pointer;
}

.result-actions { display: flex; gap: 8px; justify-content: center; margin: 14px 0 6px; }
#btn-see-stats, .modal-card button:not(.primary):not(.modal-close) {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 16px; font-size: 14px; cursor: pointer;
}
#countdown { font-size: 12.5px; color: var(--ink-dim); }
#countdown a { color: var(--ink-dim); }

/* ---- modals ---- */
.modal {
  position: fixed; inset: 0; background: rgba(4, 8, 18, .72);
  display: flex; align-items: center; justify-content: center; padding: 18px; z-index: 20;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  max-width: 440px; width: 100%; max-height: 82dvh; overflow-y: auto;
  padding: 20px; position: relative;
}
.modal-card h2 { font-size: 18px; margin-bottom: 10px; }
.modal-card p { font-size: 14.5px; color: var(--ink-dim); margin-bottom: 10px; }
.modal-card p b { color: var(--ink); }
.modal-card .fine { font-size: 12px; }
.bands-row { text-align: center; background: var(--bg); border-radius: 10px; padding: 8px; font-size: 13px !important; }
.help-details { margin-bottom: 10px; }
.help-details summary {
  cursor: pointer; font-size: 13.5px; color: var(--acc); font-weight: 700;
  padding: 2px 0;
}
.help-details p { margin-top: 6px; }
.modal-close {
  position: absolute; top: 10px; right: 12px; background: none; border: none;
  color: var(--ink-dim); font-size: 22px; cursor: pointer;
}
.modal-ok { width: 100%; margin-top: 6px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat small { font-size: 10.5px; color: var(--ink-dim); }
.spark-wrap { text-align: center; margin: 6px 0; }
.spark-cap { font-size: 11.5px; color: var(--ink-dim); }

.archive-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 4px; border-bottom: 1px solid var(--line); font-size: 14px;
}
.archive-row button { padding: 5px 12px !important; font-size: 13px !important; }

#toast {
  position: fixed; bottom: 74px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); border-radius: 10px;
  padding: 9px 16px; font-size: 14px; font-weight: 600; z-index: 30;
}

footer {
  text-align: center; font-size: 12px; color: var(--ink-dim);
  padding: 12px; border-top: 1px solid var(--line);
}
footer a { color: var(--ink-dim); }

@media (max-width: 400px) {
  #year-big { font-size: 38px; min-width: 110px; }
  .dec-chip { padding: 4px 8px; font-size: 11.5px; }
}
