:root {
  /* brand: teal מִקְרָא, copper rule, charcoal wordmark (from the logo).
     --bg is the page frame (header, book list), --paper the reading column, --surface panels and cards. */
  --bg: #d8ccb2;
  --paper: #f3ecdd;
  --surface: #ebe2cf;
  --surface-2: #dfd3bb;
  --ink: #262a29;
  --ink-soft: #565a54;
  --ink-faint: #857f6b;
  --line: #c8ba9c;
  --accent: #006b60;
  --accent-soft: #d0e2da;
  --copper: #a8661f;
  --select: #e3d7bd;
  --hl-yellow: #fbe7a1; --hl-green: #d3ecc6; --hl-blue: #cfe1f6; --hl-pink: #f8d5de; --hl-purple: #e3d7f4;
  --serif: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --hebrew: 'Noto Serif Hebrew', 'SBL Hebrew', 'Ezra SIL', 'Times New Roman', serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161b1a; --paper: #1b2120; --surface: #1e2524; --surface-2: #27302e; --ink: #ebe6da; --ink-soft: #b1ad9f;
    --ink-faint: #7c7a6e; --line: #313a38; --accent: #5cc2b3; --accent-soft: #173430; --copper: #d8944a; --select: #2c3533;
    --hl-yellow: #5a4b1a; --hl-green: #2e4a29; --hl-blue: #24405f; --hl-pink: #5c2c3a; --hl-purple: #433163;
  }
}
:root[data-theme="dark"] {
  --bg: #161b1a; --paper: #1b2120; --surface: #1e2524; --surface-2: #27302e; --ink: #ebe6da; --ink-soft: #b1ad9f;
  --ink-faint: #7c7a6e; --line: #313a38; --accent: #5cc2b3; --accent-soft: #173430; --copper: #d8944a; --select: #2c3533;
  --hl-yellow: #5a4b1a; --hl-green: #2e4a29; --hl-blue: #24405f; --hl-pink: #5c2c3a; --hl-purple: #433163;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 14px; display: flex; flex-direction: column; }
button, select { font: inherit; color: inherit; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 2px 6px; flex-shrink: 0; white-space: nowrap; text-decoration: none; color: var(--ink); }
.brand-he { font-family: 'Noto Sans Hebrew', 'Arial Hebrew', var(--hebrew); font-weight: 500; font-size: 28px; line-height: 1.05; color: var(--accent); }
.brand-rule { width: 64px; height: 2px; border-radius: 1px; background: var(--copper); }
.brand-en { font-family: var(--serif); font-size: 12.5px; font-weight: 500; letter-spacing: .16em; text-transform: uppercase; line-height: 1.2; }
.controls { display: flex; gap: 14px; flex-wrap: wrap; }
.ctl { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.ctl select { text-transform: none; letter-spacing: 0; font-size: 13px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink); }
.spacer { flex: 1; }
.toplinks { display: flex; align-items: center; gap: 16px; font-size: 13px; }
.toplink { color: var(--ink-soft); }
.toplink:hover { color: var(--accent); }
.search-form { flex: 0 1 260px; min-width: 150px; }
.search-form input { width: 100%; padding: 6px 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); color: var(--ink); font: inherit; font-size: 13px; }
.search-form input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.search-q { font-family: var(--serif); font-size: 30px; color: var(--accent); }
mark { background: var(--hl-yellow); color: inherit; border-radius: 2px; padding: 0 1px; }
.theme-toggle {width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper); color: var(--copper); font-size: 15px; line-height: 1; cursor: pointer; padding: 0; }
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.account {display: flex; align-items: center; gap: 10px; padding-left: 16px; border-left: 1px solid var(--line); }
.who { color: var(--ink-faint); font-size: 12px; }

/* Three-column layout */
.layout { flex: 1; display: grid; grid-template-columns: 230px minmax(0, 1fr) 360px; min-height: 0; }
.books, .reader, .panel { overflow-y: auto; min-height: 0; }

.books { border-right: 1px solid var(--line); padding: 12px 0 40px; background: var(--bg); }
.books h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); margin: 18px 18px 6px; font-weight: 600; }
.books h3:first-child { margin-top: 6px; }
.book { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 4px 18px; cursor: pointer; font-family: var(--serif); font-size: 16px; color: var(--ink); }
.book:hover { background: var(--surface-2); }
.book.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.book.missing { color: var(--ink-faint); cursor: default; font-style: italic; }
.book.missing:hover { background: none; }
.book small { font-family: var(--sans); font-size: 10px; color: var(--ink-faint); margin-left: 4px; font-style: normal; }

