@font-face {
  font-family: Literata;
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../assets/fonts/literata_5.2.8_latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: Literata;
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../assets/fonts/literata_5.2.8_latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: Literata;
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../assets/fonts/literata_5.2.8_latin-700-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../assets/fonts/source-sans-3_5.2.6_latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../assets/fonts/source-sans-3_5.2.6_latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../assets/fonts/source-sans-3_5.2.6_latin-700-normal.woff2") format("woff2");
}

:root {
  --parchment: #efe4cc;
  --sea: #d5e0db;
  --ink: #241c14;
  --panel: rgba(22, 26, 32, 0.94);
  --panel-2: #242a33;
  --line: rgba(198, 161, 90, 0.45);
  --brass: #c6a15a;
  --brass-2: #e3cc8d;
  --text: #f4efe6;
  --muted: #b7b0a3;
  --danger: #e07a68;
  --ok: #9dcc96;
  --serif: Literata, Palatino, "Palatino Linotype", Georgia, serif;
  --sans: "Source Sans 3", "Segoe UI", sans-serif;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  overflow: hidden;
  color: var(--text);
  font-family: var(--sans);
  background: #12161c;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--brass-2); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}

#app { height: 100dvh; position: relative; overflow: hidden; }
#stage { position: absolute; inset: 0; }
#map { width: 100%; height: 100%; display: block; touch-action: none; background: var(--sea); }
#map.tool-move { cursor: grab; }
#map.tool-move.is-dragging, #map.tool-space.is-dragging { cursor: grabbing; }
#map.tool-space { cursor: grab; }
#map.tool-paint { cursor: crosshair; }
#map.tool-pick { cursor: copy; }
.sea { fill: var(--sea); }
#atoms { opacity: 0.88; }
.atom {
  stroke-width: 1.15;
  stroke-linejoin: round;
  pointer-events: none;
}
#terrain, #province-borders, #national-borders, #hover-ring, #selected-ring {
  pointer-events: none;
}
#province-borders, #national-borders, #hover-ring, #selected-ring {
  fill: none; vector-effect: non-scaling-stroke; stroke-linejoin: round;
}
#province-borders { stroke: rgba(36, 28, 20, 0.33); stroke-width: 0.75px; }
#national-borders { stroke: #24180f; stroke-width: 2.2px; }
#hover-ring { stroke: #f7f1e4; stroke-width: 2px; }
#selected-ring { stroke: #f7f1e4; stroke-width: 2.5px; stroke-dasharray: 6 4; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.map-label {
  position: absolute; transform: translate(-50%, -50%);
  white-space: nowrap; letter-spacing: 0.01em;
  text-shadow: 0 1px 0 rgba(255, 248, 236, 0.85), 0 0 6px rgba(255, 248, 236, 0.8);
  color: var(--ink);
}
.map-label-city { font-size: 12px; font-weight: 600; }
.map-label-country { font-family: var(--serif); font-size: 13px; font-weight: 600; letter-spacing: 0.04em; }
.map-label-province { font-size: 11px; color: #3a3128; }
.map-label-sea { font-family: var(--serif); font-size: 12px; font-style: italic; letter-spacing: 0.14em; text-transform: uppercase; color: #3d534c; }

#topbar, #dock, #detail, #brush, #zoom, #mobilebar, .modal, .gate-card, .banner {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
#topbar {
  position: absolute; z-index: 5; top: calc(10px + var(--safe-top)); left: 10px; right: 10px;
  min-height: 58px; display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: 14px;
}
.brand { min-width: 140px; }
.eyebrow {
  margin: 0; color: var(--brass-2); letter-spacing: 0.16em; text-transform: uppercase;
  font-size: 10px;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; }
h1 { font-size: 22px; line-height: 1; }
.scenario-label { margin: 0; color: var(--muted); flex: 1; }
.desktop-tools, .top-actions, .tabs, .search-row, .zoom, .mobilebar, .row-actions, .dialog-actions {
  display: flex; gap: 6px; align-items: center;
}
button, .create-btn {
  background: #2a313b; border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 10px;
  padding: 8px 10px; min-height: 36px;
}
button[aria-pressed="true"], .tabs button[aria-selected="true"] {
  border-color: var(--brass); box-shadow: inset 0 -2px 0 var(--brass);
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
kbd {
  font-family: var(--sans); font-size: 10px; border: 1px solid var(--line);
  border-radius: 4px; padding: 0 4px; color: var(--brass-2);
}

#dock {
  position: absolute; z-index: 6; top: calc(78px + var(--safe-top)); left: 10px; bottom: 12px;
  width: min(360px, calc(100vw - 20px)); border-radius: 16px;
  display: flex; flex-direction: column; overflow: hidden;
}
#dock[hidden] { display: none; }
.dock-head { padding: 12px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.search-row input {
  flex: 1; min-width: 0; background: #12161c; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px; padding: 10px 12px;
}
.tabs button { flex: 1; }
.create-btn { width: 100%; background: transparent; border-style: dashed; border-color: var(--line); color: var(--brass-2); }
.list { overflow: auto; padding: 8px; flex: 1; }
.list-section { margin: 8px 6px 4px; color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.entry, .entry-main {
  width: 100%; display: flex; gap: 8px; align-items: center; text-align: left;
  background: transparent; border: 0; border-radius: 10px; padding: 8px;
}
.entry { padding: 2px; }
.entry.is-active { background: rgba(198, 161, 90, 0.12); }
.swatch {
  width: 14px; height: 14px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.7);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.35); flex: none;
}
.entry-copy { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.entry-copy strong, .entry-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-copy span, .meta { color: var(--muted); font-size: 12px; }
.icon-btn { min-width: 36px; padding: 8px; background: transparent; }
.empty { color: var(--muted); padding: 16px; }

#detail {
  position: absolute; z-index: 5; top: calc(78px + var(--safe-top)); right: 12px;
  width: min(320px, calc(100vw - 24px)); max-height: min(520px, calc(100dvh - 150px));
  overflow: auto; border-radius: 16px; padding: 14px;
}
#detail h3 { font-size: 22px; }
.detail-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.detail-actions button { width: 100%; text-align: left; }
.badge {
  display: inline-block; border: 1px solid var(--line); color: var(--brass-2);
  border-radius: 999px; padding: 2px 8px; font-size: 11px; letter-spacing: 0.04em;
}

body.dock-open #brush { left: 388px; }
#brush {
  position: absolute; z-index: 5; left: 12px; bottom: 14px;
  display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 14px;
  max-width: min(560px, calc(100vw - 24px));
}
#brush .brush-copy { min-width: 180px; }
#brush strong { white-space: nowrap; }
#brush strong { display: block; }
#brush .swatch { width: 18px; height: 18px; }
#zoom {
  position: absolute; z-index: 5; right: 12px; bottom: 14px;
  flex-direction: column; padding: 6px; border-radius: 12px; background: var(--panel);
}
#zoom button { width: 40px; height: 40px; }

