:root {
  --bg: #1a0709;
  --panel: #2b0d10;
  --red: #8b1a1f;
  --red-bright: #b3262d;
  --gold: #d4a84b;
  --gold-soft: #f0d58a;
  --text: #f3e9dc;
  --muted: rgba(243, 233, 220, 0.6);
  --radius: 8px;
  --heading: Georgia, 'Times New Roman', serif;
  --body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* Thin scrollbars in the color scheme */
* { scrollbar-width: thin; scrollbar-color: var(--red) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--red); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--red-bright); }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--body);
}

/* Desktop: settings | map | report */
.app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 320px;
  grid-template-areas: 'settings stage side';
  height: 100vh;
}

.app > .panel:first-child { grid-area: settings; }
.stage { grid-area: stage; }
.panel.side { grid-area: side; border-right: 0; border-left: 1px solid var(--red); }

/* Controls */
.panel {
  background: var(--panel);
  border-right: 1px solid var(--red);
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

h1 {
  margin: 0;
  font: 700 22px/1.15 var(--heading);
  color: var(--gold);
}

h1 span {
  display: block;
  font-size: 15px;
  font-weight: 400;
  color: var(--gold-soft);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h2 {
  margin: 0 0 8px;
  font: 600 12px/1 var(--body);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}

.option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}

/* Segmented radio buttons */
.segmented {
  display: flex;
  flex: 1;
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  overflow: hidden;
}

.seg { flex: 1; position: relative; }
.seg + .seg { border-left: 1px solid var(--red); }

.seg input { position: absolute; opacity: 0; pointer-events: none; }

.seg span {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 7px 6px;
  cursor: pointer;
  text-align: center;
}

.seg input:checked + span { background: var(--red); color: var(--gold-soft); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--gold-soft); outline-offset: -2px; }
.seg input:disabled + span { cursor: not-allowed; color: var(--muted); opacity: 0.5; }

.badge {
  font-style: normal;
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gold);
}

/* Toggle switch */
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  flex: 1;
}

.toggle input { position: absolute; opacity: 0; pointer-events: none; }

.switch {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--gold);
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s;
}

.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--gold-soft);
  transition: transform 0.15s;
}

.toggle input:checked + .switch { background: var(--red-bright); }
.toggle input:checked + .switch::after { transform: translateX(16px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--gold-soft); outline-offset: 2px; }
.toggle:has(input:disabled) { cursor: not-allowed; opacity: 0.55; }

/* !-icon + explanation */
.info {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--gold);
  background: var(--red);
  color: var(--gold-soft);
  font: 700 13px/1 var(--body);
  cursor: pointer;
  flex-shrink: 0;
}

.info[hidden], .tip[hidden] { display: none; }

.tip {
  margin: 4px 0 8px;
  padding: 8px 10px;
  border-left: 2px solid var(--gold);
  background: var(--bg);
  font-size: 13px;
  color: var(--gold-soft);
}

/* Buttons */
.actions { display: flex; flex-direction: column; gap: 8px; }

.btn {
  padding: 10px 14px;
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  background: transparent;
  color: var(--gold-soft);
  font: 600 15px/1 var(--body);
  cursor: pointer;
}

.btn:hover:not(:disabled) { background: var(--red); }
.btn.primary { background: var(--red-bright); color: var(--text); }
.btn.primary:hover:not(:disabled) { background: var(--red); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.status { font-size: 13px; color: var(--muted); }
.status p { margin: 0 0 4px; }

/* Collapsible report + legend */
.fold {
  border: 1px solid var(--red);
  border-radius: var(--radius);
  background: var(--bg);
}

.fold summary {
  padding: 8px 12px;
  cursor: pointer;
  font: 600 12px/1.4 var(--body);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  list-style: none;
  display: flex;
  justify-content: space-between;
}

.fold summary::-webkit-details-marker { display: none; }
.fold summary::after { content: '+'; color: var(--gold-soft); }
.fold[open] summary::after { content: '−'; }
.fold summary:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: -2px; }
.fold > div { padding: 0 12px 10px; }

/* Legend: titles + paragraphs (no tables, readable on phones) */
.legend { font-size: 14px; line-height: 1.5; color: var(--text); }
.legend h3 {
  margin: 22px 0 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--red);
  font: 600 12px/1.3 var(--body);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}
.legend h3:first-child { margin-top: 0; }
.legend h4 { margin: 12px 0 2px; font: 600 14px/1.3 var(--body); color: var(--gold-soft); }
.legend p { margin: 0 0 8px; color: var(--muted); }
.legend strong { color: var(--text); }
.legend strong.neg { color: var(--red-bright); }

