:root {
  color-scheme: dark;
  --bg: #080b08;
  --surface: #10150f;
  --surface-2: #171d14;
  --surface-3: #202719;
  --ink: #eef3df;
  --muted: #aeb79f;
  --faint: #717a68;
  --line: #3b4434;
  --accent: #a8d36b;
  --accent-2: #d8b45f;
  --map-water: #0c1817;
  --map-land: #1f2b1d;
  --map-line: #40503d;
  --danger: #efdfaa;
  --shadow: 0 18px 60px rgb(0 0 0 / 0.35);
  --display: "DIN Condensed", "Avenir Next Condensed", "Arial Narrow", "Eurostile", "Bank Gothic", sans-serif;
  --sans: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

body[data-theme="light"] {
  color-scheme: light;
  --bg: #e5e0d2;
  --surface: #f1eddf;
  --surface-2: #e8e2d2;
  --surface-3: #dad3bf;
  --ink: #151811;
  --muted: #565d4d;
  --faint: #737866;
  --line: #aaa18c;
  --accent: #4f6e31;
  --accent-2: #77612a;
  --map-water: #d4ddd4;
  --map-land: #b8b79c;
  --map-line: #8b8b73;
  --danger: #2b2f22;
  --shadow: 0 16px 50px rgb(40 34 24 / 0.18);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-width: 1180px;
  min-height: 100%;
  overflow-y: auto;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  letter-spacing: 0;
}

a,
button,
input,
select {
  font: inherit;
}

button,
a {
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  overflow: visible;
}

.topbar {
  min-height: 78px;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--surface) 94%, transparent), var(--bg)),
    repeating-linear-gradient(0deg, transparent 0 11px, color-mix(in srgb, var(--line) 28%, transparent) 11px 12px);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 10px;
  max-width: 560px;
}

.topbar > div:first-child {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(28px, 3.4vw, 44px);
  line-height: 0.95;
}

h2 {
  font-size: 25px;
  line-height: 1;
}

.lede {
  max-width: 760px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.cta,
.actions a,
.secondary-action,
.drawer-actions button,
.download-action,
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface-3);
  color: var(--ink);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  cursor: pointer;
}

.cta {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--bg);
}

.cta:hover,
.secondary-action:hover,
.drawer-actions button:hover,
.download-action:hover,
.theme-toggle:hover,
.actions a:hover {
  transform: translateY(-1px);
  border-color: var(--accent-2);
  background: var(--accent-2);
  color: var(--bg);
}

.actions a.disabled,
.actions a.disabled:hover {
  transform: none;
  border-color: var(--line);
  background: transparent;
  color: var(--faint);
  cursor: not-allowed;
}

.theme-toggle {
  background: transparent;
  color: var(--accent);
}

