/* The living map. Uses the sketchbook tokens from style.css. */
:root {
  --land-spring: #dfe9cf; --land-summer: #e6e6c3; --land-autumn: #ecdcbc; --land-winter: #e7edef;
  --land-drought: #ead3a3; --land-dim: #d7d9d3; --land-rock: #e2d2c3;
  --canopy-autumn: #f0d9b0; --canopy-winter: #f4f6f6; --field-winter: #eef1f2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --land-spring: #2f3a2a; --land-summer: #393a28; --land-autumn: #3f3426; --land-winter: #313a3e;
    --land-drought: #4a3c22; --land-dim: #2a2d2e; --land-rock: #3d3029;
    --canopy-autumn: #5a4a33; --canopy-winter: #4a5559; --field-winter: #3c4447;
  }
}
.living-page { min-height: 100vh; display: flex; flex-direction: column; }
.living-page .nav { width: 100%; }
.living-page [hidden] { display: none !important; }
.stage { position: relative; flex: 1; display: flex; flex-direction: column; padding: 0 16px 16px; }
.places { justify-content: center; margin: 4px 0 0; }
#world { width: 100%; height: auto; max-height: calc(100vh - 150px); display: block; margin: 0 auto; }

/* paper and ground */
.living .waves { fill: none; stroke: var(--line); stroke-width: 1.1; stroke-linecap: round; opacity: 0.8; }
.living .land-shadow { fill: var(--ink); opacity: 0.06; }
.living .land-wash { opacity: 0.9; transition: fill 2.5s ease; }
.living[data-season="spring"] .land-wash { fill: var(--land-spring); }
.living[data-season="summer"] .land-wash { fill: var(--land-summer); }
.living[data-season="autumn"] .land-wash { fill: var(--land-autumn); }
.living[data-season="winter"] .land-wash { fill: var(--land-winter); }
.living[data-season="winter"] .land-line { filter: drop-shadow(0 0 2px var(--canopy-winter)); }
.living .shock-food .land-wash { fill: var(--land-drought); }
.living .shock-energy .land-wash { fill: var(--land-dim); }
.living .shock-materials .land-wash { fill: var(--land-rock); }
.living .ink { fill: none; stroke: var(--ink); stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
.living .ink.faint { opacity: 0.45; }
.living .tree .canopy { fill: var(--paper); stroke: var(--ink); stroke-width: 1.1; opacity: 0.7; }
.living[data-season="autumn"] .tree .canopy { fill: var(--canopy-autumn); }
.living[data-season="winter"] .tree .canopy { fill: var(--canopy-winter); }
.living .region-name { font: 400 21px var(--hand); fill: var(--muted); text-anchor: middle; }
.living .ring { fill: none; stroke-width: 2.6; stroke-linecap: round; opacity: 0.85; }

/* settlements */
.settlement { cursor: pointer; }
.settlement.appear { animation: settle 1.2s ease-out both; transform-box: fill-box; }
@keyframes settle { from { opacity: 0; } to { opacity: 1; } }
.house, .field, .landmark, .smoke, .ruins { transition: opacity 1.4s ease; }
.gone { opacity: 0; pointer-events: none; }
.house-body { fill: var(--paper); }
.field-patch { fill: color-mix(in srgb, var(--food) 28%, var(--paper)); }
.living[data-season="summer"] .field-patch { fill: color-mix(in srgb, var(--energy) 32%, var(--paper)); }
.living[data-season="autumn"] .field-patch { fill: color-mix(in srgb, var(--materials) 30%, var(--paper)); }
.living[data-season="winter"] .field-patch { fill: var(--field-winter); }
.living .shock-food .field-patch { fill: color-mix(in srgb, var(--materials) 22%, var(--paper)); }
.tent { fill: color-mix(in srgb, var(--fallen) 30%, var(--paper)); }
.flag { fill: var(--fallen); stroke: var(--ink); stroke-width: 0.8; }
.smoke path { fill: none; stroke: var(--muted); stroke-width: 1.3; stroke-linecap: round; opacity: 0.7; }
.smoke:not(.gone) { animation: rise 4.2s ease-in infinite; }
@keyframes rise { 0% { transform: translate(0, 2px); opacity: 0; } 25% { opacity: 0.75; } 100% { transform: translate(3px, -9px); opacity: 0; } }
.smoke { transform-box: fill-box; }
.settlement.fallen .ink { stroke: var(--fallen); }
.ruins .broken { stroke: var(--materials); stroke-dasharray: 3 2; }
.crow { animation: circle 6s linear infinite; transform-origin: 0 0; }
@keyframes circle { from { transform: rotate(0deg) translate(16px, -22px) rotate(0deg); } to { transform: rotate(360deg) translate(16px, -22px) rotate(-360deg); } }
.settlement:hover .house-body, .settlement:focus .house-body { fill: var(--wash); }

/* roads and caravans */
.road { fill: none; stroke: var(--faint); stroke-width: 1.4; stroke-dasharray: 2 5; stroke-linecap: round; }
.trade-route { fill: none; stroke: var(--energy); stroke-width: 1.6; stroke-dasharray: 6 5; opacity: 0.55; }
.cart .house-body { fill: var(--paper); }
.cargo.food { fill: var(--food); } .cargo.energy { fill: var(--energy); }
.cargo.materials { fill: var(--materials); } .cargo.goods { fill: var(--goods); }

/* weather */
.cloud { fill: var(--paper); stroke: var(--ink); stroke-width: 1.2; }
.cloud.dark { fill: color-mix(in srgb, var(--ink) 30%, var(--paper)); }
.forecast .cloud { animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-2px); } }
.drift { animation: drift 12s ease-in-out infinite alternate; }
@keyframes drift { from { transform: translateX(-14px); } to { transform: translateX(14px); } }
.sun-disc { fill: color-mix(in srgb, var(--energy) 55%, var(--paper)); stroke: var(--ink); stroke-width: 1.2; }
.sun { animation: glare 5s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes glare { 50% { transform: scale(1.08); } }
.cracks { fill: none; stroke: var(--materials); stroke-width: 1.2; stroke-linecap: round; opacity: 0.7; }
.rock { fill: var(--materials); stroke: var(--ink); stroke-width: 0.8; }
.rock.fall { animation: fall 2.6s ease-in infinite; }
@keyframes fall { from { opacity: 0; translate: 0 0; } 20% { opacity: 1; } to { opacity: 0; translate: 0 70px; } }
.weather-label { font: 700 13px var(--hand); fill: var(--muted); text-anchor: middle; }
.weather-label.active { fill: var(--fallen); }

/* labels */
.town-name { font: 700 17px var(--hand); fill: var(--ink); text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: var(--paper); stroke-width: 4px; }
.town-name.fallen { fill: var(--fallen); }
.town-pop { font: 400 12px var(--sans); fill: var(--muted); text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: var(--paper); stroke-width: 3px; }

/* zoomed into one colony: the card carries the words */
.living.zoomed .town-name, .living.zoomed .town-pop, .living.zoomed .weather-label, .living.zoomed .region-name { opacity: 0; }
.town-name, .town-pop, .weather-label, .region-name { transition: opacity 0.4s ease; }

/* HUD */
.hud { position: absolute; left: 24px; top: 0; pointer-events: none; z-index: 1; padding: 6px 12px 8px; border-radius: 10px;
  background: color-mix(in srgb, var(--paper) 88%, transparent); }
.hud p { margin: 0; }
.hud-when { font: 700 28px/1.1 var(--hand); display: flex; align-items: center; gap: 10px; }
.hud-season { font: 400 18px var(--hand); color: var(--muted); }
.hud-facts { color: var(--muted); font-size: 14px; margin-top: 2px; }
.back { position: absolute; left: 32px; bottom: 28px; }
.card { position: absolute; right: 32px; top: 16px; width: min(320px, calc(100% - 64px)); background: var(--paper);
  border: 1.5px solid var(--ink); border-radius: 10px; padding: 14px 18px; box-shadow: 4px 5px 0 color-mix(in srgb, var(--ink) 18%, transparent); }
.card h2 { font: 700 26px/1.1 var(--hand); margin: 0 0 4px; }
.card p { margin: 0 0 8px; }
.source { position: absolute; right: 32px; bottom: 20px; margin: 0; font-size: 15px; }

@media (max-width: 640px) {
  .stage { padding: 0 8px 8px; }
  .hud { position: static; padding: 0 8px 6px; background: none; }
  .hud-when { font-size: 22px; }
  .card { position: static; width: auto; margin: 10px 8px 0; }
  .back { position: static; margin: 10px 8px 0; }
  .source { position: static; margin: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .smoke, .crow, .drift, .sun, .forecast .cloud, .rock.fall, .settlement.appear { animation: none !important; }
}

/* ---- the live page: map + Gazette ---- */
.live-page .nav { width: 100%; }
.live-page [hidden] { display: none !important; }
.live-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(340px, 1fr); align-items: start; }
.live-grid .stage { border-right: 1px solid var(--line); min-height: calc(100vh - 80px); }
.live-grid #world { max-height: calc(100vh - 250px); }
.live-grid .hud { position: static; background: none; padding: 4px 8px 6px; }

.gazette { padding: 4px 26px 40px; max-height: calc(100vh - 80px); overflow: auto; }
.masthead { text-align: center; border-top: 4px double var(--ink); border-bottom: 1px solid var(--ink); padding: 12px 8px 10px; }
.mast-name { margin: 0; font: 700 36px/1.05 var(--display); letter-spacing: -0.01em; font-variant-numeric: lining-nums; }
.mast-line { margin: 4px 0 0; font: italic 14px var(--display); color: var(--muted); }
.lead { border-bottom: 1px solid var(--line); padding: 16px 0 14px; }
.lead-title { margin: 0 0 6px; font: 700 30px/1.12 var(--display); letter-spacing: -0.01em; }
.lead-body { margin: 0; font: 17px/1.55 var(--display); color: var(--ink); max-width: 60ch; }
.columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 20px; }
.columns > section + section { border-left: 1px solid var(--line); padding-left: 20px; }
.col-head { font: italic 600 15px var(--display); margin: 18px 0 8px; padding-bottom: 7px; border-bottom: 1px solid var(--ink); }
.col-list { list-style: none; margin: 0; padding: 0; }
.col-list li { font: 15px/1.45 var(--display); padding: 4px 0; border-bottom: 1px dashed var(--line); }
.vitals { margin: 0; font: 15px/1.5 var(--display); }
.markets { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
.markets th { text-align: left; font: 400 13px var(--sans); color: var(--muted); padding: 0 6px 4px 0; }
.markets td { padding: 5px 6px 5px 0; border-top: 1px dashed var(--line); }
.markets .m-colony { font: 700 16px var(--hand); }
.mast-foot { margin: 18px 0 0; font-size: 15px; }
.mast-foot a { display: inline-block; padding: 6px 0; }

/* great houses in the Gazette, and the colony card's crest */
.houses { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px 18px; }
.house { display: grid; grid-template-columns: 52px minmax(0, 1fr) 52px; gap: 10px; align-items: center; }
.house .arms-slot { width: 52px; }
.house-name { margin: 0; font: 700 17px var(--hand); }
.house-text p { margin: 0; font-size: 13px; line-height: 1.4; }
.portrait-slot.small { width: 52px; padding: 4px 4px 0; border-width: 1.2px; }
.card-crest { display: grid; grid-template-columns: 56px 56px minmax(0, 1fr); gap: 10px; align-items: center; margin-bottom: 6px; }
.card-crest .arms-slot { width: 56px; }
.card-crest p { margin: 0; font-size: 13px; }

/* title cards: a notice stamped over the map */
.title-card { position: absolute; left: 50%; top: 38%; z-index: 3; width: min(560px, calc(100% - 40px));
  translate: -50% -50%; text-align: center; cursor: pointer;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 6px; padding: 18px 26px 20px;
  box-shadow: 6px 7px 0 color-mix(in srgb, var(--ink) 22%, transparent); }
.title-card[data-type="colony_collapse"], .title-card[data-type="era_end"] { border-color: var(--fallen); }
.title-card[data-type="shock_start"] { border-color: var(--energy); }
.title-card[data-type="split"] { border-color: var(--food); }
.tc-kicker { margin: 0; font: 400 17px var(--hand); color: var(--muted); }
.tc-title { margin: 2px 0 6px; font: 700 40px/1.08 var(--display); letter-spacing: -0.015em; }
.title-card[data-type="colony_collapse"] .tc-title, .title-card[data-type="era_end"] .tc-title { color: var(--fallen); }
.tc-body { margin: 0; font: 17px/1.5 var(--display); color: var(--muted); }
.title-card.in { animation: stamp 0.6s cubic-bezier(0.16, 1, 0.3, 1) both; }
.title-card.out { animation: lift 0.45s ease-in both; }
@keyframes stamp { from { opacity: 0; scale: 1.25; rotate: -4deg; } to { opacity: 1; scale: 1; rotate: -1deg; } }
@keyframes lift { from { opacity: 1; rotate: -1deg; } to { opacity: 0; scale: 0.96; rotate: -1deg; translate: -50% -56%; } }

@media (max-width: 980px) {
  .live-grid { grid-template-columns: minmax(0, 1fr); }
  .live-grid .stage { border-right: 0; border-bottom: 1px solid var(--line); min-height: 0; }
  .gazette { max-height: none; padding: 4px 16px 32px; }
}
@media (max-width: 640px) {
  .living .town-name { font-size: 34px; stroke-width: 7px; }
  .living .town-pop, .living .weather-label { display: none; }
  .living .region-name { font-size: 34px; }
  .houses { grid-template-columns: minmax(0, 1fr); }
  .columns { grid-template-columns: minmax(0, 1fr); }
  .columns > section + section { border-left: 0; padding-left: 0; }
  .mast-name { font-size: 28px; }
  .lead-title { font-size: 24px; }
  .tc-title { font-size: 28px; }
  .title-card { top: 34%; padding: 14px 16px; }
}
@media (prefers-reduced-motion: reduce) { .title-card.in, .title-card.out { animation: none; } }
