/* آل جاد الله — palette and type follow the reference (ansabsira.com); see DESIGN.md. */
:root {
  color-scheme: light;
  --parch: #f4ecd8;
  --card: #fbf6e9;
  --paper: #fffdf6;
  --ink: #2a2620;
  --ink-soft: #6b6353;
  --stone: #a99e8c;
  --gold: #b8902f;
  --gold-2: #caa548;
  --gold-soft: #e3cd8f;
  --gold-ink: #7a5d17;
  /* Gold dark enough for white text (6:1) */
  --gold-deep: #8f6d1c;
  --emerald: #0d5c45;
  --emerald-2: #0a4a37;
  --emerald-soft: #127a5c;
  --rose: #b03e60;
  --blue: #2f6fb0;
  --line: rgb(42 38 32 / 0.14);
  --card-line: rgb(184 144 47 / 0.32);

  /* Bark of the trunk and branches (leaf colours live in js/leaves.js) */
  --bark: #6b4f37;
  --bark-edge: #4f3a28;

  --font-head: 'Reem Kufi', 'Amiri', serif;
  --font-name: 'Amiri', serif;
  --font-ui: 'IBM Plex Sans Arabic', 'Noto Sans Arabic', 'Segoe UI', 'Geeza Pro', Tahoma, system-ui, sans-serif;

  --rad-xs: 8px;
  --rad-sm: 12px;
  --rad-lg: 18px;
  --rad-pill: 999px;
  --shadow: 0 10px 30px -12px rgb(40 32 16 / 0.35);
  --shadow-lg: 0 26px 60px -24px rgb(30 24 8 / 0.55);
  --ease: cubic-bezier(0.3, 1, 0.32, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --topbar: 64px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--parch);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p, dl, dd { margin: 0; }
[hidden] { display: none !important; }

.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

:focus-visible { outline: 3px solid var(--emerald-soft); outline-offset: 3px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: var(--rad-sm);
  background: var(--paper);
  font-weight: 500;
  font-size: 14.5px;
  white-space: nowrap;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s, transform 0.2s var(--ease), box-shadow 0.2s;
}
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--emerald); border-color: var(--emerald); color: var(--card); }
.btn-primary:hover:not(:disabled) { background: var(--emerald-2); border-color: var(--emerald-2); }
.btn-gold {
  background: var(--gold-deep);
  border-color: var(--gold-deep);
  color: #fff;
  border-radius: var(--rad-pill);
  box-shadow: 0 10px 22px -14px rgb(122 93 23 / 0.8);
}
.btn-gold:hover:not(:disabled) { background: var(--gold-ink); border-color: var(--gold-ink); }
.btn-lg { min-height: 54px; padding: 10px 30px; font-size: 16.5px; font-weight: 600; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-ghost:hover:not(:disabled) { background: rgb(184 144 47 / 0.1); border-color: transparent; color: var(--ink); }
.btn-ghost[aria-pressed='true'] { background: rgb(13 92 69 / 0.1); color: var(--emerald); }
.btn-quiet { background: transparent; color: var(--ink-soft); }
.btn[aria-busy='true'] { position: relative; color: transparent; }
.btn[aria-busy='true']::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid var(--card);
  border-top-color: transparent;
  border-radius: 50%;
  @media (prefers-reduced-motion: no-preference) { animation: spin 0.8s linear infinite; }
}
@keyframes spin { to { rotate: 360deg; } }