.download-action {
  background: transparent;
  color: var(--ink);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.metrics div {
  padding: 9px 24px;
  border-right: 1px solid var(--line);
}

.metrics span {
  display: block;
  font-family: var(--display);
  color: var(--danger);
  font-size: 26px;
  line-height: 0.95;
}

.metrics label {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

.overview {
  height: clamp(500px, 58vh, 680px);
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.map-panel {
  min-width: 0;
}

.map-panel {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.groups-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 246px);
  border-bottom: 1px solid var(--line);
}

.section-head {
  min-height: 74px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.map-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.group-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  overflow: auto;
}

.group-card {
  min-height: 78px;
  padding: 13px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.group-card:hover,
.group-card.active {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
}

.group-card strong {
  display: block;
  min-height: 30px;
  font-family: var(--display);
  font-size: 20px;
  line-height: 0.95;
}

.group-card span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  line-height: 1.3;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  color: var(--accent);
  background: var(--surface);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.map-wrap {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 286px;
}

#map-svg {
  width: 100%;
  height: 100%;
  min-height: 0;
  cursor: grab;
  touch-action: none;
  background:
    radial-gradient(circle at 68% 48%, color-mix(in srgb, var(--accent) 13%, transparent), transparent 31%),
    repeating-linear-gradient(90deg, transparent 0 71px, color-mix(in srgb, var(--map-line) 45%, transparent) 71px 72px),
    repeating-linear-gradient(0deg, transparent 0 55px, color-mix(in srgb, var(--map-line) 45%, transparent) 55px 56px),
    var(--map-water);
}

#map-svg.dragging {
  cursor: grabbing;
}

.map-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.map-zoom-buttons {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.map-zoom-buttons button {
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 6px 9px;
  min-width: 30px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.map-zoom-buttons button:last-child {
  border-right: 0;
}

.map-zoom-buttons button:hover {
  background: var(--accent);
  color: var(--bg);
}

.map-grid {
  stroke: color-mix(in srgb, var(--map-line) 65%, transparent);
  stroke-width: 0.55;
}

.land {
  fill: var(--map-land);
  stroke: var(--map-line);
  stroke-width: 0.55;
}

.map-point {
  fill: var(--accent-2);
  stroke: var(--bg);
  stroke-width: 1.35;
  cursor: pointer;
}

.map-point.active {
  fill: var(--accent);
  stroke: var(--ink);
}

.map-label {
  fill: var(--ink);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 800;
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--map-water);
  stroke-width: 3.5px;
}

.map-list {
  min-height: 0;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--surface-2);
}

.map-list button {
  width: 100%;
  display: block;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 13px 14px;
  cursor: pointer;
}

.map-list button:hover,
.map-list button.active {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

.map-list strong {
  display: block;
  font-family: var(--display);
  font-size: 19px;
  line-height: 0.95;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.map-list span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
}

.workspace {
  min-height: 620px;
  display: grid;
  grid-template-columns: 318px minmax(520px, 1fr) 292px;
  background: var(--bg);
}

.records-panel,
.document-panel,
.evidence-panel {
  min-height: 0;
  border-right: 1px solid var(--line);
}

.records-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--surface);
}

.filters {
  padding: 12px;
  display: grid;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 2px;
  padding: 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

.record-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
}

