/* One stylesheet, no preprocessor. The palette and its three-way declaration
   come from cheshbon:

     :root                                        the light values
     @media (prefers-color-scheme: dark)
       :root:not([data-theme="light"])            the system's dark preference
     :root[data-theme="dark"]                     an explicit choice

   so an explicit setting beats the system in both directions. Never give a
   colour its only definition inside the media query. */

:root {
  --bg: #faf8f4;
  --panel: #ffffff;
  --panel-lit: #f4f0e8;
  --line: #e4ddd0;
  --line-soft: #efe9de;
  --text: #241f18;
  --dim: #6b6153;
  --faint: #9c9184;

  --accent: #8a5a2b;
  --accent-soft: #f0e4d4;
  --bad: #a33a2c;
  --target: #fbf1c9;
  --edit: #3f7d4e;
  --ins: #dcefd9;
  --del: #f6dcd6;
  --up: #2f6a9a;
  --up-soft: #e1ecf5;

  --radius: 12px;
  --radius-sm: 8px;
  --tap: 44px;

  --font: ui-serif, Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --font-he: "SBL Hebrew", "Taamey Frank CLM", "Frank Ruehl CLM", "David", "Times New Roman", serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --topbar-h: 52px;
  --shadow: 0 1px 2px rgba(36, 31, 24, 0.06), 0 4px 16px rgba(36, 31, 24, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171512;
    --panel: #201d19;
    --panel-lit: #2a2621;
    --line: #35302a;
    --line-soft: #2b2722;
    --text: #ede7dd;
    --dim: #a89c8c;
    --faint: #7a7063;
    --accent: #d6a06a;
    --accent-soft: #33291f;
    --bad: #d97a68;
    --target: #3a3222;
    --edit: #86c493;
    --ins: #23402a;
    --del: #4a2621;
    --up: #7fb0dc;
    --up-soft: #1f2d3a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  }
}

:root[data-theme="dark"] {
  --bg: #171512;
  --panel: #201d19;
  --panel-lit: #2a2621;
  --line: #35302a;
  --line-soft: #2b2722;
  --text: #ede7dd;
  --dim: #a89c8c;
  --faint: #7a7063;
  --accent: #d6a06a;
  --accent-soft: #33291f;
  --bad: #d97a68;
  --target: #3a3222;
  --edit: #86c493;
  --ins: #23402a;
  --del: #4a2621;
  --up: #7fb0dc;
  --up-soft: #1f2d3a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* The other colour schemes. Each is a data-palette on the root (sepia, above,
   is the default and has none), with its light and dark values declared the
   same three ways. A scheme's light and dark blocks set the same colours, so
   whichever wins leaves nothing of the other behind. --bad, --edit, --ins and
   --del mean the same in every scheme; --up changes only where it would be
   lost against a blue accent. */

:root[data-palette="blue"] {
  --bg: #f5f8fc;
  --panel: #ffffff;
  --panel-lit: #eaf0f8;
  --line: #d5dfec;
  --line-soft: #e5ecf5;
  --text: #16202e;
  --dim: #4f5f75;
  --faint: #8593a6;
  --accent: #2a5694;
  --accent-soft: #dce6f4;
  --target: #fbf1c9;
  --up: #1d7a76;
  --up-soft: #d8efed;
  --shadow: 0 1px 2px rgba(22, 32, 46, 0.06), 0 4px 16px rgba(22, 32, 46, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root[data-palette="blue"]:not([data-theme="light"]) {
    --bg: #0f141c;
    --panel: #161d28;
    --panel-lit: #1e2734;
    --line: #2a3546;
    --line-soft: #212b39;
    --text: #e3e9f2;
    --dim: #9aa8bb;
    --faint: #6b788b;
    --accent: #7fa7e0;
    --accent-soft: #1d2c44;
    --target: #33301f;
    --up: #6cc5bd;
    --up-soft: #173230;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  }
}

:root[data-palette="blue"][data-theme="dark"] {
  --bg: #0f141c;
  --panel: #161d28;
  --panel-lit: #1e2734;
  --line: #2a3546;
  --line-soft: #212b39;
  --text: #e3e9f2;
  --dim: #9aa8bb;
  --faint: #6b788b;
  --accent: #7fa7e0;
  --accent-soft: #1d2c44;
  --target: #33301f;
  --up: #6cc5bd;
  --up-soft: #173230;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
}

:root[data-palette="gray"] {
  --bg: #f6f6f6;
  --panel: #ffffff;
  --panel-lit: #eeeeee;
  --line: #dcdcdc;
  --line-soft: #e8e8e8;
  --text: #1f1f1f;
  --dim: #5e5e5e;
  --faint: #929292;
  --accent: #4b5563;
  --accent-soft: #e4e6e9;
  --target: #f3efd6;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root[data-palette="gray"]:not([data-theme="light"]) {
    --bg: #161616;
    --panel: #1e1e1e;
    --panel-lit: #272727;
    --line: #333333;
    --line-soft: #2a2a2a;
    --text: #e6e6e6;
    --dim: #a3a3a3;
    --faint: #737373;
    --accent: #b8c0ca;
    --accent-soft: #2c3036;
    --target: #36332a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  }
}

:root[data-palette="gray"][data-theme="dark"] {
  --bg: #161616;
  --panel: #1e1e1e;
  --panel-lit: #272727;
  --line: #333333;
  --line-soft: #2a2a2a;
  --text: #e6e6e6;
  --dim: #a3a3a3;
  --faint: #737373;
  --accent: #b8c0ca;
  --accent-soft: #2c3036;
  --target: #36332a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
}

:root[data-palette="mono"] {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-lit: #f2f2f2;
  --line: #cfcfcf;
  --line-soft: #e6e6e6;
  --text: #000000;
  --dim: #444444;
  --faint: #777777;
  --accent: #000000;
  --accent-soft: #e6e6e6;
  --target: #ebebeb;
  --shadow: 0 0 0 1px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root[data-palette="mono"]:not([data-theme="light"]) {
    --bg: #000000;
    --panel: #000000;
    --panel-lit: #141414;
    --line: #3a3a3a;
    --line-soft: #222222;
    --text: #ffffff;
    --dim: #bbbbbb;
    --faint: #888888;
    --accent: #ffffff;
    --accent-soft: #262626;
    --target: #262626;
    --shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
  }
}

:root[data-palette="mono"][data-theme="dark"] {
  --bg: #000000;
  --panel: #000000;
  --panel-lit: #141414;
  --line: #3a3a3a;
  --line-soft: #222222;
  --text: #ffffff;
  --dim: #bbbbbb;
  --faint: #888888;
  --accent: #ffffff;
  --accent-soft: #262626;
  --target: #262626;
  --shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

/* ------------------------------------------------------------------ base */

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }

body {
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font); font-weight: 600; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* --------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
}

/* The breadcrumb stands where a title would: "Mishneh Torah › book ›
   section", all one size. When space runs short the book's name gives way
   first, then the section's. */
.crumbs {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-width: 0;
  font-family: var(--font);
  font-size: 15px;
  white-space: nowrap;
}
.crumb { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--dim); text-decoration: none; }
.crumbs > .crumb:first-child { flex: none; }
.crumbs > .crumb:nth-child(3):not(:last-child) { flex: 0 3 auto; }
.crumbs > .crumb:last-child { flex: 0 1 auto; color: var(--text); font-weight: 600; }
a.crumb:hover { color: var(--accent); }
.crumbs .sep { flex: none; color: var(--faint); }
/* Phones have room for one: where you are (the Books button goes home). */
@media (max-width: 640px) {
  .crumbs > :not(:last-child) { display: none; }
}

.iconbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--dim);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.iconbtn svg { width: 21px; height: 21px; }
.iconbtn:hover { background: var(--panel-lit); }
.iconbtn.on { color: var(--accent); }
.iconbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.iconbtn.off { opacity: 0.3; cursor: default; }
.iconbtn.off:hover { background: none; }
.iconbtn { position: relative; }
@media (max-width: 420px) {
  .topbar { gap: 2px; padding-left: 12px; padding-right: 8px; }
  .crumbs { font-size: 14px; gap: 5px; }
}
.badge {
  position: absolute;
  top: 1px;
  right: 0;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--edit);
  color: var(--bg);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

