/* ==========================================================================
   The Affair of the Telegraphs — simulation only
   Ink on parchment, with red reserved for the private signal.
   ========================================================================== */

:root {
  --paper: #efe6d4;
  --paper-2: #e7dbc4;
  --ink: #2f2417;
  --ink-soft: #5c4a33;
  --rule: #b9a785;
  --secret: #a32820;

  --serif: "EB Garamond", "IM Fell English", "Iowan Old Style", "Palatino Linotype",
    Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --mono: "Iosevka", "SF Mono", "Cascadia Mono", "DejaVu Sans Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  --radius: 3px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.fallback { margin: 2rem auto; padding: 1rem; max-width: 40rem; border: 1px solid var(--rule); }

/* ------------------------------------------------------------------ header */

.masthead { max-width: 64rem; margin: 0 auto; padding: 1.8rem 1.5rem 0.6rem; }
.masthead h1 { margin: 0; font-size: clamp(1.6rem, 1.1rem + 1.4vw, 2.3rem); font-weight: 600; }
.subtitle { margin: 0.15rem 0 0; color: var(--ink-soft); font-style: italic; }

main {
  max-width: 64rem; margin: 0 auto; padding: 0 1.5rem 2.5rem;
  display: grid; gap: 1rem;
}

.map-section, .controls, .demonstration {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.9rem 1rem 1rem;
  background: var(--paper-2);
}

/* --------------------------------------------------------------------- map */

.map-section { background: var(--paper); }
.map-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(11rem, 15rem);
  gap: 0.9rem;
  align-items: start;
}
@media (max-width: 58rem) { .map-grid { grid-template-columns: minmax(0, 1fr); } }