.record-item {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.record-item:hover,
.record-item.active {
  background: color-mix(in srgb, var(--accent) 13%, transparent);
}

.empty-list {
  padding: 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.record-group {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.record-name {
  font-family: var(--display);
  font-size: 18px;
  line-height: 0.98;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.record-sub {
  margin-top: 8px;
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  line-height: 1.35;
}

.tag {
  color: var(--accent-2);
}

.document-panel {
  display: grid;
  grid-template-rows: auto auto 1fr;
  background: var(--surface);
}

.document-head,
.json-head {
  min-height: 78px;
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.document-head h2 {
  max-width: 780px;
  font-size: 24px;
}

.muted {
  color: var(--muted);
}

#record-meta {
  max-width: 820px;
  margin: 9px 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.45;
}

.record-chips {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.record-chips span {
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 5px 7px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
}

.actions {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.viewer-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.viewer-tabs button {
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 12px 16px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  cursor: pointer;
}

.viewer-tabs button:hover,
.viewer-tabs button.active {
  color: var(--bg);
  background: var(--accent);
}

.parsed-view {
  min-height: 0;
  display: grid;
  grid-template-columns: 96px 1fr;
}

.page-rail {
  overflow: auto;
  border-right: 1px solid var(--line);
  padding: 10px;
  background: var(--surface-2);
}

.page-rail button {
  width: 100%;
  display: block;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 2px;
  padding: 7px 5px;
  font-family: var(--mono);
  font-size: 10px;
  cursor: pointer;
}

.page-rail button:hover,
.page-rail button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--bg);
}

.page-output {
  min-width: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.page-output-head {
  min-height: 38px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 10px;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  overflow: auto;
  font-family: var(--mono);
  line-height: 1.55;
}

.block-stack {
  overflow: auto;
  padding: 18px 24px 34px;
}

.parsed-block {
  max-width: 920px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.parsed-block:first-child {
  padding-top: 0;
}

.parsed-block h3,
.parsed-block h4,
.parsed-block p {
  margin: 0;
}

.parsed-block h3 {
  color: var(--danger);
  font-size: 28px;
  line-height: 0.98;
}

.parsed-block h4 {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.text-lines {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}

.text-lines .bullet {
  padding-left: 18px;
  text-indent: -14px;
}

.table-wrap {
  overflow: auto;
  margin-top: 11px;
  border: 1px solid var(--line);
  background: var(--bg);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th,
.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--accent);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.figure-block {
  display: grid;
  gap: 11px;
}

.figure-block img {
  max-width: min(100%, 680px);
  border: 1px solid var(--line);
  background: var(--bg);
}

.caption {
  max-width: 75ch;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.empty-page {
  max-width: 720px;
  color: var(--muted);
  border: 1px dashed var(--line);
  padding: 16px;
  border-radius: 2px;
}

.view-pane[hidden] {
  display: none !important;
}

.evidence-panel {
  display: grid;
  align-content: start;
  background: var(--surface);
}

.evidence-section {
  padding: 17px;
  border-bottom: 1px solid var(--line);
}

.facts-list {
  margin: 14px 0 0;
  display: grid;
}

.facts-list div {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.facts-list dt {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.facts-list dd {
  margin: 0;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.35;
}

.location-card {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.location-card strong,
.location-card span {
  display: block;
}

.location-card strong {
  font-family: var(--display);
  font-size: 26px;
  line-height: 0.95;
  text-transform: uppercase;
}

.location-card span,
.supporting {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.secondary-action {
  width: 100%;
  margin-top: 13px;
}

.json-drawer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
}

.json-drawer.open {
  display: block;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 0.58);
}

.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(720px, 82vw);
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--bg);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.drawer-actions {
  display: flex;
  gap: 8px;
}

#json-output {
  padding: 18px;
  color: var(--accent);
  font-size: 12px;
}

.view-pane {
  min-height: 0;
}

.image-view {
  min-height: 0;
  overflow: auto;
  background: var(--bg);
}

.image-stage {
  min-height: 100%;
  display: grid;
  grid-template-columns: minmax(420px, 1fr) 320px;
  gap: 0;
}

.image-stack {
  min-width: 0;
  padding: 18px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.visual-frame {
  margin: 0;
  min-height: 360px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background:
    repeating-linear-gradient(45deg, color-mix(in srgb, var(--surface-2) 84%, transparent) 0 14px, var(--bg) 14px 28px);
}

.visual-frame img {
  display: block;
  max-width: 100%;
  max-height: min(68vh, 720px);
  object-fit: contain;
}

.image-notes {
  padding: 18px;
  border-left: 1px solid var(--line);
  background: var(--surface-2);
}

.image-notes h3 {
  color: var(--danger);
  font-size: 24px;
  line-height: 1;
}

.image-notes p:not(.eyebrow),
.visual-missing span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.visual-missing {
  min-height: 260px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 22px;
  border: 1px dashed var(--line);
  color: var(--muted);
}

.visual-missing strong {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.parsed-block {
  position: relative;
  scroll-margin-top: 16px;
}

.parsed-block.active {
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

.markdown-view {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.markdown-toolbar {
  min-height: 44px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.md-scope,
.md-actions {
  display: inline-flex;
  gap: 6px;
}

.md-scope button,
.md-actions button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 7px 10px;
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
}

.md-scope button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--bg);
}

.md-scope button:hover,
.md-actions button:hover {
  border-color: var(--accent);
  color: var(--ink);
}

#markdown-output {
  margin: 0;
  padding: 18px 22px;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  background: var(--bg);
  min-height: 0;
}

@media (max-width: 1280px) {
  body {
    min-width: 0;
  }

  .shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .overview {
    height: auto;
  }

  .map-panel {
    min-height: 560px;
  }

  .group-grid {
    grid-template-columns: 1fr;
  }

  .group-card {
    border-right: 0;
  }

  .map-wrap {
    min-height: 486px;
  }

  .workspace {
    grid-template-columns: 300px 1fr;
  }

  .evidence-panel {
    display: none;
  }

  .image-stage {
    grid-template-columns: 1fr;
  }

  .image-notes {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

}

@media (max-width: 860px) {
  body {
    overflow-x: hidden;
  }

  .shell {
    display: block;
    min-height: 100vh;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding: 16px;
  }

  .topbar > div:first-child {
    max-width: none;
  }

  h1 {
    font-size: 36px;
    overflow-wrap: anywhere;
  }

  .lede {
    font-size: 13px;
  }

  .top-actions {
    width: 100%;
    max-width: none;
    justify-content: flex-start;
  }

  .top-actions > * {
    flex: 1 1 calc(50% - 6px);
    min-width: 150px;
  }

  .cta {
    flex-basis: 100%;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metrics div {
    min-height: 76px;
    padding: 10px 14px;
  }

  .metrics div:last-child {
    grid-column: 1 / -1;
  }

  .overview {
    display: block;
  }

  .map-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .map-panel {
    min-height: 470px;
  }

  .section-head {
    height: auto;
    min-height: 60px;
    align-items: flex-start;
  }

  .map-title {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .map-controls {
    width: 100%;
    justify-content: space-between;
  }

  .group-card {
    min-height: 74px;
    border-right: 0;
  }

  .map-wrap {
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
  }

  #map-svg {
    height: 380px;
    min-height: 380px;
  }

  .map-list {
    height: auto;
    max-height: 220px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .workspace {
    display: block;
  }

  .records-panel {
    display: block;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .filters {
    position: sticky;
    top: 0;
    z-index: 5;
    grid-template-columns: 1fr;
  }

  .record-list {
    max-height: 360px;
  }

  .document-panel {
    display: block;
    border-right: 0;
  }

  .document-head {
    flex-direction: column;
    align-items: stretch;
    min-height: 0;
    padding: 14px;
  }

  .document-head h2 {
    font-size: 22px;
    overflow-wrap: anywhere;
  }

  .actions {
    width: 100%;
    justify-content: stretch;
  }

  .actions a {
    width: 100%;
    justify-content: center;
  }

  .viewer-tabs {
    overflow-x: auto;
  }

  .viewer-tabs button {
    flex: 0 0 auto;
    padding: 12px 14px;
  }

  .parsed-view {
    display: block;
  }

  .page-rail {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 8px 10px;
  }

  .page-rail button {
    flex: 0 0 auto;
    width: auto;
    min-width: 58px;
    margin: 0;
  }

  .page-output {
    display: block;
    min-height: 0;
  }

  .page-output-head {
    min-height: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 10px 12px;
  }

  .block-stack {
    padding: 14px 16px 28px;
    overflow: visible;
  }

  .parsed-block {
    max-width: none;
    padding: 14px 0;
  }

  .parsed-block h3 {
    font-size: 24px;
  }

  .text-lines {
    font-size: 13px;
  }

  .facts-list div {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .drawer-panel {
    width: 100%;
  }

  .markdown-toolbar {
    min-height: 0;
    flex-direction: column;
    align-items: stretch;
    padding: 10px;
  }

  .md-scope,
  .md-actions {
    width: 100%;
  }

  .md-scope button,
  .md-actions button {
    flex: 1 1 0;
  }

  #markdown-output {
    max-height: none;
    min-height: 420px;
    padding: 14px;
    font-size: 11px;
  }

  .image-stack {
    padding: 14px;
  }

  .image-stage {
    grid-template-columns: 1fr;
  }

  .visual-frame {
    min-height: 240px;
  }

  .visual-frame img {
    max-height: 60vh;
  }

  .image-notes {
    padding: 14px;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 32px;
  }

  .top-actions > * {
    flex-basis: 100%;
    min-width: 0;
    width: 100%;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .metrics div:last-child {
    grid-column: auto;
  }

  .section-head {
    flex-direction: column;
    gap: 10px;
  }

  .map-controls,
  .sort-row,
  .actions,
  .md-scope,
  .md-actions {
    flex-direction: column;
  }

  .map-controls select,
  .sort-row button,
  .actions a,
  .md-scope button,
  .md-actions button {
    width: 100%;
  }

  .record-list {
    max-height: 300px;
  }

  .viewer-tabs button {
    min-width: max-content;
  }

  .parsed-block h3 {
    font-size: 22px;
  }
}
