: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; }
[hidden] { display: none !important; }

/* 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; }

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

.panel.side { grid-area: side; border-right: 0; border-left: 1px solid var(--red); }

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);
}

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

.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; }

.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; }

/* Holes slider (Low / Medium / Many), indented under the Holes toggle */
.range { padding: 0 0 4px 46px; }
.range input {
  width: 100%;
  height: 6px;
  margin: 10px 0 6px;
  border-radius: 3px;
  background: rgba(212, 168, 75, 0.35);
  appearance: none;
  cursor: pointer;
}

/* Knob: light red with a golden border */
.range input::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  border: 2px solid var(--gold);
  border-radius: 50%;
  background: var(--red-bright);
  appearance: none;
}

.range input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid var(--gold);
  border-radius: 50%;
  background: var(--red-bright);
}

.range input:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 4px; }
.range-labels { display: flex; justify-content: space-between; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

/* Modifier sliders: label + current step word, range, step marks (locked steps dimmed) */
.modifiers { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.modifier-head { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.modifier-head label { flex: 1; }
.modifier-value { font-size: 12px; color: var(--gold-soft); }
.modifier .range { padding: 0; }
.modifier .range input { margin-top: 8px; }
.range-labels .locked { opacity: 0.3; text-decoration: line-through; }

/* !-icon + explanation, auto-switch notice */
.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;
}

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

.tip { margin: 4px 0 8px; }
.notice { margin: 8px 0 0; border-left-color: var(--gold-soft); }

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

/* Action row: button + i-icon; the tooltip shows above the row on hover, focus or tap */
.action { position: relative; display: flex; align-items: center; gap: 6px; }
.action .btn { flex: 1; min-width: 0; }

.hint {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  padding: 0;
  border: 1px solid var(--gold);
  border-radius: 50%;
  background: transparent;
  color: var(--gold-soft);
  font: italic 700 13px/1 var(--heading);
  cursor: help;
}

.hint:hover, .action.show-tip .hint { background: var(--red); }
.hint:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 2px; }

.hint-tip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 10;
  padding: 8px 10px;
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.hint:hover + .hint-tip, .hint:focus-visible + .hint-tip, .action.show-tip .hint-tip { visibility: visible; opacity: 1; }

.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;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}

.btn:hover:not(:disabled) { background: var(--red); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.done { border-color: var(--gold-soft); color: var(--text); }
.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; }
.btn.subtle { align-self: center; padding: 6px 12px; border-color: transparent; color: var(--muted); font-size: 13px; text-decoration: underline dotted; text-underline-offset: 3px; }
.btn.subtle:hover:not(:disabled) { background: transparent; color: var(--gold-soft); }

.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); }

.close {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--gold-soft);
  font: 400 28px/1 var(--body);
  cursor: pointer;
}

.close:hover { color: var(--text); }
.close:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 2px; border-radius: 4px; }
.close.small { width: 24px; height: 24px; font-size: 22px; }

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

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

/* Map report (collapsible) */
.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; }

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

/* 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 h2 { margin: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }

.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 .cap-note { margin: 4px 0 0; color: var(--muted); }
.capital-details .cap-note { margin-top: 10px; font-size: 12px; }

/* Line samples (capital card): solid = 2 steps, dashed = 3 steps, frame = selected capital */
.line { display: inline-block; flex-shrink: 0; width: 22px; height: 0; margin-right: 8px; vertical-align: middle; border-top: 2px solid var(--gold-soft); }
.line.dashed { border-top-style: dashed; }
.line.frame { height: 10px; border: 3px solid var(--gold); border-radius: 2px; }
.map-key { margin: 12px 0 0; padding: 10px 0 0; border-top: 1px solid var(--red); list-style: none; color: var(--muted); }
/* Fixed symbol column so all key texts start at the same x */
.map-key li { display: grid; grid-template-columns: 40px 1fr; align-items: center; column-gap: 8px; padding: 3px 0; }
.map-key li > i { justify-self: center; margin-right: 0; }

.key-badge {
  flex-shrink: 0;
  margin-right: 8px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--gold-soft);
  font: 700 11px/1.4 var(--body);
  font-style: normal;
}

.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;
  gap: 10px;
  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 span { flex-shrink: 0; white-space: nowrap; font-size: 11px; letter-spacing: 0.08em; color: var(--muted); }