/* ---------- Title card ---------- */
.intro {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(circle at 50% 38%, rgb(255 253 246 / 0.9), transparent 62%),
    var(--parch);
  transition: opacity 0.6s var(--ease-out), visibility 0.6s, translate 0.7s var(--ease-out);
}
body[data-stage='tree'] .intro {
  opacity: 0;
  visibility: hidden;
  @media (prefers-reduced-motion: no-preference) { translate: 0 -28px; }
}
.intro-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 560px;
}
.ornament { width: 92px; height: 92px; margin-bottom: 18px; overflow: visible; }
.ornament :is(rect, circle, path) { fill: none; stroke-width: 2.2; }
.ornament .orn-a, .ornament .orn-b { stroke: var(--gold); }
.ornament .orn-c { stroke: var(--emerald-soft); stroke-width: 1.6; }
.ornament .orn-d { fill: var(--emerald); stroke: none; }
.intro-kicker { color: var(--gold-ink); font-weight: 600; font-size: 14px; }
.intro-title {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: clamp(46px, 11vw, 78px);
  line-height: 1.25;
  color: var(--emerald-2);
}
.intro-lede { margin-top: 10px; color: var(--ink-soft); font-size: 16.5px; max-width: 36ch; }
.intro-stats {
  display: flex;
  gap: 0;
  margin: 26px 0 30px;
  padding: 14px 6px;
  border-block: 1px solid var(--card-line);
}
.intro-stats div { display: flex; flex-direction: column-reverse; align-items: center; padding-inline: 26px; }
.intro-stats div + div { border-inline-start: 1px solid var(--card-line); }
.intro-stats dd { font-family: var(--font-head); font-size: 30px; line-height: 1.2; color: var(--gold-ink); font-weight: 600; }
.intro-stats dt { font-size: 13px; color: var(--ink-soft); }
.intro-status { min-height: 1.7em; margin-top: 14px; color: var(--ink-soft); font-size: 14px; }
.intro-status[data-tone='error'] { color: var(--rose); }

@media (prefers-reduced-motion: no-preference) {
  .ornament .orn-a, .ornament .orn-b, .ornament .orn-c {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    animation: draw 1.6s var(--ease-out) forwards;
  }
  .ornament .orn-b { animation-delay: 0.2s; }
  .ornament .orn-c { animation-delay: 0.45s; }
  .ornament .orn-d { opacity: 0; scale: 0.6; transform-origin: 60px 60px; animation: bloom 0.8s var(--ease) 0.9s forwards; }
  .intro-inner > :not(.ornament) { opacity: 0; translate: 0 14px; animation: rise 0.8s var(--ease-out) forwards; }
  .intro-kicker { animation-delay: 0.35s !important; }
  .intro-title { animation-delay: 0.45s !important; }
  .intro-lede { animation-delay: 0.6s !important; }
  .intro-stats { animation-delay: 0.72s !important; }
  #enter, .intro-status, #retry { animation-delay: 0.85s !important; }
}
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes bloom { to { opacity: 1; scale: 1; } }
@keyframes rise { to { opacity: 1; translate: 0 0; } }

/* ---------- App shell ---------- */
.app { position: fixed; inset: 0; opacity: 0; transition: opacity 0.6s 0.15s; }
body[data-stage='tree'] .app { opacity: 1; }

.topbar {
  position: absolute;
  inset: 0 0 auto;
  z-index: 10;
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 16px;
  padding-inline: 16px;
  background: rgb(251 246 233 / 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--card-line);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; flex: none; }
.brand-mark { width: 34px; height: 34px; }
.brand-mark :is(rect, circle) { fill: none; stroke: var(--gold); stroke-width: 6; }
.brand-mark circle { stroke: var(--emerald-soft); stroke-width: 5; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-family: var(--font-head); font-weight: 700; font-size: 19px; color: var(--emerald-2); }
.brand-sub { font-size: 12px; color: var(--ink-soft); }

