:root {
  --ink: #1d1a16;
  --muted: #5d564c;
  --paper: #fbf8f1;
  --card: #ffffff;
  --line: #ddd5c4;
  --accent: #7a2e12;
  --gold: #ffb000;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--ink);
  background: var(--paper);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

body { display: flex; flex-direction: column; overflow: hidden; }
[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }

button {
  min-height: 36px;
  padding: 4px 12px;
  border: 1px solid #b9ae98;
  border-radius: 8px;
  background: var(--card);
  cursor: pointer;
}
button:hover { background: #fff2d1; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
input, select {
  min-height: 36px;
  padding: 4px 8px;
  border: 1px solid #b9ae98;
  border-radius: 8px;
  background: var(--card);
}
:focus-visible { outline: 3px solid #0b63ce; outline-offset: 2px; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
}
.brand h1 { margin: 0; font: 700 22px/1.1 Georgia, serif; color: var(--accent); }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }
.timebar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin: 0; }
.field { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); }
.field select, .field input { font-size: 15px; color: var(--ink); }
#year { width: 96px; font-weight: 700; text-align: center; }
.stepper { display: flex; align-items: flex-end; gap: 4px; }
.error { flex-basis: 100%; margin: 0; color: #a3001b; font-size: 13px; }
.error:empty { display: none; }
.examples { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; }
.examples button { min-height: 30px; font-size: 13px; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) clamp(320px, 29vw, 440px); }
.mapwrap { position: relative; min-height: 0; overflow: hidden; }
#map { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#map.dragging { cursor: grabbing; }
#map:focus-visible { outline-offset: -3px; }

.map-status, .legend, .tooltip {
  position: absolute;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}
