:root {
  --ink: #191510;
  --ink-soft: #241f18;
  --parchment: #f2e4c3;
  --parchment-dark: #d6c096;
  --panel: #221d16;
  --panel-raised: #2e271d;
  --panel-line: #4a3d2a;
  --text: #efe2c5;
  --muted: #b6a684;
  --accent: #b45a3c;
  --accent-soft: #8c3b2e;
  --gold: #d3a84f;
  --ok: #6fae78;
  --err: #c16459;
  --focus: #f2c14e;
  --actor: #e6c785;
  --grid: rgba(211, 168, 79, 0.16);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius: 10px;
  --font-body: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-ui: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(211, 168, 79, 0.12), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(140, 59, 46, 0.16), transparent 55%),
    var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}

h1,
h2,
h3 {
  font-family: var(--font-ui);
  letter-spacing: 0.02em;
  margin: 0 0 0.5rem;
}

h1 {
  font-size: 1.7rem;
  color: var(--parchment);
}

h2 {
  font-size: 1.25rem;
  color: var(--gold);
}

h3 {
  font-size: 1rem;
  color: var(--parchment-dark);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 50;
  background: var(--gold);
  color: var(--ink);
  padding: 0.6rem 1rem;
  font-family: var(--font-ui);
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
}

.chronicle-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: linear-gradient(180deg, rgba(46, 39, 29, 0.95), rgba(34, 29, 22, 0.95));
  border-bottom: 1px solid var(--panel-line);
  box-shadow: var(--shadow);
}

.brand .tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-family: var(--font-ui);
}

.header-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.9rem;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  color: var(--muted);
}

.control.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

select,
input[type="number"],
input[type="range"],
button {
  font-family: var(--font-ui);
  font-size: 0.9rem;
}

select,
input[type="number"] {
  background: var(--ink-soft);
  color: var(--text);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  min-width: 9rem;
}

input[type="range"] {
  accent-color: var(--gold);
}

button {
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

button:hover:not(:disabled) {
  background: #3a3125;
  border-color: var(--gold);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.spoiler-control {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--gold);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  background: var(--ink-soft);
  cursor: pointer;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-ok {
  color: #cdeccf;
  background: rgba(111, 174, 120, 0.18);
  border-color: rgba(111, 174, 120, 0.5);
}

.badge-err {
  color: #f4c8c2;
  background: rgba(193, 100, 89, 0.18);
  border-color: rgba(193, 100, 89, 0.5);
}

.tabbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.75rem 1.5rem 0;
  border-bottom: 1px solid var(--panel-line);
  background: rgba(25, 21, 16, 0.75);
}

.tab {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0.6rem 1.1rem;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.9rem;
}

.tab:hover:not(:disabled) {
  color: var(--text);
  background: rgba(211, 168, 79, 0.08);
}

.tab-active {
  background: var(--panel);
  border-color: var(--panel-line);
  color: var(--gold);
  box-shadow: inset 0 2px 0 var(--gold);
}

.chronicle-main {
  padding: 1.25rem 1.5rem 2rem;
  max-width: 1600px;
  margin: 0 auto;
}

.panel {
  background: linear-gradient(180deg, rgba(34, 29, 22, 0.92), rgba(29, 25, 19, 0.92));
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem 1.4rem;
  box-shadow: var(--shadow);
}

.panel-title {
  margin-bottom: 0.9rem;
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(260px, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.map-column,
.side-column {
  min-width: 0;
}

.map-frame {
  position: relative;
}

.chronicle-canvas {
  display: block;
  width: 100%;
  height: 460px;
  background: var(--ink);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  touch-action: none;
  cursor: grab;
}

.chronicle-canvas.dragging {
  cursor: grabbing;
}

.map-toolbar {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  display: flex;
  gap: 0.35rem;
  background: rgba(25, 21, 16, 0.8);
  padding: 0.3rem;
  border-radius: 8px;
  border: 1px solid var(--panel-line);
}

.map-toolbar button {
  min-width: 2.1rem;
  padding: 0.3rem 0.5rem;
}

.legend {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-family: var(--font-ui);
  font-size: 0.82rem;
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
}

.legend-swatch {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 3px;
  display: inline-block;
}

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-height: 520px;
  overflow-y: auto;
}

.feed li {
  background: var(--ink-soft);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font-size: 0.9rem;
}

.feed .meta {
  display: block;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.74rem;
  letter-spacing: 0.03em;
  margin-bottom: 0.15rem;
}

.feed .body {
  display: block;
  color: var(--text);
}

.feed .empty {
  color: var(--muted);
  font-style: italic;
}

.timeline-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.8rem;
  font-family: var(--font-ui);
  font-size: 0.85rem;
}

.timeline-controls input[type="range"] {
  flex: 1 1 220px;
}

.tick-label,
.caption {
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.82rem;
}

.caption {
  min-height: 1.4rem;
  margin: 0.6rem 0 0;
}

.warning {
  margin: 0 0 0.9rem;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  border: 1px solid rgba(193, 100, 89, 0.55);
  background: rgba(193, 100, 89, 0.14);
  color: #f6d1cb;
  font-family: var(--font-ui);
  font-size: 0.88rem;
}

.gazette {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.gazette .quote {
  background: var(--ink-soft);
  border-left: 3px solid var(--gold);
  border-radius: 0 8px 8px 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}

.gazette .quote .meta {
  display: block;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.74rem;
}

.legends-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.legend-block {
  background: var(--ink-soft);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  min-width: 0;
}

.legend-block.wide {
  grid-column: 1 / -1;
}

.svg-host {
  width: 100%;
  min-height: 180px;
}

.svg-host svg {
  display: block;
  width: 100%;
  height: auto;
}

.svg-host .empty {
  color: var(--muted);
  font-style: italic;
  font-family: var(--font-ui);
  font-size: 0.85rem;
}

.download-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.button-link {
  display: inline-block;
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
  padding: 0.45rem 0.9rem;
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: 0.88rem;
}

.button-link:hover {
  border-color: var(--gold);
  background: #3a3125;
}

.chronicle-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.5rem 1.4rem;
  border-top: 1px solid var(--panel-line);
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.8rem;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .panel-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .legends-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .chronicle-canvas {
    height: 360px;
  }

  .chronicle-main {
    padding: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