/* The top bar's menus: Bookmarks and GitHub. */
.menuwrap { position: relative; }
.iconbtn svg[viewBox="0 0 16 16"] { width: 19px; height: 19px; }
.iconbtn.offbase { box-shadow: inset 0 0 0 2px var(--up); color: var(--up); }
/* In a live session: a dot, pulsing while all is well, red and still while
   something of this device's hasn't been shared. */
.iconbtn.live::after {
  content: "";
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  background: var(--up);
  animation: livedot 2.4s ease-in-out infinite;
}
.iconbtn.live.stuck::after { background: var(--bad); animation: none; }
@keyframes livedot { 50% { opacity: 0.35; } }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  min-width: 230px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.menu > [role="menuitem"] {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.menu > [role="menuitem"]:hover, .menu > [role="menuitem"]:focus-visible { background: var(--panel-lit); outline: none; }
.menu svg { width: 18px; height: 18px; flex: none; color: var(--dim); }
.mi-label { flex: 1; }
.mi-aside { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dim); font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
/* Bookmarks: the section's name over the law and date, and a remove
   button that stays out of the way until the row is pointed at. */
.bmmenu { min-width: 280px; max-width: min(360px, calc(100vw - 24px)); }
.menu-sep { height: 1px; margin: 5px 4px; background: var(--line-soft); }
.menu-empty { margin: 6px 10px; max-width: 250px; color: var(--dim); font-family: var(--font-ui); font-size: 13px; line-height: 1.45; }
.bm-item { display: flex; align-items: center; border-radius: 6px; }
.bm-item:hover, .bm-item:focus-within { background: var(--panel-lit); }
.bm-item.cur .bm-title { color: var(--accent); }
.bm-link { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; padding: 7px 10px; color: var(--text); font-family: var(--font-ui); font-size: 14px; text-decoration: none; }
.bm-link:focus-visible { outline: none; }
.bm-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bm-sub { color: var(--dim); font-size: 12.5px; }
.bm-x { flex: none; width: 30px; height: 30px; margin-right: 4px; border: 0; border-radius: 50%; background: none; color: var(--faint); font-size: 18px; line-height: 1; cursor: pointer; opacity: 0; }
.bm-item:hover .bm-x, .bm-x:focus-visible { opacity: 1; }
.bm-x:hover { color: var(--bad); background: var(--panel); }
.bm-x:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (hover: none) { .bm-x { opacity: 1; } }
/* Phones: the menus hang from the top bar's right edge, not their button. */
@media (max-width: 480px) {
  .menuwrap { position: static; }
  .menu { right: 8px; top: calc(100% + 4px); }
}
.iconbtn.has svg path { fill: currentColor; fill-opacity: 0.18; }
#menu-changes .mi-aside:not(:empty) { padding: 0 6px; border-radius: 8px; background: var(--edit); color: var(--bg); font-family: var(--font-ui); font-weight: 700; }

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 3px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--dim);
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------------------------------------------------------------- main */

#main { padding-bottom: 48px; }
.screen { display: none; max-width: 1480px; margin: 0 auto; padding: 16px 20px 0; }
.screen.on { display: block; }
#screen-books, #screen-settings { max-width: 860px; margin: 0 auto; }

.page-title { font-size: 26px; margin: 8px 0 2px; }
.page-sub { color: var(--faint); font-size: 13px; margin: 0 0 18px; font-family: ui-monospace, Consolas, monospace; }

.message { padding: 48px 8px; text-align: center; color: var(--dim); }
.message p { max-width: 560px; margin: 0 auto 14px; }
.message.error p { color: var(--bad); }
.message.loading p { color: var(--faint); }