.map-status { bottom: 10px; right: 10px; max-width: min(400px, calc(100% - 130px)); padding: 7px 11px; display: flex; flex-direction: column; pointer-events: none; }
.map-status strong { font: 700 18px Georgia, serif; }
.map-status span { font-size: 12px; color: var(--muted); }
.map-buttons { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.map-buttons button { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); }
.map-buttons .georgia { background: var(--gold); border-color: #6b3d00; font-weight: 700; }
.zoom-pair { display: flex; gap: 6px; justify-content: flex-end; }
.zoom-pair button { width: 40px; font-size: 20px; }

.legend { left: 10px; bottom: 10px; max-width: min(340px, calc(100% - 20px)); max-height: 70%; overflow: auto; font-size: 12.5px; }
.legend summary { padding: 7px 12px; cursor: pointer; font-weight: 600; }
#legend-body { padding: 0 12px 10px; }
.key { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.swatch { flex: none; width: 22px; height: 14px; border: 1.5px solid #333; border-radius: 3px; }
.swatch.nodata { background: repeating-linear-gradient(45deg, #e7e2d6 0 3px, #c4bba6 3px 4px); }
.swatch.disputed { background: repeating-linear-gradient(-45deg, #fff 0 3px, #222 3px 5px); }
.swatch.previous { background: none; border: 2px dashed #7a007a; }
.swatch.battle { width: 16px; height: 16px; margin: 0 3px; border-radius: 50%; background: #111; border: 2px solid #fff; box-shadow: 0 0 0 1px #111; }
.swatch.war { width: 12px; height: 12px; margin: 0 5px; transform: rotate(45deg); border-radius: 0; background: #fff; border: 2.5px solid #111; }

.tooltip { pointer-events: none; padding: 4px 9px; font-size: 13px; max-width: 260px; }
.loading { position: absolute; inset: 0; display: grid; place-content: center; padding: 20px; text-align: center; background: var(--paper); font-weight: 600; }

.panel { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: var(--paper); }
.search { padding: 8px 12px 0; display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); }
.search input { font-size: 15px; color: var(--ink); }
.tabs { display: flex; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border-radius: 8px 8px 0 0; border-bottom: 0; padding: 4px 6px; font-size: 13.5px; }
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.content { flex: 1; min-height: 0; overflow: auto; padding: 12px; overflow-wrap: anywhere; }

.content h2 { margin: 0 0 4px; font: 700 21px/1.2 Georgia, serif; }
.content h3 { margin: 18px 0 6px; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); }
.content h4 { margin: 0 0 2px; font-size: 15.5px; }
.content p { margin: 4px 0; }
.content ul { margin: 4px 0; padding-left: 18px; }
.content a { color: #0a4f9e; }
.meta { font-size: 12.5px; color: var(--muted); }
.card { margin: 8px 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.card.battle { border-left: 5px solid #111; }
.card.georgian { border-left: 5px solid var(--gold); }
.card.flash { box-shadow: 0 0 0 3px #0b63ce; }
.notice { margin: 8px 0; padding: 9px 11px; border-radius: 8px; background: #fff3cd; border: 1px solid #e5c46b; font-size: 13.5px; }
.gap { margin: 8px 0; padding: 9px 11px; border-radius: 8px; border: 1px dashed #a89c83; background: repeating-linear-gradient(45deg, #f6f2e8 0 8px, #efe9da 8px 9px); font-size: 13.5px; }
.badge { display: inline-block; margin: 0 4px 3px 0; padding: 0 7px; border-radius: 999px; background: #efe8d8; font-size: 11.5px; font-weight: 600; }
.badge.warn { background: #fff0bf; }
.links { margin-top: 5px; font-size: 12px; }
.links a { margin-right: 10px; }
.side { margin: 6px 0; font-size: 13.5px; }
.side b { display: block; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.actions button { min-height: 30px; font-size: 12.5px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chips button { min-height: 28px; padding: 2px 8px; font-size: 12.5px; }
.title-row { display: flex; align-items: center; gap: 9px; }
details.more summary { cursor: pointer; font-size: 13px; margin-top: 6px; }

@media (max-width: 820px) {
  .topbar { gap: 6px; padding: 6px 8px; }
  .brand { display: flex; align-items: baseline; gap: 8px; width: 100%; }
  .brand h1 { font-size: 18px; }
  .field > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .timebar > .field { width: 100%; }
  .timebar > .field select { width: 100%; }
  .stepper { width: 100%; justify-content: space-between; }
  .stepper .field { flex: 1; }
  .stepper #year { width: 100%; }
  .map-status span { display: none; }
  .tabs { padding-top: 6px; }
  .search { padding-top: 6px; }
  .timebar { width: 100%; gap: 5px; }
  .timebar > .field select { max-width: 100%; }
  .timebar button { min-height: 40px; padding: 4px 9px; }
  .timebar input, .timebar select { min-height: 40px; font-size: 16px; }
  #year { width: 78px; }
  .examples { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 2px; }
  .examples button { flex: none; }
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1.35fr) minmax(0, 1fr); }
  .panel { border-left: 0; border-top: 2px solid var(--line); }
  .search label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .map-status { top: 8px; bottom: auto; left: 8px; right: auto; max-width: calc(100% - 140px); }
  .map-status strong { font-size: 15px; }
  .map-status span { font-size: 11px; }
  .map-buttons button { font-size: 13px; padding: 3px 8px; }
}

@media (max-height: 560px) and (max-width: 820px) {
  body { overflow: auto; }
  .layout { flex: none; grid-template-rows: 70vh 70vh; }
}

/* Language switch */
.langs { display: flex; gap: 4px; order: 3; }
.langs button { min-height: 30px; font-size: 13px; padding: 3px 10px; }
.langs button[aria-pressed="true"] { background: #7a2e12; border-color: #7a2e12; color: #fff; }

/* Pictures of people */
.portrait { width: 56px; height: 70px; object-fit: cover; object-position: top; border-radius: 6px; border: 1px solid var(--line); background: #eee7da; }
.portrait.blank { display: inline-grid; place-content: center; font: 700 22px Georgia, serif; color: #8a7b62; }
.card.person > .portrait { float: right; margin: 0 0 6px 10px; }
.card.person { display: flow-root; }
.credit { font-size: 11px; color: var(--muted); }

.rulers { position: absolute; z-index: 5; width: 250px; max-width: calc(100% - 12px); padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; background: rgba(255, 255, 255, 0.97); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22); font-size: 12.5px; }
.rulers[hidden] { display: none; }
.rulers-title { font: 700 14px Georgia, serif; }
.rulers-year, .rulers-none, .rulers small { color: var(--muted); font-size: 11.5px; }
.rulers-year { margin-top: -6px; }
.ruler { display: flex; gap: 8px; align-items: center; }
.ruler .portrait { flex: none; width: 46px; height: 56px; }
.ruler small { display: block; }
@media (max-width: 820px) {
  .langs button { min-height: 32px; font-size: 12px; padding: 2px 8px; }
  .rulers { width: 210px; }
  .ruler .portrait { width: 38px; height: 46px; }
}