/* Reader */
.reader { padding: 24px 48px 80px; outline: none; background: var(--paper); }
.reader-head { display: flex; align-items: center; justify-content: center; gap: 18px; max-width: 760px; margin: 0 auto; }
.reader-head h1 { font-family: var(--serif); font-weight: 500; font-size: 34px; margin: 0; text-align: center; min-width: 260px; }
.title-sub { display: block; font-family: var(--sans); font-size: 12px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--copper); margin-top: 2px; }
.nav-btn {border: 1px solid var(--line); background: var(--surface); border-radius: 50%; width: 34px; height: 34px; font-size: 20px; line-height: 1; cursor: pointer; color: var(--ink-soft); }
.nav-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.nav-btn:disabled { opacity: .3; cursor: default; }
.chapters { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; max-width: 760px; margin: 14px auto 6px; }
.chapters button { min-width: 30px; padding: 3px 6px; border: 1px solid transparent; border-radius: 4px; background: none; cursor: pointer; color: var(--ink-soft); font-size: 12px; }
.chapters button:hover { border-color: var(--line); }
.chapters button.active { background: var(--accent); color: var(--surface); }
.notice { max-width: 760px; margin: 12px auto 0; padding: 8px 12px; border-radius: 6px; background: var(--accent-soft); color: var(--ink-soft); font-size: 13px; }

.text { max-width: 760px; margin: 22px auto 0; font-family: var(--serif); font-size: 20px; line-height: 1.7; }
.text.parallel { max-width: 1100px; }
.v { cursor: pointer; border-radius: 3px; padding: 1px 0; transition: background .12s; }
.v:hover { background: var(--surface-2); }
.v.sel { background: var(--select); }
.vn { font-family: var(--sans); font-size: 11px; font-weight: 600; color: var(--accent); vertical-align: super; margin: 0 3px 0 6px; }
.v i, .cell i { color: var(--ink-soft); }
.sign { color: var(--ink-faint); font-size: .7em; vertical-align: .25em; }
.prow { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; padding: 4px 6px; border-radius: 4px; cursor: pointer; }
.prow:hover { background: var(--surface-2); }
.prow.sel { background: var(--select); }
.prow .cell { min-width: 0; }
.phead { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; font-family: var(--sans); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); padding: 0 6px 8px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.empty-cell { color: var(--ink-faint); font-style: italic; }

