/* Raíces — editorial family-history studio */
:root {
  --paper: #f4eee2;
  --paper-2: #efe7d7;
  --card: #fffcf6;
  --ink: #1d2721;
  --ink-2: #4a4639;
  --muted: #7d715c;
  --line: #e0d4bd;
  --line-2: #cfc0a3;
  --forest: #234a3c;
  --forest-2: #2e5a49;
  --forest-soft: #dfe7dc;
  --terra: #b8563d;
  --terra-soft: #f5e1d8;
  --gold: #c9a96a;
  --danger: #a8402c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(58, 44, 24, .06), 0 8px 28px rgba(58, 44, 24, .10);
  --shadow-lg: 0 2px 6px rgba(58, 44, 24, .08), 0 24px 60px rgba(58, 44, 24, .18);
  --serif: 'Fraunces', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --sans: 'Instrument Sans', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --topbar-h: 68px;
  --panel-w: 400px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg { display: block; }
kbd {
  font-family: var(--sans); font-size: .8em; padding: 1px 6px; border-radius: 5px;
  background: var(--card); border: 1px solid var(--line-2); box-shadow: 0 1px 0 var(--line-2);
}
:focus-visible { outline: 2.5px solid var(--forest-2); outline-offset: 2px; border-radius: 6px; }

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 100; padding: 8px 14px;
  background: var(--forest); color: var(--paper); border-radius: 8px; text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; font-size: 14px; letter-spacing: .01em; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .1s, box-shadow .15s;
}
.btn svg { width: 17px; height: 17px; flex: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--forest); color: #f7f2e8; box-shadow: 0 1px 0 rgba(0,0,0,.12), inset 0 1px 0 rgba(255,255,255,.08); }
.btn-primary:hover { background: #1b3c30; }
.btn-ghost { background: transparent; border-color: var(--line-2); color: var(--ink); }
.btn-ghost:hover { background: rgba(255,255,255,.6); border-color: var(--muted); }
.btn-danger { background: var(--danger); color: #fff6f2; }
.btn-danger:hover { background: #8e3221; }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { background: var(--terra-soft); border-color: var(--terra); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; gap: 6px; }
.btn-sm svg { width: 15px; height: 15px; }
.btn-lg { height: 48px; padding: 0 22px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border-radius: 999px; border: 1px solid transparent; background: transparent; color: var(--ink-2);
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover:not(:disabled) { background: rgba(35, 74, 60, .08); color: var(--forest); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn-sm { width: 32px; height: 32px; }
.icon-btn-sm svg { width: 16px; height: 16px; }
.link-btn {
  background: none; border: 0; padding: 4px; color: var(--forest-2);
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-2); font-size: 14px;
}
.link-btn:hover { text-decoration-color: currentColor; }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 30;
  display: flex; align-items: center; gap: 18px; padding: 0 20px;
  background: rgba(244, 238, 226, .92);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand-mark { width: 36px; height: 36px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { font-family: var(--serif); font-size: 23px; font-weight: 600; font-style: italic; letter-spacing: -.01em; color: var(--forest); }
.brand-sub { font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); margin-top: 3px; }

.menu-wrap { position: relative; }
.tree-switch { flex: 0 1 auto; min-width: 0; max-width: 340px; padding-left: 18px; border-left: 1px solid var(--line); }
.tree-btn {
  display: flex; align-items: center; gap: 8px; max-width: 100%; height: 44px; padding: 0 12px 0 10px;
  background: transparent; border: 1px solid transparent; border-radius: 12px; text-align: left;
}
.tree-btn:hover { background: rgba(255,255,255,.6); border-color: var(--line); }
.tree-btn-kicker { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.tree-btn-name { font-family: var(--serif); font-size: 17px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.chev { width: 16px; height: 16px; flex: none; color: var(--muted); }

.search { position: relative; flex: 1 1 220px; min-width: 160px; max-width: 380px; margin-left: auto; }
.search > svg { position: absolute; left: 13px; top: 50%; width: 17px; height: 17px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; height: 40px; padding: 0 14px 0 38px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255,255,255,.7); outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.search input::placeholder { color: #9a8f7a; }
.search input:focus { border-color: var(--forest-2); background: #fff; box-shadow: 0 0 0 3px rgba(46,90,73,.14); }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; min-width: 300px; margin: 0; padding: 6px; list-style: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg); z-index: 40;
}
.search-results li { display: flex; align-items: center; gap: 10px; padding: 7px 9px; border-radius: 10px; cursor: pointer; }
.search-results li.active, .search-results li:hover { background: var(--forest-soft); }
.search-results .no-results { color: var(--muted); cursor: default; font-size: 14px; }
.search-results .no-results:hover { background: none; }

.top-actions { display: flex; align-items: center; gap: 6px; flex: none; }

/* ---------- Menus & popover ---------- */
.menu, .popover {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 50; min-width: 260px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg);
  padding: 8px; animation: pop .14s ease-out;
}
.menu-right, .popover { left: auto; right: 0; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.menu button {
  display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 12px; border: 0; border-radius: 10px; background: none; text-align: left; font-size: 14px;
}
.menu button:hover, .menu button:focus-visible { background: var(--forest-soft); outline: none; }
.menu button.danger { color: var(--danger); }
.menu button.danger:hover { background: var(--terra-soft); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }
.menu-heading { margin: 6px 12px 4px; font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.tree-list { max-height: 260px; overflow: auto; }
.tree-item .mi-name { font-family: var(--serif); font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item .mi-meta { font-size: 12px; color: var(--muted); flex: none; }
.tree-item.current { background: var(--forest-soft); }
.tree-item.current .mi-name::before { content: '● '; color: var(--forest-2); font-size: 10px; vertical-align: 2px; }

.popover { width: min(420px, calc(100vw - 24px)); padding: 20px 22px; }
.popover h2 { margin: 0 0 10px; font-family: var(--serif); font-weight: 500; font-size: 22px; }
.tips { margin: 0; padding-left: 20px; display: grid; gap: 10px; font-size: 14px; color: var(--ink-2); }
.tips li::marker { font-family: var(--serif); color: var(--terra); font-weight: 600; }
.tips strong { color: var(--ink); }

/* ---------- Stage ---------- */
.stage {
  position: fixed; inset: var(--topbar-h) 0 0 0; overflow: hidden;
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(125, 113, 92, .16) 1px, transparent 0),
    radial-gradient(ellipse at 20% 0%, rgba(255,255,255,.55), transparent 60%),
    radial-gradient(ellipse at 100% 100%, rgba(201,169,106,.10), transparent 55%);
  background-size: 26px 26px, 100% 100%, 100% 100%;
}
.tree-svg { width: 100%; height: 100%; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.tree-svg.panning { cursor: grabbing; }
.tree-svg:focus { outline: none; }
.print-title { display: none; }

.zoom-controls {
  position: absolute; right: 18px; bottom: 56px; z-index: 5;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px;
  background: rgba(255, 252, 246, .94); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow);
  transition: right .25s ease;
}
.zoom-sep { width: 22px; height: 1px; background: var(--line); margin: 3px 0; }
body.panel-open .zoom-controls { right: calc(var(--panel-w) + 34px); }

.status-bar {
  position: absolute; left: 18px; bottom: 16px; z-index: 5; max-width: calc(100% - 120px);
  display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 10px;
  font-size: 12.5px; color: var(--muted);
  background: rgba(255, 252, 246, .9); border: 1px solid var(--line); border-radius: 999px;
}
.status-bar svg { width: 15px; height: 15px; flex: none; color: var(--forest-2); }
.status-bar .privacy { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-status { flex: none; padding-left: 8px; border-left: 1px solid var(--line); color: var(--forest-2); font-weight: 500; }
.save-status:empty { display: none; }
.save-status.bad { color: var(--danger); }

.tooltip {
  position: absolute; left: 0; top: 0; z-index: 8; pointer-events: none;
  display: flex; flex-direction: column; gap: 1px; max-width: 260px; padding: 8px 12px;
  background: var(--ink); color: #f4eee2; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow);
}
.tooltip strong { font-family: var(--serif); font-weight: 500; font-size: 15px; }
.tooltip span { color: #cfc6b2; font-size: 12px; letter-spacing: .03em; }

/* ---------- Empty state ---------- */
.empty {
  position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%); z-index: 4;
  width: min(520px, calc(100% - 32px)); padding: 36px 36px 28px; text-align: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow-lg);
}
.empty-art { width: 190px; height: auto; margin: 0 auto 8px; }
.empty h1 { margin: 0 0 8px; font-family: var(--serif); font-weight: 500; font-size: 32px; letter-spacing: -.01em; line-height: 1.15; }
.empty p { margin: 0 auto 22px; max-width: 400px; color: var(--ink-2); }
.empty-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 10px; }
body.is-empty .zoom-controls { display: none; }

/* ---------- Panel ---------- */
.panel {
  position: fixed; top: calc(var(--topbar-h) + 12px); right: 12px; bottom: 12px; z-index: 20;
  width: var(--panel-w); display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-lg);
  animation: slideIn .22s ease-out;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
.panel-grip { display: none; }
.panel-close { position: absolute; top: 12px; right: 12px; z-index: 2; background: var(--card); }
.panel-body { flex: 1; overflow-y: auto; padding: 24px 24px 28px; overscroll-behavior: contain; }

.avatar {
  --tone: #d9c7a7;
  display: inline-grid; place-items: center; flex: none; overflow: hidden; border-radius: 50%;
  background: var(--tone); color: #2c2a22; font-family: var(--serif); font-weight: 600;
  box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ring, #aaa08d);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.g-male { --ring: var(--forest-2); }
.avatar.g-female { --ring: var(--terra); }
.avatar.g-other { --ring: #b08a45; }
.avatar-sm { width: 34px; height: 34px; font-size: 13px; box-shadow: 0 0 0 1.5px var(--card), 0 0 0 3px var(--ring, #aaa08d); }
.avatar-lg { width: 76px; height: 76px; font-size: 26px; }

.pv-head { display: flex; gap: 16px; align-items: flex-start; padding-right: 36px; }
.pv-head .avatar-lg { margin-top: 4px; }
.pv-title { min-width: 0; }
.pv-kicker { margin: 0 0 2px; font-size: 12.5px; color: var(--terra); font-weight: 600; letter-spacing: .02em; }
.pv-kicker .muted { color: var(--muted); font-weight: 400; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--forest); color: #f4eee2; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.pv-name { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 27px; line-height: 1.12; letter-spacing: -.01em; overflow-wrap: anywhere; }
.pv-alias { margin: 4px 0 0; font-family: var(--serif); font-style: italic; color: var(--ink-2); }
.pv-life { margin: 6px 0 0; color: var(--muted); font-size: 13.5px; letter-spacing: .03em; }
.pv-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 18px 0 6px; }
.pv-facts { margin: 16px 0 0; display: grid; gap: 0; border-top: 1px solid var(--line); }
.pv-facts div { display: grid; grid-template-columns: 112px 1fr; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.pv-facts dt { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding-top: 2px; }
.pv-facts dd { margin: 0; font-size: 14.5px; }
.pv-notes {
  margin: 16px 0 0; padding: 12px 16px; border-left: 3px solid var(--gold);
  background: var(--paper); border-radius: 0 12px 12px 0; font-family: var(--serif); font-size: 15px; color: var(--ink-2);
}
.pv-section { margin-top: 22px; }
.pv-section h3 {
  margin: 0 0 8px; font-family: var(--serif); font-weight: 500; font-size: 18px;
  display: flex; align-items: center; gap: 8px;
}
.count { font-family: var(--sans); font-size: 11.5px; font-weight: 600; color: var(--forest-2); background: var(--forest-soft); border-radius: 999px; padding: 1px 8px; }
.group-label { margin: 10px 0 4px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.rel-row { display: flex; align-items: center; gap: 2px; }
.rel-chip {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 11px; padding: 7px 8px; margin: 1px 0;
  background: none; border: 1px solid transparent; border-radius: 12px; text-align: left;
}
.rel-chip:hover { background: var(--paper); border-color: var(--line); }
.rel-text { display: flex; flex-direction: column; min-width: 0; }
.rel-name { font-weight: 500; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rel-meta { font-size: 12.5px; color: var(--muted); }
.add-rel {
  display: flex; align-items: center; gap: 8px; width: 100%; margin-top: 6px; padding: 9px 12px;
  border: 1.5px dashed var(--line-2); border-radius: 12px; background: none; color: var(--forest-2); font-weight: 600; font-size: 13.5px;
  transition: background .15s, border-color .15s;
}
.add-rel svg { width: 16px; height: 16px; }
.add-rel:hover:not(:disabled) { background: var(--forest-soft); border-color: var(--forest-2); border-style: solid; }
.add-rel:disabled { color: var(--muted); opacity: .7; cursor: not-allowed; }
.muted { color: var(--muted); }
.small { font-size: 13px; margin: 2px 0; }
.hint { display: block; margin-top: 4px; font-size: 12.5px; color: var(--muted); line-height: 1.4; }

/* ---------- Forms ---------- */
.pf-title { margin: 0 0 14px; font-family: var(--serif); font-weight: 500; font-size: 26px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2); }
.req { color: var(--terra); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-2);
  background: #fffefb; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 92px; line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--forest-2); box-shadow: 0 0 0 3px rgba(46,90,73,.15); }
.field-error { color: var(--danger); font-size: 12.5px; font-weight: 500; }
.form-error { margin: 4px 0 10px; padding: 10px 12px; border-radius: 10px; background: var(--terra-soft); color: #7d2c1c; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.check { display: flex; align-items: center; gap: 10px; margin: 2px 0 14px; font-size: 14.5px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--forest); flex: none; }
.fullname-preview { margin: -6px 0 14px; font-size: 13px; color: var(--muted); }
.fullname-preview strong { color: var(--ink); font-family: var(--serif); font-weight: 500; font-size: 14.5px; }
.photo-field { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.photo-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.photo-actions .hint { width: 100%; margin: 0; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-btn:focus-within { outline: 2.5px solid var(--forest-2); outline-offset: 2px; }
.pf-foot {
  position: sticky; bottom: -28px; display: flex; justify-content: flex-end; gap: 8px;
  margin: 8px -24px -28px; padding: 14px 24px 18px; background: linear-gradient(to bottom, rgba(255,252,246,.85), var(--card) 30%);
  border-top: 1px solid var(--line); border-radius: 0 0 20px 20px;
}

/* ---------- Modal ---------- */
.modal {
  width: min(460px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--line);
  border-radius: 20px; background: var(--card); color: var(--ink); box-shadow: var(--shadow-lg);
}
.modal.modal-wide { width: min(560px, calc(100vw - 24px)); }
.modal[open] { animation: pop .16s ease-out; }
.modal::backdrop { background: rgba(29, 39, 33, .38); backdrop-filter: blur(2px); }
.modal-form { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 6px; }
.modal-head h2 { margin: 4px 0 0; font-family: var(--serif); font-weight: 500; font-size: 23px; line-height: 1.2; }
.modal-body { padding: 10px 22px 4px; overflow-y: auto; }
.modal .form-error { margin: 0 22px 8px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px 20px; border-top: 1px solid var(--line); margin-top: 8px; }
.confirm-text { margin: 4px 0 10px; color: var(--ink-2); font-size: 15px; }
.seg { display: inline-flex; padding: 4px; margin-bottom: 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 999px; }
.seg-btn { border: 0; background: none; padding: 7px 14px; border-radius: 999px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.seg-btn.active { background: var(--card); color: var(--forest); box-shadow: 0 1px 3px rgba(58,44,24,.14); }
.seg-btn:disabled { opacity: .45; cursor: not-allowed; }
.pick-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 10px; }
.pick-item { display: flex; align-items: center; gap: 10px; padding: 7px 9px; border-radius: 9px; cursor: pointer; }
.pick-item:hover { background: var(--paper); }
.pick-item input { accent-color: var(--forest); width: 16px; height: 16px; flex: none; }
.pick-item:has(input:checked) { background: var(--forest-soft); }
.rel-extra { margin-top: 12px; padding-top: 14px; border-top: 1px dashed var(--line-2); }
.sub-h { margin: 0 0 10px; font-family: var(--serif); font-weight: 500; font-size: 17px; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 60;
  display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(520px, calc(100vw - 24px)); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px; padding: 11px 14px 11px 18px;
  background: var(--ink); color: #f4eee2; border-radius: 14px; box-shadow: var(--shadow-lg); font-size: 14px;
  animation: toastIn .22s ease-out; transition: opacity .3s, transform .3s;
}
.toast-error { background: #6f2617; }
.toast-warn { background: #5b4718; }
.toast.out { opacity: 0; transform: translateY(8px); }
.toast-action { flex: none; border: 1px solid rgba(244,238,226,.35); background: none; color: #f4eee2; border-radius: 999px; padding: 4px 12px; font-weight: 600; font-size: 13px; }
.toast-action:hover { background: rgba(244,238,226,.12); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .tree-btn-kicker { display: none; }
  .tree-switch { max-width: 280px; }
}
@media (max-width: 1100px) {
  .brand-sub { display: none; }
  .btn-label { display: none; }
  #addPersonBtn, #shareBtn { width: 40px; padding: 0; }
}
@media (max-width: 760px) {
  :root { --topbar-h: 112px; }
  .topbar { flex-wrap: wrap; align-content: center; gap: 6px 8px; padding: 8px 12px; }
  .brand-text { display: none; }
  .brand-mark { width: 32px; height: 32px; }
  .tree-switch { flex: 1; padding-left: 6px; border-left: 0; }
  .tree-btn { max-width: 100%; height: 40px; }
  .tree-btn-kicker { display: none; }
  .top-actions { gap: 0; }
  .top-actions #redoBtn { display: none; }
  .search { order: 5; flex: 1 1 100%; max-width: none; margin: 0; }
  .menu, .popover { position: fixed; top: 60px; left: 10px; right: 10px; width: auto; min-width: 0; }
  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%; height: min(72vh, 640px);
    border-radius: 22px 22px 0 0; border-bottom: 0; animation: sheetIn .24s ease-out;
  }
  @keyframes sheetIn { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
  .panel-grip { display: block; width: 44px; height: 5px; margin: 8px auto 0; border-radius: 9px; background: var(--line-2); }
  .panel-body { padding: 14px 18px 24px; }
  .pf-foot { margin: 8px -18px -24px; padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); bottom: -24px; }
  .pv-facts div { grid-template-columns: 96px 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .zoom-controls { right: 10px; bottom: 54px; }
  body.panel-open .zoom-controls { display: none; }
  .search-results { min-width: 0; }
  body.panel-open .status-bar { display: none; }
  .status-bar { left: 10px; bottom: 10px; max-width: calc(100% - 20px); font-size: 11.5px; }
  .status-bar .privacy { white-space: normal; line-height: 1.3; }
  .empty { padding: 26px 20px 20px; top: 48%; }
  .empty h1 { font-size: 26px; }
  .toasts { bottom: 70px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Print ---------- */
@media print {
  @page { size: landscape; margin: 12mm; }
  html, body { height: auto; overflow: visible; background: #fff; }
  .topbar, .panel, .zoom-controls, .status-bar, .toasts, .tooltip, .empty, .modal, .skip-link { display: none !important; }
  .stage { position: static; inset: auto; background: #fff; }
  .print-title { display: block; margin: 0 0 6mm; font-family: var(--serif); font-weight: 500; font-size: 22pt; color: #1d2721; }
  .tree-svg { width: 100%; height: 165mm; }
  .card .card-shadow { display: none; }
}