/* Modal */
.modal {
  max-width: min(420px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
}

.modal::backdrop { background: rgba(10, 2, 3, 0.7); }
.modal h2 { margin-bottom: 10px; font-size: 14px; }
.modal p { margin: 0 0 16px; font-size: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.legend-modal { max-width: min(640px, calc(100vw - 32px)); max-height: 85vh; padding: 0; }
.legend-modal .legend { padding: 4px 24px 20px; }
.legend-modal .legend p { font-size: 14px; margin: 0 0 8px; }
.modal-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--red);
  margin-bottom: 16px;
}
.modal-head h2 { margin: 0; }
.close {
  width: 32px;
  height: 32px;
  border: 1px solid var(--gold);
  border-radius: 50%;
  background: transparent;
  color: var(--gold-soft);
  font: 400 20px/1 var(--body);
  cursor: pointer;
}
.close:hover { background: var(--red); }
.status .error { color: var(--gold-soft); }

/* Map */
.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 16px;
}

#map { display: block; width: 100%; height: 100%; touch-action: manipulation; }

/* Side panel cards (capital details, downloads) */
.card {
  padding: 12px;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 13px;
}
.card[hidden] { display: none; }
.card h2 { margin: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.close.small { width: 24px; height: 24px; font-size: 16px; }

.capital-details { border-color: var(--gold); }
.cap-value { display: flex; align-items: baseline; gap: 10px; margin: 0 0 10px; }
.cap-value strong { font: 700 24px/1 var(--heading); color: var(--gold-soft); }
.delta { font-weight: 600; }
.delta.pos { color: var(--text); }
.delta.neg { color: var(--red-bright); }
.capital-details h3 {
  display: flex;
  justify-content: space-between;
  margin: 10px 0 4px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--red);
  font: 600 12px/1.3 var(--body);
  color: var(--gold);
}
.contrib { margin: 0; padding: 0; list-style: none; }
.contrib li { display: flex; justify-content: space-between; padding: 2px 0; color: var(--text); }
.contrib li span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.capital-details .empty, .capital-details .hint { margin: 4px 0 0; color: var(--muted); }
.capital-details .hint { margin-top: 10px; font-size: 12px; }

.downloads h2 { margin-bottom: 8px; }
.downloads ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.downloads a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  color: var(--gold-soft);
  text-decoration: none;
}
.downloads a:hover { background: var(--red); }
.downloads a:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 2px; }
.downloads a { gap: 10px; }
.downloads a span { flex-shrink: 0; white-space: nowrap; font-size: 11px; letter-spacing: 0.08em; color: var(--muted); }

/* Tile rule modal: same size for every tile */
.tile-modal {
  width: min(580px, calc(100vw - 32px));
  max-width: none;
  height: min(340px, calc(100vh - 32px));
  padding: 0;
  overflow-y: auto;
}
.tile-extra h3 { margin: 14px 0 2px; font: 600 14px/1.3 var(--body); color: var(--gold-soft); }
.modal .tile-extra p { margin: 0; font-size: 15px; color: var(--text); }
.tile-extra[hidden] { display: none; }

/* Copyright: small, always visible */
.copyright {
  position: fixed;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  z-index: 5;
  padding: 2px 10px;
  border-radius: 10px;
  background: rgba(26, 7, 9, 0.8);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.link {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
  cursor: pointer;
}
.link:hover, .link:focus-visible { color: var(--gold-soft); }
.modal em { color: var(--gold-soft); }
.tile-body { display: flex; gap: 20px; align-items: center; padding: 0 24px 24px; }
.tile-body img { width: 180px; height: auto; flex-shrink: 0; }
.tile-kind {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}
.modal .tile-rule { margin: 0; font-size: 16px; line-height: 1.45; color: var(--text); }

/* Medium: report panel moves under the settings */
@media (max-width: 1100px) {
  .app {
    grid-template-columns: 300px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: 'settings stage' 'side stage';
  }
  .panel.side { border-left: 0; border-right: 1px solid var(--red); border-top: 1px solid var(--red); }
}

/* Phone: settings, map, report stacked */
@media (max-width: 760px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    grid-template-areas: 'settings' 'stage' 'side';
    height: auto;
  }
  .panel, .panel.side { border: 0; border-bottom: 1px solid var(--red); padding: 16px; }
  .panel.side { border-top: 1px solid var(--red); }
  .legend-modal .legend { padding: 4px 16px 16px; }
  body { padding-bottom: 28px; }
  .tile-modal { height: min(520px, calc(100vh - 32px)); }
  .tile-body { flex-direction: column; padding: 0 16px 16px; text-align: center; }
  .tile-body img { width: 160px; }
  .modal-head { padding: 14px 16px 10px; }
  .actions { flex-direction: row; }
  .actions .btn { flex: 1; padding: 10px 6px; }
  .stage { height: auto; aspect-ratio: 1 / 1.05; max-height: 85vh; padding: 8px; }
}
