* { box-sizing: border-box; }
body { background: var(--page); color: var(--text); font-family: var(--font-body); font-size: 17px; line-height: 1.4; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { display: flex; flex-direction: column; min-height: 100vh; }


/* header + desk tools */
.head { background: var(--head-bg); color: var(--head-text); display: flex; align-items: center; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; padding: 10px 16px; }
.head h1 { font-family: var(--font-display); font-weight: 400; font-size: 1.35rem; margin: 0; letter-spacing: 0.01em; }
.status { font-family: var(--font-hand); font-size: 1.25rem; display: flex; gap: 6px 14px; flex-wrap: wrap; align-items: baseline; }
.status span + span::before { content: "·"; margin-right: 14px; opacity: .6; }
.status .age { position: relative; cursor: help; border-bottom: 1px dotted currentColor; }
.status .age::after { content: attr(data-tip); position: absolute; top: 34px; left: 0; width: 240px; white-space: normal; font-family: var(--font-body); font-size: .9rem; line-height: 1.3; background: var(--note); color: var(--text); border: 1px solid var(--note-edge); padding: 4px 8px; border-radius: 3px; opacity: 0; pointer-events: none; z-index: 20; }
.status .age:hover::after, .status .age:focus-visible::after { opacity: 1; }
.desk { display: flex; gap: 4px; }
.tool { position: relative; background: none; border: 1px solid transparent; border-radius: 4px; width: 40px; height: 40px; font-size: 1.25rem; cursor: pointer; line-height: 1; }
.tool:hover, .tool[aria-pressed="true"] { border-color: color-mix(in srgb, var(--head-text) 45%, transparent); }
.tool[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.tool::after { content: attr(data-label); position: absolute; top: 46px; right: 0; white-space: nowrap; font-family: var(--font-hand); font-size: 1.1rem; background: var(--note); color: var(--text); border: 1px solid var(--note-edge); padding: 0 8px; border-radius: 3px; opacity: 0; pointer-events: none; z-index: 20; }
.tool:hover::after, .tool:focus-visible::after { opacity: 1; }

/* notice below the header (refused follow etc.) */
.notice { font-family: var(--font-hand); font-size: 1.25rem; color: var(--text-soft); text-align: center; }
.notice:not(:empty) { padding: 4px 16px; }

/* stage + map */
.stage { position: relative; flex: 1; background: var(--stage); min-height: 800px; display: flex; justify-content: center; padding: 24px 16px; overflow: hidden;
  background-image: linear-gradient(color-mix(in srgb, var(--line) 12%, transparent) 1px, transparent 1px), linear-gradient(90deg, color-mix(in srgb, var(--line) 12%, transparent) 1px, transparent 1px);
  background-size: 40px 40px; }
.map-wrap { width: min(612px, 100%); aspect-ratio: 1; align-self: flex-start; position: relative; }
.map { width: 100%; height: 100%; display: block; border: 2px solid var(--text); box-shadow: 0 0 0 5px var(--stage), 0 0 0 6px var(--line); background: var(--stage); }
.map .t-fertile { fill: var(--wash-fertile); }
.map .t-plain { fill: var(--wash-plain); }
.map .t-harsh { fill: var(--wash-harsh); }
.map .stip { fill: var(--stipple); opacity: .35; }
.map .crack { fill: none; stroke: var(--text); stroke-width: .4; stroke-linecap: round; opacity: .35; }
.map .heat-layer { display: none; }
.map.show-heat .heat-layer { display: inline; }
.map .heat { fill: var(--accent); }
.map .hut { fill: var(--stage); stroke: var(--text); stroke-width: .45; stroke-linejoin: round; }
.map .sel { fill: none; stroke: var(--text); stroke-width: .8; stroke-dasharray: 2 1.2; }
.map .hov { fill: none; stroke: var(--text); stroke-width: .6; }
.map .follow-tile { fill: none; stroke: var(--emph); stroke-width: .6; animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 50% { stroke-opacity: .25; } }
.map:focus-visible { outline: 3px solid var(--accent); outline-offset: 6px; }
.map-label { position: absolute; font-family: var(--font-hand); font-size: 1.1rem; background: var(--note); border: 1px solid var(--note-edge); padding: 0 8px; border-radius: 3px; pointer-events: none; transform: translate(-50%, -135%); white-space: nowrap; }
.compass { position: absolute; left: -6px; bottom: -34px; font-family: var(--font-hand); font-size: 1.05rem; color: var(--text-soft); }

/* legend */
.legend { position: absolute; left: 24px; bottom: 18px; font-family: var(--font-hand); font-size: 1.1rem; display: grid; gap: 4px; }
.legend div { display: flex; align-items: center; gap: 8px; }
.legend svg { width: 26px; height: 18px; border: 1px solid var(--text); background: var(--stage); }
.switch { align-self: flex-start; background: none; border: 1px solid var(--text); border-radius: 3px; padding: 0 12px; font-family: var(--font-hand); font-size: 1.1rem; line-height: 1.3; cursor: pointer; margin-top: 4px; }
.switch[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

/* lens */
.lens { position: absolute; left: calc(50% + 250px); top: 24px; width: 232px; z-index: 5; }
.lens-ring { width: 232px; height: 232px; border-radius: 50%; border: 3px solid var(--text); box-shadow: 0 0 0 5px var(--stage), 0 0 0 6px var(--line), 0 10px 24px color-mix(in srgb, var(--ink) 25%, transparent); overflow: hidden; background: var(--stage); }
.lens-ring svg { width: 100%; height: 100%; display: block; }
.lens-cap { font-family: var(--font-hand); font-size: 1.15rem; line-height: 1.15; text-align: center; margin-top: 12px; background: var(--note); border: 1px solid var(--note-edge); border-radius: 3px; padding: 2px 8px; }
.lens-cap .small { display: block; font-family: var(--font-body); font-size: .85rem; }
.lens .ground { fill: var(--wash-plain); }
.lens .dot { fill: var(--text); animation: drift 6s ease-in-out infinite alternate; animation-delay: var(--d, 0s); }
@keyframes drift { to { transform: translate(var(--dx, 2px), var(--dy, -2px)); } }
.lens .coop { stroke: var(--text); stroke-width: .9; fill: none; }
.lens .betray { fill: var(--accent); stroke: var(--text); stroke-width: .5; }
.lens .follow { fill: none; stroke: var(--emph); stroke-width: 2.2; }

/* notes */
.note { position: absolute; width: 276px; background: var(--note); color: var(--text); border: 1px solid var(--note-edge); border-radius: 3px; padding: 18px 16px 14px; box-shadow: 0 8px 18px color-mix(in srgb, var(--ink) 22%, transparent); z-index: 6; }
.note .pin { position: absolute; top: -9px; left: 50%; width: 16px; height: 16px; border-radius: 50%; background: var(--emph); box-shadow: inset -2px -2px 0 color-mix(in srgb, var(--ink) 35%, transparent), 0 2px 3px color-mix(in srgb, var(--ink) 35%, transparent); transform: translateX(-50%); }
.note h2 { font-family: var(--font-display); font-weight: 400; font-size: 1.35rem; margin: 0; line-height: 1.15; }
.note .sub { font-family: var(--font-hand); font-size: 1.15rem; color: var(--text-soft); line-height: 1.15; }
.note hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
/* desktop slots: specimen cards down the right column, the Family and Past pages they open beside it
   (towards the map, below the lens, so they do not cover the card), everything else down the left;
   each next note of a column sits --rank slots lower (set by the note host) */
.note-left { left: 24px; top: calc(40px + var(--rank, 0) * 44px); transform: rotate(-1.2deg); }
.note-right { right: 24px; top: calc(345px + var(--rank, 0) * 44px); transform: rotate(.8deg); }
.note-inner { right: calc(24px + 276px + 18px); top: calc(345px + var(--rank, 0) * 44px); transform: rotate(-.6deg); }

.spec-top { display: grid; grid-template-columns: 76px 1fr; gap: 12px; align-items: center; }
.portrait { width: 76px; height: 92px; border: 1px solid var(--line); background: var(--stage); }
.portrait path, .portrait circle, .portrait line { stroke: var(--text); stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.traits { display: grid; gap: 3px; margin: 0; padding: 0; list-style: none; font-size: .98rem; }
.traits li { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.bar { display: inline-flex; gap: 2px; }
.bar i { width: 11px; height: 9px; border: 1px solid var(--text); }
.bar i.on { background: var(--text); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn { background: var(--accent); color: var(--on-accent); border: 1px solid var(--text); border-radius: 3px; padding: 3px 12px; font-family: var(--font-hand); font-size: 1.15rem; line-height: 1.2; cursor: pointer; }
.btn.quiet { background: none; color: var(--text); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.confirm { background: var(--emph); color: var(--cream); border-color: var(--emph); }
.small { font-size: .88rem; color: var(--text-soft); }

/* stage 2: biography, family, strategies, ages and hall of fame, chronicle (from ui/mockup.html) */
.link { display: inline; background: none; border: 0; padding: 0; font: inherit; color: var(--text); text-align: left; text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 2px; cursor: pointer; }
.btn.quiet[aria-pressed="true"] { background: var(--text); color: var(--note); }
.sect { font-family: var(--font-hand); font-weight: 500; font-size: 1.15rem; line-height: 1.15; color: var(--text-soft); margin: 0 0 2px; }
.bio { font-family: var(--font-hand); font-size: 1.2rem; line-height: 1.2; margin: 0; }
.kin { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; font-size: 1rem; }
.kin li { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 0 10px; }
.life { font-family: var(--font-hand); font-size: 1.1rem; color: var(--text-soft); }
.kin.scroll { max-height: 260px; overflow-y: auto; }
.ages { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ages li { border-left: 1px solid var(--line); padding-left: 10px; }
.ages li.now { border-left: 3px solid var(--text); padding-left: 8px; }
.ages b { font-family: var(--font-display); font-weight: 400; font-size: 1.2rem; }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 1rem; }
.events li { display: grid; grid-template-columns: 5.4em 1fr; gap: 8px; align-items: baseline; }
.events .day { font-family: var(--font-hand); font-size: 1.1rem; color: var(--text-soft); }
.gap { border: 1px dashed var(--text-soft); border-radius: 3px; padding: 0 8px; color: var(--text-soft); }
.chart { width: 100%; height: auto; display: block; margin: 8px 0 4px; }
.chart text { font-family: var(--font-hand); font-size: 12px; fill: var(--text); }
.chart .tick { fill: var(--text-soft); font-size: 11px; }
.chart .halo { paint-order: stroke; stroke: var(--note); stroke-width: 3px; stroke-linejoin: round; }
.chart .grid { stroke: var(--line); stroke-width: .5; opacity: .6; }
.chart .axis { stroke: var(--text); stroke-width: 1; }
.chart .mark { stroke: var(--text-soft); stroke-width: .8; stroke-dasharray: 2 2; }
.chart .hatch { stroke: var(--line); stroke-width: .8; }
.chart .l1 { fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.chart .l2 { fill: none; stroke: var(--series-b); stroke-width: 1.8; stroke-dasharray: 5 3; stroke-linecap: round; }



/* narrower: notes stack under the map like a bottom sheet, lens sits above the map */
@media (max-width: 1199px) {
  .stage { flex-direction: column; align-items: center; gap: 28px; padding-bottom: 96px; }
  .lens { position: static; order: -1; }
  .lens-ring { width: min(80vw, 320px); height: min(80vw, 320px); }
  .lens { width: min(80vw, 320px); }
  .map-wrap { align-self: center; }
  .legend { position: static; }
  .sheet { width: min(100%, 460px); display: grid; gap: 22px; }
  .note { position: relative; left: auto; right: auto; top: auto; width: 100%; transform: none; }
  .sheet::before { content: ""; display: block; width: 44px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto -12px; }
  .head { padding-bottom: 8px; }
}
@media (min-width: 1200px) {
  .sheet { display: contents; }
  /* room for both columns of stacked notes */
  .stage { min-height: 1100px; }
}
@media (prefers-reduced-motion: reduce) { .lens .dot, .map .follow-tile { animation: none; } }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.conn { font-size: 1rem; }
.conn.offline { color: var(--accent); }
.note .close { position: absolute; top: 4px; right: 6px; width: 24px; height: 24px; background: none; border: 0; font-size: 1.2rem; line-height: 1; cursor: pointer; color: var(--text-soft); }
.note .drag-handle { position: absolute; top: 0; left: 0; right: 32px; height: 26px; cursor: grab; touch-action: none; }
.sw-fertile { fill: var(--wash-fertile); }
.sw-plain { fill: var(--wash-plain); }
.sw-harsh { fill: var(--wash-harsh); }
.sw-tribe-border { fill: none; stroke: var(--text); stroke-width: 1.3; }
.sw-tribe-band { fill: none; stroke: var(--tribe-0); stroke-width: 1; stroke-dasharray: 1.6 1.4; }
.sw-hut { fill: var(--stage); stroke: var(--text); stroke-width: 1.2; stroke-linejoin: round; }
.sort { display: flex; gap: 6px; margin-bottom: 6px; }
.sort .btn:not([aria-pressed="true"]) { background: none; color: var(--text); }
.sort .btn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.residents { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; display: grid; gap: 2px; }
.residents li { display: flex; justify-content: space-between; gap: 8px; }
.resident { background: none; border: 0; padding: 0; text-align: left; cursor: pointer; text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; }
.specimen.memorial { border: 3px solid var(--text); padding: 6px; }
.specimen.memorial .portrait { opacity: .55; }
.dagger { font-weight: 600; color: var(--text); }
.specimen .obit { font-family: var(--font-hand); font-size: 1.2rem; margin: 6px 0 0; }
@media (max-width: 1199px) { .note { translate: none !important; } }

/* ribbon: the newest events along the bottom, scrolling sideways when they do not fit */
.ribbon { background: var(--note); border-top: 2px solid var(--text); font-family: var(--font-hand); font-size: 1.25rem; padding: 6px 16px; display: flex; gap: 6px 22px; overflow-x: auto; white-space: nowrap; }
.ribbon > span { flex: none; }
.ribbon .link { white-space: nowrap; }
.ribbon span.day { color: var(--text-soft); }

/* stage 3: tribes (the tints are --tribe-0..5 in tokens.css) */
.tint-0 { --tc: var(--tribe-0); }
.tint-1 { --tc: var(--tribe-1); }
.tint-2 { --tc: var(--tribe-2); }
.tint-3 { --tc: var(--tribe-3); }
.tint-4 { --tc: var(--tribe-4); }
.tint-5 { --tc: var(--tribe-5); }
.band { fill: none; stroke: var(--tc); stroke-width: .6; }
.band-dot { fill: var(--tc); }
.band-ring { fill: none; stroke: var(--tc); stroke-width: .4; }
.map { --sg-bg: var(--stage); }
.map .tribe-fill { opacity: .07; fill: var(--tc); }
.map .lands-hl path { fill: var(--accent); fill-opacity: .24; }
.map .tribe-border { fill: none; stroke: var(--text); stroke-width: .8; stroke-linejoin: round; stroke-linecap: round; }
.map .tribe-name { font-family: var(--font-display); font-size: 5px; letter-spacing: 1.3px; fill: var(--text); text-anchor: middle; paint-order: stroke; stroke: var(--stage); stroke-width: 1.4px; stroke-linejoin: round; }
.sg-bg { fill: var(--sg-bg, var(--note)); stroke: var(--text); stroke-width: .5; }
.sg-path { stroke: var(--text); stroke-width: .7; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.sg { width: 1.1em; height: 1.1em; vertical-align: -.2em; flex: none; }
.chip { width: 40px; height: 29px; flex: none; display: block; }
.chip.chip-lg { width: 60px; height: 44px; }
.chip .wash { fill: var(--tc); opacity: .14; }
.chip .frame { fill: none; stroke: var(--text); stroke-width: .8; }
.tribe-page.memorial { border: 3px solid var(--text); padding: 6px; }
.memorial .chip { opacity: .55; }
.tribes { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; width: 100%; background: none; border: 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent); border-radius: 2px; padding: 6px 4px; text-align: left; cursor: pointer; }
.row:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.row b { font-family: var(--font-display); font-weight: 400; font-size: 1.15rem; }
.row .meta { display: block; font-size: .9rem; line-height: 1.25; color: var(--text-soft); }
.row.compact { grid-template-columns: minmax(0, 1fr) auto; padding: 3px 4px; font-size: 1rem; }
.row .life { text-align: right; }
.spark { width: 56px; height: 18px; display: block; }
.spark .area { fill: var(--text); opacity: .12; }
.spark .ln { fill: none; stroke: var(--text); stroke-width: 1.2; stroke-linejoin: round; }
.spark .end { fill: var(--text); }
.tribe-top { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: center; }
.held { display: flex; justify-content: space-between; align-items: center; gap: 4px 8px; flex-wrap: wrap; }
.held .switch { margin-top: 0; align-self: auto; }
.fold { margin: 0; }
.fold-btn { display: flex; align-items: center; gap: 6px; width: 100%; background: none; border: 0; padding: 2px 0; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.fold-btn::before { content: "\25B8"; font-size: .9em; width: 1em; }
.fold-btn[aria-expanded="true"]::before { content: "\25BE"; }
.fold-body { padding-bottom: 4px; }
.chart .area { fill: var(--text); opacity: .1; }

/* stage 4: the Omen note and the vote */
.tool-dot { position: absolute; top: 3px; right: 3px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); border: 1.5px solid var(--head-text); }
.omen-line { font-family: var(--font-hand); font-size: 1.15rem; line-height: 1.15; margin: 4px 0 0; }
.omen-refusal { font-family: var(--font-hand); font-size: 1.15rem; line-height: 1.15; margin: 0; border: 1px dashed var(--text-soft); border-radius: 3px; padding: 2px 8px; }
.omen-art { width: 100%; height: 74px; border: 1px solid var(--line); background: var(--stage); display: block; margin-top: 8px; }
.omen-art path { stroke: var(--text); stroke-width: 1.2; fill: none; stroke-linecap: round; }
.countdown { font-family: var(--font-hand); font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.tally-list { font-family: var(--font-hand); font-size: 1.15rem; margin: 0; padding: 0; list-style: none; display: grid; gap: 0; }
.tally-list li { display: flex; justify-content: space-between; }
.tally-marks { letter-spacing: .08em; white-space: pre; }
.map .event-near { fill: color-mix(in srgb, var(--accent) 38%, transparent); }
.map .event-struck { fill: color-mix(in srgb, var(--accent) 22%, transparent); stroke: var(--accent); stroke-width: 1.6; }
.map .event-struck-ink { fill: none; stroke: var(--text); stroke-width: .5; }
.map .event-glyph { font-size: 7px; text-anchor: middle; dominant-baseline: central; fill: var(--text); paint-order: stroke; stroke: var(--stage); stroke-width: 1.2px; pointer-events: none; }
.map .tally-svg { stroke: var(--text); stroke-width: .6; stroke-linecap: round; fill: none; }
.map .seal-body { fill: var(--emph); }
.map .seal-ring { fill: none; stroke: var(--cream); stroke-width: .5; opacity: .7; }
.map .seal-mark { stroke: var(--cream); stroke-width: .7; fill: none; stroke-linecap: round; }
.map .seal.provisional { opacity: .8; }
.map.choosing { cursor: crosshair; }
/* while a tile is being chosen the tag must not stand between the visitor and the tiles under it */
.app.voting .event-tag { pointer-events: none; }
@media (max-width: 1199px) { .event-tag { font-size: .95rem; padding: 0 8px; } }
/* a phone: while choosing, the Omen note shrinks to a bar at the bottom so the map stays in view */
@media (max-width: 1199px) {
  .app.voting .note-omen { position: fixed; left: 0; right: 0; top: auto; bottom: 0; z-index: 30; width: auto; border-radius: 0; border-width: 2px 0 0; padding: 8px max(16px, env(safe-area-inset-left, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-right, 0px)); }
  .app.voting .note-omen :is(h2, .pin, .close, .drag-handle, .omen-line, .omen-art, .countdown, hr) { display: none; }
  .app.voting .note-omen .countdown + .small { display: none; }
  .app.voting .note-omen .small { margin: 0 0 6px; }
}
.event-tag { position: absolute; left: 10px; top: 10px; max-width: calc(100% - 20px); z-index: 4; background: var(--note); color: var(--text); border: 1px solid var(--text); border-radius: 3px; padding: 2px 10px; font-family: var(--font-hand); font-size: 1.1rem; line-height: 1.15; text-align: left; cursor: pointer; }
.verdict-live { position: absolute; inset: 0; z-index: 8; pointer-events: none; display: grid; align-items: center; }
.verdict-band { pointer-events: auto; cursor: pointer; background: var(--ink); color: var(--cream); border-block: 2px solid var(--cream); padding: 14px 20px; text-align: center; font-family: var(--font-display); animation: verdict-in .6s ease-out, verdict-out .6s ease-in 5.4s forwards; }
.verdict-band small { display: block; letter-spacing: .18em; text-transform: uppercase; font-size: .68rem; opacity: .9; }
.verdict-band h3 { margin: 2px 0; font-size: 2rem; font-weight: 400; letter-spacing: .14em; text-transform: uppercase; overflow-wrap: anywhere; }
.verdict-band .rule { width: 140px; height: 2px; background: var(--cream); margin: 6px auto; }
.verdict-band p { margin: 0; font-size: .85rem; }
.verdict-band .tally { margin-top: 8px; font-size: .72rem; letter-spacing: .1em; }
@keyframes verdict-in { from { clip-path: inset(0 50% 0 50%); } to { clip-path: inset(0); } }
@keyframes verdict-out { to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .verdict-band { animation: none; } }
