:root {
  --ink: #0e2230;
  --ink-deep: #081621;
  --paper: #ece4d2;
  --paper-dim: #c9bd9e;
  --brass: #d2a44e;
  --brass-bright: #e8c172;
  --teal: #4f8b87;
  --teal-dim: #2f5957;
  --rust: #b4533a;
  --good: #7fa86b;

  --font-display: "Fraunces", serif;
  --font-body: "Public Sans", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", monospace;

  --radius: 14px;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over any component's own `display`
   rule. Without this, any element that sets display:flex/grid (almost
   everything here) silently ignores .hidden = true in JS — that bug bit us
   once already (the missed-panel) and was patched one-off; this single
   high-specificity rule fixes it everywhere, including every future
   show/hide toggle, instead of requiring a matching [x][hidden]{} override
   for each new component. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  min-height: 100vh;
  background: var(--ink-deep);
  color: var(--paper);
  font-family: var(--font-body);
}

body {
  display: flex;
  justify-content: center;
  padding: 24px 16px 48px;
  position: relative;
  overflow-x: hidden;
}

/* faint lat/long graticule across the whole page, evokes a chart table */
.grid-bg {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--ink) 1px, transparent 1px),
    linear-gradient(90deg, var(--ink) 1px, transparent 1px);
  background-size: 42px 42px;
  opacity: 0.35;
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 560px;
}

/* ---------- Header ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--brass-bright);
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.brand h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  margin: 0;
  letter-spacing: 0.3px;
  color: var(--paper);
}

.tagline {
  margin: 0;
  font-size: 12px;
  color: var(--paper-dim);
  text-transform: uppercase;
  letter-spacing: 1.4px;
}

.stats {
  display: flex;
  gap: 16px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 44px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  color: var(--brass-bright);
}

.stat-label {
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--paper-dim);
}

/* ---------- Mode tabs ---------- */

/* ---------- Home screen ---------- */

.career-panel {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.career-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 14px 10px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(210, 164, 78, 0.08), rgba(210, 164, 78, 0.02));
  border: 1px solid rgba(210, 164, 78, 0.22);
}

.career-value {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  color: var(--brass-bright);
  line-height: 1.1;
}

.career-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--paper-dim);
}

#home-screen {
  padding-top: 8px;
}

.home-tagline {
  color: var(--paper-dim);
  font-size: 14px;
  margin: 0 0 18px;
  text-align: center;
}

.region-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -6px 0 18px;
  padding-left: 2px;
}

.region-chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(236, 228, 210, 0.14);
  background: transparent;
  color: var(--paper-dim);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.region-chip:hover { color: var(--paper); border-color: rgba(236, 228, 210, 0.35); }

.region-chip.is-active {
  background: var(--teal-dim);
  border-color: var(--teal);
  color: var(--paper);
}

.start-btn {
  display: block;
  width: 100%;
  padding: 16px;
  font-size: 16px;
  border-radius: 14px;
  margin-top: 8px;
  letter-spacing: 0.3px;
}

.home-btn {
  font-size: 13px;
  align-self: center;
  white-space: nowrap;
}
/* ---------- Mode tabs ---------- */

.mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.mode-tab {
  flex: 1 1 28%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 10px;
  background: rgba(236, 228, 210, 0.04);
  border: 1px solid rgba(236, 228, 210, 0.15);
  border-radius: var(--radius);
  color: var(--paper-dim);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.tab-icon { width: 18px; height: 18px; }

.mode-tab:hover { border-color: rgba(236, 228, 210, 0.35); color: var(--paper); }

.mode-tab.is-active {
  background: rgba(210, 164, 78, 0.12);
  border-color: var(--brass);
  color: var(--brass-bright);
}

/* ---------- Modifiers ---------- */

.modifiers-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 20px;
}

.mod-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 7px 14px;
  border-radius: 12px;
  border: 1px solid rgba(236, 228, 210, 0.18);
  background: transparent;
  color: var(--paper-dim);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  font-family: var(--font-body);
}

