/*
 * AlterRebbe app styles: "Aleph Poster".
 * Source of truth: alterrebbe-theme-aleph-poster.css
 *   sha256 4c978b50024585dd59e115aca21ad12b592d4f885fd52a5de22b55f3806d97ba
 * Part 1 is that artifact's tokens, verbatim. Part 2 is its components, adapted to this DOM where marked
 * "adapted:". Part 3 bridges the existing app classes onto the same tokens.
 *
 * Locks: orange ground, dark ink, one serif stack (local fallbacks only, no remote fonts: the PWA must
 * work offline); lesson/source content only on paper; no white text on orange; provenance on paper;
 * honest empty states. Ink on ground 5.30:1, ink on paper 13.69:1, paper on ink 13.69:1.
 */

/* ===== 1. Approved tokens ===== */
:root {
  --ar-ground: #E8711C;
  --ar-ink: #13212E;
  --ar-paper: #F7E9D7;
  --ar-on-ink: #F7E9D7;
  --ar-rule: 1.5px;

  --ar-font: 'Frank Ruhl Libre', 'Frank Ruehl CLM', 'David Libre', Georgia, 'Times New Roman', serif;
  --ar-text-xs: 12px;      /* labels, step names: never smaller */
  --ar-text-sm: 13px;      /* provenance, captions */
  --ar-text-base: 15px;    /* UI copy */
  --ar-text-md: 18px;      /* buttons */
  --ar-text-read: 23px;    /* Hebrew lesson text */
  --ar-text-title: 26px;   /* portion title */
  --ar-text-letter: 132px; /* the chapter letter */
  --ar-leading-read: 1.75;

  --ar-space-1: 4px;
  --ar-space-2: 8px;
  --ar-space-3: 12px;
  --ar-space-4: 16px;
  --ar-space-5: 20px;
  --ar-radius: 6px;
  --ar-pill: 999px;
  --ar-touch: 44px;        /* minimum touch target */
  --ar-cta: 54px;
}