.map-stack {
  position: relative;
  width: 100%;
  aspect-ratio: 1000 / 971;
  max-height: 72vh;
  max-width: calc(72vh * 1.0299);
  margin: 0 auto;
}
.map, .fx { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.fx { pointer-events: none; }

.coastline {
  fill: var(--paper); stroke: #59462f; stroke-width: 1.1;
  stroke-linejoin: round; vector-effect: non-scaling-stroke;
}
.graticule { stroke: rgba(90, 72, 48, 0.16); stroke-width: 0.6; }

.link {
  stroke: #7d6949; stroke-width: 1.2; stroke-dasharray: 3 3;
  stroke-opacity: 0.8; vector-effect: non-scaling-stroke;
}
.link.in-flight { stroke: var(--ink); stroke-dasharray: none; stroke-width: 2; }
.link.secret-trail { stroke: var(--secret); stroke-dasharray: none; stroke-width: 2.2; }

.tower .tower-base { fill: var(--ink); stroke: none; }
.tower .arm { stroke: var(--ink); stroke-linecap: round; }
.tower .arm-bar { stroke-width: 2.4; }
.tower .arm-indicator { stroke-width: 2; }
.tower .tower-ring {
  fill: none; stroke: none; stroke-width: 1.6; opacity: 0;
  vector-effect: non-scaling-stroke;
}
.tower.injection .tower-base { fill: var(--secret); }
.tower.active .tower-ring { stroke: var(--ink); opacity: 0.75; }
.tower.secret-seen .tower-ring { stroke: var(--secret); opacity: 0.5; }
.tower.showing-secret .arm { stroke: var(--secret); }
.tower.showing-secret .tower-ring { stroke: var(--secret); opacity: 1; stroke-width: 2.4; }
.tower.focused .tower-base { fill: var(--secret); }
.station-hit { fill: transparent; stroke: none; cursor: pointer; }

.arm-regulator, .arm-frame {
  transition: transform var(--arm-ms, 620ms) cubic-bezier(0.34, 0.02, 0.28, 1);
  transform-box: view-box;
  transform-origin: 0 0;
}
.station-label {
  font-size: 9px; fill: var(--ink-soft); font-weight: 600;
  paint-order: stroke; stroke: rgba(239, 230, 212, 0.85); stroke-width: 2.4px;
  pointer-events: none;
}

/* ------------------------------------------------------------- tower panel */

.tower-panel {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0.4rem 0.5rem 0.55rem;
}
.tower-panel .semaphore { display: block; width: 100%; height: auto; }
.semaphore .tower-mast-halo { fill: var(--paper); stroke: none; }
.semaphore .tower-mast { fill: #b5a382; stroke: #6b573a; stroke-width: 1.5; }
.semaphore .tower-roof { fill: var(--paper-2); stroke: var(--ink); stroke-width: 4; stroke-linejoin: round; }
.semaphore .tower-roof-strut { stroke: var(--ink); stroke-width: 2.5; }
.semaphore .tower-plinth { fill: var(--paper-2); stroke: var(--ink); stroke-width: 3; }
.semaphore .arm { stroke: var(--ink); stroke-linecap: round; }
.semaphore .arm-bar { stroke-width: 9; }
.semaphore .arm-indicator { stroke-width: 7; }
.semaphore .tower-base { fill: var(--ink); }

.tower-name { margin: 0.25rem 0 0; text-align: center; font-weight: 600; }
.tower-status { margin: 0 0 0.4rem; text-align: center; font-size: 0.82rem; color: var(--ink-soft); min-height: 1.2em; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.6rem; margin: 0; font-size: 0.8rem; }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; font-family: var(--mono); font-size: 0.8rem; overflow-wrap: anywhere; }

.flash {
  margin: 0.6rem 0 0; padding: 0.35rem 0.5rem;
  border-left: 3px solid var(--secret); color: var(--secret); font-size: 0.85rem;
}
.flash[hidden] { display: none; }

/* ---------------------------------------------------------------- controls */

.control-grid {
  display: grid; gap: 0.6rem 1rem;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.9rem; }
.field > span { color: var(--ink-soft); }
.field[hidden] { display: none; }

select {
  font-family: var(--serif); font-size: 1rem; color: var(--ink);
  background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 0.3rem 0.4rem;
}
select:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--ink); outline-offset: 1px;
}
.check { display: flex; align-items: center; gap: 0.45rem; font-size: 0.95rem; cursor: pointer; padding-bottom: 0.1rem; }
.check input { accent-color: var(--secret); }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.8rem; }
button {
  font-family: var(--serif); font-size: 1rem; cursor: pointer;
  border-radius: var(--radius); padding: 0.4rem 0.9rem;
  border: 1px solid var(--rule); background: var(--paper); color: var(--ink);
}
button:hover:not(:disabled) { background: var(--paper-2); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 600; }
button.primary:hover:not(:disabled) { background: #3f3020; }
button.ghost { background: transparent; }

.warn { margin: 0.5rem 0 0; font-size: 0.88rem; color: var(--secret); }
.warn[hidden] { display: none; }

/* ----------------------------------------------------------- demonstration */

.demonstration[hidden] { display: none; }

.wire-strip { list-style: none; margin: 0 0 0.35rem; padding: 0; display: flex; flex-wrap: wrap; gap: 0.25rem; }
.chip {
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--paper); padding: 0.1rem 0.35rem;
  font-family: var(--mono); font-size: 0.78rem;
}
.chip.secret, .chip.correction {
  border-color: var(--secret); color: var(--secret);
  background: rgba(163, 40, 32, 0.08);
}
.chip.correction { text-decoration: line-through; }

.badge { display: inline-block; margin: 0.2rem 0 0.7rem; font-size: 0.9rem; font-weight: 600; }
.badge.ok { color: var(--ink); }
.badge.bad { color: var(--secret); }

.verdict-grid { display: grid; gap: 0.7rem; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); }
.verdict-card { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper); padding: 0.6rem 0.7rem; }
.verdict-card h3 { margin: 0 0 0.3rem; font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); }
.verdict-card .mono { margin: 0; font-family: var(--mono); font-size: 0.85rem; }
.verdict-card .reading { margin: 0; font-size: 1.2rem; font-weight: 600; }
.verdict-card.accomplice { border-color: var(--secret); }
.verdict-card.accomplice .reading { color: var(--secret); }

/* --------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  .arm-regulator, .arm-frame { transition-duration: 120ms !important; }
}
