/* Goetic–Shem Grimoire
   Dark grimoire theme by default, parchment theme on [data-theme="light"].
   Type scale is set in rem from --fs, so the Settings text-size slider scales everything. */
:root {
  --bg: #0f0d11;
  --bg-2: #17141a;
  --panel: #1b181f;
  --panel-2: #241f29;
  --line: #342e3b;
  --line-soft: #2a2530;
  --text: #ece5d3;
  --muted: #a99f8a;
  --gold: #c8a24c;
  --gold-2: #e6c77c;
  --day: #d6ae55;
  --night: #8496c4;
  --danger: #dc7a66;
  --edit: #8fc3db;
  --seal: #eadcb4;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 10px 30px rgba(0, 0, 0, .25);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --display: "Cinzel", "Trajan Pro", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --hebrew: "SBL Hebrew", "Ezra SIL", "Taamey Frank CLM", "Times New Roman", "Arial Hebrew", "David", serif;
  --fs: 17px;
  --radius: 14px;
  --gap: 1rem;
  --tabbar-h: 0px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f1e8d4;
  --bg-2: #e9ddc2;
  --panel: #faf4e6;
  --panel-2: #efe4cb;
  --line: #d6c49f;
  --line-soft: #e4d6b8;
  --text: #2a2016;
  --muted: #6e5e46;
  --gold: #8a6420;
  --gold-2: #6b4a10;
  --day: #95680f;
  --night: #3c5085;
  --danger: #a63c27;
  --edit: #22607c;
  --seal: #2a2016;
  --shadow: 0 1px 2px rgba(80, 55, 20, .12), 0 10px 26px rgba(80, 55, 20, .10);
  color-scheme: light;
}
/* phones get a larger base size; the Settings slider still overrides it */
@media (max-width: 700px) { :root { --fs: 18px; --gap: .85rem; } }

* { box-sizing: border-box; }
html { font-size: var(--fs); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: var(--gold-2); text-underline-offset: .15em; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { font-family: var(--display); font-weight: 600; color: var(--gold-2); margin: 0 0 .6rem; line-height: 1.25; letter-spacing: .02em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 .8rem; }
.hebrew, [lang="he"] { font-family: var(--hebrew); direction: rtl; unicode-bidi: isolate; font-size: 1.25em; line-height: 1.2; }
.zg, .wheel .glyph { font-family: "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols 2", "Noto Sans Symbols", serif; font-variant-emoji: text; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 1rem;
  padding: calc(.6rem + env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) .6rem max(1.25rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(10px);
  -webkit-backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: baseline; gap: .55rem; text-decoration: none; min-width: 0; }
.brand-mark { color: var(--gold); font-size: 1.15rem; }
.brand-name { font-family: var(--display); color: var(--gold-2); font-size: 1.05rem; letter-spacing: .06em; white-space: nowrap; }
.brand small { color: var(--muted); font-family: var(--ui); font-size: .72rem; letter-spacing: .02em; white-space: nowrap; }
.nav { display: flex; gap: .15rem; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.nav a {
  padding: .4rem .7rem; border-radius: 999px; color: var(--muted); text-decoration: none;
  font-family: var(--ui); font-size: .82rem; font-weight: 500;
}
.nav a:hover { color: var(--text); background: var(--panel); }
.nav a[aria-current="page"] { color: var(--gold-2); background: var(--panel-2); }

/* ---------- tab bar (phones, tablets in portrait) ---------- */
.tabbar { display: none; }
@media (max-width: 900px) {
  :root { --tabbar-h: 62px; }
  .nav { display: none; }
  .brand small { display: none; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding: 4px max(6px, env(safe-area-inset-left)) env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--bg-2) 92%, transparent);
    backdrop-filter: saturate(1.2) blur(12px);
    -webkit-backdrop-filter: saturate(1.2) blur(12px);
    border-top: 1px solid var(--line);
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); text-decoration: none; font-family: var(--ui); font-size: .68rem; font-weight: 500; letter-spacing: .01em;
  }
  .tabbar .ti { font-size: 1.25rem; line-height: 1; font-family: "Segoe UI Symbol", "Apple Symbols", var(--hebrew), serif; }
  .tabbar a[aria-current="page"] { color: var(--gold-2); }
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .5rem 1rem; min-height: 44px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--text); text-decoration: none; cursor: pointer;
  font-family: var(--ui); font-size: .88rem; font-weight: 500;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--gold); }