/* Modals */
.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 em { color: var(--gold-soft); }
/* Modal buttons: the red primary button first at full width, the others below in two columns */
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.modal-actions .btn { flex: 1 1 calc(50% - 4px); line-height: 1.2; }
.modal-actions .btn.primary { flex-basis: 100%; }

.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 titles in the heading font; initial focus sits here without a ring */
.modal-head h2 {
  margin: 0;
  font: 700 26px/1.15 var(--heading);
  letter-spacing: 0;
  text-transform: none;
  color: var(--gold);
}

.modal-head h2:focus { outline: none; }

/* Legend: titles, paragraphs and the tile weight table */
.legend-modal { max-width: min(640px, calc(100vw - 32px)); max-height: 85vh; padding: 0; }
.legend { padding: 4px 24px 20px; 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); }

.weights { width: 100%; max-width: 360px; margin: 4px 0 12px; border-collapse: collapse; font-size: 14px; }
.weights th { padding: 4px 8px; border-bottom: 1px solid var(--gold); text-align: left; font-weight: 600; color: var(--gold-soft); }
.weights td { padding: 4px 8px; border-bottom: 1px solid var(--red); color: var(--text); }
.weights th:last-child, .weights td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.weights td span { margin-left: 6px; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

/* Tile rule modal: same size for every tile, content centered under the header */
.tile-modal {
  width: min(580px, calc(100vw - 32px));
  max-width: none;
  height: min(360px, calc(100vh - 32px));
  padding: 0;
  overflow-y: auto;
}

.tile-modal form { display: flex; flex-direction: column; min-height: 100%; }
.tile-modal .modal-head { margin-bottom: 0; }
.tile-body { flex: 1; display: flex; gap: 28px; align-items: center; justify-content: center; padding: 28px 40px 56px; }
.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);
}

.tile-rules { margin: 0; padding: 0 0 0 18px; font-size: 15px; line-height: 1.45; color: var(--text); }
.tile-rules li { margin: 0 0 8px; }
.tile-rules li:last-child { margin-bottom: 0; }
.tile-rules li::marker { color: var(--gold); }
.tile-rules strong { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold-soft); }
.tile-rules span { display: block; }
.tile-rules span + span { margin-top: 2px; }

/* Copyright: small, always visible; lower left on big screens */
.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;
}

@media (min-width: 1101px) {
  .copyright { left: 16px; transform: none; }
}

/* 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) {
  /* Generate New first at full width, the others in two columns (a single one stretches) */
  .actions { flex-direction: row; flex-wrap: wrap; }
  .actions .action { flex: 1 1 calc(50% - 4px); }
  .actions .action:first-child { flex-basis: 100%; }
  .actions .btn { padding: 10px 6px; line-height: 1.2; }
  body { padding-bottom: 28px; }
  .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); }
  .stage { height: auto; aspect-ratio: 1 / 1.05; max-height: 85vh; padding: 8px; }
  .modal-head { padding: 14px 16px 10px; }
  .modal-head h2 { font-size: 22px; }
  .legend { padding: 4px 16px 16px; }
  .tile-modal { height: min(520px, calc(100vh - 32px)); }
  .tile-body { flex-direction: column; gap: 20px; padding: 24px 24px 48px; text-align: center; }
  .tile-body img { width: 160px; }
  .tile-rules { display: inline-block; text-align: left; }
}

/* Soft animations (off with reduced motion) */
@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: modal-in 0.18s ease-out; }
  dialog[open]::backdrop { animation: fade-in 0.18s ease-out; }
  .card:not([hidden]) { animation: fade-in 0.2s ease-out; }
  .status p { animation: fade-in 0.25s ease-out both; }
  .tip:not([hidden]) { animation: fade-in 0.15s ease-out; }
  .seg span, .info, .hint, .close, .downloads a, .fold summary { transition: background-color 0.15s, color 0.15s, border-color 0.15s; }
  .hint-tip { transition: opacity 0.15s, visibility 0.15s; }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
}

@keyframes fade-in {
  from { opacity: 0; }
}

/* Very narrow screens: all buttons full width */
@media (max-width: 420px) {
  .actions .action, .modal-actions .btn { flex-basis: 100%; }
}
