:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-subtle: #f7f7f8;
  --bg-hover: #f0f0f2;
  --map-bg: #ececef;
  --text: #1c1c1f;
  --text-muted: #6b6b73;
  --border: #e4e4e7;
  --border-strong: #d1d1d6;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --focus: rgba(37, 99, 235, .35);
  --tooltip-bg: #ffffff;
  --card-bg: #ffffff;
  --tab-active: #ffffff;
  --batch-surface: #fffaeb;
  --batch-surface-border: #f1e2b3;
  --batch-locked-surface: #f2f2f4;
  --shadow: 0 4px 16px rgba(0, 0, 0, .12);

  /* Map and chart layer colors. app.js reads these so the legend matches the canvas. */
  --layer-deaths: #e5484d;
  --layer-progress: #0091ff;
  --layer-checkpoints: #30a46c;
  --layer-hazards: #8e4ec6;
  --layer-reach: #f5a524;
  --chart-grid: rgba(0, 0, 0, .08);
  --chart-text: #6b6b73;

  --body: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --header-height: 52px;
}

/* The theme on <html>: chosen in the header, or the system one (index.html sets it before the first paint). */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161618;
  --bg-subtle: #1c1c1f;
  --bg-hover: #26262a;
  --map-bg: #0f0f11;
  --text: #ececef;
  --text-muted: #9b9ba3;
  --border: #2a2a2e;
  --border-strong: #3a3a40;
  --accent: #3b82f6;
  --focus: rgba(59, 130, 246, .45);
  --tooltip-bg: #232326;
  --card-bg: #26262a;
  --tab-active: #303035;
  --batch-surface: #24211a;
  --batch-surface-border: #3d3622;
  --batch-locked-surface: #1d1d20;
  --shadow: 0 4px 16px rgba(0, 0, 0, .5);
  --chart-grid: rgba(255, 255, 255, .08);
  --chart-text: #9b9ba3;
}

* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
body { margin: 0; overflow: hidden; color: var(--text); background: var(--bg); font: 13px/1.45 var(--body); }
button, select { font: inherit; color: inherit; }
h1, h2, h3, p, dl, dd { margin: 0; }
[hidden] { display: none !important; }

/* Header */
.topbar {
  height: var(--header-height); display: flex; align-items: center; gap: 24px;
  padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--bg);
}
.brand { display: inline-flex; align-items: center; gap: 6px; color: inherit; font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap; }
.brand img { display: block; width: 20px; height: 20px; }
/* Section tabs: plain links at rest, a grey button on hover, and a raised
   button for the open section. One weight and size for all, so nothing shifts. */
.page-nav { display: flex; align-items: center; gap: 4px; }
.page-tab {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border: 0; border-radius: 6px;
  background: none; color: var(--text-muted); cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: color .15s, background-color .15s, box-shadow .15s;
}
.page-tab svg {
  width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.page-tab:hover { background: var(--bg-hover); color: var(--text); }
.page-tab.active { background: var(--tab-active); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 0 0 1px var(--border-strong); }
.page-tab.active svg { color: var(--accent); }
.page-tab:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
/* Theme switcher: the icon of the chosen theme, a menu to change it. */
.theme { margin-left: auto; }
.theme + .account { margin-left: -14px; }
.theme-button {
  display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 6px;
  background: none; color: var(--text-muted); cursor: pointer;
}
.theme-button:hover, .theme-button[aria-expanded="true"] { background: var(--bg-hover); color: var(--text); }
.theme-button svg, .theme-menu .theme-check {
  width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.theme-menu { min-width: 160px; }
.theme-menu .theme-check { width: 15px; height: 15px; margin-left: auto; color: var(--accent); }
.account { position: relative; display: flex; align-items: center; color: var(--text-muted); white-space: nowrap; }
.account-login {
  display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 6px;
  color: var(--text); font-weight: 500; text-decoration: none;
}
.account-login:hover { background: var(--bg-hover); }
.account-avatar {
  position: relative; display: grid; place-items: center; width: 30px; height: 30px; flex: none; overflow: hidden; padding: 0;
  border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-text); cursor: pointer; font-size: 13px; font-weight: 600;
}
.account-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.account-avatar:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* Opens on hover or keyboard focus; the padding bridges the gap under the avatar. */
.account-menu {
  position: absolute; top: 100%; right: -8px; z-index: 20; display: none; min-width: 200px; max-width: 280px; padding: 14px 8px 8px;
}
.account:hover .account-menu, .account:focus-within .account-menu { display: grid; }
.account-menu::before {
  content: ""; position: absolute; inset: 6px 0 0; z-index: -1; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); box-shadow: var(--shadow);
}
.account-name, .account-email { overflow: hidden; padding: 0 8px; text-overflow: ellipsis; }
.account-name { color: var(--text); font-weight: 600; }
.account-email { margin-bottom: 6px; font-size: 12px; }
.account-action { height: 30px; padding: 0 8px; border: 0; border-radius: 5px; background: none; color: var(--text); cursor: pointer; font: inherit; text-align: left; }
.account-email + .account-action { border-top: 1px solid var(--border); border-radius: 0 0 5px 5px; }
.account-action:hover { background: var(--bg-hover); }
.account-version { margin-top: 6px; padding: 0 8px; color: var(--text-muted); font-size: 11px; font-weight: 300; opacity: .8; }
.account-version a { color: inherit; text-decoration: none; }
.account-version a:hover { text-decoration: underline; }