.btn.on { border-color: var(--gold); color: var(--gold-2); background: var(--panel-2); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #1a140a; font-weight: 600; }
.btn.small { min-height: 36px; padding: .3rem .8rem; font-size: .8rem; }
.btn.ghost { background: transparent; }
.btn[disabled] { opacity: .6; }

/* ---------- page frame ---------- */
main {
  max-width: 1200px; margin: 0 auto;
  padding: 1.5rem max(1.25rem, env(safe-area-inset-right)) 2.5rem max(1.25rem, env(safe-area-inset-left));
}
.lede { color: var(--muted); }
.notice {
  border: 1px solid var(--line); border-left: 3px solid var(--gold);
  background: var(--panel); padding: .75rem 1rem; border-radius: 10px; color: var(--muted); font-size: .92rem; margin: 1rem 0;
}

/* ---------- home: switches + filters ---------- */
.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin: 1rem 0; }
.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); }
.seg button {
  border: 0; background: transparent; padding: .4rem 1rem; min-height: 38px; border-radius: 999px; cursor: pointer;
  font-family: var(--ui); font-size: .85rem; font-weight: 500; color: var(--muted);
}
.seg button.on { background: var(--gold); color: #1a140a; }
.filters {
  display: grid; gap: .7rem; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1.25rem;
}
.filters label { display: flex; flex-direction: column; gap: .3rem; font-family: var(--ui); font-size: .75rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.filters input, .filters select {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: .55rem .7rem; min-height: 44px; font-family: var(--ui); font-size: 16px; /* 16px stops iOS zooming on focus */
  text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text);
}
.filters .wide { grid-column: span 2; }
.filters-actions { display: flex; align-items: end; gap: .6rem; }
.count { color: var(--muted); font-family: var(--ui); font-size: .82rem; }
.filters-toggle { display: none; }

/* ---------- wheel ---------- */
.wheel-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.25rem; align-items: start; }
.wheel { width: 100%; max-width: min(760px, 82vh); margin: 0 auto; display: block; touch-action: manipulation; }
.wheel .sector { cursor: pointer; transition: opacity .15s; }
.wheel .sector:hover, .wheel .sector:focus { opacity: .82; outline: none; }
.wheel .sector.dim { opacity: .22; }
.wheel text { font-family: var(--ui); fill: var(--text); pointer-events: none; }
.wheel .glyph { font-size: 24px; fill: var(--gold-2); }
.wheel .num { font-size: 10px; fill: var(--muted); }
.wheel .loaded-name { font-family: var(--serif); font-size: 9.5px; fill: var(--text); font-weight: 500; }
.wheel .wc-title { font-family: var(--display); font-size: 24px; fill: var(--gold-2); letter-spacing: .04em; }
.wheel .wc-title2 { font-family: var(--display); font-size: 18px; fill: var(--gold); }
.wheel .wc-sub { font-size: 12px; fill: var(--muted); }
.wheel-side {
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 1.1rem; font-size: .95rem;
  position: sticky; top: 5rem;
}
.legend { display: grid; gap: .4rem; margin-top: .8rem; color: var(--muted); font-family: var(--ui); font-size: .82rem; }
.sw { display: inline-block; width: .9em; height: .9em; border-radius: 3px; vertical-align: -.1em; margin-right: .4em; }

