/* The web viewer's look: the Godot viewer's color tokens (ViewerColors) as
   CSS variables, in its four palettes. The settings (src/settings.ts) pick
   one as data-palette; before they run, the OS's preferences do. */

@font-face { font-family: "Inter"; src: url("../fonts/Inter.ttf") format("truetype"); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Inter"; src: url("../fonts/Inter-Italic.ttf") format("truetype"); font-weight: 100 900; font-style: italic; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("../fonts/AtkinsonHyperlegible-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("../fonts/AtkinsonHyperlegible-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

/* Dark (ViewerColors.Default). */
:root {
	--window: #0f2438; --surface: #121c28; --raised: #1b2838; --hover: #243449; --pressed: #2c3e56;
	--border: #2a3a4f; --text: #e7edf4; --muted: #9aabbd; --disabled: #7a8ba0; --accent: #f0b94a; --accent-text: #1a1204; --contrast: 4.5;
	--font: "Inter", system-ui, sans-serif;
	--text-size: 15px; --line-height: 1.45; --letter-spacing: 0em;
	color-scheme: dark;
}
/* Light. */
@media (prefers-color-scheme: light) {
	:root:not([data-palette]) {
		--window: #dde5ee; --surface: #f7f9fc; --raised: #ffffff; --hover: #e8eef5; --pressed: #d6e0ec;
		--border: #7a8898; --text: #17212c; --muted: #4c5b6b; --disabled: #6b7888; --accent: #9a5b00; --accent-text: #ffffff;
		color-scheme: light;
	}
}
/* High contrast, dark and light. */
@media (prefers-contrast: more) {
	:root:not([data-palette]) {
		--contrast: 7;
		--window: #000000; --surface: #050505; --raised: #141414; --hover: #2e2e2e; --pressed: #3d3d3d;
		--border: #e0e0e0; --text: #ffffff; --muted: #cfcfcf; --disabled: #a0a0a0; --accent: #ffd400; --accent-text: #000000;
	}
}
@media (prefers-contrast: more) and (prefers-color-scheme: light) {
	:root:not([data-palette]) {
		--contrast: 7;
		--window: #ffffff; --surface: #ffffff; --raised: #ffffff; --hover: #e6e6e6; --pressed: #cccccc;
		--border: #000000; --text: #000000; --muted: #333333; --disabled: #555555; --accent: #0033cc; --accent-text: #ffffff;
	}
}

/* The palette the settings chose. */
:root[data-palette="dark"] { --window: #0f2438; --surface: #121c28; --raised: #1b2838; --hover: #243449; --pressed: #2c3e56;
	--border: #2a3a4f; --text: #e7edf4; --muted: #9aabbd; --disabled: #7a8ba0; --accent: #f0b94a; --accent-text: #1a1204; --contrast: 4.5; color-scheme: dark; }
:root[data-palette="light"] { --window: #dde5ee; --surface: #f7f9fc; --raised: #ffffff; --hover: #e8eef5; --pressed: #d6e0ec;
	--border: #7a8898; --text: #17212c; --muted: #4c5b6b; --disabled: #6b7888; --accent: #9a5b00; --accent-text: #ffffff; --contrast: 4.5; color-scheme: light; }
:root[data-palette="hc-dark"] { --window: #000000; --surface: #050505; --raised: #141414; --hover: #2e2e2e; --pressed: #3d3d3d;
	--border: #e0e0e0; --text: #ffffff; --muted: #cfcfcf; --disabled: #a0a0a0; --accent: #ffd400; --accent-text: #000000; --contrast: 7; color-scheme: dark; }
:root[data-palette="hc-light"] { --window: #ffffff; --surface: #ffffff; --raised: #ffffff; --hover: #e6e6e6; --pressed: #cccccc;
	--border: #000000; --text: #000000; --muted: #333333; --disabled: #555555; --accent: #0033cc; --accent-text: #ffffff; --contrast: 7; color-scheme: light; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
	display: grid; grid-template-rows: auto 1fr auto;
	background: var(--surface); color: var(--text);
	font: var(--text-size)/var(--line-height) var(--font); letter-spacing: var(--letter-spacing);
}
code { font-size: 0.9em; }
.muted { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -40px; padding: 6px 10px; background: var(--accent); color: var(--accent-text); z-index: 10; }
.skip:focus { top: 8px; }

/* Controls, as the Godot viewer draws them. */
button, input, select {
	font: inherit; color: var(--text); background: var(--raised);
	border: 1px solid var(--border); border-radius: 4px; padding: 4px 10px;
}
button:hover:not(:disabled) { background: var(--hover); }
button:active:not(:disabled) { background: var(--pressed); }
button:disabled, input:disabled { color: var(--disabled); background: var(--surface); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 700; }
button.primary:disabled { background: var(--surface); color: var(--disabled); border-color: var(--border); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--surface); min-width: 0; }
.bar .title { font-size: 1em; font-weight: 700; margin: 0; }
.bar .title, .bar button { white-space: nowrap; flex-shrink: 0; }
/* The run's summary gives way first (cut short, whole for screen readers
   and in its tooltip), so the buttons stay on the bar's row. */
.bar .run { margin: 0 auto 0 0; color: var(--muted); min-width: 4em; flex: 0 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.body { display: grid; grid-template-columns: 1fr minmax(320px, 40%); min-height: 0; }
.map { position: relative; background: var(--window); min-height: 0; }
.map canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.map canvas:focus-visible { outline: none; } /* the map draws its own ring */
/* Compare: the branch's map on the left, the history it branched from on the right. */
.map.comparing > #map-canvas, .map.comparing > #globe-canvas { width: 50%; }
.compare-pane { position: absolute; top: 0; bottom: 0; left: 50%; right: 0; border-left: 2px solid var(--border); }
.compare-label { position: absolute; top: 6px; left: 8px; margin: 0; max-width: calc(50% - 24px); padding: 2px 8px; border-radius: 6px; background: var(--surface); color: var(--text); font-size: 0.85em; z-index: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compare-pane .compare-label { max-width: calc(100% - 24px); }
.map.comparing .map-controls { max-width: calc(50% - 20px); }
.compare-tools { display: flex; gap: 16px; flex-wrap: wrap; margin: 8px 0; }
.map-card { position: absolute; z-index: 4; pointer-events: none; padding: 4px 8px; border-radius: 4px;
	background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--border); font-size: 0.9em; }
:root[data-solid] .map-card { background: var(--surface); }
/* The map mode's picker and its legend, over the map's corner (as the
   Godot viewer's MapLegend: solid with reduced transparency). */
.map-controls { position: absolute; left: 10px; bottom: 10px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; max-width: calc(100% - 20px); }
.nation-chart { display: block; width: 100%; height: 150px; margin: 4px 0 8px; border-radius: 4px; }
.chronicle-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
#chronicle-search { flex: 1; min-width: 10em; }
#chronicle-search::placeholder { color: var(--muted); }
.chronicle-bar label.check { display: flex; align-items: center; gap: 6px; }
.chronicle-bar input[type="checkbox"] { accent-color: var(--accent); width: 1.1em; height: 1.1em; padding: 0; }
.kind-list { margin: 0 0 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; display: grid; grid-template-columns: repeat(auto-fill, minmax(11em, 1fr)); gap: 4px 12px; }
.kind-list label { display: flex; align-items: center; gap: 6px; }
.kind-list button { grid-column: 1 / -1; justify-self: start; }
.bb .icon, .kind-list .icon { vertical-align: -0.15em; }
.map-row { display: flex; gap: 6px; flex-wrap: wrap; }
#ties[aria-pressed="true"], #globe[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.legend .tie-sample { flex: none; }
.legend { padding: 8px 10px; border-radius: 6px; border: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 90%, transparent); font-size: 0.9em; }
:root[data-solid] .legend { background: var(--surface); }
.legend h2 { font-size: 1em; margin: 0 0 4px; }
.legend ul { list-style: none; margin: 0; padding: 0; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend .swatch { flex: none; width: 12px; height: 12px; border-radius: 2px; border: 1px solid rgb(0 0 0 / 0.4); }
.legend svg.swatch { width: 14px; height: 14px; border: 0; border-radius: 0; }
.start { position: absolute; inset: 0; display: grid; place-content: center; max-width: 34em; margin: auto; padding: 24px; }
.start h2 { margin: 0 0 8px; }

.panel { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-left: 1px solid var(--border); }
/* Tabs that don't fit scroll in their row, not the page. */
.tabs { display: flex; gap: 2px; padding: 0 8px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: thin; }
.tabs [role="tab"] { flex: none; white-space: nowrap; border: 0; border-top: 2px solid transparent; border-radius: 0; background: transparent; color: var(--muted); padding: 8px 10px; }
.tabs [role="tab"][aria-selected="true"] { color: var(--text); border-top-color: var(--accent); background: var(--surface); font-weight: 600; }
.view { flex: 1; overflow: auto; padding: 12px 16px; }

.timeline .track { position: relative; flex: 1; display: flex; align-items: center; }
.timeline input[type="range"] { flex: 1; accent-color: var(--accent); position: relative; }
/* Events worth a mark: thin lines over the track at their year. */
.timeline .marks { position: absolute; left: 8px; right: 8px; top: 0; bottom: 0; pointer-events: none; }
.timeline .mark { position: absolute; top: 2px; bottom: 2px; width: 2px; margin-left: -1px; border-radius: 1px; opacity: 0.85; }
.timeline .strip { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 10px; }
.timeline .strip .bar { fill: var(--muted); opacity: 0.6; }
.timeline .strip .era { stroke: var(--text); stroke-width: 1px; vector-effect: non-scaling-stroke; opacity: 0.7; }
.timeline .track { min-height: 34px; }
.timeline .year { font-weight: 700; font-size: 1.4em; min-width: 6em; }

/* Panel text (src/bbcode.ts), in an element of class "bb": spaces kept,
   as the Godot viewer keeps them (the dynasties' trees are indented so). */
.bb { white-space: pre-wrap; overflow-wrap: anywhere; }
.bb-table { border-collapse: collapse; }
/* As in Godot: a cell that expands shares the room left over; the others
   keep their own width, unbroken. */
.bb-table:has(td.expand) { width: 100%; }
.bb-table td { vertical-align: top; padding: 0; overflow-wrap: normal; }
.bb-table td:not(.expand) { width: 1%; white-space: nowrap; }
.bb-indent { display: inline-block; padding-left: 1.5em; }
a.link { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
a.link:hover { text-decoration-thickness: 2px; }
/* A hint: underlined with dots, its tip shown on hover and focus (and read
   by screen readers from the hidden text after it). */
.hint { position: relative; text-decoration: underline dotted; text-underline-offset: 3px; cursor: help; }
.hint:hover::after, .hint:focus-visible::after {
	content: attr(data-tip); position: absolute; left: 0; top: calc(100% + 4px); z-index: 5;
	width: max-content; max-width: 28em; padding: 6px 10px; white-space: normal;
	background: var(--raised); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
	font-size: 0.9rem; font-weight: 400; font-style: normal;
}

/* A panel's sections (src/panels.ts): jump links that stay in view, and
   headings that fold their section (a chevron drawn in CSS, turned when
   folded). */
#pin { display: block; margin: 0 0 10px; }
.jumps { position: sticky; top: -12px; z-index: 3; display: flex; flex-wrap: wrap; gap: 2px 12px; margin: -12px -16px 8px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.jumps a { color: var(--accent); text-decoration: none; }
.jumps a:hover { text-decoration: underline; }
h3.section { margin: 12px 0 4px; font-size: 1.13em; }
h3.section button { all: unset; cursor: pointer; display: flex; align-items: center; gap: 8px; font-weight: 700; width: 100%; border-radius: 4px; padding: 2px; }
h3.section button:hover { background: var(--hover); }
h3.section button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h3.section button::before { content: ""; width: 0.45em; height: 0.45em; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translate(-2px, -2px); transition: transform 0.15s; }
h3.section button[aria-expanded="false"]::before { transform: rotate(-45deg); }
.trait-bar { width: 7.3em; height: 0.93em; vertical-align: -0.1em; color: var(--text); }
/* A nation's name inside other text (a chronicle line): its card on hover. */
.nation-name { text-decoration: underline dotted; text-underline-offset: 3px; }
/* A nation's card (src/cards.ts). */
.card { position: fixed; z-index: 20; display: flex; gap: 10px; align-items: flex-start; max-width: 28em; padding: 8px 12px; pointer-events: none;
	background: var(--raised); color: var(--text); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 4px 16px rgb(0 0 0 / 0.35); }
.card .swatch { flex: none; width: 12px; height: 12px; margin-top: 0.3em; border-radius: 2px; }

/* The Chronicle and History tabs. */
#chronicle-view, #measure { margin-bottom: 8px; }
.view.history:not([hidden]) { display: flex; flex-direction: column; }
#measure-about { margin: 0 0 8px; font-size: 0.9em; }
#history-chart { width: 100%; flex: 1; min-height: 240px; }
#history-legend { margin-top: 8px; }
/* Every line of the chronicle is a link: underlined only when pointed at. */
#chronicle-text a.link { text-decoration: none; }
#chronicle-text a.link:hover, #chronicle-text a.link:focus-visible { text-decoration: underline; }

/* Reduced motion: nothing animates. */
:root[data-reduce-motion] *, :root[data-reduce-motion] *::before, :root[data-reduce-motion] *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }

/* Dialogs (src/dialogs.ts). */
.dialog { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 20px 24px; width: min(36em, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
.dialog::backdrop { background: rgb(0 0 0 / 0.5); }
:root[data-solid] .dialog::backdrop { background: rgb(0 0 0 / 0.85); }
.dialog h2 { margin: 0 0 12px; font-size: 1.25em; }
.dialog h3 { margin: 16px 0 6px; font-size: 1em; }
.dialog-buttons { display: flex; justify-content: flex-end; margin-top: 16px; }
.settings { display: grid; grid-template-columns: auto 1fr; gap: 2px 16px; align-items: center; }
.settings label { font-weight: 600; }
.settings .help { grid-column: 2; margin: 0 0 10px; color: var(--muted); font-size: 0.9em; }
.keys dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 0; }
.keys dt { white-space: pre; }
.keys dd { margin: 0; }
kbd { font: inherit; font-weight: 600; color: var(--accent); }

/* Narrow windows: the panel goes under the map. */
@media (max-width: 760px) {
	.body { grid-template-columns: 1fr; grid-template-rows: 50vh auto; }
	.panel { border-left: 0; border-top: 1px solid var(--border); }
}
/* Narrower still: the title, then the buttons together, then the summary. */
@media (max-width: 520px) {
	.bar { flex-wrap: wrap; row-gap: 6px; }
	.bar .title { flex-basis: 100%; }
	.bar .run { order: 1; flex-basis: 100%; white-space: normal; }
}

/* The Languages tab's family tree (LanguageTree in the Godot viewer): each
   tongue under the one it comes from, joined by a line; the selected
   nation's lineage bold and bright, fallen nations' muted. */
.tongue-tree, .tongue-tree ul { list-style: none; margin: 0; padding: 0; }
.tongue-tree { margin-top: 10px; }
.tongue-tree ul { margin-left: 7px; padding-left: 14px; border-left: 1px solid var(--border); }
.tongue-tree li { padding: 2px 0; color: var(--muted); }
.tongue-tree li.lineage > :first-child, .tongue-tree li.lineage > .bb-line { color: var(--text); font-weight: 700; }
.tongue-tree li.fallen { opacity: 0.75; }
.tongue-tree.has-selection li:not(.lineage) > :first-child { opacity: 0.55; }
#language-view { margin-bottom: 4px; }

/* A module's web (the Knowledge tab): its tools, the drawing (scrolling
   both ways), and the list in columns side by side where there's room. */
.web-tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.web-scroll { overflow: auto; max-height: 60vh; border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
.web-scroll svg { display: block; }
.web-scroll .web-entry { cursor: pointer; }
.web-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(14em, 1fr)); gap: 12px; margin-top: 8px; }
#web-details { margin-top: 10px; }
