/* Base: reset, shell (header, steps, bottom nav, menu) and the shared visual language (contract section 3).
   Colours, spacing, radii, fonts and motion come only from tokens.css variables. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + var(--stepper-h) + var(--sp-4)); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: var(--lh-read);
  padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; }
h1, h2, h3, h4 { margin: 0; line-height: var(--lh-tight); font-weight: var(--fw-semibold); }
p { margin: 0 0 var(--sp-3); }
a { color: var(--accent); text-underline-offset: 0.18em; }
a:hover { color: var(--accent-hover); }
button { font: inherit; color: inherit; }
ol, ul { margin: 0; padding: 0; }
[hidden] { display: none !important; }
main { display: block; min-height: 60vh; padding-bottom: var(--sp-16); }
main:focus { outline: none; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }
.skip-link {
  position: absolute; left: var(--sp-2); top: -64px; z-index: var(--z-tooltip);
  background: var(--accent); color: var(--accent-ink); padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius); font-family: var(--font-ui); text-decoration: none;
}
.skip-link:focus { top: var(--sp-2); }

/* ---------- containers ---------- */
.wrap { width: 100%; max-width: calc(var(--wide-max) + 2 * var(--gutter)); margin: 0 auto; padding: 0 var(--gutter); }
.read { width: 100%; max-width: calc(var(--read-max) + 2 * var(--gutter)); margin: 0 auto; padding: 0 var(--gutter); }
.greek { font-family: var(--font-greek); }
.hebrew { font-family: var(--font-hebrew); }
.view-title { font-size: var(--fs-h1); font-weight: var(--fw-semibold); letter-spacing: -0.005em; }
.section-title { font-size: var(--fs-h2); margin: var(--sp-10) 0 var(--sp-4); }
.meta { font-family: var(--font-ui); font-size: var(--fs-sm); color: var(--ink-3); line-height: var(--lh-ui); }
.empty { font-family: var(--font-ui); font-size: var(--fs-sm); color: var(--ink-3); margin: var(--sp-3) 0; }
.card {
  background: var(--surface); border: var(--border); border-radius: var(--radius-lg);
  padding: var(--sp-5); box-shadow: var(--shadow-1);
}
.banner {
  background: var(--warn-soft); color: var(--warn-ink); font-family: var(--font-ui); font-size: var(--fs-sm);
  text-align: center; padding: var(--sp-1) var(--sp-4);
}

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: var(--z-header); height: var(--header-h);
  background: var(--bg); border-bottom: var(--border); font-family: var(--font-ui);
}
.hdr {
  height: 100%; width: 100%; max-width: calc(var(--wide-max) + 2 * var(--gutter)); margin: 0 auto;
  padding: 0 var(--gutter); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: var(--sp-4);
}
.site-title {
  justify-self: start; font-family: var(--font-body); font-weight: var(--fw-semibold); font-size: 1.15rem;
  color: var(--ink); text-decoration: none; white-space: nowrap;
}
.site-title:hover { color: var(--accent); }
.title-short { display: none; }
.hdr-actions { justify-self: end; display: flex; align-items: center; gap: var(--sp-3); }
.hdr-actions .menu-btn { display: none; }

