/* Family Tree Studio
   The studio wears the family tree's own clothes: warm paper, deep green ink,
   a serif for names. The tree's lineage colours appear only as small dots so
   the preview stays the loudest thing on screen. */

:root {
  color-scheme: light;
  --paper: #f7f6f2;
  --paper-2: #efeee7;
  --panel: #fffefa;
  --line: #e4e4db;
  --line-strong: #d6d9ce;
  --ink: #28382b;
  --ink-2: #344a38;
  --muted: #5f6b5a;
  --faint: #8a9285;
  --accent: #3f6249;
  --accent-ink: #ffffff;
  --accent-soft: #e6ede1;
  --hover: #f0f2ea;
  --selected: #e3eadb;
  --warm: #b4570f;
  --warm-soft: #fbefe2;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --good: #2f7a4b;
  --focus: #28382b;
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-pop: 0 14px 36px -10px rgba(40, 56, 43, 0.28), 0 2px 6px rgba(40, 56, 43, 0.08);
  --side-w: clamp(340px, 30vw, 430px);
  --bar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 13px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
code { font: 0.92em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--paper-2); padding: 0.05em 0.35em; border-radius: 4px; }
kbd { font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

svg.i, .btn svg, .icon-btn svg, .menu svg {
  width: 16px; height: 16px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* ------------------------------------------------------------------ */
/* Layout                                                              */
/* ------------------------------------------------------------------ */

.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  grid-template-rows: var(--bar-h) minmax(0, 1fr);
}

.app[data-view="loading"] > *,
.app[data-view="welcome"] > :not(.welcome),
.app[data-view="studio"] > .welcome { display: none; }

/* ------------------------------------------------------------------ */
/* Buttons                                                             */
/* ------------------------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 13px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--panel); color: var(--ink-2);
  font-weight: 600; white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:active:not(:disabled) { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08); }
.btn.primary:hover:not(:disabled) { background: #355540; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger-soft); border-color: #f3c3bd; }
.btn.danger.confirming { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 7px; }
.btn.small svg { width: 14px; height: 14px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: var(--ink-2);
}
.icon-btn:hover:not(:disabled) { background: var(--hover); }
.icon-btn:disabled { opacity: 0.35; }
.icon-btn.small { width: 28px; height: 28px; border-radius: 7px; }
.icon-btn.small svg { width: 14px; height: 14px; }

.link-btn {
  border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600;
  text-decoration: underline; text-underline-offset: 2px; text-decoration-color: #a9bba9;
}
.link-btn:hover { text-decoration-color: currentColor; }

/* ------------------------------------------------------------------ */
/* Welcome                                                             */
/* ------------------------------------------------------------------ */

.welcome {
  grid-column: 1 / -1; grid-row: 1 / -1;
  display: grid; place-items: center;
  padding: 32px 16px;
  overflow: auto;
  background-color: var(--paper);
  background-image: radial-gradient(#d8d8cf 0.8px, transparent 0.8px);
  background-size: 20px 20px;
}
.welcome-card {
  width: min(560px, 100%);
  padding: 40px 40px 30px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  box-shadow: 0 30px 60px -30px rgba(40, 56, 43, 0.35);
}
.eyebrow { margin: 0; color: #65705e; font-size: 10.5px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; }
.welcome h1 { margin: 10px 0 10px; font: 400 34px/1.12 var(--serif); letter-spacing: -0.8px; color: var(--ink); text-wrap: balance; }
.lede { margin: 0 0 24px; color: var(--muted); font-size: 15px; line-height: 1.55; text-wrap: pretty; }
.drop {
  display: grid; justify-items: center; gap: 10px;
  padding: 26px 20px 22px;
  border: 1.5px dashed #c5cbbd; border-radius: 14px;
  background: #fbfbf6;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.drop.is-over { border-color: var(--accent); background: var(--accent-soft); }
.drop-art { width: 64px; height: 64px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.drop-art rect { fill: var(--panel); }
.drop-title { margin: 4px 0 4px; font-weight: 600; font-size: 14px; }
.drop-note { margin: 2px 0 0; color: var(--faint); font-size: 12px; }
.fine { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 18px 0 0; color: var(--muted); font-size: 12px; }
.fine .i { width: 14px; height: 14px; }
.welcome-error { margin: 14px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-size: 13px; }

/* ------------------------------------------------------------------ */
/* Top bar                                                             */
/* ------------------------------------------------------------------ */

.bar {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 14px;
  padding: 0 12px 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.brand-mark { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; }
.brand-mark circle { fill: var(--accent); stroke: none; }
.brand-name { font: 400 18px/1 var(--serif); letter-spacing: -0.3px; color: var(--ink); }
.file-chip {
  display: flex; align-items: baseline; gap: 10px; min-width: 0;
  padding-left: 14px; border-left: 1px solid var(--line);
}
.file-name { font-weight: 600; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-state { color: var(--faint); font-size: 12px; white-space: nowrap; }
.save-state.warn { color: var(--danger); }
.save-state .dot { display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--warm); vertical-align: 1px; }
.bar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.bar-sep { width: 1px; height: 22px; margin: 0 6px; background: var(--line); }
.pane-switch { display: none; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40;
  min-width: 248px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 12px;
  box-shadow: var(--shadow-pop);
}
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: 7px; background: transparent;
  text-align: left; color: var(--ink);
}
.menu button:hover:not(:disabled), .menu button:focus-visible { background: var(--hover); outline: none; }
.menu button:disabled { color: var(--faint); }
.menu button svg { color: var(--muted); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }

/* ------------------------------------------------------------------ */
/* Side panel                                                          */
/* ------------------------------------------------------------------ */

.side {
  grid-row: 2;
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.side-head { padding: 12px 12px 0; border-bottom: 1px solid var(--line); flex-shrink: 0; }

.search {
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: 9px; background: #fff;
}
.search:focus-within { outline: 2px solid var(--focus); outline-offset: 1px; }
.search .i { color: var(--faint); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search-key { padding: 1px 6px; border: 1px solid var(--line-strong); border-radius: 5px; color: var(--faint); background: var(--paper); }
.search:focus-within .search-key { display: none; }

.tabs { display: flex; gap: 2px; margin-top: 10px; }
.tabs [role="tab"] {
  position: relative;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 10px 11px;
  border: 0; background: none; color: var(--muted); font-weight: 600;
}
.tabs [role="tab"]:hover { color: var(--ink); }
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); }
.tabs [role="tab"][aria-selected="true"]::after {
  content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent);
}
.count {
  min-width: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--paper-2); color: var(--muted);
  font-size: 11px; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums;
}
.count:empty { display: none; }
.count.warm { background: var(--warm-soft); color: var(--warm); }

.side-body { flex: 1 1 0; min-height: 140px; overflow: auto; padding: 8px 0 16px; outline: none; }

/* Group headings in the people list */
.group + .group { margin-top: 10px; }
.group-head {
  position: sticky; top: -8px; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px 6px 14px;
  background: linear-gradient(var(--panel) 75%, rgba(255, 254, 250, 0));
}
.group-head h3 {
  margin: 0; font-size: 10.5px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
}
.group-head .count { margin-right: auto; }
.group-head .btn { margin-left: auto; }

/* Rows */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.row {
  --level: 0;
  position: relative;
  display: flex; align-items: center; gap: 7px;
  min-height: 32px;
  margin: 0 6px;
  padding: 3px 8px 3px calc(6px + var(--level) * 18px);
  border-radius: 7px;
  cursor: pointer;
  user-select: none;
}
.row:hover { background: var(--hover); }
.row[aria-selected="true"] { background: var(--selected); }
.row[aria-selected="true"]::before {
  content: ""; position: absolute; left: -6px; top: 6px; bottom: 6px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.row:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.twisty {
  display: inline-grid; place-items: center;
  width: 20px; height: 20px; margin: 0 -2px 0 -2px; padding: 0;
  border: 0; border-radius: 5px; background: none; color: var(--faint);
  flex-shrink: 0;
}
.twisty:hover { background: rgba(40, 56, 43, 0.08); color: var(--ink); }
.twisty svg { width: 13px; height: 13px; transition: transform 0.15s ease; stroke-width: 2.2; }
.twisty[aria-expanded="true"] svg { transform: rotate(90deg); }
.twisty-spacer { width: 16px; flex-shrink: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--dot, var(--faint)); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9); }
.row-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.row-label .nm { font-weight: 600; }
.amp { color: var(--faint); margin: 0 0.25em; }
.row-label .sp { color: var(--muted); }
.row-label .ph { color: var(--warm); font-style: italic; font-weight: 500; }
.row-label mark { background: #fdf0b8; color: inherit; border-radius: 2px; padding: 0 1px; }
.row-meta { color: var(--faint); font-size: 11.5px; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.row-lock { width: 12px; height: 12px; color: var(--faint); flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; }
.row.is-flash { animation: flash 1.2s ease; }
@keyframes flash { 0%, 30% { background: #f9e7b0; } 100% { background: transparent; } }

.empty-note { margin: 28px 20px; color: var(--muted); text-align: center; line-height: 1.6; }
.empty-note strong { display: block; color: var(--ink); font: 400 17px/1.3 var(--serif); margin-bottom: 4px; }
.empty-note .big-check { display: block; width: 36px; height: 36px; margin: 0 auto 8px; color: var(--good); fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Issues banner */
.issues { margin: 4px 12px 6px; padding: 9px 11px; border-radius: 9px; background: var(--danger-soft); color: #8f1f15; font-size: 12.5px; }
.issues.warn { background: var(--warm-soft); color: #8a4310; }
.issues p { margin: 0; display: flex; gap: 8px; align-items: baseline; }
.issues p + p { margin-top: 4px; }
.issues .link-btn { color: inherit; }

/* Fill-in list */
.fill-intro { margin: 6px 14px 10px; color: var(--muted); line-height: 1.5; }
.fill-intro strong { color: var(--ink); font: 400 16px/1.3 var(--serif); display: block; margin-bottom: 2px; }
.fill-row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 6px; align-items: center;
  margin: 0 8px; padding: 8px 6px 9px;
  border-bottom: 1px solid var(--line);
}
.fill-context { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.fill-context .ctx-was { color: var(--warm); font-style: italic; }
.fill-row input {
  height: 34px; padding: 0 10px; min-width: 0;
  border: 1px solid var(--line-strong); border-radius: 8px; background: #fff;
}
.fill-row input:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent; }
.fill-row.is-done input { border-color: #9cc5a9; background: #f3faf4; }
.fill-row.is-done .fill-context::after { content: "✓"; color: var(--good); font-weight: 700; }

/* Change list */
.change-list { list-style: none; margin: 0; padding: 4px 8px; }
.change-list li { display: flex; gap: 9px; align-items: flex-start; padding: 8px 8px; border-radius: 7px; }
.change-list li.clickable { cursor: pointer; }
.change-list li.clickable:hover { background: var(--hover); }
.change-tag {
  flex-shrink: 0; min-width: 62px; padding: 1px 7px; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; text-align: center;
  background: var(--paper-2); color: var(--muted);
}
.change-tag.added { background: #e3f3e8; color: #23683d; }
.change-tag.removed { background: var(--danger-soft); color: var(--danger); }
.change-tag.renamed { background: #e8eefb; color: #2f4f8f; }
.change-tag.moved { background: #f1ebfa; color: #5b3d8f; }
.change-foot { display: flex; justify-content: flex-end; padding: 10px 14px; }

/* ------------------------------------------------------------------ */
/* Inspector                                                           */
/* ------------------------------------------------------------------ */

.inspector {
  flex: 0 0 auto;
  max-height: 62%;
  overflow: auto;
  border-top: 1px solid var(--line-strong);
  background: #fdfcf7;
  box-shadow: 0 -10px 24px -18px rgba(40, 56, 43, 0.35);
}
.inspector:empty { display: none; }
.insp { padding: 14px 16px 18px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; margin: 0 0 4px; color: var(--faint); font-size: 11.5px; }
.crumbs button { border: 0; background: none; padding: 1px 3px; border-radius: 4px; color: var(--muted); }
.crumbs button:hover { background: var(--hover); color: var(--ink); }
.crumbs .sep { color: #c2c7bb; }
.insp-title { display: flex; align-items: flex-start; gap: 10px; }
.insp-title h2 { flex: 1; min-width: 0; margin: 0; font: 400 21px/1.2 var(--serif); letter-spacing: -0.3px; color: var(--ink); overflow-wrap: anywhere; }
.insp-title .icon-btn { margin: -4px -6px 0 0; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 2px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px; background: var(--paper-2); color: var(--muted);
  font-size: 11.5px; font-weight: 600;
}
.badge svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 2.2; }
.badge .dot { width: 7px; height: 7px; box-shadow: none; }

.sec { margin-top: 16px; }
.sec-title { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.sec-title .count { letter-spacing: 0; }

.field { display: grid; gap: 5px; margin-bottom: 10px; }
.field-label { display: flex; align-items: baseline; gap: 6px; font-weight: 600; color: var(--ink-2); font-size: 12.5px; }
.field-label small { color: var(--faint); font-weight: 500; }
.field-row { display: flex; gap: 6px; align-items: center; }
.field input[type="text"], .field select, .field textarea, .add-input {
  width: 100%; min-width: 0; height: 36px; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: 8px; background: #fff;
}
.field textarea, .add-input { height: auto; min-height: 36px; padding: 8px 10px; resize: none; line-height: 1.4; }
.field input:focus, .field select:focus, .field textarea:focus, .add-input:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent; }
.field input[readonly] { background: var(--paper); color: var(--muted); }
.field input.is-placeholder { color: var(--warm); font-style: italic; }
.field-hint { margin: 0; color: var(--faint); font-size: 11.5px; line-height: 1.45; }
.field-note { margin: 0 0 10px; padding: 9px 11px; border-radius: 8px; background: var(--paper); color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.add-spouse { margin: -2px 0 10px; }
.couple-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 4px 10px; border: 1px solid var(--line-strong); border-radius: 999px; background: #fff;
  color: var(--ink); font-size: 12.5px;
}
.chip:hover { background: var(--hover); border-color: #c5cbbd; }
.chip .ph { color: var(--warm); font-style: italic; }
.chip .dot { width: 6px; height: 6px; box-shadow: none; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.seg { display: inline-flex; padding: 2px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--paper); }
.seg button {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-weight: 600; font-size: 12px;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-checked="true"], .seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(40, 56, 43, 0.16), 0 0 0 1px rgba(40, 56, 43, 0.06); }
.seg button svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.seg.full { display: flex; }
.seg.full button { flex: 1; justify-content: center; }

.place-row { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; }
.muted-line { margin: 0; color: var(--muted); font-size: 12.5px; display: flex; gap: 7px; align-items: flex-start; line-height: 1.45; }
.muted-line svg { width: 13px; height: 13px; margin-top: 2px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; }

details.advanced { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
details.advanced summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 12.5px; list-style: none; display: flex; align-items: center; gap: 6px; }
details.advanced summary::-webkit-details-marker { display: none; }
details.advanced summary::before { content: "›"; display: inline-block; width: 10px; transition: transform 0.15s ease; font-size: 15px; line-height: 1; }
details.advanced[open] summary::before { transform: rotate(90deg); }
details.advanced .adv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; margin-top: 10px; }
details.advanced .field input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.insp-foot { display: flex; align-items: center; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.insp-foot .grow { flex: 1; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 4px; }
.stat { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.stat b { display: block; font: 400 22px/1.1 var(--serif); color: var(--ink); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 11.5px; }
.tips { margin: 14px 0 0; padding: 0; list-style: none; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.tips li { display: flex; gap: 8px; padding: 4px 0; }
.tips li::before { content: ""; flex-shrink: 0; width: 5px; height: 5px; margin-top: 7px; border-radius: 50%; background: #b9c2b1; }

/* ------------------------------------------------------------------ */
/* Preview pane                                                        */
/* ------------------------------------------------------------------ */

.stage-pane { grid-row: 2; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--paper-2); }
.stage-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  min-height: 48px; padding: 7px 10px 7px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.grow { flex: 1; }
.preview-status { color: var(--faint); font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.preview-status.busy::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  border: 1.6px solid #c8cdc0; border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); font-weight: 600; font-size: 12.5px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; width: 30px; height: 18px; border-radius: 999px; background: #cfd4c7; transition: background 0.15s ease; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); transition: transform 0.15s ease; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(12px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }

.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }

/* ------------------------------------------------------------------ */
/* Dialogs, toasts, drop overlay                                       */
/* ------------------------------------------------------------------ */

.dialog {
  width: min(500px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--line-strong); border-radius: 16px;
  background: var(--panel); color: var(--ink);
  box-shadow: 0 30px 80px -20px rgba(40, 56, 43, 0.45);
}
.dialog.small { width: min(420px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(32, 40, 33, 0.36); backdrop-filter: blur(2px); }
.dialog form { padding: 22px 22px 18px; }
.dialog-head h2 { margin: 0 0 4px; font: 400 22px/1.2 var(--serif); letter-spacing: -0.3px; }
.dialog-head p { margin: 0 0 16px; color: var(--muted); line-height: 1.5; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dialog-error { margin: 10px 0 0; padding: 9px 11px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); }

.choice { margin: 0 0 14px; padding: 0; border: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.choice legend { padding: 0; margin-bottom: 7px; font-weight: 600; color: var(--ink-2); font-size: 12.5px; }
.choice.compact { grid-template-columns: repeat(4, 1fr); }
.choice label { position: relative; cursor: pointer; }
.choice input { position: absolute; opacity: 0; }
.choice label > span {
  display: flex; flex-direction: column; gap: 2px; height: 100%;
  padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 10px; background: #fff;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.choice.compact label > span { flex-direction: row; align-items: center; justify-content: center; gap: 7px; padding: 8px 6px; font-weight: 600; }
.choice small { color: var(--faint); font-size: 11.5px; line-height: 1.3; }
.choice input:checked + span { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: #f8fbf6; }
.choice input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.swatch { width: 14px; height: 14px; border-radius: 4px; border: 1px solid #d3d6cb; flex-shrink: 0; }
.swatch.paper { background-color: #f7f6f2; background-image: radial-gradient(#b9b9ad 0.9px, transparent 0.9px); background-size: 4px 4px; }
.swatch.plain { background: #f7f6f2; }
.swatch.white { background: #fff; }
.swatch.clear { background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0 / 6px 6px; }
.check { display: flex; align-items: center; gap: 8px; margin: -4px 0 16px; color: var(--ink-2); cursor: pointer; }
.check input { width: 15px; height: 15px; accent-color: var(--accent); margin: 0; }

.toasts {
  position: fixed; left: 50%; bottom: 20px; z-index: 60;
  display: grid; gap: 8px; justify-items: center;
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 14px;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 12px 10px 16px;
  border-radius: 11px; background: #233127; color: #f3f5ef;
  box-shadow: 0 16px 34px -12px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
  animation: toast-in 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
.toast.warn { background: #6a2d0b; }
.toast.error { background: #7a1c13; }
.toast button { border: 0; background: rgba(255, 255, 255, 0.14); color: #fff; font-weight: 700; padding: 5px 10px; border-radius: 7px; }
.toast button:hover { background: rgba(255, 255, 255, 0.24); }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.2s ease, transform 0.2s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

.drop-overlay {
  position: fixed; inset: 0; z-index: 70;
  display: grid; place-items: center;
  background: rgba(63, 98, 73, 0.16);
  border: 3px dashed var(--accent);
  pointer-events: none;
}
.drop-overlay p { padding: 14px 22px; border-radius: 12px; background: var(--panel); box-shadow: var(--shadow-pop); font: 400 20px var(--serif); }

/* ------------------------------------------------------------------ */
/* Narrow screens: edit and preview take turns                         */
/* ------------------------------------------------------------------ */

@media (max-width: 1080px) {
  .file-chip .save-state { display: none; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .bar { flex-wrap: wrap; row-gap: 8px; padding: 8px 10px; }
  .brand-name { display: none; }
  .file-chip { border-left: 0; padding-left: 0; flex: 1; }
  .pane-switch { display: inline-flex; order: 5; width: 100%; padding: 2px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--paper); }
  .pane-switch button { flex: 1; height: 30px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-weight: 600; }
  .pane-switch button[aria-selected="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(40, 56, 43, 0.16); }
  .hide-sm { display: none; }
  .btn { padding: 0 10px; }
  .side, .stage-pane { grid-column: 1; grid-row: 2; }
  .app[data-pane="edit"] .stage-pane { display: none; }
  .app[data-pane="preview"] .side { display: none; }
  .side { border-right: 0; }
  .inspector { max-height: 58%; }
  .stage-bar { gap: 8px; }
  .welcome-card { padding: 28px 20px 22px; }
  .welcome h1 { font-size: 28px; }
  .choice { grid-template-columns: 1fr; }
  .choice.compact { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