/* A modal over the page: settings, or the one thing an action needs first. */
.modal {
  width: min(440px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg); color: var(--text); box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(0, 0, 0, .35); }
.modal-body { display: grid; gap: 16px; padding: 20px; }
.modal h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-field { display: grid; gap: 6px; font-weight: 500; }
.modal-field input {
  width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg);
  color: inherit; font: 13px/1 var(--mono);
}
.modal-field input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.modal-hint { color: var(--text-muted); font-size: 12px; font-weight: 400; line-height: 1.45; }
.modal-hint kbd {
  display: inline-block; padding: 0 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px;
  background: var(--bg); color: var(--text); font: 500 11px/15px var(--body); white-space: nowrap; vertical-align: 1px;
}
.modal-hint strong { color: var(--text); font-weight: 500; white-space: nowrap; }
.modal-hint code { padding: 0 4px; border: 1px solid var(--border-strong); border-radius: 4px; background: var(--bg-subtle); color: var(--text); font: 11px/16px var(--mono); }
.modal-error { color: #e5484d; font-size: 12px; font-weight: 400; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions button {
  height: 32px; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg); color: var(--text);
  cursor: pointer; font: inherit;
}
.modal-actions button:hover { background: var(--bg-hover); }
.modal-actions button.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-text); font-weight: 500; }
.modal-actions button.primary:hover { filter: brightness(1.08); }
.modal-actions button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* Form controls */
select {
  width: 100%; height: 32px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--bg); cursor: pointer; font-variant-numeric: tabular-nums;
}
select:hover { border-color: var(--text-muted); }
select:focus-visible, button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
select:disabled { cursor: default; opacity: .5; }
.field { display: block; }
.field + .field { margin-top: 12px; }
.field > span { display: block; margin-bottom: 4px; color: var(--text-muted); font-size: 12px; }
.hint, .muted { color: var(--text-muted); font-size: 12px; }

/* Atlas layout */
.workspace { height: calc(100vh - var(--header-height)); display: grid; grid-template-columns: 240px minmax(0, 1fr) 300px; grid-template-rows: minmax(0, 1fr); }
/* Tall rails scroll inside the window instead of stretching the row past it. */
.workspace > * { min-height: 0; }
.control-rail, .insight-rail { overflow-y: auto; background: var(--bg); }
.control-rail { display: flex; flex-direction: column; border-right: 1px solid var(--border); }
.insight-rail { border-left: 1px solid var(--border); }
.rail-section { padding: 16px; border-bottom: 1px solid var(--border); }
.rail-section:last-child { border-bottom: 0; }
.rail-heading, .section-heading h3 { font-size: 12px; font-weight: 600; color: var(--text); }
.rail-heading { margin-bottom: 6px; }

.layer-toggle { display: flex; align-items: center; gap: 8px; padding: 5px 0; cursor: pointer; }
.layer-toggle input { margin: 0; accent-color: var(--accent); }
.swatch { flex: 0 0 12px; height: 12px; border-radius: 3px; }
.swatch-heat { background: linear-gradient(90deg, #ffd23f, #ef4830); }
.swatch-deaths { background: var(--layer-deaths); border-radius: 50%; }
.swatch-progress { height: 3px; background: var(--layer-progress); }
.swatch-checkpoints { width: 9px; height: 9px; flex-basis: 9px; margin: 0 1.5px; transform: rotate(45deg); border-radius: 1px; background: var(--layer-checkpoints); }
.swatch-hazards { border: 1.5px dashed var(--layer-hazards); }
.swatch-reach { height: 3px; background: var(--layer-reach); }
.layer-toggle + .hint { margin-top: 6px; }

.sync-control { margin-top: auto; border-top: 1px solid var(--border); }
.sync-control button {
  width: 100%; height: 32px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg); cursor: pointer;
}
.sync-control button:hover:not(:disabled) { background: var(--bg-hover); }
.sync-control button:disabled { cursor: default; opacity: .5; }
.sync-control .hint { margin-top: 6px; }

/* Map */
.map-column { min-width: 0; }
.map-viewport { position: relative; width: 100%; height: 100%; overflow: hidden; background: var(--map-bg); cursor: crosshair; touch-action: none; }
.map-viewport.panning { cursor: grabbing; }
#map-canvas, #design-canvas { display: block; width: 100%; height: 100%; }
.map-empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.map-empty.hidden { display: none; }
.map-empty h3 { font-size: 14px; font-weight: 600; }
.map-empty p { max-width: 320px; margin-top: 4px; color: var(--text-muted); }
.reach-note, .zoom-readout {
  position: absolute; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); font-size: 12px; pointer-events: none;
}
.reach-note { top: 12px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 24px); }
.zoom-readout { right: 12px; bottom: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; pointer-events: auto; }
.tooltip {
  position: absolute; z-index: 4; max-width: 280px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--tooltip-bg); box-shadow: var(--shadow); font-size: 12px; line-height: 1.5; font-variant-numeric: tabular-nums;
  pointer-events: none; opacity: 0; transform: translate(10px, 10px);
}
.tooltip.visible { opacity: 1; }
.tooltip strong { font-weight: 600; }