.mod-chip-label { font-size: 13px; font-weight: 600; }
.mod-chip-mult { font-size: 10.5px; font-family: var(--font-mono); letter-spacing: 0.3px; color: var(--paper-dim); }

.mod-chip:hover { color: var(--paper); border-color: rgba(236, 228, 210, 0.4); }

.mod-chip.is-active {
  background: rgba(210, 164, 78, 0.12);
  border-color: var(--brass);
  color: var(--brass-bright);
}
.mod-chip.is-active .mod-chip-mult { color: var(--brass-bright); }

.multiplier-readout {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--brass-bright);
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- Board / card ---------- */

.board { position: relative; }

.timer-track {
  height: 5px;
  border-radius: 4px;
  background: rgba(236, 228, 210, 0.12);
  overflow: hidden;
  margin-bottom: 14px;
}

.timer-fill {
  height: 100%;
  width: 100%;
  background: var(--brass);
  transform-origin: left;
  transition: width 0.2s linear, background-color 0.3s;
}

.card {
  background: linear-gradient(180deg, rgba(236,228,210,0.05), rgba(236,228,210,0.02));
  border: 1px solid rgba(236, 228, 210, 0.14);
  border-radius: 20px;
  padding: 18px 18px 8px;
  position: relative;
  overflow: hidden;
}

.card-region {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--teal);
  text-align: center;
  margin-bottom: 6px;
  min-height: 14px;
}

.art-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 240px;
  position: relative;
}

.art-transform {
  width: 200px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.4s ease;
}

.art-transform svg {
  width: 100%;
  height: auto;
  display: block;
}

.art-transform img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  object-fit: contain;
}

.outline-shape {
  fill: var(--brass-bright);
  stroke: var(--ink-deep);
  stroke-width: 0.6;
}

.art-wrap.is-map {
  height: auto;
  width: 100%;
  padding: 4px 0;
}

.art-transform.is-map {
  width: 100%;
  height: auto;
  flex-direction: column;
  gap: 10px;
}

.map-svg {
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: var(--ink-deep);
  border: 1px solid rgba(236, 228, 210, 0.12);
}

.map-land { fill: #3a5a4d; stroke: none; }

.map-link {
  stroke: var(--paper-dim);
  stroke-width: 1.6;
  stroke-dasharray: 5 4;
  fill: none;
  opacity: 0.7;
}

.dot-birth { fill: var(--teal); stroke: var(--paper); stroke-width: 1.5; }
.dot-death { fill: var(--rust); stroke: var(--paper); stroke-width: 1.5; }

.dot-pulse {
  fill: none;
  stroke-width: 1.2;
  opacity: 0.6;
}

.map-legend {
  display: flex;
  justify-content: center;
  gap: 22px;
  font-size: 12px;
  color: var(--paper-dim);
  letter-spacing: 0.4px;
}

.legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.art-transform.is-grayscale img {
  filter: grayscale(1) contrast(1.05);
}

.art-wrap.is-text {
  height: auto;
  width: 100%;
  padding: 18px 0;
}

.art-transform.is-text {
  width: 100%;
  height: auto;
}

.event-text {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  text-align: center;
  color: var(--paper);
  line-height: 1.3;
  padding: 0 8px;
}

.event-year {
  font-family: var(--font-mono);
  font-size: 40px;
  letter-spacing: 1px;
  color: var(--brass-bright);
}

.year-answer-form {
  display: flex;
  gap: 10px;
}

.year-input {
  flex: 1;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(236, 228, 210, 0.25);
  background: rgba(236, 228, 210, 0.06);
  color: var(--paper);
  font-family: var(--font-mono);
  font-size: 18px;
  letter-spacing: 1px;
  text-align: center;
}

.year-input:focus {
  outline: none;
  border-color: var(--brass);
}

.art-wrap.is-photo {
  height: auto;
  width: 100%;
  padding: 8px 0;
}

.art-transform.is-photo {
  width: 100%;
  height: auto;
  flex-direction: column;
}

/* satellite (city mode) */
.sat-frame {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid rgba(236, 228, 210, 0.18);
  margin: 0 auto;
  background: #0a1a14;
}

.sat-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 768px;
  height: 768px;
}