/* ---------- grid of pairs ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: var(--gap); }
.pcard {
  display: block; text-decoration: none; color: inherit;
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: .9rem 1rem; box-shadow: var(--shadow); transition: border-color .15s, transform .15s;
}
.pcard:hover { border-color: var(--gold); }
.pcard:active { transform: scale(.99); }
.pcard.unloaded { opacity: .45; box-shadow: none; }
.pcard .pos { font-family: var(--ui); font-size: .78rem; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: .4rem; }
.pcard .names { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem .8rem; margin-top: .5rem; align-items: center; }
.pcard .who { font-family: var(--display); color: var(--gold-2); font-size: 1.02rem; line-height: 1.2; }
.pcard .who small { display: block; font-family: var(--ui); color: var(--muted); font-size: .72rem; letter-spacing: .02em; margin-top: .15rem; }
.pill { display: inline-block; font-family: var(--ui); font-size: .7rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; padding: .1rem .5rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.pill.day { color: var(--day); border-color: color-mix(in srgb, var(--day) 60%, transparent); }
.pill.night { color: var(--night); border-color: color-mix(in srgb, var(--night) 60%, transparent); }

/* ---------- pair page ---------- */
.pair-head {
  display: flex; flex-wrap: wrap; gap: .3rem 1rem; align-items: center;
  padding: 0 0 1rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line-soft);
}
.pair-head h1 { margin: 0; font-size: 1.85rem; }
.pair-head .meta { color: var(--muted); font-size: .95rem; width: 100%; }
.pair-nav { display: flex; gap: .5rem; flex-wrap: wrap; margin-left: auto; }
.pair-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; }
.tabs-mobile { display: none; }
.entity { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 1.25rem; min-width: 0; box-shadow: var(--shadow); }
.entity > header { display: flex; justify-content: space-between; gap: .75rem; align-items: flex-start; flex-wrap: wrap; padding-bottom: .9rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line-soft); }
.entity > header .kind { font-family: var(--ui); font-size: .75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.entity > header h2 { font-size: 1.7rem; margin: .1rem 0 0; }
.entity-tabs { display: flex; gap: .4rem; flex-wrap: wrap; }

.seal-main {
  display: grid; justify-items: center; background: var(--bg-2); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 1.25rem 1rem 1rem; color: var(--seal);
}
/* Explicit sizes, not aspect-ratio: Safari otherwise lets a traced SVG (viewBox of ~1000 units, no width)
   grow to its natural size and break the layout. */
.seal-main .svgbox { width: min(100%, 340px); height: min(340px, 78vw); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.svgbox > svg, .svgbox > img { display: block; width: 100%; height: 100%; max-width: 100%; max-height: 100%; }
main svg:not(.wheel) { max-width: 100%; }
.cap { font-family: var(--ui); font-size: .8rem; color: var(--muted); margin-top: .5rem; text-align: center; line-height: 1.45; }
.seal-actions { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: center; margin-top: .75rem; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: .55rem; margin-top: .75rem; }
.gallery button {
  background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: 10px; padding: .45rem .35rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: .3rem; color: var(--seal); min-height: 44px;
}
.gallery button.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.gallery .thumb { width: 68px; height: 68px; display: flex; align-items: center; justify-content: center; overflow: hidden; flex: none; }
.gallery .thumb > svg, .gallery .thumb > img { display: block; width: 100%; height: 100%; }
.mini-svg > div { overflow: hidden; }
.mini-svg svg { display: block; width: 100%; height: 100%; }
.gallery span { font-family: var(--ui); font-size: .7rem; color: var(--muted); line-height: 1.25; text-align: center; }
img.raster { width: 100%; height: 100%; object-fit: contain; background: #fff; border-radius: 6px; }
.engraving img { width: 100%; max-width: 380px; display: block; margin: 0 auto; border-radius: 8px; filter: sepia(.2); }
:root[data-theme="light"] .engraving img { filter: none; }

/* sections of a card: collapsible */
.group { margin-top: 1.25rem; border-top: 1px solid var(--line-soft); padding-top: .4rem; }
.group > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; padding: .55rem 0; }
.group > summary::-webkit-details-marker { display: none; }
.group > summary h3 { margin: 0; font-size: 1.1rem; }
.group > summary::after { content: "⌄"; color: var(--muted); font-family: var(--ui); font-size: 1.2rem; transition: transform .2s; }
.group:not([open]) > summary::after { transform: rotate(-90deg); }
.engraving > h3 { margin-top: .4rem; }

.field { padding: .8rem 0; border-bottom: 1px solid var(--line-soft); }
.field:last-of-type { border-bottom: 0; }
.field > .label {
  display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; margin-bottom: .35rem;
  font-family: var(--ui); font-size: .74rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
}
.field ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: .55rem; }
.reading { display: block; min-width: 0; font-size: 1rem; overflow-wrap: anywhere; }
.reading .v.quote { font-style: italic; }
.reading .v.quote::before { content: "“"; color: var(--gold); }
.reading .v.quote::after { content: "”"; color: var(--gold); }
.reading details summary { cursor: pointer; color: var(--text); }
.reading details summary::marker { color: var(--gold); }
.reading details[open] summary { color: var(--muted); font-size: .85rem; margin-bottom: .3rem; }
.cite {
  display: inline-block; margin-left: .35rem; vertical-align: .08em;
  font-family: var(--ui); font-size: .74rem; font-weight: 500; line-height: 1.5; color: var(--gold);
  border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent); border-radius: 6px; padding: 0 .4rem;
  background: color-mix(in srgb, var(--gold) 7%, transparent); cursor: pointer; max-width: 100%; text-align: left;
}
.reading .note { display: block; font-family: var(--ui); font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.badge { font-family: var(--ui); font-size: .66rem; font-weight: 600; border-radius: 999px; padding: .05rem .5rem; border: 1px solid; letter-spacing: .03em; text-transform: none; }
.badge.differ { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 70%, transparent); }
.badge.inf { color: var(--night); border-color: var(--night); }
.badge.edit { color: var(--edit); border-color: var(--edit); }
.badge.nf { color: var(--danger); border-color: var(--danger); }
.nf-text { color: var(--danger); font-style: italic; }
.inference { border-left: 2px solid var(--night); padding-left: .6rem; }
.conflict-note { font-family: var(--ui); font-size: .82rem; color: var(--muted); margin-top: .45rem; padding: .45rem .6rem; border-radius: 8px; background: color-mix(in srgb, var(--danger) 8%, transparent); }
.useredit { border-left: 3px solid var(--edit); padding: .45rem .65rem; background: color-mix(in srgb, var(--edit) 9%, transparent); border-radius: 6px; margin-bottom: .5rem; }
.useredit .hist { font-family: var(--ui); font-size: .78rem; color: var(--muted); margin-top: .35rem; }
.useredit .hist summary { cursor: pointer; }
.edit-btn { display: none; }
body.editing .edit-btn { display: inline-flex; }
.editor { display: grid; gap: .5rem; margin-top: .4rem; }
.editor textarea { width: 100%; min-height: 5em; background: var(--bg-2); border: 1px solid var(--edit); border-radius: 10px; padding: .6rem; font-size: 16px; }
.editor .row { display: flex; gap: .5rem; flex-wrap: wrap; }
.edit-banner { display: none; }
body.editing .edit-banner { display: block; border-color: var(--edit); border-left-color: var(--edit); color: var(--text); }
.position-box { background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: 10px; padding: .65rem .85rem; }
.position-box b { color: var(--gold-2); font-weight: 600; }