/* Toasts: short notices after an action, bottom centre, gone after a few seconds. */
.toasts {
  position: fixed; left: 50%; bottom: 24px; z-index: 1000; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  max-width: min(480px, calc(100vw - 32px)); padding: 8px 14px; border-radius: 8px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: 13px;
  opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s;
}
.toast.visible { opacity: 1; transform: none; }
.toast.error { background: #c4322f; color: #fff; }
.toast.warning { background: #f5a524; color: #1f1300; }

/* Loading: a small spinner inside any container marked data-loading. */
.spinner {
  display: none; flex: none; width: 12px; height: 12px; border: 1.5px solid var(--border-strong); border-top-color: var(--text-muted);
  border-radius: 50%; vertical-align: -2px; animation: spin .7s linear infinite;
}
[data-loading] .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.field .spinner { margin-left: 4px; }
.map-loading {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: none; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text-muted); font-size: 12px;
}
.map-viewport[data-loading] .map-loading { display: flex; }
.map-viewport[data-loading] .map-empty { display: none; }
/* Rail tabs: a spinner instead of the count, and a spinner line instead of empty content. */
.panel-loading { display: none; align-items: center; gap: 8px; padding: 12px 0; color: var(--text-muted); font-size: 12px; }
[data-loading] > .panel-loading { display: flex; }
.panel-tabs [role=tab][data-loading] .tab-count { display: none; }
.batches-panel[data-loading] > :not(.panel-loading):not(#batches-status) { display: none !important; }
.catalog-panel[data-loading] .catalog-list { display: none; }
.movement-loading { display: none; align-items: center; gap: 6px; color: var(--text-muted); }
.movement-page[data-loading] .movement-loading { display: flex; }
.movement-page[data-loading] .movement-empty { display: none; }

/* Summary rail */
.summary-title { display: flex; align-items: center; gap: 8px; }
.summary-header h2 { font-size: 18px; font-weight: 600; }
.summary-header p { margin-top: 2px; color: var(--text-muted); font-size: 12px; }
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 14px; }
.metric-grid dt { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.metric-grid dd { margin-top: 2px; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.section-heading span { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.cause-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; padding: 4px 0; }
.cause-row > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cause-count { color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.cause-bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--bg-hover); overflow: hidden; }
.cause-bar i { display: block; height: 100%; }

/* Each area is a button: a bordered row with a chevron, like a link to the map. */
.death-area-list { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.death-area-button {
  width: 100%; display: grid; grid-template-columns: 20px minmax(0, 1fr) auto 10px; align-items: center; gap: 8px;
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--card-bg); color: inherit;
  font: inherit; cursor: pointer; text-align: left; transition: background .12s, border-color .12s;
}
.death-area-button::after { content: "›"; color: var(--text-muted); font-size: 16px; line-height: 1; text-align: right; }
.death-area-button:hover, .death-area-button.active { border-color: var(--border-strong); background: var(--bg-hover); }
.death-area-button:hover::after { color: var(--text); }
.death-area-button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.death-area-number { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.death-area-copy { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.death-area-count { font-weight: 600; font-variant-numeric: tabular-nums; }
.death-area-list + .hint { margin-top: 6px; }
/* Only shown for warnings, e.g. a map that does not match the events. */
.source-note { color: var(--text-muted); font-size: 12px; }
.source-note:has(p:empty) { display: none; }

/* Movement page */
.movement-page { height: calc(100vh - var(--header-height)); overflow: auto; background: var(--bg-subtle); }
.movement-inner { max-width: 1100px; margin: 0 auto; padding: 24px 24px 48px; }
/* The description on the left, the build it describes on the right. */
.movement-hero { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.movement-build { flex: none; width: 240px; }
.movement-build .hint { min-height: 1.45em; margin-top: 4px; }
.movement-hero h1 { max-width: 760px; color: var(--text-muted); font-size: 14px; font-weight: 400; line-height: 1.5; }
.movement-empty { padding: 32px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.movement-empty h2 { font-size: 15px; font-weight: 600; }
.movement-empty p { margin-top: 4px; color: var(--text-muted); }
.capability-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.capability-strip article { padding: 14px 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.capability-strip span, .capability-strip small { display: block; color: var(--text-muted); font-size: 12px; }
.capability-strip strong { display: inline-block; margin: 4px 4px 0 0; font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.capability-strip small { display: inline; }
.movement-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card { min-width: 0; padding: 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.card-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card-heading h2 { font-size: 14px; font-weight: 600; }
.legend { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.legend i { width: 14px; height: 3px; margin-left: 6px; border-radius: 2px; }
.legend-jump { background: var(--layer-progress); }
.legend-wall { background: var(--layer-reach); }
.legend-speed { background: var(--layer-progress); }
.card canvas { display: block; width: 100%; height: 240px; margin-top: 12px; }
.chart-caption { margin-top: 8px; color: var(--text-muted); font-size: 12px; }
.detail-list { margin-top: 8px; }
.detail-list > div { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-top: 1px solid var(--border); }
.detail-list > div:first-child { border-top: 0; }
.detail-list dt { color: var(--text-muted); }
.detail-list dd { text-align: right; font-variant-numeric: tabular-nums; }
.method-note { margin-top: 16px; color: var(--text-muted); font-size: 12px; }

/* Level design */
.design-workspace { grid-template-columns: 250px minmax(0, 1fr) 340px; }
.design-level-note { margin-top: 8px; }
.tunnel-options { margin-top: 12px; }
.tunnel-options .layer-toggle { margin-top: 6px; }
#design-tunnel-note { margin-top: 8px; }
.category-toggle { display: grid; grid-template-columns: auto 12px minmax(0, 1fr) auto; }
.category-toggle.is-empty { opacity: .45; }
.category-count { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.muted-toggle { margin-top: 6px; color: var(--text-muted); }
.swatch-grid { border: 1px solid var(--text-muted); background: linear-gradient(var(--text-muted), var(--text-muted)) center / 1px 100% no-repeat, linear-gradient(var(--text-muted), var(--text-muted)) center / 100% 1px no-repeat; }
.swatch-zones { border: 1.5px dashed #5ec8ff; }
.coordinate-readout {
  position: absolute; left: 12px; bottom: 12px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; pointer-events: none;
}

/* The right rail is a tabbed panel: the tabs stay put, each panel scrolls on its own. */
.design-rail { display: flex; flex-direction: column; overflow: hidden; }
.design-rail > [role=tabpanel] { flex: 1 1 auto; min-height: 0; overflow-y: auto; border-bottom: 0; }
.panel-tabs {
  flex: none; display: flex; align-items: stretch; gap: 2px; height: 40px; padding: 0 8px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.panel-tabs [role=tab] {
  position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 0 10px; border: 0; background: none;
  color: var(--text-muted); cursor: pointer; font-size: 12px; font-weight: 500; white-space: nowrap;
}
.panel-tabs [role=tab]:hover, .panel-tabs [role=tab].active { color: var(--text); }
.panel-tabs [role=tab].active::after, .panel-tab-closable.active::after {
  content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; border-radius: 1px; background: var(--accent);
}
.panel-tabs [role=tab]:focus-visible { outline: 2px solid var(--focus); outline-offset: -6px; border-radius: 8px; }
.tab-count {
  min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--bg-hover); color: var(--text-muted);
  font-size: 11px; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums;
}
.tab-count:empty { display: none; }
.panel-tab-closable { position: relative; display: inline-flex; align-items: center; }
.panel-tab-closable [role=tab] { align-self: stretch; padding-right: 2px; }
.panel-tab-closable [role=tab]::after { display: none; }
.panel-tab-close {
  width: 20px; height: 20px; margin-right: 4px; border: 0; border-radius: 4px; background: none;
  color: var(--text-muted); cursor: pointer; font-size: 15px; line-height: 1;
}
.panel-tab-close:hover { background: var(--bg-hover); color: var(--text); }
.search-input {
  width: 100%; height: 32px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--bg); color: inherit; font: inherit;
}
.search-input:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.catalog-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0 4px; }
.catalog-heading {
  display: flex; align-items: center; gap: 6px; margin: 14px 0 6px; font-size: 12px; font-weight: 600;
}
.catalog-heading i { width: 10px; height: 10px; border-radius: 3px; }
.catalog-heading span { margin-left: auto; color: var(--text-muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.catalog-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.catalog-card {
  min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 4px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); cursor: pointer; text-align: left;
}
.catalog-card:hover { background: var(--bg-hover); }
.catalog-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.catalog-thumb {
  position: relative; display: grid; place-items: center; aspect-ratio: 1; border-radius: 5px; overflow: hidden;
  background: repeating-conic-gradient(var(--bg-hover) 0% 25%, var(--bg-subtle) 0% 50%) 50% / 12px 12px;
}
.catalog-thumb img { width: 100%; height: 100%; object-fit: contain; }
.catalog-thumb.no-image {
  color: var(--text-muted); font-size: 10px; text-align: center;
  background: color-mix(in srgb, var(--category) 18%, var(--bg-subtle));
}
.catalog-badge {
  position: absolute; top: 3px; right: 3px; min-width: 18px; padding: 0 4px; border-radius: 9px;
  background: var(--accent); color: var(--accent-text); font-size: 10px; font-weight: 600; line-height: 16px; text-align: center;
}
.catalog-name { overflow: hidden; font-size: 11px; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.catalog-meta { color: var(--text-muted); font-size: 10px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.selection-header { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 10px; align-items: start; }
.selection-header h2 { overflow-wrap: anywhere; font-size: 14px; font-weight: 600; }
.selection-header p { margin-top: 2px; color: var(--text-muted); font-size: 12px; }
.selection-panel .detail-list { margin-top: 10px; }
.selection-panel .detail-list > div { padding: 6px 0; }
.selection-panel .detail-list dd { min-width: 0; overflow-wrap: anywhere; }
.selection-panel .detail-list dd.mono { font: 11px/1.4 var(--mono); }
.selection-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.selection-actions button, .level-chip {
  height: 28px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg); cursor: pointer;
}
.selection-actions button:hover, .level-chip:hover { background: var(--bg-hover); }
.level-uses { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 12px; }
.level-uses h3 { width: 100%; margin-bottom: 2px; font-size: 12px; font-weight: 600; }
.level-chip { height: 24px; padding: 0 8px; font-size: 11px; font-variant-numeric: tabular-nums; }
.level-chip.current { border-color: var(--accent); color: var(--accent); }

/* Level edits */
.task-toolbar {
  position: absolute; top: 12px; left: 12px; right: 12px; z-index: 3; display: flex; flex-wrap: wrap; gap: 4px; pointer-events: none;
}
.task-toolbar button {
  height: 30px; display: inline-flex; align-items: center; gap: 6px; padding: 0 10px 0 8px; border: 1px solid var(--border-strong);
  border-radius: 6px; background: var(--bg); box-shadow: var(--shadow); cursor: pointer; font-size: 12px; pointer-events: auto;
}
.task-toolbar svg {
  width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.task-toolbar button:hover { background: var(--bg-hover); }
.task-toolbar button.active { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.task-hint {
  position: absolute; top: 50px; left: 12px; z-index: 3; max-width: min(560px, calc(100% - 24px)); padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--bg); box-shadow: var(--shadow); font-size: 12px; pointer-events: none;
}
.task-popover {
  position: absolute; z-index: 5; width: 280px; display: grid; gap: 8px; padding: 10px; border: 1px solid var(--border-strong);
  border-radius: 8px; background: var(--bg); box-shadow: var(--shadow);
}
.task-popover-title { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.task-popover-title::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--edit-color, var(--accent)); }
.task-popover textarea {
  width: 100%; max-height: 50vh; padding: 6px 8px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg); color: inherit; font: inherit; resize: vertical;
}
.task-popover textarea:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.task-popover-actions { display: flex; gap: 6px; }
.task-popover-actions button {
  height: 28px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg); cursor: pointer;
}
.task-popover-actions button:first-child { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.task-popover-actions button.danger { margin-left: auto; color: #e5484d; }
.map-viewport[data-tool="comment"], .map-viewport[data-tool="addition"], .map-viewport[data-tool="measurement"] { cursor: copy; }
.map-viewport[data-tool="cut"], .map-viewport[data-tool="insertion"] { cursor: col-resize; }
.map-viewport.space-pan { cursor: grab; }

.batches-panel .hint { margin-bottom: 8px; }
.task-toolbar button:disabled { cursor: not-allowed; opacity: .45; }
.tab-count.attention { background: var(--accent); color: var(--accent-text); }

/* Batches: the level's list, then one open batch. */
.batches-login {
  display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 6px;
  color: var(--text); font-weight: 500; text-decoration: none;
}
.batches-login:hover { background: var(--bg-hover); }
.batch-list { display: grid; }
.batch-new {
  height: 32px; border: 1px dashed var(--border-strong); border-radius: 6px; background: none; color: var(--text); cursor: pointer; font-weight: 500;
}
.batch-new:hover { border-style: solid; background: var(--bg-hover); }
.batch-list > .hint { margin: 12px 0 0; }
/* Sets are cards, like the edits in a set: bordered, with a chevron, so they
   read as something to open. */
.batch-group { display: grid; gap: 6px; margin: 0; }
/* Every group heading has the same rhythm: 16px above, 6px to its first row. */
.batch-group h4, .batch-group summary {
  margin: 0; padding: 16px 0 0; color: var(--text-muted); font-size: 11px; font-weight: 600; line-height: 16px;
  letter-spacing: .02em; text-transform: uppercase;
}
.batch-group summary { display: block; cursor: pointer; list-style: none; }
.batch-group summary::-webkit-details-marker { display: none; }
.batch-group summary::after { content: " ▸"; }
.batch-group[open] summary::after { content: " ▾"; }
.batch-group summary:hover { color: var(--text); }
.batch-group summary:focus { outline: none; }
.batch-group summary:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.batch-group > .task-warning { margin: 0 0 6px; }
/* The unfinished sets need no heading: each card shows its status. */
.batch-group.untitled { margin-top: 12px; }
.batch-card {
  position: relative; display: grid; justify-items: start; gap: 3px; width: 100%; padding: 10px 16px; border: 0;
  background: none; color: inherit; font: inherit; text-align: left;
}
.batch-group > button.batch-card {
  padding: 10px 30px 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--card-bg);
  transition: background .12s, border-color .12s;
}
.batch-group > button.batch-card::after {
  content: "›"; position: absolute; top: 50%; right: 12px; transform: translateY(-50%); color: var(--text-muted); font-size: 18px; line-height: 1;
}
button.batch-card { cursor: pointer; }
.batch-group > button.batch-card:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.batch-group > button.batch-card:hover::after { color: var(--text); }
/* The grey draft chip would vanish into the hovered card. */
.batch-group > button.batch-card:hover .batch-status.status-draft { background: var(--card-bg); }
.batch-group > button.batch-card:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.batch-card-title { max-width: 100%; font-size: 13px; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.batch-card-meta { color: var(--text-muted); font-size: 12px; }
.batch-card-other { color: #d97706; font-size: 12px; }
.batch-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; }
.batch-card-count { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.batch-header .batch-card-top { padding-right: 28px; }
.batch-status {
  align-self: start; padding: 1px 7px; border-radius: 9px; background: var(--bg-hover); color: var(--text-muted);
  font-size: 11px; font-weight: 500; white-space: nowrap;
}
.batch-status.status-submitted { background: rgba(37, 99, 235, .14); color: var(--accent); }
.batch-status.status-in_progress { background: rgba(245, 165, 36, .18); color: #b7791f; }
.batch-status.status-review { background: rgba(124, 58, 237, .14); color: #7c3aed; }
.batch-status.status-done { background: rgba(70, 167, 88, .16); color: #2f855a; }
.batch-back { margin: -4px 0 8px -6px; padding: 4px 6px; border: 0; border-radius: 6px; background: none; color: var(--text-muted); cursor: pointer; }
.batch-back:hover { background: var(--bg-hover); color: var(--text); }
/* The open set: its header is a tinted full-width band, the edits follow
   in the same column. */
/* The open set: its header on top and its edits below as cards, in one
   full-width column down to the bottom of the rail. Yellow like an editing
   mode while it is a draft, grey once it is sent to work and locked. */
.batch-view:not([hidden]) { display: flex; flex-direction: column; min-height: 100%; }
.batch-sheet {
  flex: 1; display: flex; flex-direction: column; margin: 0 -16px -16px; padding: 12px 16px 16px;
  border-top: 1px solid var(--batch-surface-border); background: var(--batch-surface);
}
.batch-sheet.locked { border-top-color: var(--border); background: var(--batch-locked-surface); }
.batch-header { padding: 0; border: 0; background: none; }
.batch-body { padding: 14px 0 0; }
.batch-body .task-list { display: grid; gap: 6px; margin: 0; }
.batch-body .task-item { border: 1px solid var(--border); border-radius: 8px; background: var(--card-bg); }
.batch-body .task-item.selected { border-color: var(--border-strong); background: var(--card-bg); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
/* Inside a card the whole card reacts, not just its first row. */
.batch-body .task-head:hover { background: none; }
.batch-body .task-item:hover { border-color: var(--border-strong); }
.batch-body .task-empty {
  padding: 14px 12px; border: 1px dashed var(--border-strong); border-radius: 8px; background: none; text-align: center;
}
.batch-header .batch-card-title { padding-right: 24px; cursor: text; }
.batch-header-menu { position: absolute; top: -3px; right: -6px; }
.batch-header > .batch-warning, .batch-header > .batch-dialog { justify-self: stretch; }
.batch-header > .batch-dialog { margin-top: 6px; }
.batch-warning { margin: 0; }
.batch-history { display: grid; grid-template-columns: max-content minmax(0, 1fr) auto; gap: 3px 12px; font-size: 12px; }
.batch-dialog-title { color: var(--text); font-weight: 600; }
.batch-dialog-close { display: flex; justify-content: flex-end; }
.batch-dialog-close button {
  height: 28px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg); color: var(--text); cursor: pointer;
}
.batch-dialog-close button:hover { background: var(--bg-hover); }
.batch-history-row { display: contents; color: var(--text-muted); }
.batch-history-row > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.batch-history-who { color: var(--text); }
.batch-history-row time { font-variant-numeric: tabular-nums; text-align: right; }
.task-empty { padding: 4px 8px; }
.batch-back { align-self: flex-start; }
.task-list { margin: 0 -8px; padding: 0; list-style: none; }
.task-item { position: relative; border-radius: 6px; }
.task-item.selected { background: var(--bg-subtle); box-shadow: inset 0 0 0 1px var(--border-strong); }
.task-item:not(.selected) { cursor: pointer; }
.task-item.status-done .task-text, .task-item.status-rejected .task-text { opacity: .55; }
.task-item.status-rejected .task-text strong { text-decoration: line-through; }
.task-head {
  width: 100%; display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px; align-items: start; padding: 6px 34px 6px 8px;
  border: 0; background: none; cursor: pointer; text-align: left;
}
.task-head:hover { background: var(--bg-hover); border-radius: 6px; }
.task-number {
  width: 22px; height: 22px; border-radius: 50%; color: #111; font-size: 11px; font-weight: 700; line-height: 22px; text-align: center;
}
.task-text { min-width: 0; display: flex; flex-direction: column; }
.task-text strong { font-size: 12px; font-weight: 600; }
.task-summary { overflow: hidden; color: var(--text-muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.task-note-preview, .task-warning { margin: -2px 8px 6px 38px; font-size: 12px; }
/* An edit's own status, under its summary; its ⋯ menu changes it. */
.task-status {
  display: inline-block; margin: -2px 8px 6px 38px; padding: 1px 7px; border-radius: 9px;
  background: var(--bg-hover); color: var(--text-muted); font-size: 11px; font-weight: 500; white-space: nowrap;
}
.task-status.status-in_progress { background: rgba(245, 165, 36, .18); color: #b7791f; }
.task-status.status-review { background: rgba(124, 58, 237, .14); color: #7c3aed; }
.task-status.status-done { background: rgba(70, 167, 88, .16); color: #2f855a; }
.task-note-preview { color: var(--text-muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.task-warning { color: #d97706; }
.task-body { display: grid; gap: 8px; padding: 0 8px 10px 38px; }
.task-body textarea, .task-field input {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg); color: inherit; font: inherit; resize: vertical;
}
.task-body textarea:focus-visible, .task-field input:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
/* It grows to its text (batches.js fitNote), so it never needs its own scrollbar. */
.task-body textarea { overflow-y: hidden; }
.task-field { display: grid; grid-template-columns: 1fr 90px; align-items: center; gap: 8px; color: var(--text-muted); font-size: 12px; }
.task-note-text { color: var(--text); font-size: 12px; white-space: pre-wrap; }

/* "⋯" menus of the open set and of each edit. */
.menu-button {
  width: 26px; height: 26px; flex: none; padding: 0; border: 0; border-radius: 6px; background: none;
  color: var(--text-muted); cursor: pointer; font-size: 16px; font-weight: 700; line-height: 1;
}
.menu-button:hover, .menu-button[aria-expanded="true"] { background: var(--bg-hover); color: var(--text); }
.menu-button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.task-menu { position: absolute; top: 4px; right: 4px; }
.task-item:not(:hover):not(.selected) .task-menu:not([aria-expanded="true"]):not(:focus-visible) { opacity: .45; }
.dropdown-menu {
  position: fixed; z-index: 50; display: grid; min-width: 200px; padding: 4px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); box-shadow: var(--shadow);
}
.dropdown-menu button {
  display: flex; align-items: center; gap: 9px; height: 30px; padding: 0 10px; border: 0; border-radius: 5px; background: none;
  color: var(--text); cursor: pointer; font: inherit; text-align: left; white-space: nowrap;
}
.dropdown-menu svg {
  width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  color: var(--text-muted);
}
.dropdown-menu button.danger svg { color: inherit; }
.dropdown-menu button:hover:not(:disabled), .dropdown-menu button:focus-visible { outline: none; background: var(--bg-hover); }
.dropdown-menu button:disabled { cursor: default; opacity: .45; }
.dropdown-menu button.danger { color: #e5484d; }
/* "Статус" opens a submenu of the fixed list of statuses; the current one is marked. */
.menu-hint { margin-left: auto; padding-left: 16px; color: var(--text-muted); font-size: 12px; }
.dropdown-menu button.has-submenu::after { content: "›"; margin-left: 8px; color: var(--text-muted); font-size: 15px; line-height: 1; }
.dropdown-menu button.has-submenu:not(:has(.menu-hint))::after { margin-left: auto; }
.dropdown-menu button[aria-expanded="true"] { background: var(--bg-hover); }
.dropdown-menu button.current { background: var(--bg-subtle); font-weight: 600; cursor: default; }
.dropdown-menu button.current:hover { background: var(--bg-subtle); }
.menu-separator { height: 1px; margin: 4px 6px; background: var(--border); }

/* Short questions under the set title: a name before sending, or delete. */
.batch-dialog { display: grid; gap: 8px; padding: 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--bg); }
.batch-dialog.danger { border-color: rgba(229, 72, 77, .4); background: rgba(229, 72, 77, .06); }
.batch-dialog p { font-size: 12px; }
.batch-dialog input, .batch-rename {
  width: 100%; height: 30px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg); color: inherit; font: inherit;
}
.batch-dialog input:focus-visible, .batch-rename:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.batch-dialog-actions { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px; }
.batch-dialog-actions button {
  height: 28px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg); color: var(--text); cursor: pointer;
  white-space: nowrap;
}
.batch-dialog-actions button:hover { background: var(--bg-hover); }
.batch-dialog-actions button.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-text); font-weight: 500; }
.batch-dialog-actions button.danger-solid { border-color: #e5484d; background: #e5484d; color: #fff; }
.batch-rename-field { display: grid; gap: 4px; font-size: 12px; font-weight: 400; color: var(--text-muted); }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 220px minmax(0, 1fr) 260px; }
  .design-workspace { grid-template-columns: 220px minmax(0, 1fr) 300px; }
  .catalog-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: 220px minmax(0, 1fr); }
  .insight-rail { display: none; }
  .capability-strip { grid-template-columns: 1fr 1fr; }
  .movement-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  body { overflow: auto; }
  .topbar { height: auto; flex-wrap: wrap; gap: 8px 16px; padding: 8px 16px 0; }
  .page-nav { order: 3; width: 100%; height: 40px; overflow-x: auto; }
  .workspace, .movement-page { height: auto; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: none; }
  .control-rail { border-right: 0; border-bottom: 1px solid var(--border); }
  .sync-control { border-top: 0; }
  .map-column { height: 70vh; min-height: 420px; }
}
/* Drawn to when a tool is used with drafts to choose from. */
.batch-list.attention .batch-card.status-draft { animation: batch-attention 1.2s ease-out 2; }
/* Drawn to when a tool is used on a set that is no longer a draft. */
.batch-status.attention { animation: status-attention .6s ease-in-out 3; }
@keyframes status-attention { 50% { box-shadow: 0 0 0 3px color-mix(in srgb, #d97706 45%, transparent); } }
@keyframes batch-attention { 0%, 100% { background: transparent; } 30% { background: color-mix(in srgb, #d97706 18%, transparent); } }

/* Pictures attached to an edit: thumbnails before its note (small on a
   folded card), a "+" to add more, and a picture dropped on a card. */
.task-images { display: flex; flex-wrap: wrap; gap: 6px; }
.task-item > .task-images { margin: -2px 8px 8px 38px; }
.task-image { position: relative; width: 64px; height: 64px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--bg-subtle); }
.task-images.small .task-image { width: 40px; height: 40px; border-radius: 5px; }
.task-image-view { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.task-image-view img { display: block; width: 100%; height: 100%; object-fit: cover; }
.task-image-view:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.task-image.uploading img { opacity: .45; }
.task-image.uploading::after {
  content: ""; position: absolute; top: 50%; left: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px;
  border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
}
.task-image-remove {
  position: absolute; top: 3px; right: 3px; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .62); color: #fff; cursor: pointer; font-size: 13px; line-height: 18px; opacity: 0; transition: opacity .12s;
}
.task-image:hover .task-image-remove, .task-image-remove:focus-visible { opacity: 1; }
.task-image-add {
  width: 64px; height: 64px; border: 1px dashed var(--border-strong); border-radius: 6px; background: none;
  color: var(--text-muted); cursor: pointer; font-size: 22px; font-weight: 300;
}
.task-image-add:hover { border-style: solid; background: var(--bg-hover); color: var(--text); }
.task-item.drop-target { box-shadow: inset 0 0 0 2px var(--accent); }

/* A picture opened over the page. */
.lightbox {
  position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; gap: 10px; align-content: center;
  padding: 24px 64px; background: rgba(10, 10, 12, .86);
}
.lightbox img { max-width: 100%; max-height: calc(100vh - 110px); border-radius: 6px; box-shadow: 0 8px 40px rgba(0, 0, 0, .5); background: #fff; }
.lightbox-caption { display: flex; gap: 16px; color: rgba(255, 255, 255, .8); font-size: 13px; }
.lightbox-caption a { color: inherit; }
.lightbox-close, .lightbox-arrow {
  position: absolute; border: 0; background: rgba(255, 255, 255, .12); color: #fff; cursor: pointer; border-radius: 50%;
}
.lightbox-close { top: 16px; right: 16px; width: 36px; height: 36px; font-size: 22px; line-height: 36px; }
.lightbox-arrow { top: 50%; width: 44px; height: 44px; margin-top: -22px; font-size: 28px; line-height: 40px; }
.lightbox-arrow.previous { left: 12px; }
.lightbox-arrow.next { right: 12px; }
.lightbox-close:hover, .lightbox-arrow:hover { background: rgba(255, 255, 255, .24); }
