:root {
  color-scheme: dark;
  --page: #181713;
  --panel: #211f19;
  --raised: #29261f;
  --border: #3a352a;
  --ink: #f5ebd8;
  --subtle: #b6ab97;
  --muted: #9e927d;
  --accent: #f2af58;
  --accent-ink: #241805;
  --map-background: #181e26;
  --unoccupied-cell: #485461;
  --occupied-cell: #f0b35d;
  --priority-cell: #ae2343;
  --upgrade-cell: #135952;
  --hub-cell: #293f76;
  --display: "Barlow Condensed", "Bahnschrift Condensed", "Arial Narrow", Impact, sans-serif;
  --sans: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--ink); font: 1rem/1.5 var(--sans); }
button, input, select, textarea { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { opacity: .42; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [role="button"]:focus-visible {
  outline: 2px solid #ffd58b;
  outline-offset: 3px;
}
.symbol-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }

.topbar { border-bottom: 1px solid var(--border); background: #1d1b16; }
.topbar-inner, .workspace { width: min(100%, 1740px); margin-inline: auto; padding-inline: clamp(16px, 3vw, 44px); }
.topbar-inner { min-height: 66px; display: flex; align-items: center; gap: 18px; }
.brand { display: flex; gap: 11px; align-items: center; font-size: 1rem; font-weight: 750; white-space: nowrap; }
.state { border-left: 1px solid var(--border); padding-left: 18px; color: var(--accent); font: 650 .81rem/1.2 ui-monospace, Consolas, monospace; letter-spacing: .035em; white-space: nowrap; }
.state span { margin-right: 5px; color: var(--muted); }
.map-actions { display: flex; margin-left: auto; align-items: center; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 13px; min-height: 38px; border: 1px solid #474031; border-radius: 7px; background: #29251d; font-size: .875rem; font-weight: 650; white-space: nowrap; }
.button:hover { background: #373024; border-color: #62533c; }
.button-primary { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.button-primary:hover { color: var(--accent-ink); background: #ffc77e; border-color: #ffc77e; }

.workspace { padding-block: 24px 30px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 19px; }
h1, .record-head h2, .dialog-head h2 { margin: 0; font-family: var(--display); font-weight: 700; line-height: 1; letter-spacing: .025em; }
h1 { text-transform: uppercase; font-size: clamp(2.45rem, 4.8vw, 4.1rem); }
.page-heading p { margin: 5px 0 0; color: var(--subtle); }
.district-total { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; color: var(--subtle); font-size: .875rem; white-space: nowrap; }
.district-total .icon, .district-total strong { color: var(--accent); }
.atlas-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 340px); gap: 16px; align-items: stretch; }
.map-card, .details { min-width: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); overflow: hidden; }
.map-card { display: flex; flex-direction: column; }
.map-viewport { height: clamp(500px, calc(100svh - 245px), 820px); position: relative; isolation: isolate; overflow: hidden; background: var(--map-background); container-type: inline-size; }
#atlas-map { display: block; width: 100%; height: 100%; background: var(--map-background); touch-action: none; cursor: grab; user-select: none; }
#atlas-map.dragging, #atlas-map.dragging * { cursor: grabbing; }
#map-labels, #cell-labels, #district-boundaries, #active-outline { pointer-events: none; }
[data-region="dustbowl"] { --district-fill: #514632; --district-edge: #d1b773; }
[data-region="rivertown"] { --district-fill: #294b5d; --district-edge: #71bdf2; }
[data-region="redstone"] { --district-fill: #5b3544; --district-edge: #f186a3; }
[data-region="fairfield"] { --district-fill: #2b4d3d; --district-edge: #72cc9c; }
[data-region="fallrock"] { --district-fill: #483a5c; --district-edge: #cba9f5; }
[data-region="highlands"] { --district-fill: #414c2b; --district-edge: #c4db7e; }
[data-region="rustvale"] { --district-fill: #634437; --district-edge: #e8ad91; }
[data-region="loneford"] { --district-fill: #313d62; --district-edge: #96a8fa; }
[data-region="el-peso"] { --district-fill: #684125; --district-edge: #ffaa73; }
[data-region="cascadas"] { --district-fill: #285152; --district-edge: #72d6d5; }
.territory, .cell { cursor: pointer; outline: none; }
.territory, .district-boundary, #active-outline { stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.territory { fill: var(--district-fill); stroke: var(--district-edge); stroke-width: 1.7; transition: fill .13s ease, stroke .13s ease; }
.territory:is(:hover, :focus-visible, .selected) { stroke: #fff4d6; stroke-width: 2.4; }
.cell-layer-off .territory:is(:hover, :focus-visible, .selected) { fill: color-mix(in srgb, var(--district-fill) 86%, var(--district-edge)); }
.cell-layer-off .cell, .cell-layer-on .territory { pointer-events: none; }
.cell-layer-off #hex-cells, .cell-layer-off #district-hubs, .cell-layer-off #upgrade-sources, .cell-layer-off #cell-labels, .cell-layer-off #district-boundaries, .cell-layer-off #active-outline,
.cell-layer-on.numbered-hexes #map-labels { display: none; }
.cell-layer-on .territory { fill: var(--map-background); stroke: none; }
.district-boundary { fill: none; stroke: var(--district-edge); stroke-width: 2.2; }
#active-outline { fill: none; stroke: #fff6dd; stroke-width: 2.1; stroke-dasharray: 6 4; }
.cell { fill: var(--unoccupied-cell); stroke: #252d38; stroke-width: 1.35; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.cell.occupied { fill: var(--occupied-cell); }
.cell:is(:hover, :focus-visible, .selected) { stroke: #fff6dc; stroke-width: 2; }
.cell:not(.occupied):is(:hover, :focus-visible, .selected) { fill: #596979; }
.cell.occupied:is(:hover, :focus-visible, .selected) { fill: #ffcb81; }
.cell.high-priority { fill: var(--priority-cell); }
.cell.high-priority:is(:hover, :focus-visible, .selected) { fill: #bd2d4b; }
.cell.upgrade-affected { stroke: #a5f7e6; stroke-width: 2.55; stroke-dasharray: 5 2; }
.cell.occupied:not(.high-priority).upgrade-affected { stroke: #12433e; }
.cell-number { display: none; fill: #f5f8fc; text-anchor: middle; font: 750 10.5px/1 var(--sans); }
.numbered-hexes .cell-number { display: initial; }
.cell-annotation.occupied:not(.high-priority) :is(.cell-number, .occupant-squares) { fill: #2d1c08; }
.cell-upgrade-icon, .priority-marker, .hub-icon { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.priority-marker { stroke: #fff5e2; }
.cell-upgrade-icon { stroke: #b9f5e4; }
.cell-annotation.occupied:not(.high-priority) .cell-upgrade-icon { stroke: #12433e; }
.occupant-squares { fill: #fff5e2; }
.district-hub path { fill: var(--hub-cell); stroke: #99b2f6; stroke-width: 1.8; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.hub-icon { stroke: #e6edff; pointer-events: none; }
.upgrade-source[role="button"] { cursor: pointer; outline: none; }
.upgrade-source polygon { fill: var(--upgrade-cell); stroke: #80e5ca; stroke-width: 1.6; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.upgrade-source:hover polygon, .upgrade-source:focus-visible polygon { fill: #1a7067; stroke: #d9fff5; stroke-width: 2.2; }
.upgrade-source.selected polygon { fill: #1b766b; stroke: #e1ffc0; stroke-width: 2.7; }
.upgrade-source-icon { fill: none; stroke: #e3fff7; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.map-label { color: #f8fafc; }
.cell-layer-off .map-label > * { cursor: pointer; pointer-events: visiblePainted; }
.cell-layer-off .map-label:hover { color: #ffdd9e; }
.map-label .map-marker { fill: var(--map-background); stroke: #e1e8f1; stroke-width: 1.5; }
.map-label .marker-icon { fill: none; stroke: #e1e8f1; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.map-label.occupied .map-marker { fill: var(--occupied-cell); stroke: #ffdda4; }
.map-label.occupied .marker-icon { stroke: #2d1c08; }
.map-label.selected .map-marker { stroke: #fff6dd; stroke-width: 2.2; }
.map-label text { fill: currentColor; text-anchor: middle; }
.map-label .map-name { font: 700 24px/1 var(--display); letter-spacing: .65px; text-transform: uppercase; }
.map-label .map-level { fill: #e5eaf2; font-size: 10px; font-weight: 750; letter-spacing: 1.35px; }
.map-label.selected .map-name, .map-label.selected .map-level { fill: #ffdb99; }

.map-toolbar { position: absolute; z-index: 3; inset: 14px 14px auto; display: flex; align-items: start; justify-content: space-between; gap: 10px; pointer-events: none; }
.map-toolbar > * { pointer-events: auto; }
.search-wrap { position: relative; width: min(235px, 50%); }
.search-field, .view-switch, .map-controls, .search-results { background: #211e18f5; border: 1px solid #63563e; box-shadow: 0 6px 16px #1b130c3b; border-radius: 8px; }
.search-field { display: flex; align-items: center; gap: 7px; padding-inline: 11px 6px; color: #dbc5a0; }
.search-field input { width: 100%; min-width: 0; border: 0; background: transparent; color: var(--ink); font-size: .875rem; padding: 9px 4px; outline: none; }
.search-field:focus-within { outline: 2px solid #e9b46d; outline-offset: 1px; }
.search-field input::placeholder { color: #c0b39d; opacity: 1; }
.search-results { position: absolute; width: min(330px, calc(100cqw - 28px)); top: calc(100% + 6px); max-height: min(350px, 55vh); overflow: auto; overscroll-behavior: contain; padding: 4px; }
.search-result { display: flex; align-items: flex-start; gap: 7px; width: 100%; padding: 8px 7px; border: 0; border-radius: 5px; background: none; color: var(--ink); text-align: left; font-size: .875rem; }
.search-result:hover, .search-result[aria-selected="true"] { background: #483827; }
.search-result .icon { color: var(--accent); margin-top: 2px; }
.search-result-text { display: grid; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.search-result-text small { color: var(--subtle); font-size: .82rem; }
.search-empty { margin: 0; padding: 7px; color: var(--subtle); font-size: .875rem; }
.view-switch { display: flex; padding: 3px; gap: 2px; white-space: nowrap; }
.view-switch button { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; background: transparent; border: 1px solid transparent; padding: 4px 9px; border-radius: 5px; font-size: .875rem; font-weight: 650; color: #dfd4c1; }
.view-switch button:hover { background: #3b3020; }
.view-switch button[aria-pressed="true"] { background: #4b3621; color: #ffcd8a; border-color: #765231; }
.compass { position: absolute; top: 65px; right: 21px; width: 28px; text-align: center; color: #ffe3b9; line-height: 1; text-shadow: 0 1px 3px #100d08; pointer-events: none; }
.compass span { font: 750 .75rem/1 var(--sans); }
.compass svg { display: block; width: 100%; filter: drop-shadow(0 1px 2px #25160f); }
.district-context { position: absolute; z-index: 2; top: 65px; left: 14px; display: flex; align-items: center; gap: 8px; max-width: calc(100% - 66px); padding: 5px 10px; border: 1px solid var(--district-edge, #8a704d); border-radius: 7px; background: #231d15eb; color: #ffe3b9; line-height: 1.2; pointer-events: none; }
.district-context .icon { color: var(--district-edge, var(--accent)); }
.district-context strong, .district-context small { display: block; }
.district-context strong { font-size: .875rem; }
.district-context small { color: #d4bb94; font-size: .75rem; }
@container (min-width: 740px) {
  .district-context { top: 14px; left: 50%; transform: translateX(-50%); }
}
.map-controls { position: absolute; bottom: 14px; right: 14px; display: grid; }
.map-controls button, .icon-button, .add-button { display: grid; place-items: center; padding: 0; color: var(--subtle); background: none; border: 0; }
.map-controls button { width: 39px; height: 38px; color: var(--ink); }
.map-controls button + button { border-top: 1px solid #4d4333; }
.map-controls button:hover:not(:disabled), .icon-button:hover, .add-button:hover { color: var(--accent); background: #3b3022; }
.map-footer { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px 16px; padding: 10px 14px; font-size: .78rem; color: var(--subtle); }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 7px 14px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.swatch { width: 12px; height: 12px; border: 1px solid; border-radius: 2px; }
.unoccupied.swatch { color: #9eabbc; background: var(--unoccupied-cell); }
.occupied.swatch { color: #ffdda4; background: var(--occupied-cell); }
.district-marker { color: #e1e8f1; background: var(--map-background); border-radius: 50%; }
.priority-swatch { display: grid; place-items: center; color: #fff5e2; background: var(--priority-cell); border-color: #f698ab; }
.priority-swatch .icon { width: 9px; height: 9px; }
.upgrade-key { color: #80e5ca; background: var(--upgrade-cell); }
.hub-key { color: #99b2f6; background: var(--hub-cell); }
.occupant-key { width: 10px; height: 10px; border: 3px solid var(--occupied-cell); border-radius: 2px; background: #2d1c08; }
@media (forced-colors: active) {
  #atlas-map, .swatch, .occupant-key { forced-color-adjust: none; }
}
.map-open-record { display: none; border: 0; padding: 3px 0; background: none; color: var(--accent); font-size: .875rem; }

.details { display: flex; flex-direction: column; }
.record-head { padding: 21px 20px 15px; border-bottom: 1px solid var(--border); background: #26231c; }
.record-type { display: flex; align-items: center; gap: 6px; margin: 0 0 7px; color: #eabb7e; font-size: .75rem; font-weight: 750; text-transform: uppercase; letter-spacing: .11em; }
.record-head h2 { font-size: clamp(2.25rem, 3.5vw, 3.25rem); text-transform: uppercase; overflow-wrap: anywhere; }
.record-status { margin: 10px 0 0; color: var(--subtle); font-size: .85rem; }
.record-status[data-error] { color: #ffb29e; }
.record-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.level-tag { border: 1px solid #6b5030; border-radius: 5px; padding: 2px 8px; color: #f1c38a; background: #3d2e1e; font-size: .79rem; font-weight: 650; }
#parent-record { background: none; border: 0; padding: 4px; font-size: .81rem; color: var(--subtle); text-decoration: underline; text-underline-offset: 3px; }
#parent-record:hover { color: var(--accent); }
.record-occupancy { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; color: var(--subtle); font-size: .875rem; }
.record-occupancy strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.upgrade-details .record-type, .upgrade-benefit { color: #b6f4df; }
.upgrade-details .record-head h2 { font-size: clamp(2rem, 3vw, 2.7rem); }
.upgrade-benefit { margin: 6px 0 0; }
.affected-plots { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.affected-plots .button { min-height: 31px; padding: 3px 8px; }
.record-body { display: grid; gap: 0; padding-inline: 20px; }
#record-fields { min-width: 0; padding-block: 0; margin: 0; border: 0; }
.record-section { padding-block: 15px; border-bottom: 1px solid var(--border); min-width: 0; }
.record-section:last-child { border: 0; }
.section-head { display: flex; justify-content: space-between; align-items: center; min-height: 28px; }
.section-head h3 { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--ink); font-size: .94rem; }
.section-head h3 > .icon { color: #d1aa73; }
.count { min-width: 22px; text-align: center; padding: 1px 4px; border-radius: 4px; font-size: .72rem; border: 1px solid var(--border); color: var(--subtle); background: var(--raised); }
.add-button { min-height: 32px; padding: 4px 7px; font-size: .875rem; }
.record-list { margin: 6px 0 0; color: var(--subtle); font-size: .875rem; overflow-wrap: anywhere; }
.record-list ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.record-list li { padding: 3px 8px; background: #2d281f; border-left: 2px solid #8f693d; border-radius: 2px; color: var(--ink); }
.record-actions { margin-top: auto; display: grid; gap: 7px; padding: 14px 20px 16px; }
.record-actions .button { min-height: 43px; }
.save-location { margin: 0; color: var(--muted); text-align: center; font-size: .76rem; }

dialog { width: min(480px, calc(100% - 28px)); max-height: calc(100dvh - 28px); padding: 0; border: 1px solid #5c4b34; border-radius: 12px; background: var(--panel); color: var(--ink); box-shadow: 0 22px 64px #080604ba; }
dialog::backdrop { background: #100d09b8; }
dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
.dialog-head, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 18px; }
.dialog-head { border-bottom: 1px solid var(--border); }
.dialog-head h2 { font-size: 2rem; }
.icon-button { width: 35px; height: 35px; border: 1px solid var(--border); border-radius: 6px; flex: none; }
.dialog-body { overflow: auto; padding: 16px 18px; }
.dialog-body p { margin: 0; }
.edit-list:not(:empty) { display: grid; gap: 6px; margin-top: 7px; }
.edit-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .9fr) auto; gap: 7px; align-items: center; }
#record-fields :is(input:not([type="checkbox"]), textarea) { width: 100%; min-width: 0; background: #181611; color: var(--ink); border: 1px solid #504433; border-radius: 6px; padding: 6px 8px; }
.settlement-fields { display: grid; gap: 8px; }
.settlement-fields label { display: block; font-size: .92rem; font-weight: 700; margin-bottom: 5px; }
.settlement-fields .priority-field { display: flex; align-items: center; gap: 8px; min-height: 33px; margin: 0; cursor: pointer; }
.priority-field input { width: 17px; height: 17px; margin: 0; accent-color: #d9606a; }
#record-fields :is(input, textarea)::placeholder { color: var(--muted); }
#record-note { margin-top: 6px; resize: vertical; }
.dialog-actions { border-top: 1px solid var(--border); justify-content: flex-end; }
.toast { z-index: 4; position: fixed; margin-inline: auto; inset: auto 16px 16px; width: fit-content; max-width: calc(100% - 32px); color: var(--ink); background: #31291c; border: 1px solid #715538; border-radius: 8px; box-shadow: 0 6px 22px #0006; padding: 8px 14px; font-size: .875rem; }
.toast:empty { clip-path: inset(50%); pointer-events: none; }

@media (max-width: 980px) {
  .atlas-layout { grid-template-columns: minmax(0, 1fr) 275px; gap: 12px; }
  .record-head, .record-actions { padding-inline: 15px; }
  .record-body { padding-inline: 15px; }
}
@media (max-width: 760px) {
  .atlas-layout { grid-template-columns: minmax(0, 1fr); }
  .map-viewport { height: clamp(380px, 66vw, 525px); }
  .record-head, .record-actions, .record-body { padding-inline: 17px; }
  .workspace { padding-block: 19px; }
  .map-help { display: none; }
  .map-open-record { display: block; }
  .map-controls { grid-auto-flow: column; }
  .map-controls button + button { border-top: 0; border-left: 1px solid #4d4333; }
  .map-label .map-name { font-size: 29px; }
  .map-label .map-level { display: none; }
}
@media (max-width: 410px) {
  .topbar-inner { gap: 8px; min-height: 56px; }
  .brand { gap: 5px; font-size: .82rem; }
  .brand img { width: 31px; height: 31px; }
  .state { border: 0; padding: 0; font-size: .69rem; }
  .state span, .map-actions span, #show-hexes .icon { display: none; }
  .map-actions .button { min-height: 33px; padding: 5px 7px; }
  .map-toolbar { inset: 9px 9px auto; gap: 5px; }
  .view-switch button { padding-inline: 5px; }
  .district-total { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