/* Optional night variant for reading in the dark: ink ground, paper text, orange as the accent. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="poster"]) {
    --ar-ground: #13212E;
    --ar-ink: #F7E9D7;
    --ar-paper: #1D2E3D;
    --ar-on-ink: #13212E;
  }
}
:root[data-theme="night"] {
  --ar-ground: #13212E;
  --ar-ink: #F7E9D7;
  --ar-paper: #1D2E3D;
  --ar-on-ink: #13212E;
}

/* App-only tokens (not in the artifact). Secondary ink is for paper only: 8.0:1 there, too weak on orange. */
:root {
  --nav-height: 66px;
  --ar-ink-soft: #3A4752;
  --ar-field: #FCF4EA;
  --ar-display: 44px;      /* poster headline on the orange ground */
}
:root[data-theme="night"] { --ar-ink-soft: #C9BBA8; --ar-field: #243747; }

/* ===== 2. Approved components ===== */
/* ---- Base ---- */
.ar-app {
  min-height: 100vh;
  background: var(--ar-ground);
  color: var(--ar-ink);
  font-family: var(--ar-font);
  font-size: var(--ar-text-base);
  display: flex;
  flex-direction: column;
}
/* adapted: zero-specificity so app button classes (.primary-btn, etc.) can set their own colours. */
:where(.ar-app) button { font: inherit; color: inherit; cursor: pointer; }
.ar-app :focus-visible { outline: 3px solid var(--ar-ink); outline-offset: 2px; }
:where(.ar-app) a { color: var(--ar-ink); }

/* ---- Header: wordmark, civil + Hebrew date, ב״ה top right ---- */
.ar-header { display: flex; justify-content: space-between; align-items: flex-start; padding: var(--ar-space-5) var(--ar-space-5) 6px; }
.ar-wordmark { font-size: var(--ar-text-sm); font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; }
.ar-bh { font-size: 19px; font-weight: 700; }

/* ---- Five steps (sticky nav). States: done (solid outline), current (ink fill), to do (dashed) ---- */
.ar-steps { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; padding: 10px var(--ar-space-5) var(--ar-space-2); position: sticky; top: 0; background: var(--ar-ground); z-index: 2; }
.ar-step { min-height: 52px; border: var(--ar-rule) dashed var(--ar-ink); border-radius: var(--ar-radius); background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 0; font-size: var(--ar-text-xs); }
.ar-step__n { font-weight: 700; }
.ar-step--done { border-style: solid; }
.ar-step[aria-current="step"] { border-style: solid; background: var(--ar-ink); color: var(--ar-on-ink); }
/* Sections scrolled to from the sticky nav must clear it. adapted: tied to --nav-height, not a fixed 84px. */
.ar-app [id] { scroll-margin-top:calc(var(--nav-height) + 18px); }

/* ---- Portion header with the poster letter ---- */
.ar-portion { display: flex; justify-content: space-between; align-items: flex-end; padding: 6px 22px var(--ar-space-3); }
.ar-kicker { font-size: var(--ar-text-xs); font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; }
.ar-portion__title { margin: 0; font-size: var(--ar-text-title); font-weight: 700; line-height: 1.1; }
.ar-letter { font-size: var(--ar-text-letter); font-weight: 900; line-height: 0.82; }
.ar-letter__label { font-size: 14px; text-align: center; }

/* ---- The paper sheet: the only place lesson text appears ---- */
/* adapted: also carries the existing .lesson-card; no side margin (the shell pads), stacked with a bottom gap. */
.ar-sheet, .lesson-card { margin: 0 0 var(--ar-space-3); background: var(--ar-paper); color: var(--ar-ink); border-radius: var(--ar-radius); padding: var(--ar-space-4) 18px; display: flex; flex-direction: column; gap: 14px; }
.ar-hebrew { margin: 0; font-size: var(--ar-text-read); line-height: var(--ar-leading-read); text-align: justify; }
.ar-hebrew:lang(he) { direction: rtl; }
.ar-note { margin: 0; font-size: var(--ar-text-base); line-height: 1.45; border-top: var(--ar-rule) solid var(--ar-ink); padding-top: var(--ar-space-3); }

/* ---- Both / עברית / English: aria-pressed carries the state; an unavailable language is disabled and struck ---- */
.ar-segmented { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: var(--ar-rule) solid var(--ar-ink); border-radius: var(--ar-pill); overflow: hidden; }
.ar-segmented button { min-height: var(--ar-touch); border: 0; border-right: var(--ar-rule) solid var(--ar-ink); background: transparent; }
.ar-segmented button:last-child { border-right: 0; }
.ar-segmented button[aria-pressed="true"] { background: var(--ar-ink); color: var(--ar-on-ink); font-weight: 700; }
.ar-segmented button:disabled { cursor: not-allowed; text-decoration: line-through; }
/* adapted: the pill clips outside outlines, so focus is drawn inside the segment in its own text colour. */
.ar-segmented button:focus-visible { outline: 3px solid currentColor; outline-offset: -6px; }

/* ---- Provenance, always under lesson text ---- */
.ar-provenance { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: var(--ar-space-3); row-gap: var(--ar-space-1); font-size: var(--ar-text-sm); line-height: 1.35; }
.ar-provenance dt { font-weight: 700; }
.ar-provenance dd { margin: 0; }

/* ---- Honest empty state (no verified schedule, no approved text, an empty lens) ---- */
.ar-empty { border: var(--ar-rule) dashed var(--ar-ink); border-radius: var(--ar-radius); padding: var(--ar-space-4); font-size: var(--ar-text-base); line-height: 1.45; }
.ar-empty__title { margin: 0 0 var(--ar-space-1); font-weight: 700; }

/* ---- Explore: lens blocks and status chips (metadata only unless the engine says otherwise) ---- */
.ar-lens { background: var(--ar-paper); border-radius: var(--ar-radius); padding: 14px var(--ar-space-4); display: flex; flex-direction: column; gap: var(--ar-space-2); }
.ar-lens__name { margin: 0; font-size: var(--ar-text-md); font-weight: 700; }
.ar-source { min-height: var(--ar-touch); display: flex; align-items: center; gap: var(--ar-space-2); border-top: 1px solid var(--ar-ink); text-decoration: none; }
.ar-chip { font-size: var(--ar-text-xs); font-weight: 700; letter-spacing: 0.06em; border: var(--ar-rule) solid var(--ar-ink); border-radius: var(--ar-pill); padding: 2px 8px; white-space: nowrap; }
.ar-chip--text { background: var(--ar-ink); color: var(--ar-on-ink); }   /* reviewed text in learner/ */

/* ---- Primary action ---- */
.ar-cta { width: 100%; min-height: var(--ar-cta); border: 0; border-radius: var(--ar-radius); background: var(--ar-ink); color: var(--ar-on-ink); font-size: var(--ar-text-md); font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 10px; }
.ar-cta:disabled { opacity: 1; background: transparent; color: var(--ar-ink); border: var(--ar-rule) dashed var(--ar-ink); cursor: not-allowed; }

/* ===== 3. Bridge: existing app DOM on the poster tokens ===== */
/* ---- Document ---- */
*, *::before, *::after { box-sizing: border-box; }
/* Flex/grid sheets below would otherwise override the hidden attribute the app relies on. */
[hidden] { display: none !important; }
html { background: var(--ar-ground); color: var(--ar-ink); font-family: var(--ar-font); scroll-padding-top:calc(var(--nav-height) + 18px); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; background: var(--ar-ground); }
::selection { background: var(--ar-ink); color: var(--ar-on-ink); }
h1, h2, h3, p { margin-top: 0; }
button, textarea { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:active { transform: translateY(1px); }
button:focus-visible, textarea:focus-visible { outline: 3px solid var(--ar-ink); outline-offset: 2px; }
.lesson-card[id], :target, textarea:focus-visible, button:focus-visible { scroll-margin-top:calc(var(--nav-height) + 18px); }

.app-shell { width: min(100%, 720px); margin: 0 auto; padding: env(safe-area-inset-top) 16px calc(96px + env(safe-area-inset-bottom)); line-height: 1.45; }
.muted { color: inherit; }
.lesson-card .muted, .lesson-card .lens-meta { color: var(--ar-ink-soft); }

/* ---- Header ---- */
.topbar { padding: var(--ar-space-5) 0 var(--ar-space-3); align-items: flex-end; gap: var(--ar-space-3); }
.topbar .ar-wordmark { margin: 0 0 var(--ar-space-1); }
.topbar h1 { margin: 0; font-size: 40px; font-weight: 900; line-height: 0.95; letter-spacing: -0.01em; }
.icon-btn { flex: 0 0 auto; width: var(--ar-touch); height: var(--ar-touch); border: var(--ar-rule) solid var(--ar-ink); border-radius: var(--ar-radius); background: transparent; color: var(--ar-ink); font-size: 20px; line-height: 1; }
.icon-btn:active { background: var(--ar-ink); color: var(--ar-on-ink); }

/* ---- Safety label: ink band, paper text, never orange-on-orange ---- */
.source-banner { display: flex; gap: var(--ar-space-3); align-items: baseline; margin: 0 0 var(--ar-space-3); padding: 10px var(--ar-space-3); background: var(--ar-ink); color: var(--ar-on-ink); border-radius: var(--ar-radius); font-size: var(--ar-text-sm); line-height: 1.35; }
.source-banner strong { flex: 0 0 auto; font-size: var(--ar-text-xs); letter-spacing: 0.16em; border: var(--ar-rule) solid currentColor; border-radius: var(--ar-pill); padding: 1px 8px; }

/* ---- Status toast (sticky under the nav) ---- */
.status-message { position: sticky; top: calc(var(--nav-height) + 8px); z-index: 6; margin: 0; border-radius: var(--ar-radius); background: var(--ar-ink); color: var(--ar-on-ink); padding: 0 var(--ar-space-3); max-height: 0; overflow: hidden; opacity: 0; transition: max-height .15s ease, opacity .15s ease, padding .15s ease; font-size: var(--ar-text-base); font-weight: 700; line-height: 1.35; }
.status-message:not(:empty) { margin-bottom: var(--ar-space-3); padding: 10px var(--ar-space-3); max-height: 88px; opacity: 1; }

/* ---- Date + progress, printed straight on the ground between ink rules ---- */
.date-card { display: flex; justify-content: space-between; align-items: center; gap: var(--ar-space-3); border-top: 3px solid var(--ar-ink); border-bottom: var(--ar-rule) solid var(--ar-ink); padding: 10px 0; margin: 0 0 var(--ar-space-2); }
.date-card p { margin: 0 0 2px; font-size: var(--ar-text-sm); }
.date-card #gregDate { font-size: var(--ar-text-md); font-weight: 700; }
.progress-ring { position: relative; flex: 0 0 52px; width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; border: 3px solid var(--ar-ink); font-size: var(--ar-text-sm); font-weight: 700; }
.progress-ring progress { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* ---- Primary navigation (sticky). Not the learning steps: plain tabs, current one filled ---- */
.tabs { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--ar-space-1); align-items: center; min-height: var(--nav-height); padding: 10px 0; margin: 0 0 var(--ar-space-3); background: var(--ar-ground); border-bottom: var(--ar-rule) solid var(--ar-ink); }
.nav-link { min-height: var(--ar-touch); padding: 0 2px; border: var(--ar-rule) solid var(--ar-ink); border-radius: var(--ar-radius); background: transparent; color: var(--ar-ink); font-size: var(--ar-text-sm); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-link[aria-current="page"] { background: var(--ar-ink); color: var(--ar-on-ink); }
.nav-link:active { background: var(--ar-paper); color: var(--ar-ink); }

.view { display: none; }
.view.active { display: block; }

/* ---- Sheets: flat paper, no shadow, spacing from the flex gap ---- */
.lesson-card > * { margin: 0; }
.lesson-card h2 { font-size: var(--ar-text-title); font-weight: 900; line-height: 1.08; }
.lesson-card h3 { font-size: 21px; font-weight: 700; line-height: 1.15; }
.step-label, .eyebrow { font-size: var(--ar-text-xs); font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; }
.lede { font-size: var(--ar-text-md); line-height: 1.45; }
.prompt { display: block; font-size: var(--ar-text-md); line-height: 1.45; }

/* ---- Poster intros: app copy (not lesson text) set large on the ground ---- */
.lesson-card.hero-card, .lesson-card.explore-intro { background: transparent; border-radius: 0; padding: var(--ar-space-2) 0 var(--ar-space-5); border-bottom: 3px solid var(--ar-ink); margin-bottom: var(--ar-space-4); gap: var(--ar-space-3); }
.hero-card h2, .explore-intro h2 { font-size: var(--ar-display); line-height: 0.98; letter-spacing: -0.015em; }
.hero-card .muted, .explore-intro .muted { color: var(--ar-ink); }

/* ---- The five learning steps: poster step numbers. To do dashed, done solid, current ink-filled ---- */
.step-head { display: flex; gap: var(--ar-space-3); align-items: center; padding-bottom: var(--ar-space-3); border-bottom: var(--ar-rule) solid var(--ar-ink); }
.step-head .step-label { margin: 0 0 2px; }
.step-number { flex: 0 0 52px; width: 52px; height: 52px; display: grid; place-items: center; border: var(--ar-rule) dashed var(--ar-ink); border-radius: var(--ar-radius); font-size: 30px; font-weight: 900; line-height: 1; }
.step-done .step-number { border-style: solid; }
.lesson-card[aria-current="step"] .step-number { border-style: solid; background: var(--ar-ink); color: var(--ar-on-ink); }

/* ---- Fields ---- */
textarea { display: block; width: 100%; min-height: 112px; resize: vertical; background: var(--ar-field); color: var(--ar-ink); border: var(--ar-rule) solid var(--ar-ink); border-radius: var(--ar-radius); padding: var(--ar-space-3); font-size: 17px; line-height: 1.45; }
textarea::placeholder { color: var(--ar-ink-soft); opacity: 1; }
textarea:focus { border-width: 2px; }
.notes-area { min-height: 260px; }

/* ---- Buttons: ink primary, outlined secondary; press inverts, disabled goes dashed (no faded contrast) ---- */
.primary-btn, .secondary-btn { width: 100%; min-height: var(--ar-cta); border-radius: var(--ar-radius); padding: 12px 16px; font-size: var(--ar-text-md); font-weight: 700; }
.primary-btn { border: var(--ar-rule) solid var(--ar-ink); background: var(--ar-ink); color: var(--ar-on-ink); }
.secondary-btn { min-height: 48px; border: var(--ar-rule) solid var(--ar-ink); background: transparent; color: var(--ar-ink); }
.primary-btn:active { background: transparent; color: var(--ar-ink); }
.secondary-btn:active, .rating-btn:active, .mode:active { background: var(--ar-ink); color: var(--ar-on-ink); }
.primary-btn[disabled], .secondary-btn[disabled], .complete-btn[disabled] { background: transparent; color: var(--ar-ink-soft); border-style: dashed; cursor: not-allowed; transform: none; }
.complete-btn.completed { background: transparent; color: var(--ar-ink); border: var(--ar-rule) solid var(--ar-ink); box-shadow: inset 0 0 0 1.5px var(--ar-ink); }
@media (hover: hover) {
  .secondary-btn:not([disabled]):hover, .rating-btn:hover, .icon-btn:hover { background: var(--ar-field); color: var(--ar-ink); }
  .nav-link:not([aria-current="page"]):hover { background: var(--ar-paper); }
}

/* ---- Reading mode: .mode-toggle carries .ar-segmented ---- */
.mode { font-size: var(--ar-text-base); color: var(--ar-ink); }

/* ---- Reading blocks ---- */
.text-block { display: flex; flex-direction: column; gap: var(--ar-space-2); border-top: var(--ar-rule) solid var(--ar-ink); padding-top: var(--ar-space-3); }
.text-block > * { margin: 0; }
.hebrew { font-family: var(--ar-font); direction: rtl; text-align: right; font-size: var(--ar-text-read); line-height: var(--ar-leading-read); }
.english { font-size: 17px; line-height: 1.6; }

/* ---- Chips: app labels in ink outline; synthetic demo content dashed. Ink fill is reserved for reviewed text. ---- */
.content-tag { align-self: flex-start; display: inline-block; font-size: var(--ar-text-xs); font-weight: 700; letter-spacing: 0.06em; line-height: 1.4; border: var(--ar-rule) solid var(--ar-ink); border-radius: var(--ar-pill); padding: 2px 8px; white-space: nowrap; }
.source-text .content-tag { border-style: dashed; }

/* ---- Review ---- */
#reviewContent { display: flex; flex-direction: column; gap: var(--ar-space-3); }
#reviewContent > * { margin: 0; }
.big-idea { font-size: 21px; font-weight: 700; line-height: 1.35; }
.argument { display: grid; gap: 0; border-top: var(--ar-rule) solid var(--ar-ink); }
.argument > div { padding: var(--ar-space-2) 0; border-bottom: 1px solid var(--ar-ink); }
.argument span { font-size: var(--ar-text-xs); font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; }
.argument p { margin: 2px 0 0; line-height: 1.45; }

/* ---- Feedback and honest empty states ---- */
.feedback { margin: 0; padding: var(--ar-space-3); border: var(--ar-rule) solid var(--ar-ink); border-left-width: 6px; border-radius: var(--ar-radius); line-height: 1.45; }
.ar-empty.muted { color: var(--ar-ink); }
.feedback.ar-empty { border-style: dashed; border-width: var(--ar-rule); }
.view > .ar-empty { background: var(--ar-paper); margin: 0 0 var(--ar-space-3); }

/* ---- Ratings: one row of three, pressed fills ---- */
.rating-group { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--ar-space-2); }
.rating-group .prompt { grid-column: 1 / -1; margin: 0; }
.rating-btn { min-height: var(--ar-touch); margin: 0; padding: 0 4px; border: var(--ar-rule) solid var(--ar-ink); border-radius: var(--ar-radius); background: transparent; color: var(--ar-ink); font-size: var(--ar-text-base); font-weight: 700; }
.rating-btn.selected, .rating-btn[aria-pressed="true"] { background: var(--ar-ink); color: var(--ar-on-ink); }

/* ---- End of today ---- */
.done-card { text-align: center; border: var(--ar-rule) dashed var(--ar-ink); }
.done-card.complete { background: var(--ar-ink); color: var(--ar-on-ink); border-style: solid; }
.done-card.complete .muted { color: var(--ar-on-ink); }
.explore-teaser { border-top: 6px solid var(--ar-ink); }

/* ---- Explore lenses ---- */
.lens-cards { display: grid; gap: var(--ar-space-3); margin: 0 0 var(--ar-space-3); }
.lens-card { margin: 0; gap: var(--ar-space-2); border-top: 6px solid var(--ar-ink); }
.lens-card .secondary-btn { margin-top: var(--ar-space-1); }
.lens-meta { font-size: var(--ar-text-sm); line-height: 1.4; padding-top: var(--ar-space-2); border-top: 1px solid var(--ar-ink); overflow-wrap: anywhere; }

/* ---- Source / provenance: always paper, framed so it never reads as lesson text ---- */
.source-detail { border: var(--ar-rule) solid var(--ar-ink); border-top-width: 6px; }
.source-detail .ar-provenance { padding: var(--ar-space-3) 0; border-top: var(--ar-rule) solid var(--ar-ink); border-bottom: var(--ar-rule) solid var(--ar-ink); }
.source-detail dt { font-size: var(--ar-text-xs); letter-spacing: 0.06em; text-transform: uppercase; padding-top: 2px; }
.source-detail dd { overflow-wrap: anywhere; }

/* ---- Memory ---- */
.concept-map { display: grid; grid-template-columns: 1fr 1fr; gap: var(--ar-space-2); }
.concept-map > div { border: var(--ar-rule) dashed var(--ar-ink); border-radius: var(--ar-radius); padding: var(--ar-space-3); font-size: var(--ar-text-md); font-weight: 700; }
.concept-map small { display: block; margin-top: 2px; font-size: var(--ar-text-sm); font-weight: 400; color: var(--ar-ink-soft); }

/* ---- Reading mode filter ---- */
body[data-mode="hebrew"] .demo-english { display: none; }
body[data-mode="english"] .demo-hebrew { display: none; }

/* ---- Small phones ---- */
@media (max-width: 420px) {
  :root { --nav-height: 64px; --ar-display: 38px; }
  .app-shell { padding-left: 12px; padding-right: 12px; }
  .lesson-card { padding: var(--ar-space-4) 14px; }
  .topbar h1 { font-size: 34px; }
  .nav-link { font-size: var(--ar-text-xs); }
}
/* ---- Wider screens ---- */
@media (min-width: 640px) {
  :root { --ar-display: 56px; }
  .lens-cards { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
  button:active { transform: none; }
}

/* Live reference links share the poster control language without implying source approval. */
.source-reference-link{display:flex;align-items:center;justify-content:center;text-decoration:none;margin-top:16px}