.note { color: var(--dim); font-size: 14px; margin: 6px 0; }

/* --------------------------------------------------------------- books */

.book {
  margin: 0 0 12px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.book > summary {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  list-style: none;
}
.book > summary::-webkit-details-marker { display: none; }
.book > summary::before { content: "▸"; color: var(--faint); font-size: 12px; }
.book[open] > summary::before { content: "▾"; }
.book-en { flex: 1; font-family: var(--font); font-size: 18px; font-weight: 600; }
.book-he { font-family: var(--font-he); font-size: 19px; color: var(--dim); }

.secs { padding: 0 8px 10px; }
.sec {
  display: grid;
  grid-template-columns: 38px 1fr auto 96px;
  align-items: baseline;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
}
.sec:hover { background: var(--panel-lit); }
.sec-id { color: var(--faint); font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.sec-en { font-family: var(--font); }
.sec-he { font-family: var(--font-he); font-size: 17px; color: var(--dim); }
.sec-meta { color: var(--faint); font-size: 12px; text-align: right; }

@media (max-width: 640px) {
  .sec { grid-template-columns: 34px 1fr; }
  .sec-he { grid-column: 2; }
  .sec-meta { display: none; }
}

/* -------------------------------------------------------------- reader */

/* The reader's header spans the window, as the top bar does; what is
   under it keeps to the width the screens have. */
#screen-read { max-width: none; }
#screen-read > :not(.rhead) { max-width: 1440px; margin-left: auto; margin-right: auto; }

/* The header sticks under the top bar (which says where you are): the
   section and chapter, and the buttons. reader.js measures it into
   --rhead-h so a row scrolled to lands clear of it. */
.rhead {
  position: sticky;
  top: calc(var(--topbar-h) + env(safe-area-inset-top));
  z-index: 19;   /* over the notes pane (18), so its menus open over it too; under the top bar */
  margin: -16px -20px 0;
  padding: 8px 20px 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
}
.rbar { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; }
.pager { display: flex; align-items: center; gap: 2px; min-width: 0; }
.pager .iconbtn { width: 32px; height: 32px; min-width: 32px; }

/* The header's names: the section, opening the contents, and the chapter,
   opening the section's chapters. */
.pager .navwrap + .navwrap, .pager .navwrap + .navtext { margin-left: 4px; }
.navwrap { position: relative; min-width: 0; }
.navbtn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: min(40vw, 340px);
  min-height: 32px;
  padding: 3px 6px 3px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  cursor: pointer;
}
.navbtn:hover { border-color: var(--faint); }
.navbtn[aria-expanded="true"] { border-color: var(--accent); }
.navbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.navbtn svg { flex: none; width: 16px; height: 16px; color: var(--dim); }
.navtext { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.navtext.solo { padding: 0 8px; color: var(--dim); font-size: 14px; }
.navpop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 40;
  width: min(640px, calc(100vw - 24px));
  max-height: min(70vh, 640px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 4px 10px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.navpop.chapters { width: min(420px, calc(100vw - 24px)); padding-top: 10px; }
.navpop .book { margin: 0; border: 0; border-radius: 0; background: none; box-shadow: none; }
.navpop .book + .book { border-top: 1px solid var(--line-soft); }
.navpop .book > summary { padding: 10px 8px; }
.navpop .book.cur > summary .book-en { color: var(--accent); }
.navpop .secs { padding: 0 0 6px; }
.navpop .tbook.cur > summary, .navpop .tsec.cur { background: var(--accent-soft); }
/* Phones: the pop-ups hang the width of the screen below the header. */
@media (max-width: 640px) {
  .navwrap { position: static; }
  .navpop, .navpop.chapters {
    position: fixed;
    top: calc(var(--topbar-h) + env(safe-area-inset-top) + var(--rhead-h, 50px) + 4px);
    left: 8px;
    right: 8px;
    width: auto;
    max-height: calc(100vh - var(--topbar-h) - var(--rhead-h, 50px) - 24px);
  }
}

/* The contents: a section opening on its chapters, or a link straight to
   its one. */
.tbook > summary, .tsec {
  display: grid;
  grid-template-columns: 1fr auto 80px;
  align-items: baseline;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  list-style: none;
}
.tbook > summary::-webkit-details-marker { display: none; }
.tbook > summary:hover, .tsec:hover { background: var(--panel-lit); }
.tbook[open] > summary { color: var(--accent); }
.chgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 4px;
  padding: 4px 10px 12px;
}
.navpop.chapters .chgrid { padding: 0; }
.chnum {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 6px;
  background: var(--panel-lit);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  text-decoration: none;
}
/* An unnumbered chapter, by its name, across the grid. */
.chnum.chname { grid-column: 1 / -1; justify-content: flex-start; padding: 6px 12px; font-family: var(--font); font-size: 14.5px; }
.chnum:hover { background: var(--accent-soft); color: var(--accent); }
.chnum[aria-current="page"] { background: var(--accent); color: var(--bg); font-weight: 600; }
.chnum.up { box-shadow: inset 0 -2px 0 var(--up); }
@media (max-width: 640px) {
  .tbook > summary, .tsec { grid-template-columns: 1fr; gap: 2px; }
  .tbook .sec-meta { display: none; }
}

.toggles { display: flex; gap: 8px; align-items: center; }

/* A button group: icons (or a letter standing for one) in one bordered strip. */
.segs { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); overflow: hidden; }
.segs:empty { display: none; }
.seg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 32px;
  padding: 0;
  border: 0;
  border-inline-start: 1px solid var(--line-soft);
  background: none;
  color: var(--dim);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.seg:first-child { border-inline-start: 0; }
.seg svg { width: 19px; height: 19px; }
.seg.glyph { font-family: var(--font); font-size: 17px; font-weight: 600; }
.seg.glyph.he { font-family: var(--font-he); font-size: 19px; line-height: 1; }
.seg:hover { background: var(--panel-lit); }
.seg[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.seg:disabled { opacity: 0.35; cursor: default; background: none; }
.seg:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.seg.markseg[aria-pressed="true"] { background: var(--up-soft); color: var(--up); }

/* The Display menu: niqqud, which texts show, where the Hebrew and the
   notes pane are. Its button shows the Hebrew as it is showing. */
.dispwrap { position: relative; }
.seg.dispbtn { width: auto; gap: 2px; padding: 0 6px 0 10px; }
.seg.dispbtn .he { font-family: var(--font-he); font-size: 19px; line-height: 1; color: var(--text); }
.seg.dispbtn svg { width: 15px; height: 15px; }
.seg.dispbtn[aria-expanded="true"] { background: var(--panel-lit); }
.dispmenu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  width: 252px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  box-shadow: var(--shadow);
  font-family: var(--font-ui);
}
.dm-head { margin: 2px 4px 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }
.dm-head:not(:first-child) { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line-soft); }
.dm-sub { margin: 5px 4px 0; font-size: 12.5px; line-height: 1.4; color: var(--dim); }
.dispmenu .hemodes { display: flex; }
.hemodes .seg.glyph.he { flex: 1; width: auto; font-size: 18px; }
.dispmenu .dm-segs { display: flex; }
.dm-segs .seg { flex: 1; width: auto; font-family: var(--font-ui); font-size: 13px; }
.dm-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 6px 6px;
  border: 0;
  border-radius: 6px;
  background: none;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.dm-item:hover { background: var(--panel-lit); }