.search { position: relative; flex: 1; max-width: 420px; margin-inline-start: auto; }
.search input {
  width: 100%;
  height: 42px;
  padding-inline: 40px 36px;
  border: 1px solid var(--line);
  border-radius: var(--rad-pill);
  background: var(--paper);
  font-size: 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search input::placeholder { color: var(--ink-soft); }
.search input::-webkit-search-cancel-button { appearance: none; }
.search input:focus { outline: none; border-color: var(--emerald-soft); box-shadow: 0 0 0 4px rgb(18 122 92 / 0.14); }
.search-icon { position: absolute; inset-inline-start: 14px; top: 11px; color: var(--ink-soft); pointer-events: none; }
.search-kbd {
  position: absolute;
  inset-inline-end: 12px;
  top: 10px;
  min-width: 22px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: var(--rad-xs);
  font: 500 12px/20px var(--font-ui);
  color: var(--stone);
  text-align: center;
}
.search input:focus ~ .search-kbd { display: none; }
.search-results {
  position: absolute;
  inset: calc(100% + 8px) 0 auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: var(--rad-sm);
  box-shadow: var(--shadow-lg);
  max-height: min(60vh, 440px);
  overflow: auto;
}
.search-results li { display: flex; flex-direction: column; padding: 8px 12px; border-radius: var(--rad-xs); cursor: pointer; }
.search-results li[aria-selected='true'] { background: rgb(13 92 69 / 0.09); }
.sr-name { font-family: var(--font-name); font-weight: 700; font-size: 18px; line-height: 1.5; }
.sr-line { font-size: 13px; color: var(--ink-soft); }
.sr-empty { color: var(--ink-soft); font-size: 14px; cursor: default !important; }

/* ---------- Canvas ---------- */
.viewport {
  position: absolute;
  inset: var(--topbar) 0 0;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}
.viewport.is-panning { cursor: grabbing; }
.world { position: absolute; inset: 0 auto auto 0; width: 0; height: 0; transform-origin: 0 0; will-change: transform; }
.edges { position: absolute; inset: 0 auto auto 0; width: 1px; height: 1px; overflow: visible; }
.edge, .root { fill: var(--bark); stroke: var(--bark-edge); stroke-width: 0.8; transition: fill 0.35s; }
.leaflet { pointer-events: none; }
/* Soft-edged discs behind the leaves blend into one crown. */
.canopy { fill: url(#canopy-g); pointer-events: none; }
.edge.on-path { fill: var(--gold); }
.ground ellipse { fill: rgb(107 79 55 / 0.13); }
.nodes { position: absolute; inset: 0 auto auto 0; }

/* One person: a leaf at the tip of the branch, the name on a small plaque under it. */
.node-wrap { position: absolute; inset: 0 auto auto 0; will-change: transform, opacity; }
.node-wrap.is-leaving { pointer-events: none; }
.node {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: var(--font-name);
  font-weight: 700;
  font-size: 16px;
  line-height: 1.35;
}
.node:focus-visible { outline: none; }
.leaf-hold { display: block; width: 44px; height: 44px; margin-top: 0; rotate: var(--leaf-rot, 0deg); transition: rotate 0.6s var(--ease); }
.kind-child .leaf-hold { width: 34px; height: 34px; margin-block: 5px; }
.leaf { display: block; width: 100%; height: 100%; overflow: visible; transform-origin: 50% 96%; transition: scale 0.3s var(--ease); }
.node:hover .leaf { scale: 1.14; }
.node-name {
  max-width: 100%;
  padding: 1px 10px;
  border-radius: var(--rad-pill);
  background: rgb(251 246 233 / 0.9);
  box-shadow: 0 0 0 1px var(--card-line);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background-color 0.25s, color 0.25s, box-shadow 0.25s;
}
.node:focus-visible .node-name { outline: 3px solid var(--emerald-soft); outline-offset: 2px; }
.node.is-unknown .node-name { color: var(--ink-soft); font-weight: 400; font-size: 14px; }
.node.on-path .node-name { background: #fff3d1; box-shadow: 0 0 0 1.5px var(--gold); }
.node.is-selected .node-name { background: var(--emerald-2); color: var(--card); box-shadow: 0 0 0 2px var(--gold); }
.node.is-selected .leaf { scale: 1.24; }

/* The great-grandfather: a plaque at the foot of the trunk. */
.node-root {
  justify-content: center;
  gap: 0;
  padding: 0 14px;
  border: 1.5px solid var(--gold);
  border-radius: var(--rad-sm);
  background: var(--card);
  outline: 1px solid var(--card-line);
  outline-offset: 4px;
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.7) inset, 0 10px 22px -12px rgb(40 32 16 / 0.55);
  transition: background-color 0.25s;
}
.node-root:focus-visible { outline: 3px solid var(--emerald-soft); }
.node-root .node-name, .node-root.is-selected .node-name { padding: 0; background: none; box-shadow: none; font-family: var(--font-head); font-size: 22px; color: var(--emerald-2); }
.node-root.is-selected { background: var(--emerald-2); }
.node-root.is-selected .node-name { color: var(--card); }
.node-kicker { font-family: var(--font-ui); font-size: 11px; font-weight: 500; color: var(--gold-ink); line-height: 1.2; }
.node-root.is-selected .node-kicker { color: var(--gold-soft); }

/* Bud beside a leaf whose children can fold away. */
.node-toggle {
  position: absolute;
  top: 10px;
  inset-inline-end: calc(50% + 18px);
  min-width: 26px;
  height: 22px;
  padding: 0 6px;
  border: 1.5px solid var(--bark);
  border-radius: var(--rad-pill);
  background: var(--card);
  color: var(--bark);
  font: 600 12px/1 var(--font-ui);
  transition: background-color 0.2s, color 0.2s, scale 0.2s var(--ease);
}
.node-toggle::after { content: ''; position: absolute; inset: -9px; }
.node-toggle:hover { scale: 1.12; }
.is-collapsed .node-toggle { background: var(--bark); color: #fff; }

@media (prefers-reduced-motion: no-preference) {
  .leaf { animation: sway var(--sway-d, 6s) ease-in-out var(--sway-delay, 0s) infinite alternate; }
  .node-wrap.is-new .leaf {
    animation:
      unfurl 0.8s var(--ease-out) var(--grow-delay, 0ms) backwards,
      sway var(--sway-d, 6s) ease-in-out var(--sway-delay, 0s) infinite alternate;
  }
}
@keyframes sway { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
@keyframes unfurl { from { scale: 0; rotate: -70deg; } }

/* ---------- Floating controls ---------- */
.legend {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  inset-inline: 80px;
  z-index: 5;
  display: flex;
  justify-content: center;
  pointer-events: none;
  transition: opacity 0.3s, translate 0.4s var(--ease);
}
/* The open card lists the person's details, so the leaf key steps aside. */
body:has(.panel[data-open='true']) .legend { opacity: 0; translate: 0 12px; visibility: hidden; }
.legend-list {
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 16px;
  margin: 0;
  padding: 4px 16px;
  list-style: none;
  border: 1px solid var(--card-line);
  border-radius: var(--rad-lg);
  background: rgb(251 246 233 / 0.94);
  box-shadow: var(--shadow);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; height: 36px; font-size: 13.5px; font-weight: 500; white-space: nowrap; }
.legend-leaves { display: inline-flex; align-items: center; }
.legend-leaves .leaf + .leaf { margin-inline-start: -5px; }
.legend .leaf { width: 22px; height: 22px; animation: none; }
.legend .kind-child .leaf { width: 17px; height: 17px; }
.legend-n { min-width: 22px; padding: 0 6px; border-radius: var(--rad-pill); background: rgb(107 79 55 / 0.1); color: var(--ink-soft); font-size: 12px; line-height: 20px; text-align: center; }

.zoom {
  position: absolute;
  inset-inline-end: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 6;
  display: flex;
  flex-direction: column;
  padding: 4px;
  border: 1px solid var(--card-line);
  border-radius: var(--rad-sm);
  background: rgb(251 246 233 / 0.94);
  box-shadow: var(--shadow);
}
.zoom-btn { width: 42px; height: 42px; display: grid; place-items: center; border: 0; border-radius: var(--rad-xs); background: transparent; color: var(--ink-soft); }
.zoom-btn:hover { background: rgb(184 144 47 / 0.12); color: var(--ink); }

/* ---------- Person panel ---------- */
.panel {
  position: absolute;
  z-index: 8;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--card-line);
  box-shadow: var(--shadow-lg);
  transition: translate 0.5s var(--ease), opacity 0.3s;
}
.panel[data-open='false'] { opacity: 0; pointer-events: none; }
.panel-body { overflow-y: auto; overscroll-behavior: contain; padding: 26px 24px 28px; }
.panel-close {
  position: absolute;
  inset-inline-end: 12px;
  top: 12px;
  z-index: 1;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
}
.panel-close:hover { background: rgb(184 144 47 / 0.12); color: var(--ink); }

@media (min-width: 900px) {
  .panel { top: calc(var(--topbar) + 14px); bottom: 16px; inset-inline-start: 16px; width: 384px; border-radius: var(--rad-lg); }
  .panel[data-open='false'] { @media (prefers-reduced-motion: no-preference) { translate: calc(100% + 32px) 0; } }
}
@media (max-width: 899.98px) {
  .panel { inset: auto 0 0; max-height: 62vh; border-radius: var(--rad-lg) var(--rad-lg) 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
  .panel::before { content: ''; align-self: center; width: 40px; height: 4px; margin-top: 8px; border-radius: 4px; background: var(--line); flex: none; }
  .panel[data-open='false'] { @media (prefers-reduced-motion: no-preference) { translate: 0 100%; } }
  .panel-body { padding-top: 12px; }
}

.panel-kicker, .panel-name { padding-inline-end: 40px; }
.panel-kicker { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink-soft); }
.panel-leaf { display: inline-block; width: 26px; height: 26px; }
.panel-leaf .leaf { animation: none; }
.tag {
  display: inline-block;
  padding: 1px 10px;
  border-radius: var(--rad-pill);
  background: rgb(184 144 47 / 0.14);
  color: var(--gold-ink);
  font-size: 12px;
  font-weight: 600;
}
.panel-name { margin-top: 6px; font-family: var(--font-name); font-weight: 700; font-size: 34px; line-height: 1.35; color: var(--emerald-2); }
.panel-hint { font-size: 13.5px; color: var(--ink-soft); }
.nasab {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: var(--rad-sm);
  background: rgb(184 144 47 / 0.08);
  border: 1px solid rgb(184 144 47 / 0.2);
  font-family: var(--font-name);
  font-size: 18.5px;
  line-height: 2;
}
.nasab-self { font-weight: 700; color: var(--emerald-2); }
.nasab-sep { color: var(--ink-soft); }
.nasab-link { color: var(--emerald-soft); font-weight: 700; text-decoration: none; border-radius: 4px; }
.nasab-link:hover { text-decoration: underline; text-decoration-color: var(--gold); text-underline-offset: 6px; }

.facts { display: grid; gap: 6px; margin-top: 16px; }
.facts:empty { display: none; }
.fact { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 6px; border-bottom: 1px dashed var(--line); font-size: 14.5px; }
.fact dt { color: var(--ink-soft); }
.fact dd { font-weight: 600; }
.panel-note { margin-top: 14px; color: var(--ink); font-size: 15px; white-space: pre-line; }

.panel-group { margin-top: 20px; }
.panel-h { font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 8px; }
.panel-count { font-weight: 400; }
.panel-empty { font-size: 14px; color: var(--ink-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 40px;
  padding: 2px 14px;
  border: 1px solid var(--card-line);
  border-radius: var(--rad-pill);
  background: var(--paper);
  font-family: var(--font-name);
  font-weight: 700;
  font-size: 16px;
  transition: border-color 0.2s, background-color 0.2s;
}
.chip:hover { border-color: var(--emerald-soft); background: rgb(18 122 92 / 0.06); }

.panel-actions { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--card-line); }
.action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.action-row .btn { padding-inline: 10px; }
.panel-fine { margin-top: 10px; font-size: 12.5px; color: var(--ink-soft); }
.panel-why { margin-top: 6px; font-size: 12.5px; color: var(--ink-soft); }

/* ---------- Suggest dialog ---------- */
.sheet {
  width: min(520px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--card-line);
  border-radius: var(--rad-lg);
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition-property: opacity, translate, display, overlay;
  transition-duration: 0.3s;
  transition-timing-function: var(--ease-out);
  transition-behavior: allow-discrete;
  @media (prefers-reduced-motion: no-preference) { translate: 0 16px; }
}
.sheet[open] {
  opacity: 1;
  translate: 0 0;
  @starting-style { opacity: 0; }
  @media (prefers-reduced-motion: no-preference) { @starting-style { translate: 0 16px; } }
}
.sheet::backdrop {
  background: rgb(42 38 32 / 0);
  transition-property: background-color, display, overlay;
  transition-duration: 0.3s;
  transition-behavior: allow-discrete;
}
.sheet[open]::backdrop { background: rgb(42 38 32 / 0.45); @starting-style { background: rgb(42 38 32 / 0); } }
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop { overflow: hidden; overscroll-behavior: contain; }
@media (max-width: 600px) {
  .sheet { width: 100%; max-width: none; margin: auto 0 0; border-radius: var(--rad-lg) var(--rad-lg) 0 0; }
  .sheet { @media (prefers-reduced-motion: no-preference) { translate: 0 40px; } }
}

.sheet-form { display: flex; flex-direction: column; gap: 14px; padding: 22px 22px 20px; }
.sheet-head { position: relative; padding-inline-end: 40px; }
.sheet-title { font-family: var(--font-head); font-weight: 600; font-size: 22px; color: var(--emerald-2); }
.sheet-about { margin-top: 2px; font-family: var(--font-name); font-size: 17px; color: var(--ink-soft); }
.sheet-close { position: absolute; inset-inline-end: -8px; top: -6px; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: var(--ink-soft); }
.sheet-close:hover { background: rgb(184 144 47 / 0.12); }
.fields { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field-label { font-size: 14px; font-weight: 600; padding: 0; }
.field-label small { font-weight: 400; color: var(--ink-soft); font-size: 12.5px; }
.field :is(input[type='text'], input[type='password']), .field textarea {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: var(--rad-sm);
  background: var(--paper);
  font-size: 16px;
  line-height: 1.6;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field textarea { resize: vertical; min-height: 80px; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--emerald-soft); box-shadow: 0 0 0 4px rgb(18 122 92 / 0.14); }
.field-check { display: flex; align-items: center; gap: 10px; min-height: 40px; font-size: 14.5px; font-weight: 600; cursor: pointer; }
.field-check input { width: 20px; height: 20px; margin: 0; accent-color: var(--emerald); }
.field input[dir='ltr'] { text-align: end; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: var(--rad-sm); background: rgb(42 38 32 / 0.06); }
.seg label { position: relative; }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 9px 4px; border-radius: var(--rad-xs); text-align: center; font-size: 14px; transition: background-color 0.2s, color 0.2s; }
.seg input:checked + span { background: var(--paper); color: var(--emerald-2); font-weight: 600; box-shadow: 0 1px 3px rgb(40 32 16 / 0.18); }
.seg input:focus-visible + span { outline: 3px solid var(--emerald-soft); outline-offset: 1px; }
.hp { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.form-error { padding: 9px 12px; border-radius: var(--rad-sm); background: rgb(176 62 96 / 0.1); color: var(--rose); font-size: 14px; }
.sheet-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 6px; }
.sheet-fine { font-size: 12.5px; color: var(--ink-soft); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; top: calc(var(--topbar) + 12px); inset-inline: 16px; z-index: 50; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  max-width: 460px;
  padding: 11px 18px;
  border-radius: var(--rad-sm);
  background: var(--emerald-2);
  color: var(--card);
  font-size: 14.5px;
  box-shadow: var(--shadow-lg);
  transition: opacity 0.3s, translate 0.3s var(--ease-out);
  @starting-style { opacity: 0; translate: 0 -10px; }
}
.toast-error { background: var(--rose); }
.toast.is-leaving { opacity: 0; translate: 0 -10px; }

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  :root { --topbar: 112px; }
  .topbar { flex-wrap: wrap; height: auto; min-height: var(--topbar); padding-block: 10px; row-gap: 10px; }
  .search { order: 3; flex-basis: 100%; max-width: none; margin: 0; }
  #expand-all { margin-inline-start: auto; }
  .search-kbd { display: none; }
  .legend { inset-inline: 12px 84px; justify-content: flex-start; }
  .legend-list { flex-wrap: nowrap; justify-content: flex-start; max-width: 100%; overflow-x: auto; border-radius: var(--rad-sm); scrollbar-width: none; }
  /* Pinch zooms on phones; the fit and family-head buttons stay. */
  #zoom-in, #zoom-out { display: none; }
  .legend-item { flex: none; }
}

/* ---------- Admin review page ---------- */
body.page-admin { overflow: auto; --topbar: 64px; }
.admin-bar { position: sticky; justify-content: space-between; flex-wrap: nowrap; min-height: 0; padding-block: 0; }
.admin { max-width: 760px; margin: 0 auto; padding: 32px 16px 64px; }
.admin-login { display: flex; flex-direction: column; gap: 14px; max-width: 420px; margin: 8vh auto 0; padding: 26px 24px; background: var(--card); border: 1px solid var(--card-line); border-radius: var(--rad-lg); box-shadow: var(--shadow); }
.admin-login .btn { align-self: flex-start; }
.admin-title { font-family: var(--font-head); font-weight: 600; font-size: 26px; color: var(--emerald-2); line-height: 1.4; }
.admin-subtitle { font-family: var(--font-head); font-weight: 600; font-size: 19px; color: var(--emerald-2); margin-bottom: 10px; }
.admin-lede { color: var(--ink-soft); font-size: 14.5px; }
.admin-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.admin-head .btn { margin-inline-start: auto; }
.admin-empty { padding: 22px; text-align: center; color: var(--ink-soft); border: 1px dashed var(--card-line); border-radius: var(--rad-sm); list-style: none; }
.proposals, .decided { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; }
.proposal { padding: 18px 20px; background: var(--card); border: 1px solid var(--card-line); border-inline-start: 4px solid var(--gold); border-radius: var(--rad-sm); box-shadow: 0 8px 18px -14px rgb(40 32 16 / 0.5); }
.proposal.kind-add_child { border-inline-start-color: var(--emerald-soft); }
.proposal.kind-remove { border-inline-start-color: var(--rose); }
.proposal-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.proposal-meta { font-size: 13px; color: var(--ink-soft); }
.proposal-about { margin-top: 8px; font-family: var(--font-name); font-size: 18px; line-height: 1.9; }
.proposal-reason { margin-top: 10px; font-size: 15px; }
.proposal-actions { display: flex; gap: 8px; margin-top: 14px; }
.diff { width: 100%; margin-top: 10px; border-collapse: collapse; font-size: 14.5px; }
.diff th, .diff td { padding: 7px 10px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.diff thead th { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.diff tbody th { font-weight: 500; color: var(--ink-soft); width: 7.5em; }
.diff tr.is-changed td:last-child { background: rgb(18 122 92 / 0.09); color: var(--emerald-2); font-weight: 600; }
.admin-decided { margin-top: 40px; }
.decided { gap: 0; }
.decided-row { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: baseline; padding: 10px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.decided-status { font-weight: 600; font-size: 12.5px; padding: 0 8px; border-radius: var(--rad-pill); }
.is-approved .decided-status { background: rgb(18 122 92 / 0.12); color: var(--emerald); }
.is-rejected .decided-status { background: rgb(176 62 96 / 0.12); color: var(--rose); }
.decided-when { color: var(--ink-soft); font-size: 12.5px; }
@media (max-width: 600px) {
  .decided-row { grid-template-columns: auto 1fr; }
  .decided-when { grid-column: 2; }
}