.steps { display: flex; align-items: stretch; height: var(--header-h); gap: var(--sp-2); }
.step {
  position: relative; display: inline-flex; align-items: center; gap: var(--sp-2); padding: 0 var(--sp-3);
  text-decoration: none; color: var(--ink-2); font-size: var(--fs-md); font-weight: var(--fw-medium);
  transition: color var(--dur) var(--ease);
}
.step:hover { color: var(--ink); }
.step-num {
  display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; flex: none;
  border: 1.5px solid var(--line-strong); border-radius: 50%; font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  line-height: 1; color: var(--ink-2); background: transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.step.is-active { color: var(--ink); font-weight: var(--fw-semibold); }
.step.is-active .step-num { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.step.is-active::after {
  content: ""; position: absolute; left: var(--sp-2); right: var(--sp-2); bottom: -1px; height: 2px; background: var(--accent);
}

/* segmented control */
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg button {
  border: 0; background: transparent; cursor: pointer; font-family: var(--font-ui); font-size: var(--fs-sm); font-weight: var(--fw-medium);
  min-width: 48px; height: 34px; padding: 0 var(--sp-3); color: var(--ink-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button:hover { background: var(--surface-2); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.seg button:focus-visible { outline-offset: -2px; }

/* library menu */
.lib-btn { gap: var(--sp-1); }
.lib-btn.is-active, .menu-btn.is-active { border-color: var(--accent); color: var(--accent); }
.menu-panel {
  position: absolute; top: calc(var(--header-h) - var(--sp-1)); right: max(var(--gutter), calc((100vw - var(--wide-max)) / 2));
  min-width: 220px; background: var(--surface); border: var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-2); padding: var(--sp-2); z-index: var(--z-menu); font-family: var(--font-ui);
}
.menu-panel .menu-heading, .menu-panel .menu-theme { display: none; }
.menu-item {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: var(--touch); padding: 0 var(--sp-3);
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--ink); text-decoration: none;
  font-size: var(--fs-md); cursor: pointer; text-align: left;
}
.menu-item:hover { background: var(--surface-2); color: var(--ink); }
.menu-item.is-active { color: var(--accent); font-weight: var(--fw-semibold); }
.menu-item:focus-visible { outline-offset: -2px; }

/* bottom nav (phone) */
.bottom-nav { display: none; }

/* ---------- buttons ---------- */
.btn, .icon-btn, .btn-link { font-family: var(--font-ui); cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); min-height: 36px; padding: 0 var(--sp-4);
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--ink);
  font-size: var(--fs-sm); font-weight: var(--fw-medium); text-decoration: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-2); color: var(--ink); }