.dm-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.dm-check { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border: 1px solid var(--line); border-radius: 4px; color: transparent; }
.dm-check svg { width: 14px; height: 14px; stroke-width: 2.4; }
.dm-item[aria-checked="true"] .dm-check { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.dm-one .dm-check { border-radius: 50%; }
/* Reading aloud: play (or stop), and beside it its options, in a menu
   drawn as the Display menu is. */
.saywrap { position: relative; }
.seg.saymore { width: 22px; }
.seg.saymore svg { width: 15px; height: 15px; }
.seg.saymore[aria-expanded="true"] { background: var(--panel-lit); }
.say-voice { display: block; margin-top: 6px; }
.say-voice .dm-sub { display: block; margin: 0 4px 3px; }
.say-voice select { width: 100%; }
.dm-sub.bad { color: var(--bad); }
@media (max-width: 480px) {
  .dispwrap, .saywrap { position: static; }
  .dispmenu { right: 8px; top: calc(100% + 2px); }
}

.rnotes:not(:empty) { padding-top: 2px; }

/* Chip rows elsewhere (search's layer filter). */
.coltoggles { display: flex; gap: 6px; flex-wrap: wrap; }
.coltoggles .chip[lang="he"] { font-family: var(--font-he); font-size: 15px; }
.chip:disabled { opacity: 0.4; cursor: default; }

.rfoot { display: flex; justify-content: center; padding: 20px 0 8px; }

/* The grid. Every row's text repeats the same column template, which is
   what keeps a Hebrew law and its translation starting on the same line.
   A hidden language drops out of the template (`show-*` classes, set by
   reader.js). A law's notes are in the pane; general remarks open under
   their marker (.open). */
.grid .row { padding: 12px 6px; border-bottom: 1px solid var(--line-soft); }
.grid .row .text { display: grid; grid-template-columns: var(--cols); gap: 28px; }
.grid.cols-1 .row { max-width: 820px; margin-left: auto; margin-right: auto; }
/* The Hebrew at the right (the Display menu's choice): last in the row. */
.grid.he-right .row .text > .cell.he { order: 1; }
.grid:not(.show-he) .text > .cell.he,
.grid:not(.show-en) .text > .cell.en,
.row.general:not(.open) .cell.co,
.cell.co.none, .cell.notes.none { display: none; }

.row.law { scroll-margin-top: calc(var(--topbar-h) + var(--rhead-h, 90px) + 12px); }
.row.law.target { background: var(--target); border-radius: var(--radius-sm); }
/* A law is chosen by its row: lit on hover, held when chosen. */
.grid .row.law:not(.vpanel) { cursor: pointer; border-radius: var(--radius-sm); }
.grid .row.law:not(.vpanel):hover { background: var(--panel-lit); }
.grid .row.law.sel:not(.vpanel) { background: var(--accent-soft); }
/* Reading aloud: the law being read, marked in the accent at its edge. */
.grid .row.law.speaking:not(.vpanel) { box-shadow: inset 3px 0 0 var(--accent); }
.row.chhead h3 { font-size: 19px; color: var(--dim); }
.row.chhead .cell.he h3 { font-family: var(--font-he); font-size: 21px; }
.row.general { padding-top: 6px; padding-bottom: 6px; }
.row.general .cell.co p { max-width: 760px; }

/* The bookmark ribbon, in the pane's bar: filled once set. A bookmarked
   law's number is underlined. */
.bmk {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--faint);
  cursor: pointer;
}
.bmk svg { width: 18px; height: 18px; }
.bmk:hover { color: var(--accent); background: var(--panel-lit); }
.bmk:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.bmk[aria-pressed="true"] { color: var(--accent); }
.bmk[aria-pressed="true"] svg path { fill: currentColor; }
.row.law.marked .text > .cell > p > .label { padding: 0 3px; border-radius: 3px; box-shadow: inset 0 -2px 0 var(--accent); }
.row.law.marked .text > .cell > p > .label.noted { padding: 0 5px; border-radius: 999px; }

/* A law with notes: its number in an outlined pill, bold, in the accent
   (green when this device has changed its notes, blue when the branch
   has). */
.label.noted {
  padding: 0 5px;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: var(--accent);
  font-weight: 700;
}
.noted.changed { color: var(--edit); }
.noted.branched { color: var(--up); }

/* In the pane (or under a general remarks marker): commentary, then review
   notes, each in columns. */
