:root {
  color-scheme: light;
  --ink: #232d22;
  --muted: #62695c;
  --green: #385944;
  --line: #dfdfd1;
  --paper: #faf9f2;
  --gold: #8c5929;
  font-family: "Aptos", "Segoe UI", sans-serif;
  color: var(--ink);
  background: #f1efe5;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid #2e6854; outline-offset: 3px; }
a { color: inherit; text-decoration: none; }
.shell { width: min(1560px, 100% - 36px); margin-inline: auto; }
.masthead { border-bottom: 1px solid #dcdbce; background: #f9f8ef; }
.bar, .brand, .intro, .clock, .world-time, .panel-head, .legend, .resident-head, .identity, .update {
  display: flex;
  align-items: center;
}
.bar, .intro, .panel-head, .resident-head, .update { justify-content: space-between; }
.bar { min-height: 41px; }
.brand { gap: 11px; }
.brand strong { display: block; font: bold 20px Georgia, serif; }
.brand small, .demo, .eyebrow, .world-time small, .stats small, .live, .event-meta {
  font: 700 10px/1.2 Consolas, monospace;
  letter-spacing: .11em;
}
.brand small { display: block; margin-top: 5px; color: var(--muted); }
.emblem { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 7px; background: #274632; color: #e7edcc; font-size: 18px; }
.demo { color: var(--green); display: flex; align-items: center; gap: 8px; }
.demo span, .live i { width: 7px; height: 7px; background: #68936c; border-radius: 100%; }
.intro { gap: 10px; padding-block: 9px; }
.eyebrow { margin: 0 0 8px; color: var(--green); }
h1, h2, h3, p { margin: 0; }
h1 { font: 500 clamp(24px, 3vw, 41px)/1 Georgia, serif; letter-spacing: -.045em; }
h1 span { color: #6d8b58; }
.subtitle { margin-top: 11px; font-size: 14px; color: var(--muted); }
.clock { gap: 6px; padding: 4px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; white-space: nowrap; }
.world-time { gap: 9px; padding: 0 6px; min-width: 99px; }
.world-time > span { color: var(--gold); font-size: 22px; }
.world-time small { display: block; color: var(--muted); }
.world-time strong { font: 700 19px/1.2 Consolas, monospace; }
.pause { width: 36px; height: 36px; color: #fbfaf4; background: #274632; border: 0; border-radius: 7px; font-weight: 800; }
.pause:hover { background: #42674e; }
.speeds { display: flex; padding: 3px; gap: 3px; background: #eeeee3; border-radius: 8px; }
.speeds button, .filters button { border: 0; border-radius: 5px; background: transparent; white-space: nowrap; }
.speeds button { padding: 6px 7px; font: 700 12px Consolas, monospace; color: #53614f; }
.speeds button[aria-pressed="true"] { background: #fffef6; color: #254731; box-shadow: 0 1px 3px #263b271f; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-bottom: 8px; }
.stats > div { display: flex; align-items: center; gap: 7px; min-width: 0; padding: 5px 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 7px; }
.stat-icon { flex: none; display: grid; place-items: center; width: 27px; height: 27px; border-radius: 6px; font-size: 16px; }
.people { background: #e6edda; color: #425d3e; }
.words { background: #e5ebe8; color: #3f665e; }
.generations { background: #eae8ef; color: #624d77; }
.maximum { background: #f2e6cc; color: #835b2d; }
.stats small { display: block; margin-bottom: 3px; color: var(--muted); }
.stats strong { font: 700 16px/1.1 Consolas, monospace; }
.stats em { font: 400 12px Consolas, monospace; color: var(--muted); }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 226px; gap: 8px; padding-bottom: 16px; align-items: start; grid-template-areas: "map journal"; }
.world-column { display: contents; }
.map-panel { grid-area: map; }
.journal { grid-area: journal; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 13px; min-width: 0; }
.panel-head { min-height: 38px; padding: 6px 10px; gap: 7px; }
h2 { font: 700 21px/1.12 Georgia, serif; letter-spacing: -.03em; }
.resident-select { display: flex; gap: 7px; align-items: center; font-size: 12px; color: var(--muted); }
select { max-width: 170px; padding: 6px 7px; border-radius: 6px; border: 1px solid #d8ddce; background: #f0f1e7; font-size: 12px; cursor: pointer; }
.map { position: relative; isolation: isolate; background: #214a4a; aspect-ratio: 60 / 43; overflow: hidden; }
canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.map canvas { image-rendering: auto; }
.map-card { position: absolute; z-index: 2; top: 8px; right: 8px; width: min(244px, calc(100% - 16px)); max-height: calc(100% - 16px); display: flex; flex-direction: column; color: #263129; background: #faf8ee; border: 1px solid #9caa94; border-radius: 8px; box-shadow: 0 3px 13px #10221954; }
.map-card.at-left { right: auto; left: 8px; }
.map-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 9px; border-bottom: 1px solid var(--line); }
.map-card-head h3 { font-size: 14px; overflow-wrap: anywhere; }
.map-card-head button { flex: none; width: 26px; height: 26px; border: 1px solid var(--line); border-radius: 4px; background: transparent; font-size: 15px; }
.map-card-body { padding: 7px 9px 9px; overflow: auto; min-height: 0; font-size: 11px; line-height: 1.3; }
.map-card-summary { color: #4f5a4f; }
.map-card h4 { margin: 9px 0 4px; font-size: 11px; }
.map-traits { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px 9px; }
.map-vitals { margin-top: 7px; padding: 5px 6px; background: #eceee2; border-radius: 4px; }
.map-traits span, .map-inventory-head, #map-inventory li { display: flex; justify-content: space-between; gap: 4px; }
.map-traits b, #map-inventory li span:last-child { flex: none; font-variant-numeric: tabular-nums; }
#map-inventory-weight { color: #4f5a4f; font-weight: 400; }
#map-inventory, #map-tribe-info ul { list-style: none; margin: 0; padding: 0; }
#map-inventory li, #map-tribe-info li { padding: 3px 0; border-top: 1px solid var(--line); }
.map.night #terrain { filter: brightness(.65) saturate(.7); }
#agents { cursor: crosshair; touch-action: none; }
.map.dragging #agents { cursor: grabbing; }
.map-controls { display: flex; align-items: center; gap: 5px; padding: 0 10px 5px; font-size: 11px; color: var(--muted); }
.map-controls button { border: 1px solid var(--line); border-radius: 5px; padding: 3px 7px; background: #f0f1e7; }
.map-controls button[aria-pressed="true"] { color: #315440; background: #e4ecdc; border-color: #becbbb; }
.map-controls output { margin-left: 4px; }
.weather { margin-left: auto; }
.wolf-range { background: #b0785e; }
.cache { background: #e3bd76; }
.water { background: #639ba9; }
.remains { background: #776c64; }
.livestock { background: #c9b39d; }
.field { background: #bc9253; }
.map.rain #terrain { filter: saturate(.62) brightness(.85); }
.map.night.rain #terrain { filter: saturate(.55) brightness(.59); }
.supplies summary { cursor: pointer; font-weight: 700; padding-block: 2px; }
[hidden] { display: none !important; }
#storage-list { display: grid; gap: 4px; margin-top: 8px; }
#tribe-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 6px; margin-top: 6px; }
.tribe-entry { background: var(--paper); border: 1px solid var(--line); border-radius: 5px; padding: 6px; }
.tribe-entry button { border: 1px solid var(--line); background: transparent; padding: 3px 5px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.tribe-entry p { margin-top: 3px; }
.trends { padding-bottom: 5px; }
#trends { position: static; width: calc(100% - 30px); height: auto; margin-inline: 15px; image-rendering: auto; }
.trends .legend { align-items: start; }
.compass, .place, .map-tag { position: absolute; z-index: 1; pointer-events: none; }
.compass { display: grid; place-items: center; top: 6%; left: 4%; color: #dfebd7; font: 700 10px Consolas, monospace; }
.compass i { font: normal 23px Georgia, serif; }
.place { color: #fff8db; font: italic 600 clamp(9px, 1.3vw, 15px) Georgia, serif; letter-spacing: .02em; text-shadow: 0 1px 2px #142d22; }
.map-tag { border: 1px solid #f6dfa6; background: #2b402b; color: #fff0c6; padding: 3px 6px; border-radius: 4px; font: 700 10px Consolas, monospace; transform: translate(-50%, -145%); white-space: nowrap; }
.legend { gap: 15px; flex-wrap: wrap; min-height: 41px; padding: 8px 15px; color: var(--muted); font-size: 11px; }
.legend span { display: flex; gap: 6px; align-items: center; }
.wall { background: #664936; }
.gate { background: #d8ac62; }
.cave { background: #272631; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 2px; }
.supplies { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 8px 15px; border-top: 1px solid var(--line); background: #f1f0e6; font-size: 11px; color: var(--muted); }
.supplies span { display: inline-flex; align-items: center; gap: 5px; }
.supplies b { color: var(--ink); font: 700 12px Consolas, monospace; }
.berries { background: #a84763; }
.timber { background: #7d613c; }
.wolf { background: #a35240; }
.danger { background: #efded3; color: #844a3c; }
.awake { background: #5b9478; }
.sleeping { background: #7a72a7; }
.gold { background: #ba853a; }
.journal { display: flex; flex-direction: column; height: clamp(430px, calc(100dvh - 170px), 740px); position: sticky; top: 8px; }
.journal .panel-head { min-height: 31px; padding: 4px 7px; border-bottom: 1px solid var(--line); }
.journal h2 { font-size: 16px; }
.live { display: flex; gap: 6px; align-items: center; color: var(--green); white-space: nowrap; letter-spacing: .04em; }
.live.paused i { background: #a48757; }
.filters { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px 5px; border-bottom: 1px solid var(--line); }
.filters button { padding: 4px; color: var(--muted); font-size: 9px; }
.filters button:hover, .speeds button:hover { background: #e4e8da; }
.filters button[aria-pressed="true"] { color: #254731; background: #e5ebdb; font-weight: 700; }
.event-feed { overflow: auto; overflow-anchor: none; flex: 1; scrollbar-color: #b9bea9 transparent; scrollbar-width: thin; }
.event { width: 100%; display: grid; grid-template-columns: 14px minmax(0, 1fr); gap: 5px; padding: 4px 6px; border: 0; border-bottom: 1px solid #e7e6da; background: transparent; text-align: left; overflow-wrap: anywhere; }
button.event:hover { background: #f1f2e8; }
.event:focus-visible { outline-offset: -3px; }
.event-icon { width: 14px; height: 14px; display: grid; place-items: center; border-radius: 4px; font-size: 9px; }
.event-meta { display: flex; justify-content: space-between; gap: 4px; margin-bottom: 1px; color: var(--muted); font-size: 8px; letter-spacing: .04em; }
.event strong { display: block; font-size: 11px; line-height: 1.15; }
.event p { margin-top: 1px; color: var(--muted); font-size: 10px; line-height: 1.16; }
.empty { padding: 16px; font-size: 13px; color: var(--muted); }
.update { gap: 5px; padding: 6px 7px; border-top: 1px solid var(--line); background: #f1f0e6; border-radius: 0 0 12px 12px; }
.update p, .family { color: var(--muted); font-size: 11px; line-height: 1.4; margin-top: 4px; }
h3 { font-size: 13px; }
.update button { border: 1px solid #c4cfbd; padding: 5px; border-radius: 5px; color: #2d513b; background: #fafaf3; font-size: 10px; font-weight: 700; white-space: nowrap; }
.update button:hover { background: #e6ecdc; }
.update button:disabled { opacity: .65; cursor: default; }

.identity { gap: 10px; }
.identity .eyebrow { margin-bottom: 4px; }
.portrait { display: grid; place-items: center; width: 37px; height: 37px; border-radius: 8px; color: #faf6e7; font: 700 19px Georgia, serif; }
.state { font-size: 11px; padding: 5px 8px; border-radius: 5px; background: #e8eddd; color: #3d5c42; }
.state.at-max { background: #f2e6cc; color: #795326; }
.inspector-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-top: 14px; }
.inventory { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 9px; }
.inventory-head, #inventory li { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.inventory-head span, #inventory li { font-size: 11px; color: var(--muted); }
#inventory { list-style: none; margin: 5px 0 0; padding: 0; }
#inventory li { padding: 4px 0; border-top: 1px solid #e7e6da; }
#inventory li span:last-child { white-space: nowrap; }
.meter { display: grid; grid-template-columns: 1fr auto; gap: 4px 6px; font-size: 11px; color: var(--muted); margin-top: 7px; }
.meter b { color: var(--ink); font: 700 10px Consolas, monospace; }
.meter progress { grid-column: 1 / -1; width: 100%; height: 5px; accent-color: #618568; border: 0; border-radius: 4px; overflow: hidden; }
progress::-webkit-progress-bar { background: #e8e8da; }
progress::-webkit-progress-value { background: #618568; }
.update button:active, .pause:active { transform: scale(.96); }
@media (max-width: 1050px) {
  .shell { width: calc(100% - 20px); }
  .inspector-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 650px) {
  .intro { flex-wrap: wrap; }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: "map" "journal"; }
  .journal { position: static; width: min(100%, 270px); height: 335px; justify-self: end; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
}
@media (min-width: 415px) and (max-width: 650px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .stats > div { padding: 5px 6px; }
  .stats .stat-icon { display: none; }
  .stats small { letter-spacing: .015em; font-size: 9px; }
}
@media (max-width: 440px) {
  .shell { width: calc(100% - 20px); }
  .intro { padding-top: 5px; }
  .stats small { letter-spacing: .03em; }
  .resident-select > span { display: none; }
  .legend { gap: 9px; }
}

#reset-world {
  color: #8a4233;
}

#reset-dialog {
  width: min(390px, calc(100% - 32px));
  padding: 20px;
  border: 1px solid #a49d86;
  border-radius: 10px;
  color: #263329;
  background: #f8f6ec;
}

#reset-dialog::backdrop { background: #18241b87; }
#reset-dialog h2 { margin: 0; font-size: 1.3rem; }
#reset-dialog p { margin: 10px 0 16px; }
.reset-actions { display: flex; justify-content: end; gap: 8px; }
.reset-actions button { padding: 7px 12px; border: 1px solid #a49d86; border-radius: 5px; }
.reset-actions .reset-confirm { background: #883b30; border-color: #883b30; color: white; }

.daily-stories { border-bottom: 1px solid var(--line); padding: 6px 8px; font-size: 11px; }
.daily-stories > summary, .story-day > summary { cursor: pointer; font-weight: 700; }
#story-list { max-height: 260px; overflow-y: auto; margin-top: 5px; }
.story-day { border-top: 1px solid var(--line); padding: 6px 0; }
.story-day p, #story-list > p { margin: 5px 0; line-height: 1.35; }
.story-day button { margin: 3px 4px 0 0; padding: 3px 6px; border: 1px solid var(--line); border-radius: 4px; }

.tech-panel { border-top: 1px solid var(--line); padding: 8px 10px; background: #f6f4e9; }
.tech-panel > summary { cursor: pointer; font-size: 13px; font-weight: 700; }
.tech-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 10px 0; font-size: 11px; }
.tech-controls select { border: 1px solid #b9c0a6; border-radius: 5px; padding: 4px 7px; color: var(--ink); background: var(--paper); }
.tech-key { display: flex; gap: 6px; margin-inline-start: auto; }
.tech-key span { padding: 3px 7px; border-radius: 12px; background: #efede1; }
.tech-key .active { background: #f0dfb9; }
.tech-key .learned { background: #dce9cf; }
#tech-graph { display: grid; grid-template-columns: repeat(6, minmax(96px, 1fr)); gap: 8px; overflow-x: auto; padding: 2px 0 8px; }
.tech-lane { padding: 8px; min-width: 0; background: #efece0; border-top: 3px solid var(--branch); border-radius: 6px; }
.tech-lane h4 { display: flex; gap: 5px; align-items: center; margin: 0; font-size: 12px; }
.tech-icon { display: grid; place-items: center; width: 20px; height: 20px; background: var(--branch); color: #fff9ea; border-radius: 5px; }
.tech-node { position: relative; display: grid; gap: 3px; padding: 6px 7px; margin-top: 9px; background: #faf8ef; border: 1px solid #e3ddcb; border-radius: 5px; font-size: 10px; }
.tech-node + .tech-node::before { content: ""; position: absolute; width: 1px; height: 9px; top: -10px; left: 13px; background: var(--branch); opacity: .38; }
.tech-node small { font-size: 9px; color: var(--muted); line-height: 1.3; }
.tech-node.active { background: #f5e9ce; border-color: #d3a35e; }
.tech-node.learned { background: #e6eddb; border-color: #98af83; }

.resident-link {
  display: inline;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 650;
  color: #345a43;
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.resident-link:hover { color: #233f2f; }
.resident-link:focus-visible { outline: 1px solid var(--green); outline-offset: 2px; }
#fullscreen { margin-inline-start: auto; }
#fullscreen-status:empty { display: none; }
/* Full screen covers only the simulation panel; the map keeps its aspect ratio and fits the screen height. */
.map-panel:fullscreen, .map-panel.viewport-full { display: flex; flex-direction: column; justify-content: center; padding: 8px; background: #17302b; }
.map-panel.viewport-full { position: fixed; inset: 0; z-index: 50; }
.map-panel:fullscreen .map, .map-panel.viewport-full .map { width: min(100%, calc((100vh - 56px) * 60 / 43)); margin: 0 auto; }
.map-panel:fullscreen .panel-head h2, .map-panel.viewport-full .panel-head h2 { display: none; }

/* Dock: panels open over the map, one at a time. */
.map-dock { position: absolute; z-index: 3; inset: 6px; align-content: flex-end; display: flex; flex-wrap: wrap; gap: 4px; pointer-events: none; }
.dock-panel { pointer-events: auto; padding: 0; border: 0; background: none; }
.dock-panel > summary { list-style: none; cursor: pointer; padding: 2px 8px; border: 1px solid #ffffff55; border-radius: 4px; background: #17302bcc; color: #f3efdd; font: 700 10px/1.5 system-ui, sans-serif; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dock-panel > summary::-webkit-details-marker { display: none; }
.dock-panel[open] > summary { background: #faf8ee; color: #263129; }
.dock-body { position: absolute; left: 0; bottom: 26px; width: min(520px, 100%); max-height: min(330px, calc(100% - 40px)); overflow: auto; padding: 7px 9px; color: #263129; background: #faf8eef2; border: 1px solid #9caa94; border-radius: 6px; box-shadow: 0 3px 13px #10221954; font-size: 10px; line-height: 1.3; }
.dock-body h3 { font-size: 11px; }
.dock-body .family, .dock-body .meter { font-size: 10px; margin-top: 3px; }
.dock-body .inspector-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 7px; }
.dock-body.legend { display: flex; flex-wrap: wrap; gap: 4px 10px; min-height: 0; }
.dock-body #trends { width: 100%; height: auto; }
.dock-panel.tech-panel { border: 0; padding: 0; background: none; }
.supplies { padding: 4px 10px; gap: 3px 10px; font-size: 10px; }
.supplies b { font-size: 11px; }
.dock-body h2 { font-size: 15px; }
.dock-body .portrait { width: 28px; height: 28px; font-size: 15px; }
.tech-needs { grid-column: 1 / -1; margin: 0; color: var(--muted); }
.tech-lane.need { box-shadow: inset 0 0 0 2px var(--branch); }
#tech-panel .dock-body { width: min(860px, 100%); }
.dock-body .tech-lane h4 { font-size: 11px; }
.dock-body .tech-node strong { font-size: 10px; }
.dock-body .tech-node small { font-size: 9px; }
