/* Single-player story reader. Loaded after style.css; every rule is scoped with an sp- prefix. */

:root {
  --sp-paper: #f7f3ea;
  /* Contrast targets for accent-derived colours (story.js reads these two by name). */
  --sp-paper-2-light: #efe8d9;
  --sp-paper-2-dark: #1f2227;
  --sp-paper-2: var(--sp-paper-2-light);
  --sp-text: #1f1c17;
  --sp-muted: #6a6257;
  --sp-line: #d9cfbd;
  --sp-up: #2e7d4f;
  --sp-down: #a23b2a;
  --sp-measure: 40rem;
  --sp-size: 1.075rem;
}
@media (prefers-color-scheme: dark) {
  :root {
    --sp-paper: #17191d;
    --sp-paper-2: var(--sp-paper-2-dark);
    --sp-text: #e9e4d8;
    --sp-muted: #a39b8d;
    --sp-line: #343840;
    --sp-up: #6cc391;
    --sp-down: #f08a76;
  }
}
html[data-sp-size='s'] { --sp-size: 0.98rem; }
html[data-sp-size='l'] { --sp-size: 1.2rem; }
html[data-sp-size='xl'] { --sp-size: 1.36rem; }

.sp-app { --sp-accent: #2f7fb5; --sp-accent-fill: #276a98; --sp-accent-text-light: #276a98; --sp-accent-text-dark: #8cc0e6; --sp-ink: #0d1b2a; background: var(--sp-paper); color: var(--sp-text); border-radius: 12px; border: 1px solid var(--sp-line); min-height: 70vh; position: relative; }
/* --sp-accent is decorative (borders, pips). --sp-accent-fill carries white button text and
   --sp-accent-text colours text on paper; both meet WCAG AA. /story/palettes.css sets each
   campaign's --sp-accent and story.js derives the other tokens from it; these House values
   apply only if that stylesheet or the script is unavailable. */
.sp-house-docks { --sp-accent: #2f7fb5; --sp-accent-fill: #276a98; --sp-accent-text-light: #276a98; --sp-accent-text-dark: #8cc0e6; }
.sp-house-archive { --sp-accent: #7652a8; --sp-accent-fill: #7652a8; --sp-accent-text-light: #7652a8; --sp-accent-text-dark: #c0a8e6; }
.sp-app { --sp-accent-text: var(--sp-accent-text-light); }
@media (prefers-color-scheme: dark) {
  .sp-app { --sp-accent-text: var(--sp-accent-text-dark); }
}
.sp-kicker { font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--sp-muted); font-weight: 600; }
.sp-loading { padding: 2rem; }

/* Selection page */
.sp-select-head { max-width: 46rem; margin: 1rem auto 1.5rem; }
.sp-select-head h1 { font-family: Georgia, 'Iowan Old Style', 'Palatino Linotype', serif; font-size: 2.3rem; }
.sp-picks { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; max-width: 980px; margin: 0 auto; }
.sp-pick { display: flex; gap: 16px; background: var(--surface, #fff); border: 1px solid var(--border, #ddd); border-top: 6px solid var(--sp-accent); border-radius: 12px; padding: 18px; min-width: 0; }
.sp-pick h2 { font-family: Georgia, serif; font-size: 1.6rem; margin: 0.1rem 0; }
.sp-pick-title { font-style: italic; margin: 0 0 0.6rem; }
.sp-pick-sigil { flex: 0 0 56px; height: 56px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, color-mix(in srgb, var(--sp-accent) 30%, transparent), color-mix(in srgb, var(--sp-accent) 80%, black)); border: 3px solid var(--sp-accent); }
.sp-pick-body { min-width: 0; }

/* Top bar */
.sp-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 14px; border-bottom: 1px solid var(--sp-line); background: var(--sp-paper-2); border-radius: 12px 12px 0 0; position: sticky; top: 0; z-index: 5; }
.sp-bar-title { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; flex: 1 1 10rem; font-weight: 600; }
.sp-progress { width: 7rem; height: 8px; accent-color: var(--sp-accent); }
.sp-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.sp-tool { background: transparent; color: var(--sp-text); border: 1px solid var(--sp-line); min-height: 36px; padding: 4px 10px; font-size: 0.9rem; }
.sp-tool.active { border-color: var(--sp-accent); color: var(--sp-accent-text); }

/* Layout */
.sp-layout { display: grid; grid-template-columns: minmax(0, 1fr) 22rem; gap: 0; }
.sp-read { padding: 18px clamp(14px, 4vw, 40px) 40px; min-width: 0; }
.sp-read > * { max-width: var(--sp-measure); margin-left: auto; margin-right: auto; }
.sp-panel { border-left: 1px solid var(--sp-line); background: var(--sp-paper-2); min-width: 0; border-radius: 0 0 12px 0; }
.sp-panel-tabs { display: flex; align-items: flex-start; gap: 4px; padding: 10px; border-bottom: 1px solid var(--sp-line); position: sticky; top: 58px; background: var(--sp-paper-2); }
.sp-tablist { display: flex; flex-wrap: wrap; gap: 2px; flex: 1 1 auto; min-width: 0; }
.sp-panel-tabs button { background: transparent; color: var(--sp-text); border: 1px solid transparent; padding: 4px 7px; min-height: 34px; font-size: 0.88rem; }
.sp-panel-tabs button.active { border-color: var(--sp-accent); color: var(--sp-accent-text); }
.sp-close { display: none; margin-left: auto; font-size: 1.4rem !important; }
.sp-panel-body { padding: 12px 16px 24px; font-size: 0.95rem; }
.sp-panel-body h2 { font-size: 1.1rem; margin-top: 0.5rem; }
.sp-panel-body h3 { font-size: 0.95rem; }

@media (max-width: 980px) {
  .sp-layout { grid-template-columns: minmax(0, 1fr); }
  .sp-panel { display: none; }
  html.sp-panel-open .sp-panel { display: block; position: fixed; inset: 0; z-index: 50; overflow-y: auto; border: 0; border-radius: 0; }
  html.sp-panel-open .sp-panel-tabs { top: 0; }
  .sp-close { display: inline-block; }
  .sp-progress { display: none; }
}
@media (min-width: 981px) {
  .sp-tool { display: none; }
  .sp-tool:last-child { display: inline-block; }
}
@media (max-width: 520px) {
  .sp-bar { padding: 8px 10px; }
  .sp-tool { padding: 4px 8px; font-size: 0.82rem; }
  .sp-read { padding: 12px 14px 32px; }
}

/* Reading */
.sp-vignette-wrap { border-radius: 10px; overflow: hidden; border: 1px solid var(--sp-line); margin-bottom: 14px; line-height: 0; }
.sp-vignette { width: 100%; height: clamp(72px, 16vw, 132px); display: block; }
.sp-scene-title { font-family: Georgia, 'Iowan Old Style', serif; font-size: 1.65rem; margin: 0.6rem auto 0.4rem; outline: none; }
.sp-scene-title:focus-visible { outline: 3px solid var(--sp-accent); outline-offset: 4px; }
.sp-prose { font-family: Georgia, 'Iowan Old Style', 'Palatino Linotype', serif; font-size: var(--sp-size); line-height: 1.68; }
.sp-prose p { margin: 0 0 0.95em; hyphens: auto; }
.sp-break { border: 0; text-align: center; margin: 1.4em 0; }
.sp-break::after { content: '⁂'; color: var(--sp-muted); }
.sp-chapter-card { border: 1px solid var(--sp-line); border-left: 6px solid var(--sp-accent); border-radius: 10px; padding: 14px 18px; margin-bottom: 16px; background: var(--sp-paper-2); }
.sp-chapter-card h2 { font-family: Georgia, serif; font-size: 1.5rem; margin: 0.2rem 0; }
.sp-blurb { font-style: italic; color: var(--sp-muted); }
.sp-council-tag { display: inline-block; font-size: 0.85rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: color-mix(in srgb, var(--sp-accent) 18%, transparent); color: var(--sp-text); }

.sp-aftermath { border-left: 4px solid var(--sp-accent); background: var(--sp-paper-2); padding: 10px 14px; border-radius: 0 10px 10px 0; margin-bottom: 14px; font-size: 0.98rem; animation: sp-in 0.35s ease-out; }
.sp-echo { margin: 0 0 0.4rem; font-weight: 600; }
.sp-fb { font-family: Georgia, serif; font-size: calc(var(--sp-size) * 0.95); }
.sp-chips { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 6px 0 0; }
.sp-chip { font-size: 0.82rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--sp-line); }
.sp-chip.up { color: var(--sp-up); }
.sp-chip.down { color: var(--sp-down); }

.sp-choices { display: flex; flex-direction: column; gap: 10px; margin-top: 1.4rem; }
.sp-choice-wrap { display: flex; flex-direction: column; gap: 4px; }
.sp-choice { display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%; background: var(--sp-paper); color: var(--sp-text); border: 1px solid var(--sp-line); border-left: 4px solid var(--sp-accent); border-radius: 10px; padding: 12px 14px; min-height: 48px; font-weight: 500; font-size: 1rem; line-height: 1.45; transition: background 0.15s, transform 0.15s; }
.sp-choice:hover:not(:disabled) { background: var(--sp-paper-2); transform: translateX(2px); }
.sp-choice:focus-visible, .sp-act:focus-visible, .sp-tool:focus-visible, .sp-panel button:focus-visible, .sp-panel summary:focus-visible { outline: 3px solid var(--sp-accent); outline-offset: 2px; }
.sp-choice:disabled { opacity: 0.55; border-left-color: var(--sp-line); }
.sp-key { flex: 0 0 auto; display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 6px; font-size: 0.82rem; font-weight: 700; background: color-mix(in srgb, var(--sp-accent) 18%, transparent); }
.sp-choice-text { min-width: 0; overflow-wrap: anywhere; }
.sp-continue { border-left-width: 4px; font-weight: 700; }
.sp-motion { border-left-width: 8px; }
.sp-locked { margin: 0 0 0 2.6rem; font-size: 0.85rem; color: var(--sp-muted); }
.sp-forecast { margin-left: 2.6rem; font-size: 0.9rem; }
.sp-forecast summary { cursor: pointer; color: var(--sp-muted); }
.sp-hint { margin-top: 1rem; }
.sp-busy .sp-choice { cursor: progress; }

.sp-council { border: 1px solid var(--sp-line); border-radius: 8px; padding: 8px 12px; margin: 6px 0; background: var(--sp-paper); }
.sp-council.pass { border-color: var(--sp-up); }
.sp-council.fail { border-color: var(--sp-down); }
.sp-votes { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.sp-votes li { display: flex; flex-wrap: wrap; gap: 0 4px; }
.sp-votes li.yes strong::before { content: '✓ '; color: var(--sp-up); }
.sp-votes li.no strong::before { content: '✗ '; color: var(--sp-down); }
.sp-vote-reason { flex-basis: 100%; color: var(--sp-muted); font-size: 0.85rem; padding-left: 1.2rem; }
.sp-council.compact .sp-vote-reason { display: none; }
.sp-tally { font-weight: 700; margin: 6px 0 0; }

/* Panel contents */
.sp-city { display: grid; gap: 6px; }
.sp-ward { display: grid; grid-template-columns: 5.5rem 1fr auto; align-items: center; gap: 8px; }
.sp-ward-name { font-weight: 600; }
.sp-pips { display: flex; gap: 3px; }
.sp-pips span { flex: 1; height: 10px; border-radius: 3px; background: var(--sp-line); }
.sp-pips span.on { background: var(--sp-accent); }
.sp-ward-docks .sp-pips span.on { background: #2f7fb5; }
.sp-ward-market .sp-pips span.on { background: #c08a1e; }
.sp-ward-foundry .sp-pips span.on { background: #b4502c; }
.sp-ward-gardens .sp-pips span.on { background: #3f8f4f; }
.sp-ward-archive .sp-pips span.on { background: #7652a8; }
.sp-ward-val { font-variant-numeric: tabular-nums; font-size: 0.85rem; color: var(--sp-muted); }
.sp-res { display: grid; gap: 8px; margin: 0; }
.sp-res > div { border: 1px solid var(--sp-line); border-radius: 8px; padding: 6px 10px; }
.sp-res dt { font-weight: 700; display: inline; }
.sp-res dd { display: inline; margin: 0 0 0 6px; font-variant-numeric: tabular-nums; font-weight: 700; }
.sp-res dd.sp-res-desc { display: block; margin: 2px 0 0; font-size: 0.82rem; font-weight: 400; font-variant-numeric: normal; color: var(--sp-muted); }
.sp-items { padding-left: 1.1rem; }
.sp-person { border: 1px solid var(--sp-line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.sp-person h3 { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.sp-person p { margin: 0 0 4px; }
.sp-meter { height: 6px; background: var(--sp-line); border-radius: 3px; position: relative; overflow: hidden; }
.sp-meter-fill { --v: 0; position: absolute; top: 0; bottom: 0; left: 50%; width: calc(var(--v) * 16.66%); background: var(--sp-up); }
.band-wary .sp-meter-fill, .band-hostile .sp-meter-fill, .band-enemy .sp-meter-fill { left: calc(50% + var(--v) * 16.66%); width: calc(var(--v) * -16.66%); background: var(--sp-down); }
.sp-thresholds { padding-left: 1rem; margin: 6px 0 0; color: var(--sp-muted); }
.sp-thresholds li.met { color: var(--sp-text); }
.sp-entry { border-bottom: 1px solid var(--sp-line); padding: 6px 0; }
.sp-entry summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; }
.sp-entry p { font-size: 0.93rem; }
.sp-log { padding-left: 1.4rem; font-size: 0.9rem; }
.sp-log li { margin-bottom: 4px; }
.sp-saves { list-style: none; padding: 0; display: grid; gap: 8px; }
.sp-saves li { border: 1px solid var(--sp-line); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.sp-slot { font-weight: 700; }
.sp-slot-sum { font-size: 0.85rem; color: var(--sp-muted); overflow-wrap: anywhere; }
.sp-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 6px 0; }
.sp-act { background: var(--sp-accent-fill); border-color: var(--sp-accent-fill); color: #fff; }
.sp-act.ghost { background: transparent; color: var(--sp-accent-text); border-color: var(--sp-accent); }

.sp-intro { max-width: 36rem; margin: 0 auto; padding: 32px 18px; text-align: left; }
/* Recovery choices stack with room between each button and the next heading. */
.sp-incompatible .sp-act { display: block; margin: 0 0 10px; }
.sp-incompatible h2 { margin-top: 1.4rem; }
.sp-intro h1 { font-family: Georgia, serif; font-size: 2rem; outline: none; }
.sp-ending-card { border: 1px solid var(--sp-line); border-top: 6px solid var(--sp-accent); border-radius: 10px; padding: 16px 18px; margin-top: 1.6rem; background: var(--sp-paper-2); }
.sp-ending-card h2 { font-family: Georgia, serif; font-size: 1.6rem; }

.sp-toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); max-width: min(92vw, 34rem); background: var(--sp-ink, #111); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); transition: opacity 0.25s; }
.sp-toast-error { background: var(--sp-down); }
.sp-toast-hidden { opacity: 0; pointer-events: none; }

/* Motion: optional, never required for progression */
@keyframes sp-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes sp-drift { from { transform: translateX(0); } to { transform: translateX(-40px); } }
@keyframes sp-fall { from { transform: translate(0, -14px); } to { transform: translate(-6px, 14px); } }
@keyframes sp-flicker { 0%, 100% { opacity: 0.22; } 50% { opacity: 0.32; } }
.sp-wave-a { animation: sp-drift 9s linear infinite alternate; }
.sp-wave-b { animation: sp-drift 6s linear infinite alternate-reverse; }
.sp-rain { animation: sp-fall 0.7s linear infinite; }
.sp-lamp { animation: sp-flicker 3s ease-in-out infinite; }
.sp-read { animation: sp-in 0.3s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .sp-app *, .sp-app *::before, .sp-app *::after { animation: none !important; transition: none !important; }
}
html.sp-reduce .sp-app *, html.sp-reduce .sp-app *::before, html.sp-reduce .sp-app *::after { animation: none !important; transition: none !important; }