.btn.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
.btn[disabled], .icon-btn[disabled] { opacity: 0.45; cursor: default; }
.btn-link {
  display: inline; padding: 0; border: 0; background: none; color: var(--accent); font-size: inherit;
  text-decoration: underline; text-underline-offset: 0.18em;
}
.btn-link:hover { color: var(--accent-hover); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: var(--touch); height: var(--touch); flex: none;
  padding: 0; border: 0; border-radius: var(--radius); background: transparent; color: var(--ink-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ---------- count, chips, tags ---------- */
.count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--radius-pill); background: var(--surface-3); color: var(--ink-2); font-family: var(--font-ui);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); line-height: 1; font-variant-numeric: tabular-nums; flex: none;
}
.count.is-zero { background: transparent; box-shadow: inset 0 0 0 1px var(--line-strong); color: var(--ink-3); font-weight: var(--fw-regular); }
.chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip {
  display: inline-flex; align-items: center; gap: var(--sp-2); min-height: 32px; padding: 0 var(--sp-3);
  border: 1px solid var(--line-strong); border-radius: var(--radius-pill); background: var(--surface); color: var(--ink);
  font-family: var(--font-ui); font-size: var(--fs-sm); font-weight: var(--fw-medium); cursor: pointer; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip[aria-pressed="true"] .count { background: color-mix(in srgb, var(--accent-ink) 22%, transparent); color: var(--accent-ink); box-shadow: none; }

.tag {
  display: inline-flex; align-items: center; padding: 1px var(--sp-2); border-radius: var(--radius-pill); background: var(--surface-3);
  color: var(--ink-2); font-family: var(--font-ui); font-size: var(--fs-xs); font-weight: var(--fw-medium); line-height: 1.5; white-space: nowrap;
}
.tag-pd { background: var(--ok-soft); color: var(--ok-ink); }
.tag-excerpt, .tag-trim { background: var(--warn-soft); color: var(--warn-ink); }
.tag-label { background: var(--accent-soft); color: var(--accent-soft-ink); }
.tag-context { background: transparent; box-shadow: inset 0 0 0 1px var(--line-strong); color: var(--ink-3); }

/* ---------- accordions ---------- */
.acc { background: var(--surface); border: var(--border); border-radius: var(--radius); }
.acc + .acc { margin-top: var(--sp-2); }
.acc > summary {
  display: flex; align-items: center; gap: var(--sp-3); min-height: 48px; padding: var(--sp-2) var(--sp-4); cursor: pointer;
  list-style: none; font-family: var(--font-ui); font-size: var(--fs-md); font-weight: var(--fw-medium);
  border-radius: var(--radius); user-select: none;
}
.acc > summary::-webkit-details-marker { display: none; }
.acc > summary::marker { content: ""; }
.acc > summary:hover { background: var(--surface-2); }
.acc > summary:focus-visible { outline-offset: -2px; }
.acc-title { flex: 1; min-width: 0; }
.acc > summary::after {
  content: ""; flex: none; width: 8px; height: 8px; margin: 0 var(--sp-1) 3px 0;
  border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg);
  transition: transform var(--dur) var(--ease);
}
.acc[open] > summary::after { transform: rotate(-135deg); margin-bottom: -3px; }
.acc[open] > summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.acc-body { padding: var(--sp-4); border-top: var(--border); }
.acc-nested { background: var(--surface-2); border-radius: var(--radius-sm); }
.acc-nested > summary { min-height: 44px; font-size: var(--fs-sm); border-radius: var(--radius-sm); }
.acc-nested > summary:hover { background: var(--surface-3); }
.acc-nested .acc-body { padding: var(--sp-3) var(--sp-4); }

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: var(--sp-1); border-bottom: var(--border); overflow-x: auto; scrollbar-width: none;
  max-width: 100%; -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs [role="tab"] {
  display: inline-flex; align-items: center; gap: var(--sp-2); min-height: 46px; padding: 0 var(--sp-4); margin-bottom: -1px;
  border: 0; border-bottom: 2px solid transparent; background: none; cursor: pointer; white-space: nowrap;
  font-family: var(--font-ui); font-size: var(--fs-md); font-weight: var(--fw-medium); color: var(--ink-2);
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tabs [role="tab"]:hover { color: var(--ink); }
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); font-weight: var(--fw-semibold); border-bottom-color: var(--accent); }
.tabs [role="tab"][aria-selected="true"] .count { background: var(--accent-soft); color: var(--accent-soft-ink); }
.tabs [role="tab"]:focus-visible { outline-offset: -3px; }
.tabpanel { padding-top: var(--sp-6); }
.tabpanel:focus { outline: none; }

/* ---------- responsive ---------- */
@media (max-width: 899px) {
  .title-full { display: none; }
  .title-short { display: inline; }
}
@media (max-width: 599px) {
  .hdr { grid-template-columns: 1fr auto; gap: var(--sp-2); }
  .steps, .lib-btn, .theme-btn { display: none; }
  .hdr-actions .menu-btn { display: inline-flex; }
  .hdr-actions { gap: var(--sp-1); }
  .seg button { height: 38px; min-width: 44px; }
  .btn, .chip { min-height: var(--touch); }
  .menu-panel {
    position: fixed; top: var(--header-h); left: 0; right: 0; border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    border-top: 0; padding: var(--sp-2) var(--gutter) var(--sp-4);
  }
  .menu-panel .menu-heading { display: block; padding: var(--sp-2) var(--sp-3); color: var(--ink-3); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em; }
  .menu-panel .menu-theme { display: flex; margin-top: var(--sp-2); border-top: var(--border); border-radius: 0; padding-top: var(--sp-2); }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-header);
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg); border-top: var(--border); font-family: var(--font-ui);
  }
  .bottom-nav .step {
    flex: 1; flex-direction: column; justify-content: center; gap: 3px; padding: 0; font-size: var(--fs-xs);
  }
  .bottom-nav .step.is-active::after { left: 25%; right: 25%; top: -1px; bottom: auto; }
  .section-title { margin-top: var(--sp-8); }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
