:root {
  --stone: #2c2a25;
  --parchment: #f4f0e8;
  --paper: #fbf9f4;
  --sage: #7a8b6f;
  --sage-light: #c5d1bc;
  --sage-dark: #4a5a40;
  --gold: #c4a265;
  --gold-light: #e6d6b3;
  --gold-dim: rgba(196, 162, 101, 0.18);
  --rose: #b07a8a;
  --rose-light: #dcc3ca;
  --ink: #1a1815;
  --muted: #8a8478;
  --faint: #c4bfb5;
  --line: rgba(26, 24, 21, 0.08);
  --shadow: 0 1px 3px rgba(26,24,21,0.12), 0 8px 24px rgba(26,24,21,0.08);
  --danger: #a04040;
  --header-h: 60px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--parchment);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* ---------- header ---------- */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-h); z-index: 50;
  display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: rgba(244, 240, 232, 0.92); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.brand { min-width: 0; }
.brand-name { font-family: 'Cormorant Garamond', serif; font-size: 20px; font-weight: 600; color: var(--stone); line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 0.4px; white-space: nowrap; }
.search { flex: 1; max-width: 480px; position: relative; margin-left: auto; }
.search > svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; stroke: var(--muted); pointer-events: none; }
.search input {
  width: 100%; padding: 10px 14px 10px 36px; border-radius: 12px;
  border: 1px solid rgba(26,24,21,0.12); background: rgba(255,255,255,0.75); outline: none; font-size: 15px;
  transition: box-shadow .2s, border-color .2s;
}
.search input:focus { border-color: var(--sage); background: #fff; box-shadow: 0 0 0 3px rgba(122,139,111,0.15); }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; max-height: min(60vh, 460px); overflow-y: auto;
  background: var(--paper); border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--line);
  display: none; padding: 6px;
}
.search-results.open { display: block; }
.sr-item { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px; }
.sr-item:hover, .sr-item.active { background: rgba(122,139,111,0.12); }
.sr-name { font-family: 'Cormorant Garamond', serif; font-size: 18px; color: var(--stone); }
.sr-maiden { font-size: 13px; font-style: italic; color: var(--muted); font-family: 'DM Sans', sans-serif; }
.sr-sub { font-size: 12px; color: var(--muted); }
.sr-empty { padding: 14px; font-size: 13px; color: var(--muted); }
.header-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid rgba(26,24,21,0.1);
  background: rgba(255,255,255,0.7); display: grid; place-items: center; font-size: 18px; color: var(--stone);
  transition: background .15s;
}
.icon-btn:hover { background: #fff; }
.icon-btn svg { width: 18px; height: 18px; stroke: var(--stone); }
body.admin #adminToggle { background: var(--sage-dark); border-color: var(--sage-dark); }
body.admin #adminToggle svg { stroke: #fff; }

/* ---------- stage ---------- */
.stage { position: fixed; inset: var(--header-h) 0 0 0; display: flex; }
.admin-panel { display: none; width: 400px; flex: 0 0 400px; background: var(--paper); border-right: 1px solid var(--line); flex-direction: column; overflow: hidden; }
body.admin .admin-panel { display: flex; }
.map-wrap { position: relative; flex: 1; min-width: 0; }
.map { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; background: var(--parchment); }
.map:active { cursor: grabbing; }
body[data-admin-mode="drawBlock"] .map, body[data-admin-mode="drawSection"] .map { cursor: crosshair; }
body[data-admin-mode="paint"] .map, body[data-admin-mode="assign"] .map, body[data-admin-mode="structure"] .map { cursor: cell; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; font-family: 'Cormorant Garamond', serif; font-size: 22px; color: var(--muted); background: var(--parchment); padding: 24px; text-align: center; }

.map-controls { position: absolute; right: 14px; top: 14px; display: flex; flex-direction: column; gap: 6px; }
.compass { position: absolute; right: 14px; top: 150px; width: 40px; height: 40px; opacity: .85; }
.compass svg { width: 40px; height: 40px; transition: transform .2s; }
.c-n { fill: #a03030; } .c-s { fill: #6a645a; } .compass text { fill: var(--stone); font-family: 'DM Sans'; font-weight: 600; }
.stats { position: absolute; left: 14px; bottom: 12px; font-size: 11px; color: var(--muted); background: rgba(244,240,232,0.85); padding: 4px 8px; border-radius: 6px; pointer-events: none; }
.attrib { position: absolute; right: 14px; bottom: 12px; font-size: 10px; color: var(--muted); background: rgba(244,240,232,0.85); padding: 3px 7px; border-radius: 6px; }
.attrib a { color: inherit; }
body.admin .attrib { display: none; }

.legend { position: absolute; right: 14px; bottom: 14px; background: var(--paper); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; display: none; font-size: 12px; color: var(--stone); min-width: 200px; }
.legend.open { display: block; }
.legend-title { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 6px; }
.legend .li { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.sw { width: 16px; height: 12px; border-radius: 3px; border: 1px solid rgba(26,24,21,0.15); display: inline-block; }
.sw-person { background: #9db08f; } .sw-notable { background: var(--gold); } .sw-f { background: #c7d6bd; }
.sw-unknown { background: rgba(255,255,255,0.55); } .sw-reserved { background: #e9e3d6; border-style: dashed; }
.sw-blocked { background: #d6d0c4; } .sw-structure { background: #3a3632; }
.sw-stone { background: transparent; border: none; border-bottom: 3px solid var(--stone); border-radius: 0; height: 6px; }

/* ---------- block panel ---------- */
.crumbs { position: absolute; left: 14px; top: 14px; z-index: 3; display: flex; align-items: center; gap: 2px; background: var(--paper); border-radius: 999px; padding: 5px 10px; box-shadow: var(--shadow); font-size: 13px; max-width: calc(100% - 28px); white-space: nowrap; overflow: hidden; }
.crumbs button { background: none; border: 0; font: inherit; color: var(--sage-dark); cursor: pointer; padding: 3px 7px; border-radius: 8px; }
.crumbs button:hover { background: rgba(122,139,111,0.15); }
.crumbs .cur { font-weight: 600; color: var(--stone); padding: 3px 7px; }
.crumbs .sep { color: var(--muted); }
.crumbs.home { opacity: .85; }
body.admin .crumbs { display: none; }
.block-panel { position: absolute; left: 14px; top: 56px; width: min(320px, calc(100% - 28px)); max-height: min(60%, 520px); background: var(--paper); border-radius: 14px; box-shadow: var(--shadow); display: none; flex-direction: column; overflow: hidden; }
.block-panel.open { display: flex; }
body.admin .block-panel { display: none; }
body.detail-open .block-panel { max-height: 44%; }
body.detail-open .block-panel .bp-list { display: none; }
body.detail-open .block-panel .bp-count::after { content: ' · close the person panel to browse'; text-transform: none; letter-spacing: 0; }
.bp-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.bp-title { font-family: 'Cormorant Garamond', serif; font-size: 20px; font-weight: 600; flex: 1; text-align: center; }
.bp-count { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); padding: 10px 14px 4px; }
.bp-list { overflow-y: auto; padding: 4px 8px 10px; }
.block-panel .muted { padding: 12px 14px; }

/* ---------- map SVG ---------- */
.map-bg { fill: var(--parchment); }
.base-image { opacity: 0.92; }
/* vector base: aerial underlay, cemetery outline, roads */
.underlay { pointer-events: none; }
.map[data-level="cemetery"] .underlay { opacity: .9; }
.map[data-level="block"] .underlay { opacity: .75; }
.map[data-level="section"] .underlay, .map[data-zoom="detail"] .underlay { opacity: .45; }
.cem-outline { fill: rgba(233,228,214,0.35); stroke: #6f6657; stroke-width: calc(1.2px / var(--k, 1)); pointer-events: none; }
.map[data-level="cemetery"] .cem-outline { fill: rgba(233,228,214,0.55); }
.road { fill: none; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.road-avenue { stroke: #f7f3ea; }
.road-road { stroke: #f3eee3; }
.road-path { stroke: rgba(247,243,234,0.7); }
.road-name { font-family: 'DM Sans', sans-serif; fill: #5d564b; letter-spacing: .14em; font-weight: 500; pointer-events: none; }
.map[data-zoom="far"] .road-name { display: none; }
/* blocks: those with a mapped grid stand out; when inside a block or section the others recede */
.block.has-sections .block-shape { fill: rgba(122,139,111,0.3); stroke: var(--sage-dark); stroke-width: calc(1px / var(--k, 1)); }
.map[data-level="block"] .block:not(.active) .block-shape, .map[data-level="section"] .block:not(.active) .block-shape { fill: rgba(26,24,21,0.18); stroke: rgba(26,24,21,0.25); }
.map[data-level="block"] .block.active .block-shape, .map[data-level="section"] .block.active .block-shape { fill: rgba(255,255,255,0.04); }
.map[data-level="block"] .block:not(.active) .block-label, .map[data-level="section"] .block:not(.active) .block-label { opacity: .22; }
.map[data-level="block"] .block.active .block-label, .map[data-level="block"] .block.active .block-count, .map[data-level="section"] .block.active .block-label, .map[data-level="section"] .block.active .block-count, .map[data-level="block"] .block:not(.active) .block-count, .map[data-level="section"] .block:not(.active) .block-count { display: none; }
/* a section seen from block level: a clickable shape with its name */
.section-light .section-outline { fill: rgba(255,255,255,0.55); stroke: var(--sage-dark); stroke-width: calc(1.5px / var(--k, 1)); cursor: pointer; transition: fill .15s; }
.section-light .section-outline.has-people { fill: rgba(122,139,111,0.5); }
.section-light:hover .section-outline { fill: rgba(196,162,101,0.5); stroke: var(--gold); }
.section-name { font-family: 'Cormorant Garamond', serif; font-weight: 600; fill: var(--stone); pointer-events: none; }
.section-count { font-family: 'DM Sans', sans-serif; fill: var(--sage-dark); pointer-events: none; }
.map[data-zoom="far"] .section-name, .map[data-zoom="far"] .section-count { display: none; }
.bp-sections { padding: 4px 8px 8px; }
.block-panel .bp-title { cursor: pointer; }
.block-panel.collapsed > :not(.bp-head) { display: none; }
.block-panel.collapsed #bpFold { transform: rotate(-90deg); }
.block-panel #bpFold { transition: transform .15s; }
.underlay-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.underlay-row input[type=range] { flex: 1; }
.block-shape { fill: rgba(255,255,255,0.08); stroke: rgba(26,24,21,0.35); stroke-width: calc(0.6px / var(--k, 1)); transition: fill .15s; }
.block:hover .block-shape { fill: rgba(122,139,111,0.25); stroke: var(--sage-dark); }
.block.has-people .block-shape { fill: rgba(122,139,111,0.22); stroke: var(--sage-dark); }
.block.active .block-shape { fill: rgba(196,162,101,0.14); stroke: var(--gold); stroke-width: calc(1.2px / var(--k, 1)); }
.block.approx .block-shape { stroke-dasharray: 2 1.2; }
.map, .map text { user-select: none; -webkit-user-select: none; }
.block-label { font-family: 'Cormorant Garamond', serif; font-weight: 600; fill: var(--stone); pointer-events: none; }
.block-count { font-family: 'DM Sans', sans-serif; fill: var(--sage-dark); pointer-events: none; font-weight: 500; }
.map[data-zoom="detail"] .block-label, .map[data-zoom="detail"] .block-count { opacity: .25; }
.map[data-zoom="detail"] .base-image { opacity: .35; }

.section-outline { fill: rgba(255,255,255,0.35); stroke: rgba(26,24,21,0.3); stroke-width: calc(0.5px / var(--k, 1)); }
.section-label { fill: var(--muted); font-family: 'DM Sans', sans-serif; text-transform: uppercase; letter-spacing: .08em; pointer-events: none; }
.cell { stroke: rgba(26,24,21,0.25); stroke-width: calc(0.35px / var(--k, 1)); cursor: pointer; transition: fill .1s; }
.cell-unknown { fill: rgba(255,255,255,0.6); }
.cell-unknown:hover { fill: rgba(122,139,111,0.25); }
.cell-person { fill: #9db08f; }
.cell-person.cell-f { fill: #bccfb0; }
.cell-person:hover { fill: var(--sage-dark); }
.cell-notable { fill: var(--gold); }
.cell-notable:hover { fill: #a98540; }
.cell-reserved { fill: #ebe5d8; stroke-dasharray: 0.6 0.4; }
.cell-empty { fill: rgba(255,255,255,0.25); stroke-dasharray: 0.6 0.4; }
.cell-blocked { fill: #d6d0c4; stroke: none; cursor: default; }
.stone { stroke: var(--stone); stroke-width: calc(1.3px / var(--k, 1)); stroke-linecap: round; pointer-events: none; opacity: .7; }
.cell-name { font-family: 'DM Sans', sans-serif; fill: #1f2a1a; pointer-events: none; font-weight: 500; }
.grid-label { fill: var(--muted); font-family: 'DM Sans', sans-serif; pointer-events: none; }
/* buildings (ohel): a stone floor inside a heavy wall that scales with the map, so the graves inside stay visible */
.structure-shape { fill: #e6dfd1; stroke: #3a3632; stroke-width: max(0.32px, calc(1px / var(--k, 1))); stroke-linejoin: miter; cursor: pointer; transition: fill .15s; }
.structure:hover .structure-shape { fill: #ece6da; stroke: #6b5a33; }
.structure-label { fill: #3a3632; font-family: 'Cormorant Garamond', serif; font-weight: 600; pointer-events: none; }
.structure-sub { fill: rgba(58,54,50,0.7); font-family: 'Cormorant Garamond', serif; pointer-events: none; }
.structure-grave-shape { fill: var(--gold); stroke: #3a3632; stroke-width: calc(0.5px / var(--k, 1)); cursor: pointer; transition: fill .1s; }
.structure-grave:hover .structure-grave-shape { fill: #a98540; }
.structure-grave .stone { opacity: .9; }
.structure-grave-name { fill: #1f1a10; font-weight: 600; }

.highlight-cell { fill: none; stroke: #a03030; stroke-width: calc(2px / var(--k, 1)); pointer-events: none; }
.highlight-ring { fill: rgba(160,48,48,0.12); stroke: #a03030; stroke-width: calc(1px / var(--k, 1)); pointer-events: none; animation: pulse 1.6s ease-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 0% { transform: scale(.6); opacity: .9; } 100% { transform: scale(1.6); opacity: 0; } }
.highlight-ring.ring2 { animation-delay: .8s; }
.highlight-dot { fill: #a03030; stroke: #fff; stroke-width: calc(1px / var(--k, 1)); pointer-events: none; }

/* admin overlay */
.draft-line { fill: none; stroke: #a03030; stroke-width: calc(1.2px / var(--k, 1)); stroke-dasharray: 2 1; }
.draft-pt { fill: #a03030; stroke: #fff; stroke-width: calc(0.6px / var(--k, 1)); }
.draft-label { fill: #a03030; font-family: 'DM Sans'; font-weight: 600; pointer-events: none; }
.sel-outline { fill: none; stroke: #a03030; stroke-width: calc(1px / var(--k, 1)); stroke-dasharray: 3 1.5; pointer-events: none; }
.sel-section { stroke: #2a6496; }
.sel-cell { fill: rgba(42,100,150,0.3); stroke: #2a6496; stroke-width: calc(1px / var(--k, 1)); pointer-events: none; }
.handle { fill: #fff; stroke: #a03030; stroke-width: calc(1.2px / var(--k, 1)); cursor: move; }
.handle-mid { fill: rgba(255,255,255,0.8); stroke: #c08080; cursor: copy; }
.handle-sec { stroke: #2a6496; }
.handle-move { fill: #2a6496; stroke: #fff; }

/* ---------- detail ---------- */
.detail-overlay { position: fixed; inset: 0; z-index: 200; display: flex; align-items: flex-end; justify-content: center; opacity: 0; pointer-events: none; transition: opacity .25s; }
.detail-overlay.active { opacity: 1; pointer-events: all; }
.detail-backdrop { position: absolute; inset: 0; background: rgba(26,24,21,0.3); backdrop-filter: blur(2px); }
.detail-card { position: relative; background: var(--parchment); border-radius: 22px 22px 0 0; width: 100%; max-width: 540px; max-height: 74vh; overflow-y: auto; transform: translateY(100%); transition: transform .4s cubic-bezier(.16,1,.3,1); box-shadow: 0 -4px 40px rgba(26,24,21,0.18); }
.detail-overlay.active .detail-card { transform: translateY(0); }
.detail-handle { width: 36px; height: 4px; background: #d6d0c4; border-radius: 2px; margin: 10px auto 8px; }
.detail-close { position: absolute; right: 12px; top: 10px; width: 32px; height: 32px; border-radius: 50%; background: rgba(26,24,21,0.06); font-size: 20px; line-height: 1; z-index: 2; }
.detail-content { padding: 0 22px 32px; }
@media (min-width: 900px) {
  .detail-overlay { align-items: stretch; justify-content: flex-end; top: var(--header-h); }
  .detail-backdrop { background: transparent; backdrop-filter: none; }
  .detail-card { max-width: 440px; max-height: none; border-radius: 0; transform: translateX(100%); box-shadow: -8px 0 40px rgba(26,24,21,0.12); border-left: 1px solid var(--line); }
  .detail-overlay.active .detail-card { transform: translateX(0); }
  .detail-handle { display: none; }
  .detail-content { padding-top: 16px; }
}

.stone-card { background: linear-gradient(145deg, #8a8478, #6a645a, #7a7468); border-radius: 14px 14px 5px 5px; padding: 26px 22px 20px; margin-bottom: 18px; text-align: center; color: #fff; position: relative; }
.stone-card.stone-f { background: linear-gradient(145deg, #8d7f84, #6d5f66, #7d6f74); }
.stone-card.stone-notable::after { content: ''; position: absolute; inset: 6px; border: 1px solid rgba(196,162,101,0.55); border-radius: 10px 10px 2px 2px; pointer-events: none; }
.stone-card.stone-structure { background: linear-gradient(145deg, #3a3632, #2a2825, #343230); }
.stone-card.stone-plain { background: linear-gradient(145deg, #b5aea0, #9c9589, #aaa295); }
.stone-hebrew { font-family: 'Cormorant Garamond', serif; font-size: 17px; letter-spacing: 2px; color: rgba(255,255,255,0.55); margin-bottom: 6px; direction: rtl; }
.stone-name { font-family: 'Cormorant Garamond', serif; font-size: 27px; line-height: 1.2; }
.stone-maiden { font-size: 13px; font-style: italic; color: rgba(255,255,255,0.55); margin-top: 3px; }
.stone-lineage { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: rgba(255,255,255,0.7); margin-top: 4px; }
.stone-lineage span { text-transform: none; letter-spacing: 0; font-family: 'Cormorant Garamond', serif; font-size: 14px; }
.lineage-row { align-items: center; gap: 14px; margin: 4px 0 8px; }
.stone-dates { font-size: 14px; color: rgba(255,255,255,0.65); margin-top: 8px; }
.stone-hebrew-date { font-size: 13px; color: rgba(255,255,255,0.55); margin-top: 3px; }
.stone-civil { font-size: 11px; color: rgba(255,255,255,0.4); margin-top: 2px; }

.d-section { margin-bottom: 20px; }
.d-section h4 { font-size: 10px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); margin-bottom: 8px; font-weight: 500; }
.tag { font-size: 9px; background: rgba(26,24,21,0.08); color: var(--muted); border-radius: 4px; padding: 1px 5px; margin-left: 6px; text-transform: uppercase; letter-spacing: .5px; vertical-align: middle; }
.tag.warn { background: rgba(196,162,101,0.25); color: #7a5c20; }
.tag.gold { background: var(--gold-dim); color: #7a5c20; }
.loc-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip { display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; min-width: 64px; }
.chip span { font-size: 9px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.chip b { font-family: 'Cormorant Garamond', serif; font-size: 20px; font-weight: 600; color: var(--stone); }
.directions { background: #fff; border-left: 3px solid var(--sage); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; line-height: 1.5; color: #4a4640; margin-bottom: 10px; }
.directions b { color: var(--sage-dark); }
.bio { font-family: 'Cormorant Garamond', serif; font-size: 17.5px; line-height: 1.6; color: #3e3a34; }
.bio p + p { margin-top: 10px; }
.muted { font-size: 13px; color: var(--muted); line-height: 1.45; }
.muted.small, .small { font-size: 11.5px; }
.rel-group { font-size: 9px; text-transform: uppercase; letter-spacing: .8px; color: var(--faint); margin: 8px 0 3px; }
.row-link { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; margin-bottom: 6px; text-decoration: none; color: inherit; transition: border-color .15s, transform .15s; }
.row-link:not(.static):hover { border-color: rgba(26,24,21,0.2); transform: translateX(2px); }
.row-link.static { opacity: .7; cursor: default; }
.row-link-main { font-family: 'Cormorant Garamond', serif; font-size: 17px; color: var(--stone); }
.row-link-sub { font-size: 11.5px; color: var(--muted); }
.row-link.link { flex-direction: row; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-link.link .row-link-main { font-family: 'DM Sans', sans-serif; font-size: 13.5px; flex: 1; min-width: 140px; }
.badge { font-size: 9px; font-weight: 600; letter-spacing: .3px; text-transform: uppercase; padding: 3px 7px; border-radius: 5px; color: #fff; background: #888; white-space: nowrap; }
.src-chabad { background: #1a3a5c; } .src-collive { background: #c41e3a; } .src-derher { background: #2c5530; } .src-anash { background: #e67e22; }
.src-ch { background: #4a3a7c; } .src-kfar { background: #5b2d8e; } .src-pedia { background: #2a6496; } .src-wiki { background: #eee; color: #333; }
.src-geni { background: #6b8e23; } .src-hb { background: #7a5c20; } .src-yt { background: #e00; } .src-fag { background: #556b2f; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.btn { padding: 9px 14px; border-radius: 10px; border: 1px solid rgba(26,24,21,0.12); background: #fff; font-size: 13px; font-weight: 500; color: var(--stone); transition: background .15s; }
.btn:hover { background: #f6f3ec; }
.btn.primary { background: var(--sage-dark); border-color: var(--sage-dark); color: #fff; }
.btn.primary:hover { background: #3d4d35; }
.btn.danger { color: var(--danger); border-color: rgba(160,64,64,0.3); }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.tiny { padding: 2px 8px; font-size: 12px; line-height: 1.4; }
.btn.icon { width: 30px; padding: 4px; }
.btn[disabled] { opacity: .5; cursor: default; }

.block-index { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.bi-item { display: flex; flex-direction: column; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px; }
.bi-item.has { background: rgba(122,139,111,0.15); border-color: rgba(74,90,64,0.3); }
.bi-item b { font-family: 'Cormorant Garamond', serif; font-size: 18px; }
.bi-item span { font-size: 10px; color: var(--sage-dark); min-height: 12px; }

#toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: var(--ink); color: var(--parchment); padding: 10px 18px; border-radius: 20px; font-size: 13px; opacity: 0; transition: all .25s; z-index: 500; pointer-events: none; }
#toast.show { opacity: .95; transform: translate(-50%, 0); }

/* ---------- admin panel ---------- */
.panel-header { padding: 12px 14px 8px; border-bottom: 1px solid var(--line); }
.panel-title-row { display: flex; align-items: center; gap: 8px; }
.panel-title { font-family: 'Cormorant Garamond', serif; font-size: 20px; font-weight: 600; }
.spacer { flex: 1; }
.panel-status { font-size: 11px; color: var(--muted); margin-top: 6px; }
.mode-banner { margin-top: 8px; background: rgba(160,48,48,0.1); border: 1px solid rgba(160,48,48,0.25); color: #6a2020; border-radius: 8px; padding: 8px 10px; font-size: 12px; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; padding: 10px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--sage-dark); border-bottom-color: var(--sage-dark); }
.panel-body { flex: 1; overflow-y: auto; padding: 12px 14px 40px; }
.panel-body h3 { font-family: 'Cormorant Garamond', serif; font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.panel-body h4 { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 16px 0 6px; font-weight: 500; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.45; margin: 8px 0; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 10px 0; }
.card.sub { background: var(--paper); }
.f { display: flex; flex-direction: column; gap: 3px; margin: 6px 0; }
.f-label { font-size: 11px; color: var(--muted); }
.f-hint { font-size: 11px; color: var(--faint); line-height: 1.35; }
.f input, .f select, .f textarea, .rel-row input, .rel-row select, .link-row input, .link-row select, input.search {
  padding: 7px 9px; border-radius: 8px; border: 1px solid rgba(26,24,21,0.14); background: var(--paper); font-size: 13px; width: 100%; min-width: 0;
}
.f input:focus, .f textarea:focus, .f select:focus { outline: none; border-color: var(--sage); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; margin: 8px 0; }
.list { display: flex; flex-direction: column; gap: 4px; }
.list-title { margin-top: 18px; }
.list-item { display: flex; flex-direction: column; text-align: left; width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid transparent; background: rgba(255,255,255,0.6); }
.list-item:hover { background: #fff; border-color: var(--line); }
.list-item.active { background: rgba(122,139,111,0.14); border-color: rgba(74,90,64,0.3); }
.li-main { font-size: 14px; color: var(--stone); }
.li-sub { font-size: 11px; color: var(--muted); }
.plot-row { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.roster-lookup { margin: 6px 0 10px; }
.roster-lookup .btn-row { flex-wrap: wrap; align-items: center; gap: 6px; }
.roster-lookup input { font-size: 13px; padding: 4px 8px; }
.roster-lookup .roster-q { flex: 1 1 120px; min-width: 100px; }
.roster-lookup .roster-y { width: 62px; }
.roster-lookup .roster-b { width: 58px; }
.roster-results { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; max-height: 340px; overflow: auto; }
.roster-row { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.roster-row.current { border-color: var(--gold); background: rgba(196,162,101,0.12); }
.roster-row .roster-sub { font-size: 11px; color: var(--muted); margin: 2px 0 4px; }
.roster-row .roster-notes { color: #9a6b2a; }
.roster-row .btn-row { gap: 6px; }
.rel-editor, .links-editor { display: flex; flex-direction: column; gap: 6px; }
.rel-row { display: grid; grid-template-columns: 120px 1fr 28px; gap: 6px; align-items: start; }
.rel-row.linked input { border-color: var(--sage); background: rgba(122,139,111,0.08); }
.rel-target { position: relative; }
.suggest { position: absolute; left: 0; right: 0; top: 100%; z-index: 5; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.suggest:empty { display: none; }
.suggest-item { text-align: left; padding: 7px 10px; font-size: 13px; }
.suggest-item:hover { background: rgba(122,139,111,0.12); }
.link-row { display: grid; grid-template-columns: 110px 1fr 1fr 80px 28px; gap: 4px; }
input.search { flex: 1; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .app-header { gap: 8px; padding: 0 10px; }
  .brand-sub { display: none; }
  .brand-name { font-size: 16px; max-width: 110px; }
  .search { max-width: none; }
  .header-actions .icon-btn { width: 34px; height: 34px; }
  .stage { flex-direction: column; }
  .admin-panel { width: 100%; flex: 0 0 45vh; border-right: none; border-bottom: 1px solid var(--line); }
  .block-panel { left: 8px; right: 8px; width: auto; top: 8px; max-height: 42%; }
  .compass { top: 150px; }
  .stats { display: none; }
  .legend { left: 8px; right: 8px; bottom: 8px; }
  .link-row { grid-template-columns: 1fr 1fr; }
  .rel-row { grid-template-columns: 100px 1fr 28px; }
}