.ann .cell { margin-top: 12px; padding-top: 8px; border-top: 1px dashed var(--line); }
.row.general .ann .cell { margin-top: 4px; }
.annhead { margin-bottom: 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }
/* A block's heading in the pane folds it: a button the width of the block. */
button.annhead {
  display: flex; align-items: center; gap: 6px; width: 100%; padding: 2px 0; border: 0; background: none;
  font-family: var(--font-ui); text-align: start; cursor: pointer;
}
button.annhead:hover .annhead-name { text-decoration: underline; text-underline-offset: 3px; }
button.annhead:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
button.annhead > svg { width: 14px; height: 14px; flex: none; stroke-width: 2.2; transition: transform 0.15s; }
.annhead-n { font-weight: 500; letter-spacing: 0; opacity: 0.8; }
.cell.folded > button.annhead { margin-bottom: 0; }
.cell.folded > button.annhead > svg { transform: rotate(-90deg); }
.cell.folded > :not(.annhead) { display: none; }
.cell.notes .annhead { color: var(--accent); }
.notelist { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px 28px; align-items: start; }
.notelist div.note { margin: 0; }

/* The marker that opens general remarks. */
.annmark {
  display: inline-flex;
  gap: 12px;
  margin-top: 6px;
  padding: 1px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--faint);
  font-family: var(--font-ui);
  font-size: 12px;
  cursor: pointer;
}
.annmark:hover, .annmark[aria-expanded="true"] { border-color: var(--line); color: var(--dim); background: var(--panel); }
.annmark > span { display: inline-flex; align-items: center; gap: 4px; }
.annmark svg { width: 15px; height: 15px; }
.annmark:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.cell { min-width: 0; }
.cell p { margin: 0 0 0.6em; }
.cell p:last-child { margin-bottom: 0; }
.cell.en { font-family: var(--font); font-size: 17px; line-height: 1.6; }
.cell.he { font-family: var(--font-he); font-size: 21px; line-height: 1.65; text-align: justify; }
.cell.co, .cell.notes { font-size: 14.5px; line-height: 1.55; color: var(--dim); }
.cell.empty .missing { color: var(--faint); font-style: italic; font-size: 14px; font-family: var(--font-ui); }

.label {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  color: var(--faint);
  text-decoration: none;
  vertical-align: 2px;
  unicode-bidi: isolate;
}
.cell.he .label { font-family: var(--font-he); font-size: 15px; vertical-align: 1px; }
.label:hover { color: var(--accent); }

/* A Vilna sub-number: apparatus, not text. */
.mk {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 4px;
  margin: 0 1px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 0.62em;
  font-weight: 600;
  line-height: 1.6;
  text-align: center;
  vertical-align: 0.25em;
  unicode-bidi: isolate;
}
.cell.he .mk { font-family: var(--font-he); font-size: 0.7em; }

/* A reference to the Tanakh, opening the verse in the Tanakh Reader. Quiet
   until pointed at, so a law dense with verses doesn't read as a page of links. */
a.ref {
  color: inherit;
  text-decoration: underline dotted;
  text-decoration-color: var(--accent);
  text-underline-offset: 0.2em;
}
a.ref:hover, a.ref:focus-visible { color: var(--accent); text-decoration-style: solid; }

/* Pointed text needs room above and below the letters for the points. */
.grid.pointed .cell.he { line-height: 1.85; }

div.note { margin: 0 0 12px; padding-left: 10px; border-left: 2px solid var(--line); }
div.note:last-child { margin-bottom: 0; }
div.note.review { border-left-color: var(--accent); }
div.note p { margin: 0 0 0.5em; }
.note-range { font-size: 12px; color: var(--faint); }
.co-head { font-size: 15px; margin: 0 0 6px; color: var(--text); }

/* ------------------------------------------------------------ the pane */

/* The pane's bar: the law, and the tools for it. */
.vp-hint, .vp-none { margin: 0; color: var(--faint); font-size: 14px; line-height: 1.5; }
.vp-ref { display: flex; flex-direction: column; gap: 1px; color: var(--text); text-decoration: none; font-family: var(--font); font-size: 17px; }
.vp-ref:hover strong { color: var(--accent); }
.vp-sec { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dim); font-size: 14px; }
.vp-tools { display: flex; align-items: center; gap: 0; }
.vp-tools .iconbtn { width: 30px; height: 30px; min-width: 30px; }
.vp-tools .iconbtn svg { width: 18px; height: 18px; }
.vp-tools .iconbtn:disabled { opacity: 0.3; cursor: default; }

/* The notes pane: fixed along the bottom, the full width. Its bar is always
   there; open, it is as high as reader.js sets it (dragged by its top edge),
   the notes scrolling inside. body.paned leaves room for it at the foot of
   the page, --pane-space being its height. */
.screen .grid > .vpanel.pane {
  position: fixed;
  top: auto;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 18;
  display: flex;
  flex-direction: column;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0 0 env(safe-area-inset-bottom);
  overflow: hidden;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  cursor: auto;
}
.pane-grip { display: none; }
.pane.open-pane .pane-grip {
  display: block;
  flex: none;
  position: relative;
  height: 12px;
  margin-bottom: -6px;
  cursor: ns-resize;
  touch-action: none;
}
.pane-grip::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 50%;
  width: 40px;
  height: 4px;
  margin-left: -20px;
  border-radius: 2px;
  background: var(--line);
}
.pane-grip:hover::after, .pane.dragging .pane-grip::after { background: var(--faint); }
.pane-grip:focus-visible { outline: none; }
.pane-grip:focus-visible::after { background: var(--accent); }
.pane.dragging { user-select: none; }
.pane-bar {
  display: flex;
  align-items: center;
  gap: 4px 12px;
  flex: none;
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: 6px 16px 6px 10px;
  cursor: pointer;
}
.pane.open-pane .pane-bar { border-bottom: 1px solid var(--line-soft); }
.pane-toggle { flex: none; width: 32px; height: 32px; min-width: 32px; }
.pane-bar .vp-ref { flex-direction: row; align-items: baseline; gap: 10px; font-size: 16px; min-width: 0; }
.pane-hint { color: var(--faint); font-size: 14px; }
.pane-count { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; color: var(--faint); font-family: var(--font-ui); font-size: 13px; }
.pane-count > span { display: inline-flex; align-items: center; gap: 4px; }
.pane-count svg { width: 15px; height: 15px; }
.pane-count .mk-notes { color: var(--accent); }
.pane-bar .vp-tools { margin-inline-start: auto; }
.pane-body { display: none; }
.pane.open-pane .pane-body {
  display: block;
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: 4px 20px 16px 52px;
}
.pane .notelist { grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); }
.pane .ann .cell:first-child, .pane .vp-hint, .pane .vp-none { margin-top: 10px; }
.pane .ann .cell.none + .cell { margin-top: 10px; }
body.paned.pane-bottom .screen.on { padding-bottom: calc(var(--pane-space, 48px) + 16px); }
body.paned.pane-bottom .toast { bottom: calc(var(--pane-space, 48px) + 16px); }