/* Study panel */
.panel { border-left: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; }
.panel-tabs { display: flex; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.tab { flex: 1; border: 0; background: none; padding: 12px 8px; cursor: pointer; color: var(--ink-soft); font-weight: 500; border-bottom: 2px solid transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.panel-body { padding: 16px 18px 40px; }
.hint { color: var(--ink-faint); font-style: italic; }
.xref-head { font-family: var(--serif); font-size: 20px; margin: 0 0 4px; }
.xref-sub { color: var(--ink-faint); font-size: 12px; margin: 0 0 14px; }
.xref { display: block; padding: 10px 0; border-top: 1px solid var(--line); text-decoration: none; color: var(--ink); cursor: pointer; }
.xref:hover .xref-ref { color: var(--accent); text-decoration: underline; }
.xref-top { display: flex; align-items: center; gap: 8px; }
.xref-ref { font-weight: 600; font-size: 13px; }
.strength { flex: 0 0 auto; height: 4px; border-radius: 2px; background: var(--accent); opacity: .55; }
.xref-text { font-family: var(--serif); font-size: 15px; line-height: 1.45; color: var(--ink-soft); margin-top: 3px; }
.copy-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: -4px 0 12px; }
.copy-tools .more { margin-top: 0; padding: 4px 10px; font-size: 12px; }
.copy-status { font-size: 12px; color: var(--accent); }
.more { margin-top: 12px; border: 1px solid var(--line); background: none; border-radius: 6px; padding: 6px 12px; cursor: pointer; color: var(--ink-soft); }

/* Highlights and note markers in the reader */
.hl-yellow { --hl: var(--hl-yellow); } .hl-green { --hl: var(--hl-green); } .hl-blue { --hl: var(--hl-blue); }
.hl-pink { --hl: var(--hl-pink); } .hl-purple { --hl: var(--hl-purple); }
.v[class*="hl-"], .prow[class*="hl-"] { background: var(--hl); }
.v.sel, .prow.sel { box-shadow: inset 0 -2px 0 var(--accent); }
.v.sel:not([class*="hl-"]), .prow.sel:not([class*="hl-"]) { background: var(--select); }
.has-note .vn::after { content: ''; display: inline-block; width: 6px; height: 6px; margin-left: 2px; border-radius: 50%; background: var(--accent); vertical-align: 2px; }

/* Note editor */
.note-editor { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-faint); margin-top: 10px; font-weight: 600; }
.swatches { display: flex; gap: 8px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); background: var(--hl); cursor: pointer; padding: 0; }
.swatch.none { background: var(--surface); position: relative; }
.swatch.none::after { content: ''; position: absolute; left: 50%; top: 4px; bottom: 4px; width: 1.5px; background: var(--ink-faint); transform: rotate(45deg); }
.swatch[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 2px; }
.tags-edit { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px; min-height: 38px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); cursor: text; }
.tag-input { flex: 1; min-width: 90px; border: 0; outline: none; background: none; font: inherit; color: var(--ink); padding: 3px; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 500; border: 1px solid transparent; font-family: var(--sans); }
button.tag { cursor: pointer; }
button.tag:hover { border-color: var(--accent); }
.tag.active { background: var(--accent); color: var(--surface); }
.tag-x { border: 0; background: none; color: inherit; cursor: pointer; padding: 0; font-size: 14px; line-height: 1; opacity: .7; }
.tag-x:hover { opacity: 1; }
.tag-n { opacity: .65; font-variant-numeric: tabular-nums; }
.note-body { min-height: 200px; resize: vertical; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink); font-family: var(--serif); font-size: 16px; line-height: 1.5; }
.note-body:focus, .tags-edit:focus-within, .search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.note-status { font-size: 12px; color: var(--ink-faint); margin: 2px 0 0; min-height: 1.4em; }
.linkbtn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; font-size: inherit; }
.btn { display: inline-block; padding: 7px 16px; border-radius: 6px; background: var(--accent); color: var(--surface); text-decoration: none; font-weight: 500; }