.sat-tile {
  position: absolute;
  width: 256px;
  height: 256px;
  display: block;
}

.sat-attribution {
  position: absolute;
  right: 4px;
  bottom: 3px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: rgba(236, 228, 210, 0.7);
  background: rgba(8, 22, 33, 0.55);
  padding: 1px 5px;
  border-radius: 4px;
}

/* leader portrait (leader mode) */
.leader-photo {
  width: 240px;
  height: 280px;
  margin: 0 auto;
  border-radius: 12px;
  border: 1px solid rgba(236, 228, 210, 0.18);
  background: rgba(236, 228, 210, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.leader-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-loading,
.photo-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--paper-dim);
  font-size: 13px;
}

/* ---------- Timeline mode (higher/lower chronology) ---------- */
.timeline-host {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 4px 0;
}

.tl-anchor,
.tl-challenger {
  border-radius: 14px;
  border: 1px solid rgba(236, 228, 210, 0.18);
  padding: 18px 16px;
  text-align: center;
  background: rgba(236, 228, 210, 0.04);
}

.tl-anchor {
  background: linear-gradient(180deg, rgba(79, 139, 135, 0.16), rgba(79, 139, 135, 0.05));
  border-color: rgba(79, 139, 135, 0.4);
}

.tl-event-name {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--paper);
  line-height: 1.3;
}

.tl-year {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 1px;
}

.tl-year-known {
  font-size: 32px;
  color: var(--brass-bright);
  margin-top: 6px;
}

.tl-anchor-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--paper-dim);
  margin-top: 2px;
  order: -1;
  margin-bottom: 4px;
}

.tl-versus {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--paper-dim);
}

.tl-question {
  font-size: 14px;
  color: var(--paper-dim);
  margin: 10px 0 14px;
}
.tl-question strong { color: var(--paper); }

.tl-buttons {
  display: flex;
  gap: 10px;
}

.tl-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 14px 10px;
  border-radius: 12px;
  border: 1px solid rgba(236, 228, 210, 0.25);
  background: rgba(236, 228, 210, 0.05);
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.08s;
}
.tl-btn:hover:not(:disabled) {
  border-color: var(--brass-bright);
  background: rgba(232, 193, 114, 0.12);
}
.tl-btn:active:not(:disabled) { transform: scale(0.97); }
.tl-btn:disabled { cursor: default; opacity: 0.85; }

.tl-btn-sub {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--paper-dim);
  font-weight: 400;
}

.tl-btn-correct {
  border-color: var(--teal) !important;
  background: rgba(79, 139, 135, 0.25) !important;
}
.tl-btn-wrong {
  border-color: var(--rust) !important;
  background: rgba(180, 83, 58, 0.22) !important;
}

.tl-year-hidden {
  font-size: 32px;
  color: var(--paper-dim);
  margin-top: 14px;
}
.tl-reveal-correct { color: var(--teal) !important; }
.tl-reveal-wrong { color: var(--rust) !important; }

.tl-reveal-correct,
.tl-reveal-wrong {
  animation: tl-pop 0.3s ease;
}
@keyframes tl-pop {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

.tl-gameover {
  text-align: center;
  padding: 24px 16px;
}
.tl-gameover-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  color: var(--rust);
}
.tl-gameover-detail {
  font-size: 14px;
  color: var(--paper);
  margin: 12px 0;
  line-height: 1.5;
}
.tl-gameover-streak {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--brass-bright);
  margin-bottom: 20px;
}
.tl-again-btn { width: 100%; }

.flag-frame {
  border-radius: 4px;
  border: 1px solid rgba(236, 228, 210, 0.25);
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
}

.feedback {
  text-align: center;
  min-height: 26px;
  font-weight: 600;
  font-size: 15px;
  margin-top: 4px;
}

.feedback.is-correct { color: var(--good); }
.feedback.is-wrong { color: var(--rust); }