/* At a side: over the text, which keeps its width, from under the reader's
   header to the foot of the screen, its grip down its inner edge. Closed, it
   is a strip of the bar's controls, one above another. */
.screen .grid > .vpanel.pane.at-left,
.screen .grid > .vpanel.pane.at-right {
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + var(--rhead-h, 50px));
  border-top: 0;
  box-shadow: 0 0 16px rgba(0, 0, 0, 0.06);
}
.screen .grid > .vpanel.pane.at-left { right: auto; border-right: 1px solid var(--line); }
.screen .grid > .vpanel.pane.at-right { left: auto; border-left: 1px solid var(--line); }
.pane.at-left.open-pane .pane-grip, .pane.at-right.open-pane .pane-grip {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 1;
  width: 10px;
  height: auto;
  margin: 0;
  cursor: ew-resize;
}
.pane.at-left .pane-grip { right: 0; }
.pane.at-right .pane-grip { left: 0; }
.pane.at-left .pane-grip::after, .pane.at-right .pane-grip::after {
  top: 50%;
  left: 3px;
  width: 4px;
  height: 40px;
  margin: -20px 0 0;
}
.pane.at-left .pane-bar, .pane.at-right .pane-bar { flex-wrap: wrap; max-width: none; padding: 8px 14px 8px 8px; }
.pane.at-right .pane-bar { padding-left: 14px; }
.pane.at-left .pane-bar .vp-ref, .pane.at-right .pane-bar .vp-ref { flex-direction: column; gap: 0; }
.pane.at-left .pane-body, .pane.at-right .pane-body { max-width: none; padding: 4px 18px 16px; }
.pane.at-left .notelist, .pane.at-right .notelist { grid-template-columns: minmax(0, 1fr); }
.pane.at-left:not(.open-pane) .pane-bar, .pane.at-right:not(.open-pane) .pane-bar {
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 10px;
  width: 44px;
  height: 100%;
  padding: 8px 0;
}
.pane.at-left:not(.open-pane) .pane-bar > .vp-ref,
.pane.at-right:not(.open-pane) .pane-bar > .vp-ref,
.pane.at-left:not(.open-pane) .pane-hint,
.pane.at-right:not(.open-pane) .pane-hint,
.pane.at-left:not(.open-pane) .pane-count.none,
.pane.at-right:not(.open-pane) .pane-count.none { display: none; }
.pane.at-left:not(.open-pane) .pane-count, .pane.at-right:not(.open-pane) .pane-count {
  flex: none;
  flex-direction: column;
  gap: 8px;
  font-size: 11px;
}
.pane.at-left:not(.open-pane) .pane-count > span, .pane.at-right:not(.open-pane) .pane-count > span { flex-direction: column; gap: 2px; }
.pane.at-left:not(.open-pane) .vp-tools, .pane.at-right:not(.open-pane) .vp-tools { flex-direction: column; margin: auto 0 0; }
/* The open pane lies over the text, but the closed strip leaves it room:
   45px of strip, less the screen's own 20px, and a little more. */
.grid:has(> .vpanel.pane.at-left:not(.open-pane)),
.screen:has(> .grid > .vpanel.pane.at-left:not(.open-pane)) > .rnotes { padding-left: 32px; }
.grid:has(> .vpanel.pane.at-right:not(.open-pane)),
.screen:has(> .grid > .vpanel.pane.at-right:not(.open-pane)) > .rnotes { padding-right: 32px; }
@media (max-width: 640px) {
  .pane-bar { gap: 8px; padding: 4px 4px 4px 4px; }
  .pane-bar .vp-ref { flex: none; font-size: 15px; }
  .pane-bar .vp-sec { display: none; }
  .pane-bar .vp-tools .iconbtn { width: 28px; min-width: 28px; }
  .pane.open-pane .pane-body { padding: 4px 14px 14px; }
  .pane-grip { height: 18px; }
  .pane.open-pane .pane-grip { height: 18px; margin-bottom: -10px; }
  .pane-grip::after { top: 6px; }
}