#mobilebar {
  display: none; position: absolute; z-index: 6; left: 8px; right: 8px;
  bottom: calc(8px + var(--safe-bottom)); padding: 6px; border-radius: 16px; justify-content: space-between;
}
#mobilebar button { flex: 1; min-height: 44px; }

#toasts { position: absolute; z-index: 8; left: 50%; bottom: 86px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100vw - 24px)); }
.toast {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
.banner, .status {
  position: absolute; z-index: 8; left: 50%; transform: translateX(-50%);
  width: min(640px, calc(100vw - 20px)); border-radius: 12px; padding: 10px 12px;
}
.banner { top: calc(78px + var(--safe-top)); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.banner[hidden] { display: none; }
.status { bottom: calc(8px + var(--safe-bottom)); margin: 0; text-align: center; background: transparent; border: 0; box-shadow: none; color: var(--muted); pointer-events: none; }
.status.error { color: var(--danger); }

.gate {
  position: absolute; inset: 0; z-index: 9; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 30%, rgba(239, 228, 204, 0.16), rgba(12, 14, 18, 0.78));
  padding: 18px;
}
.gate[hidden] { display: none; }
.gate-card { width: min(860px, 100%); border-radius: 20px; padding: 22px; max-height: calc(100dvh - 36px); overflow: auto; }
.lede { color: var(--muted); max-width: 62ch; }
.era-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-top: 14px; }
.era-card { text-align: left; min-height: 92px; background: #1b2129; }
.era-card strong { display: block; font-family: var(--serif); font-size: 22px; }
.era-card span { color: var(--muted); }

#modal-root:empty { display: none; }
.backdrop { position: absolute; inset: 0; z-index: 10; background: rgba(8, 10, 14, 0.55); }
.modal {
  position: absolute; z-index: 11; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto;
  border-radius: 16px; padding: 16px;
}
.modal h3 { margin-bottom: 8px; }
.modal label { display: block; margin: 10px 0 4px; color: var(--muted); }
.modal input[type="text"], .modal input[type="search"], .modal input:not([type="checkbox"]):not([type="color"]) {
  width: 100%; background: #12161c; border: 1px solid rgba(255,255,255,0.12); border-radius: 10px; padding: 10px;
}
.choice { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
.dialog-actions { justify-content: flex-end; margin-top: 14px; }
.danger { color: var(--danger); }
.note { color: var(--muted); font-size: 13px; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.layers-pop {
  position: absolute; z-index: 7; top: calc(76px + var(--safe-top)); right: 12px;
  width: min(280px, calc(100vw - 24px)); padding: 12px; border-radius: 14px;
}

@media (max-width: 860px) {
  .desktop-tools, .scenario-label, #open-search { display: none; }
  .brand { min-width: 0; }
  h1 { font-size: 17px; }
  #topbar { gap: 6px; padding: 6px 8px; }
  .top-actions button { padding: 8px; }
  #topbar { min-height: 52px; }
  #mobilebar { display: flex; }
  #dock {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%;
    height: min(74dvh, 680px); border-radius: 18px 18px 0 0;
  }
  #brush {
    left: 8px; right: 8px; max-width: none;
    bottom: calc(74px + var(--safe-bottom));
  }
  #zoom { right: 8px; bottom: calc(132px + var(--safe-bottom)); }
  #detail {
    left: 8px; right: 8px; top: auto; width: auto;
    bottom: calc(188px + var(--safe-bottom));
    max-height: 32dvh;
  }
  #toasts { bottom: calc(188px + var(--safe-bottom)); }
  .entry, .icon-btn, #close-dock, #clear-search { min-height: 44px; }
}

@media (max-width: 860px) and (orientation: landscape) {
  #dock { height: min(86dvh, 100%); }
  #detail { max-height: 28dvh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