/* ---------- Answer zone ---------- */

.answer-zone {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.answer-zone.is-grid {
  grid-template-columns: 1fr 1fr;
}

.choice-btn {
  padding: 14px 12px;
  border-radius: 12px;
  border: 1px solid rgba(236, 228, 210, 0.18);
  background: rgba(236, 228, 210, 0.04);
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.choice-btn:hover { border-color: var(--brass); transform: translateY(-1px); }

.choice-btn.is-correct {
  background: rgba(127, 168, 107, 0.18);
  border-color: var(--good);
  color: var(--good);
}

.choice-btn.is-wrong {
  background: rgba(180, 83, 58, 0.18);
  border-color: var(--rust);
  color: var(--rust);
}

.choice-btn:disabled { cursor: default; }

.text-answer-form {
  display: flex;
  gap: 10px;
}

.text-input {
  flex: 1;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(236, 228, 210, 0.25);
  background: rgba(236, 228, 210, 0.06);
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 15px;
}

.text-input:focus {
  outline: none;
  border-color: var(--brass);
}

.submit-btn {
  padding: 14px 20px;
  border-radius: 12px;
  border: none;
  background: var(--brass);
  color: var(--ink-deep);
  font-weight: 700;
  cursor: pointer;
}

.submit-btn:hover { background: var(--brass-bright); }

/* ---------- Bottom actions ---------- */

.board-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
}

.ghost-btn {
  background: none;
  border: none;
  color: var(--paper-dim);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: text-decoration-color 0.15s, color 0.15s;
}

.ghost-btn:hover { color: var(--paper); text-decoration-color: var(--paper-dim); }

.primary-btn {
  padding: 12px 22px;
  border-radius: 12px;
  border: none;
  background: var(--teal);
  color: var(--paper);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.primary-btn:hover { background: var(--teal-dim); }

/* ---------- Footer / missed panel ---------- */

.session-footer {
  margin-top: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--paper-dim);
  font-family: var(--font-mono);
}

.link-btn {
  background: none;
  border: none;
  color: var(--teal);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
}

.missed-panel {
  position: fixed;
  inset: 0;
  background: rgba(8, 22, 33, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 24px;
}

.missed-panel[hidden] {
  display: none;
}

.missed-panel-card {
  background: var(--ink);
  width: 100%;
  max-width: 420px;
  border-radius: 16px;
  padding: 24px;
  border: 1px solid rgba(236, 228, 210, 0.15);
}

.missed-panel h2 {
  font-family: var(--font-display);
  color: var(--brass-bright);
  margin-top: 0;
}

.missed-panel ul {
  list-style: none;
  padding: 0;
  margin: 12px 0;
  max-height: 50vh;
  overflow-y: auto;
}

.missed-panel li {
  padding: 8px 0;
  border-bottom: 1px solid rgba(236, 228, 210, 0.1);
  display: flex;
  justify-content: space-between;
}

.missed-panel .ghost-btn { margin-top: 8px; }

@media (max-width: 420px) {
  .answer-zone.is-grid { grid-template-columns: 1fr; }
  .stats { gap: 10px; }
  .brand h1 { font-size: 22px; }
}

/* ===================== Website ad placeholders ===================== */
.web-ad {
  width: min(728px, 100%);
  min-height: 90px;
  margin: 28px auto 0;
  padding: 18px;
  box-sizing: border-box;
  border: 1px dashed rgba(236, 228, 210, 0.28);
  border-radius: 16px;
  background: rgba(236, 228, 210, 0.035);
  color: var(--paper-dim, #c9bd9e);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.web-ad span {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.85;
}

.web-ad small {
  font-size: 11px;
  opacity: 0.65;
}

.web-ad-break {
  margin-top: 32px; /* keeps ad away from answer buttons/game area */
}

.web-ad[hidden] {
  display: none !important;
}

@media (max-width: 700px) {
  .web-ad {
    min-height: 70px;
    margin-top: 20px;
    padding: 12px;
  }

  .web-ad small {
    display: none;
  }
}
