:root {
  --bg: #fbfaf7;
  --fg: #1f2328;
  --muted: #6a6f76;
  --grid: #e7e4dc;
  --line: #2d3a4a;
  --accent: #1f6feb;
  --span: #8a6d3b;
  --hover: #d1242f;
  --label-bg: #fbfaf7;
  --drop: rgba(31, 111, 235, 0.10);
  --cover: rgba(138, 109, 59, 0.09);
  --cover-edge: rgba(138, 109, 59, 0.35);
  --panel-bg: #ffffff;
  --border: #d8d4ca;
  --canvas-font: system-ui, "Segoe UI", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c;
    --fg: #e6e8eb;
    --muted: #9aa1a9;
    --grid: #262b31;
    --line: #a9b6c6;
    --accent: #58a6ff;
    --span: #d4a95e;
    --hover: #ff7b72;
    --label-bg: #15181c;
    --drop: rgba(88, 166, 255, 0.14);
    --cover: rgba(212, 169, 94, 0.10);
    --cover-edge: rgba(212, 169, 94, 0.35);
    --panel-bg: #1c2026;
    --border: #343a42;
  }
}
:root[data-theme="dark"] {
  --bg: #15181c;
  --fg: #e6e8eb;
  --muted: #9aa1a9;
  --grid: #262b31;
  --line: #a9b6c6;
  --accent: #58a6ff;
  --span: #d4a95e;
  --hover: #ff7b72;
  --label-bg: #15181c;
  --drop: rgba(88, 166, 255, 0.14);
  --cover: rgba(212, 169, 94, 0.10);
  --cover-edge: rgba(212, 169, 94, 0.35);
  --panel-bg: #1c2026;
  --border: #343a42;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--canvas-font);
}

.app { display: flex; flex-direction: column; height: 100dvh; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}
.toolbar h1 { font-size: 18px; margin: 0; flex: 1 1 auto; }
.buttons, .nav { display: flex; gap: 6px; }
.toolbar button {
  min-width: 36px;
  height: 36px;
  font-size: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--fg);
  cursor: pointer;
}
.toolbar button:hover { border-color: var(--accent); }
.toolbar button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); }

.zoom-level {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 72px;
  justify-content: center;
  font-size: 13px;
  color: var(--muted);
}
.zoom-level output { font-variant-numeric: tabular-nums; color: var(--fg); font-weight: 600; }

.menu-anchor { position: relative; }
.layers-menu {
  position: absolute;
  z-index: 10;
  inset-block-start: calc(100% + 6px);
  inset-inline-start: 0;
  display: grid;
  gap: 2px;
  min-width: 140px;
  padding: 8px 12px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  font-size: 14px;
}
.layers-menu label { display: flex; gap: 6px; align-items: center; white-space: nowrap; cursor: pointer; }
.layers-menu[hidden] { display: none; }
.toolbar button:focus-visible, .langs a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.langs { display: flex; gap: 8px; font-size: 14px; }
.langs a { color: var(--muted); text-decoration: none; }
.langs a[aria-current="true"] { color: var(--fg); font-weight: 600; }

.stage { position: relative; flex: 1 1 auto; min-height: 0; }
#timeline {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#timeline.pointing { cursor: pointer; }
.editing #timeline.pointing { cursor: move; }
#timeline.dragging { cursor: grabbing; }

.tooltip {
  position: absolute;
  transform: translate(-50%, calc(-100% - 14px));
  max-width: 280px;
  padding: 6px 10px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.panel {
  position: absolute;
  inset-block: 12px;
  inset-inline-end: 12px;
  width: min(360px, calc(100% - 24px));
  overflow: auto;
  padding: 16px 20px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}
.panel h2 { margin: 0 0 4px; font-size: 20px; padding-inline-end: 28px; }
.panel h3 { margin: 16px 0 4px; font-size: 14px; color: var(--muted); }
.panel .dates { margin: 0; color: var(--muted); }
.panel .links { margin: 0; padding-inline-start: 18px; }
.panel .links a { color: var(--accent); }
.panel .lang-tag {
  font-size: 11px;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  text-transform: uppercase;
}
.panel .part-of { margin: 8px 0 0; }
.panel .sub-events { margin: 0; padding-inline-start: 18px; }
.panel .event-link {
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.panel .lane-select { display: block; margin-top: 12px; font-size: 14px; }
.panel .lane-select select { font: inherit; margin-inline-start: 6px; }
.panel .hint { font-size: 13px; color: var(--muted); }
.panel .close {
  position: absolute;
  inset-block-start: 8px;
  inset-inline-end: 8px;
  width: 32px;
  height: 32px;
  font-size: 20px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.help { padding: 4px 16px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