/* Narrow screens: one column, the cells of a law stacked. */
@media (max-width: 900px) {
  .screen { padding: 12px 14px 0; }
  .rhead { margin: -12px -14px 0; padding: 6px 14px; }
  .grid .row .text { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .grid.he-right .row .text > .cell.he { order: 0; }   /* stacked, the Hebrew first */
  .cell.he { font-size: 20px; }
}
/* Phones: the names and arrows above the buttons. */
@media (max-width: 480px) {
  .rhead .navbtn { max-width: 34vw; }
  .rbar { gap: 6px; }
  .toggles { gap: 6px; }
  .seg { width: 30px; }
  .seg svg { width: 17px; height: 17px; }
}

/* ------------------------------------------------------------- editing */


.draftnote { font-size: 13.5px; color: var(--dim); margin: 10px 0 0; }

/* At the end of a law's text, its pencil: there on the row pointed at or
   chosen (on touch screens, only the chosen), out of the way otherwise. */
.cell-edit {
  display: inline-flex;
  width: 26px;
  height: 26px;
  min-width: 26px;
  margin-inline-start: 4px;
  vertical-align: middle;
  color: var(--faint);
  opacity: 0;
}
.cell-edit svg { width: 15px; height: 15px; }
.row.law:hover .cell-edit, .row.law.sel .cell-edit, .cell-edit:focus-visible { opacity: 1; }
.cell-edit:hover { color: var(--accent); }
@media (hover: none) {
  .row.law:hover:not(.sel) .cell-edit { opacity: 0; }
}

/* Under a note, its pencil: faint until the note is hovered or the pencil
   focused (always, faintly, on touch screens). */
.note-tools { display: flex; justify-content: flex-end; margin-top: 2px; }
.note-edit { width: 26px; height: 26px; min-width: 26px; color: var(--faint); opacity: 0; }
.note-edit svg { width: 15px; height: 15px; }
div.note:hover .note-edit, .note-edit:focus-visible { opacity: 1; }
.note-edit:hover { color: var(--accent); }
@media (hover: none) { .note-edit { opacity: 0.6; } }
/* The pane's add buttons take their layer's colour. */
.vp-add.add-notes { color: var(--accent); }

/* A changed law or note: a green rule on its reading edge, drawn outside the
   text so that the columns stay aligned. */
.cell.changed { border-inline-start: 3px solid var(--edit); padding-inline-start: 9px; margin-inline-start: -12px; }
div.note.changed, div.note.new { border-left-color: var(--edit); }
div.note.deleted { border-left-color: var(--bad); }
div.note.deleted p { text-decoration: line-through; opacity: 0.65; }

/* What the branch being read changed compared with its base (review.js):
   the same rule in blue. A draft's green, drawn after, wins where both are. */
.cell.branched { border-inline-start: 3px solid var(--up); padding-inline-start: 9px; margin-inline-start: -12px; }
.cell.branched.changed { border-inline-start-color: var(--edit); }
div.note.branched { border-left-color: var(--up); }
div.note.branched.changed { border-left-color: var(--edit); }
.chg.up { color: var(--up); }
.draftnote.up { color: var(--up); }
.draftnote.up.bad { color: var(--bad); }

/* A live session (session.js): how it stands, in one line; what has just
   arrived from someone else, fading; and the note under an open editor when
   the thing being edited changed on the branch meanwhile. */
.liveline { color: var(--up); }
.liveline::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-inline-end: 7px;
  border-radius: 50%;
  background: currentColor;
}
.liveline.bad { color: var(--bad); }
.liveline .linkbtn { font-size: inherit; }
.card .liveline { margin: 0 0 4px; }
.cell.fresh, div.note.fresh { animation: fresh 8s ease-out both; border-radius: 4px; }
@keyframes fresh {
  from, 25% { background: var(--up-soft); box-shadow: 0 0 0 4px var(--up-soft); }
  to { background: transparent; box-shadow: 0 0 0 4px transparent; }
}
.edit-warn {
  margin: 6px 0 0;
  padding: 8px 10px;
  border-inline-start: 3px solid var(--up);
  border-radius: var(--radius-sm);
  background: var(--up-soft);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.45;
  direction: ltr;
  text-align: left;
}
.edit-warn .diff { margin: 6px 0; background: var(--bg); font-family: var(--font); font-size: 15px; }
.edit-warn .diff[lang="he"] { font-family: var(--font-he); font-size: 18px; }
.edit-warn span { display: block; color: var(--dim); }

/* The resolver, over whatever screen is open. */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 16px 24px;
  overflow-y: auto;
  background: color-mix(in srgb, var(--text) 45%, transparent);
}
.overlay-box { width: 100%; max-width: 900px; }
.overlay-box .card { margin: 0; box-shadow: var(--shadow); }

.chg {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: baseline;
  margin-top: 4px;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--edit);
  direction: ltr;
  text-align: left;
}
.linkbtn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 12.5px;
  cursor: pointer;
}
.linkbtn:hover { text-decoration: underline; }
.linkbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.showdiff > :not(.diff):not(.chg) { display: none; }
.diff {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--panel-lit);
  font-size: 0.85em;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.diff ins { background: var(--ins); text-decoration: none; border-radius: 3px; }
.diff del { background: var(--del); text-decoration: line-through; text-decoration-color: var(--bad); border-radius: 3px; }


.editor { width: 100%; }
.edit-area {
  display: block;
  width: 100%;
  min-height: 5em;
  padding: 8px 10px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  line-height: inherit;
  resize: vertical;
  overflow: hidden;
}
.edit-area:focus { outline: 2px solid var(--accent-soft); }
.edit-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--faint);
  direction: ltr;
}
.edit-status { flex: 1; }
.edit-hint { font-family: ui-monospace, Consolas, monospace; }
.edit-error { margin: 6px 0 0; font-family: var(--font-ui); font-size: 13px; color: var(--bad); direction: ltr; text-align: left; }
.btn.small { min-height: 30px; padding: 3px 12px; font-size: 13px; }

.seltools {
  position: absolute;
  z-index: 30;
  display: flex;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--text);
  box-shadow: var(--shadow);
}
.seltools button {
  padding: 7px 12px;
  border: 0;
  background: none;
  color: var(--bg);
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
}
.seltools button + button { border-left: 1px solid color-mix(in srgb, var(--bg) 25%, transparent); }
.seltools button:hover { background: color-mix(in srgb, var(--bg) 15%, transparent); }

/* ------------------------------------------------------------- changes */