/* source comparator */
.compare-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line-soft); border-radius: 10px; }
table.compare { border-collapse: collapse; font-size: .85rem; min-width: 680px; width: 100%; }
table.compare th, table.compare td { border-bottom: 1px solid var(--line-soft); padding: .5rem .6rem; vertical-align: top; text-align: left; }
table.compare th { position: sticky; top: 0; background: var(--panel-2); color: var(--gold-2); font-family: var(--ui); font-weight: 600; font-size: .78rem; }
table.compare td:first-child, table.compare th:first-child { position: sticky; left: 0; background: var(--panel-2); color: var(--muted); min-width: 110px; font-family: var(--ui); font-size: .78rem; }
table.compare td.empty { color: var(--line); }

/* reference pages */
.ref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: var(--gap); }
.ref-card { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.ref-card + .ref-card { margin-top: var(--gap); }
.ref-grid .ref-card + .ref-card { margin-top: 0; }
.ref-card .fig { color: var(--seal); background: var(--bg-2); border-radius: 10px; padding: .8rem; display: grid; place-items: center; }
.ref-card .fig svg { display: block; width: 100%; height: min(320px, 80vw); }
table.plain { border-collapse: collapse; width: 100%; font-size: .92rem; }
table.plain th, table.plain td { border-bottom: 1px solid var(--line-soft); padding: .55rem .5rem; text-align: left; vertical-align: top; }
table.plain th { color: var(--gold-2); font-family: var(--ui); font-weight: 600; font-size: .8rem; letter-spacing: .03em; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.bous { border-collapse: collapse; margin: .6rem 0; direction: rtl; }
.bous td { font-family: var(--hebrew); font-size: 1.45rem; width: 1.7em; text-align: center; border: 1px solid var(--line-soft); padding: .15rem; }
.bous td.diff { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.bous tr.idx td { font-family: var(--ui); font-size: .62rem; color: var(--muted); border: 0; }
.bous td.hl { background: color-mix(in srgb, var(--gold) 20%, transparent); }
.report-list { display: grid; gap: .6rem; padding: 0; }
.report-list li { background: var(--panel); border: 1px solid var(--line-soft); border-radius: 10px; padding: .7rem .9rem; list-style: none; }
.report-list .kind { display: block; font-family: var(--ui); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--gold); margin-bottom: .2rem; }

/* More page */
.more-links { display: grid; gap: .6rem; }
.more-link {
  display: flex; flex-direction: column; gap: .1rem; padding: .9rem 1.1rem; text-decoration: none;
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); color: var(--text);
}
.more-link b { font-family: var(--display); color: var(--gold-2); font-weight: 600; }
.more-link span { font-family: var(--ui); font-size: .85rem; color: var(--muted); }
.more-link:hover { border-color: var(--gold); }

/* settings */
.settings { display: grid; gap: var(--gap); max-width: 680px; }
.settings .ref-card + .ref-card { margin-top: 0; }
.settings .row { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; font-family: var(--ui); }
.settings input[type="range"] { width: 220px; accent-color: var(--gold); }

/* password screen */
body.locked .tabbar, body.locked .nav { visibility: hidden; }
.lock { max-width: 380px; margin: 12vh auto 0; display: grid; gap: .9rem; text-align: center; }
.lock-mark { font-size: 2.6rem; color: var(--gold); line-height: 1; }
.lock h1 { font-size: 1.5rem; margin: 0; }
.lock input[type="password"] {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; font-size: 17px; text-align: center; min-height: 48px;
}
.lock .remember { font-family: var(--ui); font-size: .88rem; color: var(--muted); display: flex; gap: .5rem; justify-content: center; align-items: center; }
.lock .btn { min-height: 48px; font-size: 1rem; }
.lock-err { color: var(--danger); font-family: var(--ui); min-height: 1.2em; margin: 0; }

/* dialogs, toast */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--gold); border-radius: var(--radius); max-width: min(560px, 92vw); padding: 1.25rem; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog p { font-size: .95rem; }
.toast {
  position: fixed; left: 50%; bottom: calc(1rem + var(--tabbar-h) + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--gold); padding: .6rem 1rem; border-radius: 999px; z-index: 50;
  font-family: var(--ui); font-size: .88rem; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }

/* ---------- tablets ---------- */
@media (max-width: 1024px) {
  .wheel-wrap { grid-template-columns: 1fr; }
  .wheel-side { position: static; }
  .wheel { max-width: min(720px, 100%); }
}
@media (max-width: 900px) {
  .pair-cols { grid-template-columns: 1fr; }
  .tabs-mobile {
    display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
    position: sticky; top: calc(3.3rem + env(safe-area-inset-top)); z-index: 20;
    background: var(--panel); border: 1px solid var(--line); border-radius: 999px; margin-bottom: 1rem;
  }
  .tabs-mobile .btn { border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-size: .95rem; }
  .tabs-mobile .btn.on { background: var(--gold); color: #1a140a; }
  .pair-cols[data-show="spirit"] .entity.angel, .pair-cols[data-show="angel"] .entity.spirit { display: none; }
}

/* ---------- phones ---------- */
@media (max-width: 700px) {
  main { padding-top: 1.1rem; }
  h1 { font-size: 1.55rem; }
  .brand-name { font-size: 1rem; }
  .filters { grid-template-columns: 1fr 1fr; padding: .85rem; }
  .filters .wide { grid-column: 1 / -1; }
  .filters-actions { grid-column: 1 / -1; justify-content: flex-start; align-items: center; flex-wrap: wrap; }
  .filters-toggle { display: inline-flex; }
  .filters:not(.open) .fopt { display: none; }
  .filters.open .filters-toggle { border-color: var(--gold); color: var(--gold-2); }
  .grid { grid-template-columns: 1fr; }
  .pair-head h1 { font-size: 1.5rem; }
  .pair-nav { margin-left: 0; width: 100%; }
  .pair-nav .btn { flex: 1; }
  .entity { padding: 1rem; border-radius: 12px; }
  .entity > header h2 { font-size: 1.5rem; }
  .entity-tabs { width: 100%; }
  .entity-tabs .btn { flex: 1; }
  .seal-main .svgbox { width: min(100%, 280px); height: min(280px, 72vw); }
  /* variants as a sideways strip instead of a tall grid */
  .gallery { display: flex; gap: .5rem; overflow-x: auto; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; padding-bottom: .3rem; }
  .gallery button { flex: 0 0 88px; scroll-snap-align: start; }
  .reading { font-size: 1rem; }
  .cite { display: inline-block; margin: .2rem 0 0; }
  .ref-grid { grid-template-columns: 1fr; }
  .ref-card { padding: 1rem; }
  /* the wheel is a navigator on a phone: bigger numbers, no names (the panel below shows them) */
  .wheel .num { font-size: 15px; }
  .wheel .dnum, .wheel .loaded-name { display: none; }
  .wheel .glyph { font-size: 34px; }
  .wheel .wc-title { font-size: 34px; }
  .wheel .wc-title2 { font-size: 26px; }
  .wheel .wc-sub { display: none; }
  .wheel-side { font-size: 1rem; }
}

/* ---------- print (Export as PDF) ---------- */
@media print {
  :root { --bg: #fff; --panel: #fff; --panel-2: #fff; --bg-2: #fff; --text: #000; --muted: #444; --line: #bbb; --line-soft: #ddd; --gold: #6f4e12; --gold-2: #4a330a; --seal: #000; --shadow: none; --tabbar-h: 0px; }
  .topbar, .tabbar, .toolbar, .pair-nav, .tabs-mobile, .entity-tabs, .edit-btn, .no-print, .gallery, .toast { display: none !important; }
  main { max-width: none; padding: 0; }
  .pair-cols { display: block !important; }
  .entity { display: block !important; border: 0; page-break-after: always; }
  .pair-cols.printing-one[data-show="spirit"] .entity.angel,
  .pair-cols.printing-one[data-show="angel"] .entity.spirit { display: none !important; }
  details.group > *:not(summary) { display: block !important; }
  .group > summary::after { display: none; }
  .pair-head { border: 0; padding: 0 0 .5rem; }
  body.print-seal main > *:not(.print-target) { display: none !important; }
  body.print-seal .print-target { display: block !important; }
  a { color: inherit; text-decoration: none; }
}