/* My notes page */
.notes-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.notes-toolbar .more { margin-top: 0; }
.search { flex: 1; min-width: 220px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit; }
.sort { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); }
.tag-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.note-list { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.note-card { padding: 14px 18px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 8px; }
.note-card[class*="edge-"] { border-left-color: var(--edge); }
.edge-yellow { --edge: #e2c35a; } .edge-green { --edge: #8cc276; } .edge-blue { --edge: #7ea9dc; } .edge-pink { --edge: #e28ea4; } .edge-purple { --edge: #a98ad6; }
.note-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.note-ref { font-family: var(--serif); font-size: 19px; font-weight: 600; color: var(--ink); text-decoration: none; }
.note-ref:hover { color: var(--accent); text-decoration: underline; }
.note-date { font-size: 12px; color: var(--ink-faint); }
.note-verse { font-family: var(--serif); font-size: 16px; line-height: 1.5; color: var(--ink-soft); margin: 6px 0 0; }
.tr-tag { font-family: var(--sans); font-size: 10px; color: var(--ink-faint); letter-spacing: .05em; }
.note-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.note-text { margin-top: 10px; white-space: pre-wrap; font-family: var(--serif); font-size: 17px; line-height: 1.55; }

/* Original-language words (panel) */
.words { display: flex; flex-wrap: wrap; gap: 6px; }
.word { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 10px; min-width: 64px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); background: var(--paper); }
a.word:hover { border-color: var(--accent); background: var(--accent-soft); }
.word .orig { font-size: 22px; line-height: 1.5; }
.orig:lang(he), .lemma:lang(he) { font-family: var(--hebrew); }
.orig:lang(grc), .lemma:lang(grc) { font-family: var(--serif); }
.word .translit { font-size: 12px; font-style: italic; color: var(--ink-soft); direction: ltr; }
.word .gloss { font-size: 12px; color: var(--ink); direction: ltr; text-align: center; }
.word .strong { font-size: 10px; color: var(--ink-faint); direction: ltr; font-variant-numeric: tabular-nums; }

/* Word study page */
.text.study { font-family: var(--sans); font-size: 15px; line-height: 1.6; }
.study-head { display: flex; align-items: baseline; gap: 18px; flex-wrap: wrap; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.lemma { font-size: 44px; line-height: 1.3; color: var(--accent); }
.study-meta { display: flex; gap: 14px; align-items: baseline; color: var(--ink-soft); }
.study-meta .translit { font-family: var(--serif); font-style: italic; font-size: 20px; color: var(--ink); }
.study-meta .strong, .study-meta .morph { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--surface-2); }
.study-stats { color: var(--ink-soft); margin: 12px 0 0; }
.definition { margin-top: 16px; padding: 14px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; font-family: var(--serif); font-size: 17px; line-height: 1.55; }
.definition a, .occ-all { color: var(--accent); }
.occ-head { font-family: var(--serif); font-weight: 500; font-size: 22px; margin: 28px 0 10px; }
.dist { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 2px 24px; }
.dist-row { display: grid; grid-template-columns: 110px 1fr 40px; align-items: center; gap: 8px; padding: 2px 4px; border-radius: 4px; text-decoration: none; color: var(--ink); font-size: 13px; }
.dist-row:hover { background: var(--surface-2); }
.dist-row.active { background: var(--accent-soft); font-weight: 600; }
.dist-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dist-track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.dist-bar { display: block; height: 100%; background: var(--accent); opacity: .7; border-radius: 4px; }
.dist-n { text-align: right; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.study-actions { margin-top: 14px; }
.occ { display: grid; grid-template-columns: 130px 1fr; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.occ:hover .occ-ref { color: var(--accent); text-decoration: underline; }
.occ-ref { font-weight: 600; font-size: 13px; padding-top: 3px; }
.occ-text { font-family: var(--serif); font-size: 17px; line-height: 1.5; }
.occ-text i { color: var(--ink-soft); }

/* Substack posts */
.posts-intro { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.posts-intro .study-stats { margin: 0; }
.post-list { display: flex; flex-direction: column; gap: 18px; margin-top: 18px; }
.post-card { display: grid; grid-template-columns: 180px 1fr; gap: 20px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.post-card:not(:has(.post-img)) { grid-template-columns: 1fr; }
.post-img { width: 180px; height: 180px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.post-date { margin: 0; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--copper); }
.post-title { font-family: var(--serif); font-weight: 500; font-size: 26px; line-height: 1.2; margin: 4px 0 6px; }
.post-title a { color: var(--ink); text-decoration: none; }
.post-title a:hover { color: var(--accent); text-decoration: underline; }
.post-subtitle { margin: 0 0 8px; font-family: var(--serif); font-style: italic; font-size: 18px; color: var(--ink-soft); }
.post-excerpt { margin: 0; font-family: var(--serif); font-size: 16px; line-height: 1.55; }
.post-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.post-read { display: inline-block; margin-top: 0; text-decoration: none; color: var(--accent); }
@media (max-width: 760px) {
  .post-card { grid-template-columns: 1fr; }
  .post-img { width: 100%; height: 200px; }
}

/* Sources page */
.sources { max-width: 720px; margin: 0 auto; font-size: 15px; line-height: 1.6; }
.sources h1 { font-family: var(--serif); font-weight: 500; font-size: 34px; }
.sources h2 { font-family: var(--serif); font-weight: 500; font-size: 22px; margin-top: 28px; }
.sources a { color: var(--accent); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 200px minmax(0, 1fr) 300px; }
  .reader { padding: 20px 24px 80px; }
}
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .layout { grid-template-columns: 1fr; }
  .books { max-height: 30vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .reader { padding: 16px 16px 40px; }
  .prow, .phead { grid-template-columns: 1fr; gap: 6px; }
  .occ { grid-template-columns: 1fr; gap: 2px; }
}

@media print {
  .topbar, .books, .panel, .chapters, .nav-btn, .study-actions, .more, .notes-toolbar, .tag-bar { display: none !important; }
  .note-card { break-inside: avoid; border-color: #ccc; }
  .v[class*="hl-"] { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .occ, .dist-row { break-inside: avoid; color: #000; }
  .layout { display: block; }
  .reader { overflow: visible; padding: 0; }
  body { background: #fff; color: #000; }
}