#screen-changes, #screen-branches { max-width: 980px; margin: 0 auto; }
.chsec-head { display: flex; align-items: baseline; gap: 12px; }
.chsec-head h2 a { color: var(--text); text-decoration: none; }
.chsec-head h2 a:hover { text-decoration: underline; }
.chsec-id { color: var(--faint); font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.chfile { margin-top: 10px; }
.chfile + .chfile { margin-top: 18px; }
.chfile-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 4px; }
.chfile-head h3 { font-size: 15.5px; }
.chfile-path { font-size: 12px; color: var(--faint); }
.chfile-when { flex: 1; font-size: 12px; color: var(--faint); }
.chitem { padding: 10px 0; border-top: 1px solid var(--line-soft); }
.chitem-head { display: flex; align-items: baseline; gap: 12px; }
.chitem-ref { font-weight: 600; font-size: 14px; text-decoration: none; }
.chitem-ref:hover { text-decoration: underline; }
.chitem-what { flex: 1; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--faint); }
.chitem .diff { font-family: var(--font); font-size: 15px; }
.chitem .diff[lang="he"] { font-family: var(--font-he); font-size: 18px; }
ul.plain { margin: 6px 0 0; padding-left: 18px; font-size: 14px; }
.chfile-pick { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.chfile-pick input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }

/* Submitting, conflicts, the last submission */
.submit-msg { width: 100%; min-height: 110px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13.5px; line-height: 1.5; }
.submit .linkbtn { align-self: flex-start; margin-top: 4px; font-size: 13px; }
.submit .field-hint { margin: 8px 0 0; }
.resolve { border-color: var(--bad); }
.resolve-file { margin-top: 14px; }
.resolve-item { padding: 12px 0; border-top: 1px solid var(--line-soft); }
.resolve-item h4 { font-size: 14px; margin: 0 0 8px; }
.resolve-sides { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 10px; }
.resolve-label { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--faint); margin-bottom: 4px; }
.resolve-side .diff { font-family: var(--font); font-size: 15px; }
.resolve-side .diff[lang="he"] { font-family: var(--font-he); font-size: 18px; }
.resolve-area { width: 100%; resize: vertical; font-family: var(--font); font-size: 15px; line-height: 1.5; }
.resolve-area[lang="he"] { font-family: var(--font-he); font-size: 18px; }
.resolve-use { display: flex; gap: 14px; margin-top: 4px; font-size: 13px; }
.resolve-item select { max-width: 100%; }
.last-head { display: flex; align-items: baseline; justify-content: space-between; }
.last p { margin: 0 0 6px; }
@media (max-width: 700px) {
  .resolve-sides { grid-template-columns: 1fr; }
}

/* -------------------------------------------------------------- search */

#screen-search { max-width: 980px; margin: 0 auto; }
.search-bar { margin: 10px 0 10px; }
.search-input { width: 100%; min-height: 48px; font-size: 18px; padding: 10px 14px; }
.search-opts { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.book-sel { min-height: 32px; padding: 3px 8px; font-size: 13px; }
.search-hint { font-size: 12.5px; color: var(--faint); margin: 8px 0 14px; }
.hit-count { font-size: 13.5px; color: var(--dim); margin: 6px 0 10px; }
.progress { height: 4px; background: var(--line-soft); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

.hit {
  display: block;
  padding: 12px 14px;
  margin: 0 0 8px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
}
.hit:hover { border-color: var(--line); background: var(--panel-lit); }
.hit-where { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 4px; }
.hit-sec { font-family: var(--font); font-weight: 600; }
.hit-ref { font-size: 13px; color: var(--accent); font-weight: 600; unicode-bidi: isolate; }
.hit-he { margin-left: auto; font-family: var(--font-he); color: var(--faint); font-size: 16px; }
.hit-text { margin: 4px 0 0; line-height: 1.55; }
.hit-text.en { font-family: var(--font); font-size: 15.5px; }
.hit-text.he { font-family: var(--font-he); font-size: 18.5px; }
.hit-text.co { font-size: 14px; color: var(--dim); }
.hit-layer {
  display: inline-block;
  margin-inline-end: 8px;
  font-family: var(--font-ui);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--faint);
}
.btn.more { margin: 6px auto 20px; display: flex; }

mark { background: #f3d77a; color: #241f18; border-radius: 3px; padding: 0 1px; }
:root[data-theme="dark"] mark { background: #8a6d1e; color: #fff6dd; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) mark { background: #8a6d1e; color: #fff6dd; } }

/* ------------------------------------------------------------ settings */

.card {
  margin: 0 0 16px;
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card h2 { font-size: 18px; margin-bottom: 12px; }
.fields { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--dim); }
.field-hint { font-size: 12.5px; color: var(--faint); }
.input {
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.btn {
  min-height: 38px;
  padding: 7px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.btn:hover { background: var(--panel-lit); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn:disabled { opacity: 0.5; cursor: default; }
.status { font-size: 13.5px; color: var(--dim); margin: 10px 0 0; }
.status.bad { color: var(--bad); }
.version { text-align: center; color: var(--faint); font-size: 12px; }

/* --------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: min(92vw, 520px);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------ branches */

.basebar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; font-size: 14px; color: var(--dim); }
.basesel { min-height: 34px; padding: 4px 10px; max-width: 100%; }
.chlayer { margin: 12px 0 2px; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--up); }
.blist { list-style: none; margin: 0; padding: 0; }
.bitem { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.bitem:first-child { border-top: 0; }
.bitem-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.bitem-title { overflow-wrap: anywhere; }
code.bitem-title { font-size: 13.5px; }
.bitem-meta { font-size: 12.5px; color: var(--faint); overflow-wrap: anywhere; }
.bitem.current .bitem-title { font-weight: 600; }
.bitem-acts { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.bitem-status { margin: 2px 0 0; font-size: 12.5px; }
.bitem-status:empty, .mergebox:empty { display: none; }
.tag { display: inline-block; margin-inline-start: 6px; padding: 1px 8px; border: 1px solid var(--line); border-radius: 999px; font-family: var(--font-ui); font-size: 11.5px; color: var(--faint); white-space: nowrap; }
.tag.on { border-color: var(--up); color: var(--up); }
.sec .tag.up { border-color: var(--up); color: var(--up); }
