:root {
  --bg: #f5efe0;
  --ink: #1a1a1a;
  --muted: #6b6257;
  --accent: #7a3b2e;
  --card: #fffdf5;
  --rule: #d9cfb7;
  --gemara-bg: #fffdf5;
  --mefaresh-bg: #faf4e4;
  --hover: #fff5dc;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body { font-family: "Iowan Old Style", Georgia, "Times New Roman", serif; line-height: 1.6; }

/* Header */
header {
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--rule);
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  background: var(--card);
}
@media (max-width: 600px) {
  header { padding: 0.75rem 1rem; gap: 0.75rem; }
  #picker { width: 100%; gap: 0.4rem; }
  #picker select { flex: 1; min-width: 0; }
  #picker input { width: 60px; }
  #daf-hint { display: none; }
}
header h1 { margin: 0; font-size: 1.4rem; color: var(--accent); }
.logo-link { display: inline-flex; align-items: center; text-decoration: none; }
.logo { height: 44px; width: auto; display: block; }

/* Header modes: minimal (landing) vs full (daf loaded) */
.header-minimal .header-picker { display: none; }

/* ═════════════════════════════════════════════════════════
   EDITORIAL LANDING  —  cream parchment · burgundy · typographic
   ═════════════════════════════════════════════════════════ */
.ed-landing {
  --ed-bg: #f4ecd6;
  --ed-surface: #ebe1c7;
  --ed-ivory: #1a1410;       /* primary ink */
  --ed-cream: #2a221b;       /* body text */
  --ed-brass: #7a1f2e;       /* deep burgundy accent */
  --ed-brass-dim: #5e1824;
  --ed-warm-muted: #6b5a47;  /* tertiary / meta */
  --ed-warm-muted-soft: #8a7864;
  --ed-rule: rgba(26, 20, 16, 0.14);
  --ed-rule-strong: rgba(26, 20, 16, 0.32);

  position: relative;
  min-height: 100vh;
  background: var(--ed-bg);
  color: var(--ed-ivory);
  font-family: 'Fraunces', Georgia, serif;
  font-feature-settings: 'ss01', 'ss02';
  overflow-x: hidden;
  padding: 0;
}

/* Subtle paper grain — very faint */
.ed-grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 2;
  opacity: 0.035;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.2  0 0 0 0 0.15  0 0 0 0 0.1  0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

.ed-container {
  position: relative; z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 4.5rem 3rem 3rem;
}

/* ─── HERO ───────────────────────────── */
.ed-hero {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 3rem;
  align-items: center;
  margin-bottom: 5rem;
  animation: edHeroRise 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
@keyframes edHeroRise {
  0%   { opacity: 0; transform: translateY(20px); }
  100% { opacity: 1; transform: translateY(0); }
}

.ed-eyebrow {
  font-size: 0.82rem;
  font-weight: 400;
  color: var(--ed-warm-muted);
  margin: 0 0 1.5rem;
  letter-spacing: 0.02em;
  display: flex; align-items: center; gap: 0.65rem;
}
.ed-eyebrow em {
  font-style: italic;
  color: var(--ed-ivory);
  font-variation-settings: 'SOFT' 100;
}
.ed-eyebrow-mark {
  color: var(--ed-brass);
  font-size: 0.9rem;
  font-family: 'Fraunces', serif;
}
.ed-preview-chip {
  font-family: 'Fraunces', serif;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ed-bg);
  background: var(--ed-brass);
  padding: 0.15rem 0.5rem;
  border-radius: 1px;
  margin-left: auto;
  animation: chipShimmer 4s ease-in-out infinite;
}
@keyframes chipShimmer {
  0%, 100% { box-shadow: 0 0 0 0 rgba(122, 31, 46, 0.35); }
  50%      { box-shadow: 0 0 0 4px rgba(122, 31, 46, 0); }
}

.ed-lede {
  font-family: 'Fraunces', Georgia, serif;
  font-size: clamp(1.75rem, 3.5vw, 2.9rem);
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.015em;
  color: var(--ed-ivory);
  margin: 0 0 1.5rem;
  font-variation-settings: 'SOFT' 30, 'WONK' 0;
  text-wrap: balance;
}
.ed-lede em {
  font-style: italic;
  color: var(--ed-brass);
  font-variation-settings: 'SOFT' 100, 'WONK' 1;
}

.ed-subcopy {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.02rem;
  line-height: 1.65;
  color: var(--ed-cream);
  margin: 0;
  max-width: 36rem;
  font-weight: 400;
}

/* Hero logo */
.ed-hero-glyph {
  text-align: center;
  position: relative;
  user-select: none;
}
.ed-logo-img {
  width: 100%;
  max-width: 460px;
  height: auto;
  display: block;
  margin: 0 auto;
  animation: edGlyphIn 1.0s cubic-bezier(0.2, 0.7, 0.2, 1) 0.15s both;
}
@keyframes edGlyphIn {
  0%   { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ─── TODAY SHORTCUTS ─────────────────── */
.ed-today {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1px;
  margin-bottom: 2.5rem;
  background: var(--ed-rule);
  border: 1px solid var(--ed-rule);
  animation: edHeroRise 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) 0.2s both;
}
.ed-today-card {
  background: var(--ed-bg);
  border: none;
  padding: 1rem 1.25rem;
  font-family: 'Fraunces', serif;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
  color: var(--ed-ivory);
  position: relative;
  overflow: hidden;
}
.ed-today-card:hover {
  background: var(--ed-surface);
}
.ed-today-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 2px;
  background: var(--ed-brass);
  transform: scaleY(0);
  transform-origin: top;
  transition: transform 0.25s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.ed-today-card:hover::before { transform: scaleY(1); }
.ed-today-card.ed-today-disabled { cursor: not-allowed; opacity: 0.55; }
.ed-today-card.ed-today-disabled:hover { background: var(--ed-bg); }

.ed-today-tag {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ed-brass);
  font-weight: 600;
  margin-bottom: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.ed-today-day {
  text-transform: none;
  letter-spacing: 0;
  font-style: italic;
  font-weight: 400;
  color: var(--ed-warm-muted);
  font-size: 0.72rem;
}
.ed-today-main {
  font-size: 1.25rem;
  font-weight: 500;
  font-style: italic;
  color: var(--ed-ivory);
  font-variation-settings: 'SOFT' 60;
  margin-bottom: 0.2rem;
}
.ed-today-daf {
  font-weight: 600;
  color: var(--ed-brass);
  font-style: normal;
}
.ed-today-meta {
  font-size: 0.75rem;
  color: var(--ed-warm-muted);
  font-style: italic;
}

/* ─── INLINE CHOOSER ─────────────────── */
.ed-chooser {
  margin-bottom: 4rem;
  padding: 1.75rem 2rem;
  background: linear-gradient(180deg, rgba(243,234,216,0.03), rgba(243,234,216,0.01));
  border-top: 1px solid var(--ed-rule);
  border-bottom: 1px solid var(--ed-rule);
  animation: edHeroRise 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) 0.25s both;
}
.ed-chooser-row {
  display: flex; align-items: flex-end; gap: 2rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.ed-inline-field {
  display: flex; flex-direction: column; gap: 0.4rem;
  flex: 1; min-width: 140px;
}
.ed-inline-field-daf { flex: 0 0 90px; min-width: 90px; }
.ed-inline-label {
  font-family: 'Fraunces', serif;
  font-size: 0.68rem;
  font-style: italic;
  letter-spacing: 0.04em;
  color: var(--ed-warm-muted);
}
.ed-inline-select, .ed-inline-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--ed-rule-strong);
  padding: 0.4rem 0 0.5rem;
  font-family: 'Fraunces', serif;
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--ed-ivory);
  transition: border-color 0.2s;
  width: 100%;
}
.ed-inline-select:focus, .ed-inline-input:focus {
  outline: none;
  border-bottom-color: var(--ed-brass);
}
.ed-inline-select {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'><path d='M1 1L6 6L11 1' stroke='%23c68b3a' stroke-width='1.5' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.25rem center;
  padding-right: 1.5rem;
}
.ed-inline-select option { background: var(--ed-surface); color: var(--ed-ivory); }
.ed-inline-select optgroup { font-style: italic; color: var(--ed-brass); }

.ed-amud { display: flex; gap: 0.3rem; }
.ed-amud-btn {
  background: transparent;
  border: 1px solid var(--ed-rule-strong);
  color: var(--ed-cream);
  padding: 0.4rem 0.9rem;
  font-family: 'Fraunces', serif;
  font-size: 1rem;
  font-weight: 500;
  font-style: italic;
  cursor: pointer;
  border-radius: 1px;
  transition: all 0.15s;
}
.ed-amud-btn:hover { border-color: var(--ed-brass); color: var(--ed-ivory); }
.ed-amud-btn.active {
  background: var(--ed-brass);
  border-color: var(--ed-brass);
  color: #f5eedb;
}

.ed-chooser-actions {
  display: flex; align-items: center; gap: 1.75rem;
  flex-wrap: wrap;
}
.ed-cta {
  background: var(--ed-ivory);
  color: var(--ed-bg);
  border: none;
  padding: 0.85rem 1.6rem;
  font-family: 'Fraunces', serif;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  border-radius: 1px;
  display: inline-flex; align-items: center; gap: 0.8rem;
  transition: all 0.2s cubic-bezier(0.2, 0.7, 0.2, 1);
  position: relative;
  overflow: hidden;
}
.ed-cta::before {
  content: ""; position: absolute; inset: 0;
  background: var(--ed-brass);
  transform: translateX(-101%);
  transition: transform 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
  z-index: 0;
}
.ed-cta > * { position: relative; z-index: 1; }
.ed-cta:hover::before { transform: translateX(0); }
.ed-cta:hover { color: #f5eedb; }
.ed-cta-arrow { transition: transform 0.25s; }
.ed-cta:hover .ed-cta-arrow { transform: translateX(4px); }

.ed-link-btn {
  background: transparent; border: none; color: var(--ed-warm-muted);
  font-family: 'Fraunces', serif; font-size: 0.9rem; font-style: italic;
  cursor: pointer; padding: 0.4rem 0;
  display: inline-flex; align-items: center; gap: 0.4rem;
  border-bottom: 1px solid transparent;
  transition: all 0.15s;
}
.ed-link-btn:hover { color: var(--ed-brass); border-bottom-color: var(--ed-brass); }
.ed-random-icon { transition: transform 0.5s; display: inline-block; font-style: normal; }
.ed-link-btn:hover .ed-random-icon { transform: rotate(180deg); }

.ed-hint {
  font-family: 'Fraunces', serif; font-size: 0.78rem; font-style: italic;
  color: var(--ed-warm-muted); margin-left: auto;
  font-variant-numeric: tabular-nums;
}

/* ─── RULES & SECTION HEADERS ────────── */
.ed-rule {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--ed-rule-strong) 20%, var(--ed-rule-strong) 80%, transparent);
  margin: 3.5rem 0 2.5rem;
}
.ed-section { margin-bottom: 3rem; animation: edHeroRise 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) 0.35s both; }
.ed-section-title {
  font-family: 'Fraunces', serif;
  font-size: 0.95rem;
  font-weight: 400;
  font-style: italic;
  color: var(--ed-warm-muted);
  margin: 0 0 1.75rem;
  letter-spacing: 0.04em;
  display: flex; align-items: baseline; gap: 0.5rem;
  font-variation-settings: 'SOFT' 100;
}
.ed-section-num {
  color: var(--ed-brass);
  font-weight: 600;
  font-style: normal;
}

/* ─── FEATURED SUGYOT (editorial list) ─ */
.ed-featured { list-style: none; padding: 0; margin: 0; }
.ed-feature {
  display: grid;
  grid-template-columns: 2.5rem 1fr auto;
  gap: 2rem;
  padding: 1.25rem 0;
  border-top: 1px solid var(--ed-rule);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.2, 0.7, 0.2, 1);
  position: relative;
  align-items: center;
}
.ed-feature:last-child { border-bottom: 1px solid var(--ed-rule); }
.ed-feature::before {
  content: "";
  position: absolute;
  left: -2rem; right: -2rem; top: 0; bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(198, 139, 58, 0.05), transparent);
  opacity: 0; transition: opacity 0.3s;
  pointer-events: none;
}
.ed-feature:hover::before { opacity: 1; }
.ed-feature:hover .ed-feature-num { color: var(--ed-brass); }
.ed-feature:hover .ed-feature-arrow { transform: translateX(6px); color: var(--ed-brass); }
.ed-feature:hover .ed-feature-title { color: var(--ed-brass); }
.ed-feature:hover .ed-feature-he { transform: translateX(-4px); }

.ed-feature-num {
  font-family: 'Fraunces', serif;
  font-size: 1.1rem;
  font-weight: 300;
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--ed-warm-muted);
  transition: color 0.25s;
  padding-top: 0.15rem;
}
.ed-feature-body { min-width: 0; }
.ed-feature-he {
  font-family: 'Frank Ruhl Libre', 'David', serif;
  font-weight: 700;
  font-size: 1.6rem;
  color: var(--ed-ivory);
  direction: rtl; text-align: right;
  margin-bottom: 0.15rem;
  transition: transform 0.25s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.ed-feature-title {
  font-family: 'Fraunces', serif;
  font-size: 0.92rem;
  font-weight: 500;
  font-style: italic;
  color: var(--ed-ivory);
  margin: 0 0 0.35rem;
  transition: color 0.25s;
  font-variation-settings: 'SOFT' 60;
}
.ed-feature-note {
  font-family: 'Fraunces', serif;
  font-size: 0.88rem;
  font-weight: 400;
  line-height: 1.55;
  color: var(--ed-cream);
  margin: 0;
  max-width: 36rem;
}
.ed-feature-meta {
  display: flex; align-items: center; gap: 0.8rem;
  color: var(--ed-warm-muted);
  padding-top: 0.15rem;
}
.ed-feature-ref {
  font-family: 'Fraunces', serif;
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ed-warm-muted);
  white-space: nowrap;
}
.ed-feature-arrow { transition: all 0.25s cubic-bezier(0.2, 0.7, 0.2, 1); }

/* ─── ROADMAP ────────────────────────── */
.ed-roadmap { margin: 0; padding: 0; }
.ed-roadmap-item {
  padding: 1rem 0;
  border-top: 1px solid var(--ed-rule);
  display: grid; grid-template-columns: 14rem 1fr; gap: 2rem;
  align-items: baseline;
}
.ed-roadmap-item:last-child { border-bottom: 1px solid var(--ed-rule); }
.ed-roadmap-item dt {
  font-family: 'Fraunces', serif;
  font-size: 1rem;
  font-weight: 500;
  font-style: italic;
  color: var(--ed-ivory);
  font-variation-settings: 'SOFT' 80;
}
.ed-roadmap-item dt::before {
  content: "→";
  color: var(--ed-brass);
  margin-right: 0.5rem;
  font-style: normal;
}
.ed-roadmap-item dd {
  font-family: 'Fraunces', serif;
  font-size: 0.88rem;
  font-weight: 400;
  line-height: 1.55;
  color: var(--ed-cream);
  margin: 0;
}

/* ─── FOOTER ─────────────────────────── */
.ed-footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--ed-rule);
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 1rem;
  font-family: 'Fraunces', serif;
  font-size: 0.8rem;
  font-style: italic;
  color: var(--ed-warm-muted);
}
.ed-footer-mark { color: var(--ed-brass); margin-right: 0.35rem; font-style: normal; }
.ed-footer a { color: var(--ed-cream); text-decoration: none; border-bottom: 1px solid var(--ed-rule-strong); }
.ed-footer a:hover { color: var(--ed-brass); border-bottom-color: var(--ed-brass); }

/* ─── RESPONSIVE ─────────────────────── */
@media (max-width: 900px) {
  .ed-container { padding: 3rem 1.75rem 2rem; }
  .ed-hero { grid-template-columns: 1fr; gap: 2rem; margin-bottom: 3rem; }
  .ed-hero-glyph { order: -1; text-align: left; }
  .ed-glyph-he { font-size: clamp(5rem, 25vw, 9rem); }
  .ed-roadmap-item { grid-template-columns: 1fr; gap: 0.35rem; }
  .ed-feature { grid-template-columns: 2rem 1fr; gap: 1rem; }
  .ed-feature-meta { grid-column: 2; padding-top: 0.5rem; }
}
@media (max-width: 540px) {
  .ed-chooser-row { gap: 1.5rem; }
  .ed-inline-field { min-width: 100%; }
  .ed-inline-field-daf { flex: 1 1 40%; min-width: 40%; }
  .ed-chooser-actions { flex-direction: column; align-items: stretch; }
  .ed-cta { width: 100%; justify-content: center; }
  .ed-hint { margin-left: 0; text-align: center; }
  .ed-footer { flex-direction: column; align-items: flex-start; }
}

/* Hide old header on landing (we keep app-header for daf view) */
.ed-landing + #app-main.app-hidden + #app-header.header-minimal,
body:has(#landing:not(.app-hidden)) #app-header { display: none; }

/* Transparent header over the editorial landing */
body:has(#landing:not(.app-hidden)) #app-header {
  background: transparent;
  border-bottom: 1px solid rgba(26, 20, 16, 0.08);
  padding: 1.1rem 3rem;
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 3;
}
body:has(#landing:not(.app-hidden)) #app-header .logo { height: 34px; }
body:has(#landing:not(.app-hidden)) #app-header .icon-btn {
  color: #1a1410;
  border-color: rgba(26, 20, 16, 0.22);
  background: transparent;
}
body:has(#landing:not(.app-hidden)) #app-header .icon-btn:hover {
  background: rgba(122, 31, 46, 0.08);
  border-color: #7a1f2e;
  color: #7a1f2e;
}
@media (max-width: 900px) {
  body:has(#landing:not(.app-hidden)) #app-header { padding: 0.9rem 1.75rem; }
}

/* ═════════════════════════════════════════════════════════
   OLD LANDING SCREEN (kept below for the daf view's flow)
   ═════════════════════════════════════════════════════════ */
#landing {
  position: relative;
  min-height: calc(100vh - 70px);
  padding: 3rem 1.5rem 4rem;
  overflow: hidden;
  background:
    radial-gradient(ellipse 800px 400px at 50% -10%, rgba(122,59,46,0.08), transparent 70%),
    radial-gradient(ellipse 600px 300px at 80% 100%, rgba(122,59,46,0.05), transparent 70%);
}

/* Ghostly Hebrew watermark behind everything */
.landing-watermark {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-family: "Frank Ruhl Libre", "SBL Hebrew", "David", serif;
  font-size: clamp(12rem, 42vw, 38rem);
  font-weight: 900;
  color: rgba(122, 59, 46, 0.04);
  line-height: 1;
  pointer-events: none;
  user-select: none;
  direction: rtl;
  z-index: 0;
  letter-spacing: -0.05em;
}

.landing-inner {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  animation: landingFade 0.6s ease-out;
}
@keyframes landingFade {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Hero: big wordmark + tagline */
.landing-hero { text-align: center; margin-bottom: 3.5rem; }
.wordmark-wrap {
  display: inline-flex; align-items: flex-start; gap: 0.6rem;
}
.preview-badge {
  display: inline-block; margin-top: 0.6rem;
  font-size: 0.6rem; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--card); background: var(--muted);
  padding: 0.25rem 0.5rem; border-radius: 3px;
  align-self: center;
}
.wordmark {
  font-family: "Frank Ruhl Libre", "David", Georgia, serif;
  font-weight: 700;
  font-size: clamp(3.5rem, 9vw, 6rem);
  line-height: 1;
  color: var(--accent);
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: baseline;
  gap: 0.15em;
}
.wordmark-he { direction: rtl; }
.wordmark-dot { color: var(--muted); font-weight: 400; margin: 0 0.08em; }
.wordmark-en {
  font-family: Georgia, "Iowan Old Style", serif;
  font-size: 0.55em;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--ink);
  text-transform: uppercase;
}
.landing-tagline {
  font-size: clamp(1rem, 1.6vw, 1.18rem);
  line-height: 1.55;
  color: var(--muted);
  margin: 1.2rem auto 0;
  max-width: 560px;
}

/* ─── Living product preview ─── */
.hero-demo {
  display: grid;
  grid-template-columns: 1.25fr auto 1fr;
  gap: 1.5rem;
  align-items: center;
  max-width: 900px;
  margin: 2.75rem auto 0;
  text-align: left;
  opacity: 0;
  animation: demoRise 0.8s ease-out 0.3s forwards;
}
@keyframes demoRise {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.demo-daf {
  display: grid;
  grid-template-columns: 1fr 1.6fr 1fr;
  gap: 0.5rem;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.75rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  font-family: "Frank Ruhl Libre", "David", serif;
}
.demo-margin {
  background: var(--mefaresh-bg);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.4rem 0.5rem;
  direction: rtl; text-align: right;
}
.demo-margin-label {
  font-family: Georgia, serif;
  direction: ltr;
  font-size: 0.55rem; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted);
  margin-bottom: 0.3rem; text-align: center;
  padding-bottom: 0.2rem; border-bottom: 1px dotted var(--rule);
}
.demo-dibur {
  font-size: 0.7rem; line-height: 1.4; color: #3a3027;
  margin-bottom: 0.3rem;
}
.demo-dibur b { color: var(--accent); }
.demo-dibur:last-child { margin-bottom: 0; }

.demo-gemara {
  background: var(--gemara-bg);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.6rem 0.7rem;
  direction: rtl; text-align: justify;
  line-height: 1.75; font-size: 0.92rem; color: #1a1a1a;
}
.demo-seg {
  display: inline;
  padding: 0.1rem 0.15rem;
  border-radius: 2px;
}
.demo-seg + .demo-seg::before { content: " "; }

.demo-active {
  position: relative;
  background: rgba(122, 59, 46, 0.12);
  box-shadow: 0 0 0 1px rgba(122, 59, 46, 0.3);
  cursor: pointer;
}
.demo-ring {
  position: absolute; inset: -3px;
  border-radius: 4px;
  border: 2px solid var(--accent);
  pointer-events: none;
  animation: ringPulse 1.6s ease-out infinite;
}
@keyframes ringPulse {
  0%   { transform: scale(1);    opacity: 0.75; }
  70%  { transform: scale(1.08); opacity: 0;    }
  100% { transform: scale(1.08); opacity: 0;    }
}
.demo-cursor-label {
  position: absolute; top: 100%; left: 50%;
  transform: translate(-50%, 4px);
  direction: ltr;
  font-family: Georgia, serif;
  font-size: 0.6rem;
  background: var(--accent); color: var(--card);
  padding: 0.15rem 0.4rem;
  border-radius: 2px;
  white-space: nowrap;
  letter-spacing: 0.04em;
  animation: labelBob 1.6s ease-in-out infinite;
}
@keyframes labelBob {
  0%, 100% { transform: translate(-50%, 4px); }
  50%      { transform: translate(-50%, 7px); }
}

.demo-arrow {
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  animation: arrowSlide 1.8s ease-in-out infinite;
}
@keyframes arrowSlide {
  0%, 100% { transform: translateX(0);    opacity: 0.5; }
  50%      { transform: translateX(4px);  opacity: 1;   }
}

.demo-explain {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.75rem 0.9rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  font-family: Georgia, serif;
}
.demo-explain-header {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.6rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
  padding-bottom: 0.4rem; border-bottom: 1px solid var(--rule);
  margin-bottom: 0.5rem;
}
.demo-explain-tag {
  background: var(--accent); color: var(--card);
  padding: 0.1rem 0.4rem; border-radius: 2px;
  font-family: Georgia, serif;
}
.demo-explain-ref { font-family: "Menlo", monospace; text-transform: none; letter-spacing: 0; }
.demo-explain-body { font-size: 0.78rem; line-height: 1.55; color: #2a2a2a; }
.demo-explain-body p { margin: 0; }
.demo-explain-body strong { color: var(--accent); }
.demo-typing-cursor {
  display: inline-block; width: 0.45ch; height: 1em;
  background: var(--accent); vertical-align: text-bottom;
  margin-left: 1px;
  animation: blink 0.9s infinite;
}
@keyframes blink { 50% { opacity: 0; } }

@media (max-width: 800px) {
  .hero-demo { grid-template-columns: 1fr; gap: 1rem; }
  .demo-arrow { transform: rotate(90deg); justify-self: center; }
  .demo-arrow svg { width: 24px; height: 24px; }
  .demo-daf { grid-template-columns: 1fr 1.6fr 1fr; }
}
@media (max-width: 520px) {
  .demo-daf { grid-template-columns: 1fr; }
  .demo-margin-label { text-align: left; }
}

/* Chooser card */
.landing-chooser {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1.75rem 1.75rem 1.5rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.05), 0 1px 0 rgba(255,255,255,0.5) inset;
  max-width: 640px;
  margin: 0 auto;
}
.chooser-label {
  font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; margin-bottom: 1rem;
}
.chooser-grid {
  display: grid;
  grid-template-columns: 1.8fr 1fr auto;
  gap: 0.9rem;
  align-items: end;
}
.chooser-field label {
  display: block; font-size: 0.7rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); font-weight: 600;
  margin-bottom: 0.35rem;
}
.chooser-field select, .chooser-field input {
  width: 100%; padding: 0.6rem 0.75rem; border: 1px solid var(--rule); border-radius: 4px;
  font-family: inherit; font-size: 0.95rem; background: var(--bg); color: var(--ink);
  transition: border-color 0.12s;
}
.chooser-field select:focus, .chooser-field input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(122, 59, 46, 0.12);
}
.landing-amud { height: 2.45rem; }
.landing-amud .amud-btn { padding: 0.6rem 0.95rem; }

.landing-hint {
  margin: 0.75rem 0 0;
  font-size: 0.78rem;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.chooser-actions { display: flex; gap: 0.7rem; margin-top: 1.25rem; }
.begin-btn {
  flex: 1;
  background: var(--accent); color: var(--card); border: none;
  padding: 0.85rem 1.2rem; border-radius: 4px; cursor: pointer;
  font-family: inherit; font-size: 1rem; font-weight: 600;
  transition: all 0.12s;
  box-shadow: 0 2px 0 rgba(0,0,0,0.1);
}
.begin-btn:hover { filter: brightness(1.1); transform: translateY(-1px); box-shadow: 0 3px 0 rgba(0,0,0,0.12); }
.begin-btn:active { transform: translateY(0); box-shadow: 0 1px 0 rgba(0,0,0,0.1); }
.random-btn {
  background: transparent; color: var(--ink);
  border: 1px solid var(--rule);
  padding: 0.85rem 1.1rem; border-radius: 4px; cursor: pointer;
  font-family: inherit; font-size: 0.9rem;
  transition: all 0.12s;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.random-btn:hover { background: var(--hover); border-color: var(--accent); }
.random-icon { display: inline-block; transition: transform 0.3s; }
.random-btn:hover .random-icon { transform: rotate(180deg); }

/* Featured sugyot section */
.featured-section { margin-top: 3rem; }
.featured-label {
  font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; text-align: center;
  margin-bottom: 1.25rem;
}
.featured-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  max-width: 900px; margin: 0 auto;
}
.featured-card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1.1rem 1.2rem 1.2rem;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: all 0.15s;
  position: relative;
  overflow: hidden;
}
.featured-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), transparent);
  transform: scaleX(0); transform-origin: left; transition: transform 0.25s;
}
.featured-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.08);
}
.featured-card:hover::before { transform: scaleX(1); }
.featured-card-he {
  font-family: "Frank Ruhl Libre", "David", serif;
  direction: rtl; text-align: right;
  font-size: 1.25rem; font-weight: 700; color: var(--accent);
  margin-bottom: 0.15rem;
}
.featured-card-name {
  font-size: 0.95rem; font-weight: 600; color: var(--ink);
  margin-bottom: 0.15rem;
}
.featured-card-ref {
  font-size: 0.73rem; color: var(--muted); letter-spacing: 0.04em;
  text-transform: uppercase; font-weight: 600; margin-bottom: 0.6rem;
}
.featured-card-note { font-size: 0.85rem; line-height: 1.45; color: var(--muted); }

/* Roadmap / coming-soon section */
.roadmap {
  margin-top: 3rem;
  max-width: 680px; margin-left: auto; margin-right: auto;
  padding: 1.25rem 1.5rem;
  background: rgba(255,253,245,0.5);
  border: 1px dashed var(--rule);
  border-radius: 6px;
}
.roadmap-label {
  font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; text-align: center;
  margin-bottom: 1rem;
}
.roadmap-list { list-style: none; padding: 0; margin: 0; }
.roadmap-list li {
  padding: 0.75rem 0; border-bottom: 1px dotted var(--rule);
  display: flex; flex-direction: column; gap: 0.2rem;
}
.roadmap-list li:last-child { border-bottom: none; }
.roadmap-title {
  font-size: 0.92rem; font-weight: 600; color: var(--ink);
}
.roadmap-title::before {
  content: "→"; color: var(--accent); margin-right: 0.5rem; font-weight: 700;
}
.roadmap-note { font-size: 0.82rem; line-height: 1.5; color: var(--muted); padding-left: 1.15rem; }
.roadmap-footnote {
  margin: 1rem 0 0; padding-top: 0.75rem;
  border-top: 1px dotted var(--rule);
  font-size: 0.75rem; text-align: center; font-style: italic;
}

.landing-footnote {
  margin-top: 2.5rem; font-size: 0.82rem; text-align: center;
}
.landing-footnote a { color: var(--accent); }

/* Hide main when landing is visible */
.app-hidden { display: none !important; }

@media (max-width: 640px) {
  .chooser-grid { grid-template-columns: 1fr; }
  .chooser-actions { flex-direction: column; }
}
.icon-btn {
  background: transparent; border: 1px solid var(--rule); color: var(--ink);
  padding: 0.3rem 0.55rem; border-radius: 3px; cursor: pointer;
  font-size: 1.1rem; line-height: 1;
}
.icon-btn:hover { background: var(--hover); border-color: var(--accent); }
#picker { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
#picker select, #picker input {
  padding: 0.4rem 0.6rem; border: 1px solid var(--rule); border-radius: 3px;
  font-family: inherit; font-size: 0.9rem; background: var(--bg); color: var(--ink);
}
#picker select { min-width: 180px; }
#picker input { width: 70px; }
#picker select:focus, #picker input:focus { outline: none; border-color: var(--accent); }

.amud-toggle { display: flex; border: 1px solid var(--rule); border-radius: 3px; overflow: hidden; }
.amud-btn {
  background: var(--bg); border: none; padding: 0.4rem 0.7rem;
  font-family: inherit; font-size: 0.85rem; cursor: pointer; color: var(--ink);
  border-right: 1px solid var(--rule);
}
.amud-btn:last-child { border-right: none; }
.amud-btn.active { background: var(--accent); color: var(--card); }
.amud-btn:hover:not(.active) { background: var(--hover); }

#load-btn {
  background: var(--accent); color: var(--card); border: none;
  padding: 0.4rem 0.85rem; border-radius: 3px; cursor: pointer;
  font-family: inherit; font-size: 0.85rem;
}
#daf-hint { font-size: 0.75rem; margin-left: 0.25rem; }

/* Main */
main { max-width: 1400px; margin: 0 auto; padding: 2rem; }
#daf-header {
  margin-bottom: 1.5rem;
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
#daf-header h2 { margin: 0; font-size: 1.6rem; color: var(--accent); }
#daf-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
#daf-nav { display: flex; gap: 0.5rem; }
.daf-logic-btn {
  background: var(--accent) !important;
  color: var(--card) !important;
  border-color: var(--accent) !important;
  font-weight: 600;
}
.daf-logic-btn:hover {
  filter: brightness(1.1);
  color: var(--card) !important;
  border-color: var(--accent) !important;
  background: var(--accent) !important;
}
.daf-iyun-btn {
  background: #3f2a4a !important;
  color: #f5eedb !important;
  border-color: #3f2a4a !important;
  font-weight: 600;
}
.daf-iyun-btn:hover {
  filter: brightness(1.2);
  color: #f5eedb !important;
  border-color: #3f2a4a !important;
  background: #3f2a4a !important;
}
.daf-nav-btn {
  background: transparent; color: var(--ink);
  border: 1px solid var(--rule);
  padding: 0.4rem 0.85rem; border-radius: 3px; cursor: pointer;
  font-family: inherit; font-size: 0.85rem;
  transition: all 0.12s;
}
.daf-nav-btn:hover { background: var(--hover); border-color: var(--accent); color: var(--accent); }
.daf-nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.daf-nav-btn:disabled:hover { background: transparent; border-color: var(--rule); color: var(--ink); }
#daf-nav-bottom {
  display: flex; justify-content: space-between; gap: 0.5rem;
  margin-top: 1.5rem; padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
}
#daf-nav-bottom .daf-nav-btn { padding: 0.55rem 1.25rem; font-size: 0.9rem; }

/* Tzuras hadaf — authentic Vilna page look */
#daf {
  background: var(--gemara-bg);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 1.75rem 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.daf-page {
  direction: rtl;
  text-align: justify;
  font-family: "Frank Ruhl Libre", "SBL Hebrew", "David", "Times New Roman", serif;
}

/* Gemara — the central flowing text block */
.gemara-body {
  font-size: 1.28rem;
  line-height: 1.85;
  color: #111;
  /* justify without trailing last-line gap looks weird in Hebrew — leave default */
}

/* Floated margins — Rashi/Rashbam on visual left, Tosafot on visual right */
.rashi-margin, .tosafot-margin {
  font-size: 0.88rem;
  line-height: 1.55;
  color: #2a2a2a;
  padding: 0.1rem 0.4rem;
  margin-bottom: 0.4rem;
}
.rashi-margin {
  float: left;
  width: 30%;
  margin-left: 0;
  margin-right: 0.9rem;
  padding-right: 0.6rem;
  border-right: 1px solid var(--rule);
}
.tosafot-margin {
  float: right;
  width: 30%;
  margin-right: 0;
  margin-left: 0.9rem;
  padding-left: 0.6rem;
  border-left: 1px solid var(--rule);
}
.margin-label {
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 0.35rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px dotted var(--rule);
  text-align: center;
  font-family: Georgia, serif;
}
.margin-label .he { display: block; font-size: 0.95rem; color: var(--accent); margin-top: 0.15rem; font-family: "Frank Ruhl Libre", "David", serif; letter-spacing: 0; text-transform: none; }

/* Clear float after both margins */
.daf-page::after { content: ""; display: table; clear: both; }

/* Clickable spans inline in the gemara body */
.seg, .dibur {
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.12s, box-shadow 0.12s;
}
.seg:hover, .dibur:hover {
  background: var(--hover);
  box-shadow: 0 0 0 2px var(--hover);
}

/* Dibur separation in margins */
.dibur { display: block; margin-bottom: 0.55rem; padding-bottom: 0.35rem; }
.dibur + .dibur { border-top: 1px dotted var(--rule); padding-top: 0.35rem; }
.dibur:last-child { border-bottom: none; margin-bottom: 0; }

/* The first few words of a dibur (headword) often in bold in print */
.dibur-head { font-weight: 700; color: var(--accent); }

/* Mobile column toggles — hidden on desktop */
.col-toggles { display: none; }

/* Cross-daf context: preceding/following segments from neighboring daf */
.context-section {
  margin: 1rem 0;
  padding: 0.9rem 1rem;
  background: rgba(216, 197, 151, 0.18);
  border: 1px dashed rgba(122, 31, 46, 0.35);
  border-radius: 4px;
  font-family: "Frank Ruhl Libre", "David", serif;
}
.context-section.context-before { margin-bottom: 1.2rem; }
.context-section.context-after  { margin-top: 1.2rem; }
.context-header {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  font-family: Georgia, serif; font-size: 0.75rem; color: var(--muted);
  font-style: italic; margin-bottom: 0.55rem;
  padding-bottom: 0.45rem; border-bottom: 1px dotted rgba(122, 31, 46, 0.3);
  direction: ltr;
}
.context-header strong { color: var(--accent); font-weight: 600; font-style: normal; }
.context-arrow { color: var(--accent); font-weight: 700; font-size: 0.95rem; }
.context-jump {
  margin-left: auto;
  background: transparent; color: var(--accent);
  border: 1px solid var(--accent); border-radius: 3px;
  padding: 0.25rem 0.6rem; cursor: pointer;
  font-family: Georgia, serif; font-size: 0.72rem; font-weight: 600;
  transition: all 0.12s;
}
.context-jump:hover { background: var(--accent); color: var(--card); }
.context-body {
  direction: rtl; text-align: justify;
  line-height: 1.75; font-size: 1rem; color: #333;
  opacity: 0.88;
}
.context-seg {
  cursor: pointer; padding: 0.1rem 0.15rem;
  border-radius: 2px; transition: background 0.12s;
}
.context-seg:hover { background: rgba(122, 31, 46, 0.1); }
@media (max-width: 600px) {
  .context-section { padding: 0.75rem; }
  .context-body { font-size: 0.95rem; }
}

/* Secondary meforshim: expandable cards below the tzuras hadaf */
.more-meforshim {
  margin-top: 1.5rem; padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
}
.more-mef-title {
  font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; margin-bottom: 0.9rem;
  font-family: Georgia, serif; text-align: center;
}
.more-mef-card {
  background: var(--card); border: 1px solid var(--rule);
  border-radius: 3px; margin-bottom: 0.5rem;
}
.more-mef-card > summary {
  padding: 0.6rem 0.9rem; cursor: pointer; list-style: none;
  display: flex; align-items: baseline; gap: 0.6rem;
  transition: background 0.12s;
}
.more-mef-card > summary:hover { background: var(--hover); }
.more-mef-card > summary::-webkit-details-marker { display: none; }
.more-mef-card > summary::before {
  content: "▸"; color: var(--accent); font-size: 0.85rem;
  transition: transform 0.15s; display: inline-block;
}
.more-mef-card[open] > summary::before { transform: rotate(90deg); }
.more-mef-name { font-weight: 600; color: var(--accent); font-size: 0.95rem; }
.more-mef-he {
  font-family: "Frank Ruhl Libre", "David", serif;
  direction: rtl; color: var(--muted); font-size: 1rem;
}
.more-mef-count {
  margin-left: auto; background: var(--bg); padding: 0.1rem 0.45rem;
  border-radius: 10px; font-size: 0.7rem; color: var(--muted);
  letter-spacing: 0.02em;
}
.more-mef-card .dibur {
  padding: 0.55rem 0.95rem; border-top: 1px solid var(--rule);
  direction: rtl; text-align: right; line-height: 1.65;
  font-size: 0.95rem;
}
.more-mef-card .dibur + .dibur { border-top: 1px dotted var(--rule); }
.more-mef-body { }
.more-mef-loading {
  padding: 0.7rem 0.95rem; color: var(--muted);
  font-style: italic; font-size: 0.85rem;
  border-top: 1px solid var(--rule);
}

/* Responsive: stack columns on narrow screens */
@media (max-width: 900px) {
  .col-toggles {
    display: flex; gap: 0.5rem; margin-bottom: 1rem;
    padding-bottom: 1rem; border-bottom: 1px solid var(--rule);
  }
  .col-toggle {
    flex: 1;
    background: transparent;
    border: 1px solid var(--rule);
    color: var(--muted);
    padding: 0.5rem 0.6rem;
    border-radius: 3px;
    font-family: inherit;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.12s;
    position: relative;
  }
  .col-toggle.active {
    background: var(--card);
    color: var(--accent);
    border-color: var(--accent);
    font-weight: 600;
  }
  .col-toggle.active::before {
    content: "✓ ";
    color: var(--accent);
    font-weight: 700;
  }
  .col-toggle:not(.active) { opacity: 0.6; }

  /* Column visibility on mobile (toggles at top of daf) */
  .daf-page.hide-gemara .mseg-gemara,
  .daf-page.hide-gemara .mseg-label { display: none; }
  .daf-page.hide-rashi .mseg-rashi { display: none; }
  .daf-page.hide-tosafot .mseg-tosafot { display: none; }

  #daf { padding: 0; background: transparent; border: none; box-shadow: none; }
  .daf-mobile { display: flex; flex-direction: column; gap: 1.25rem; }

  /* Per-segment card: gemara → rashi → tosafot */
  .mseg {
    background: var(--gemara-bg);
    border: 1px solid var(--rule);
    border-radius: 5px;
    padding: 0.85rem 0.95rem;
    position: relative;
  }
  .mseg-label {
    font-family: Georgia, serif;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    direction: ltr; text-align: right;
    margin-bottom: 0.4rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px dotted var(--rule);
  }
  .mseg-gemara {
    font-family: "Frank Ruhl Libre", "David", serif;
    font-size: 1.18rem;
    line-height: 1.85;
    direction: rtl;
    text-align: justify;
    color: #111;
    margin-bottom: 0.5rem;
  }
  .mseg-gemara .seg {
    padding: 0.15rem 0.2rem;
    margin: -0.15rem -0.2rem;
  }

  /* Inset commentary blocks within each segment */
  .mseg-comm {
    margin-top: 0.65rem;
    padding: 0.55rem 0.75rem 0.6rem;
    background: var(--mefaresh-bg);
    border-radius: 4px;
    border-left: 2px solid var(--accent);
  }
  .mseg-tosafot { border-left: 2px solid #7a6055; }
  .mseg-other { border-left: 2px solid #a89677; opacity: 0.96; }
  .mseg-comm-label {
    font-family: Georgia, serif;
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.4rem;
    direction: ltr;
    display: flex; align-items: baseline; gap: 0.5rem;
  }
  .mseg-comm-name { color: var(--accent); }
  .mseg-comm-he {
    font-family: "Frank Ruhl Libre", "David", serif;
    direction: rtl;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ink);
  }
  .mseg-comm .dibur {
    font-family: "Frank Ruhl Libre", "David", serif;
    direction: rtl; text-align: right;
    font-size: 0.98rem !important;
    line-height: 1.7;
    padding: 0.35rem 0;
    margin-bottom: 0;
    border-top: none;
  }
  .mseg-comm .dibur + .dibur {
    border-top: 1px dotted var(--rule);
    padding-top: 0.45rem;
    margin-top: 0.25rem;
  }
}

@media (max-width: 600px) {
  main { padding: 1rem; }
  #daf-header { flex-direction: column; align-items: flex-start; gap: 0.6rem; }
  #daf-header h2 { font-size: 1.25rem; }
  #daf-actions { width: 100%; flex-direction: column; gap: 0.5rem; align-items: stretch; }
  .daf-logic-btn { width: 100%; }
  #daf-nav { width: 100%; justify-content: space-between; }
  #daf-nav .daf-nav-btn, #daf-nav-bottom .daf-nav-btn { flex: 1; padding: 0.5rem; }
  .gemara-body { font-size: 1.08rem; }
  .modal-box { width: 94vw; max-height: 90vh; }
  .modal-body { font-size: 0.9rem; padding: 0.85rem 1rem; }
}

/* Modal */
.modal-hidden { display: none !important; }
#modal, #settings-modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.15s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(20, 15, 10, 0.55);
  z-index: 0;
}
.modal-box {
  position: relative;
  z-index: 1;
  background: var(--card);
  border-radius: 6px;
  width: min(720px, 90vw);
  min-height: 140px;
  max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--rule);
  background: var(--mefaresh-bg);
}
.modal-kind {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--card); background: var(--accent);
  padding: 0.2rem 0.55rem; border-radius: 3px; margin-right: 0.6rem;
}
.modal-kind.modal-kind-deep {
  background: #4a2a3a;
  animation: deepPulse 2.2s ease-in-out infinite;
}
.modal-kind.modal-kind-iyun {
  background: #3f2a4a;
  animation: deepPulse 2.2s ease-in-out infinite;
}
@keyframes deepPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 42, 58, 0.4); }
  50%      { box-shadow: 0 0 0 5px rgba(74, 42, 58, 0); }
}
.modal-ref { font-size: 0.85rem; color: var(--muted); font-family: monospace; }
.modal-header-actions { display: flex; gap: 0.3rem; align-items: center; }
.modal-close, .modal-minimize {
  background: transparent; border: 1px solid transparent;
  color: var(--muted);
  line-height: 1; cursor: pointer;
  font-family: inherit; border-radius: 3px;
  transition: all 0.12s;
  display: flex; align-items: center; justify-content: center;
}
.modal-close { font-size: 1.5rem; width: 32px; height: 32px; }
.modal-minimize {
  font-size: 1.5rem; font-weight: 700;
  width: 32px; height: 32px; padding-bottom: 5px;
}
.modal-close:hover, .modal-minimize:hover {
  color: var(--accent);
  background: var(--bg);
  border-color: var(--rule);
}
.modal-minimize::after { content: ""; } /* prevents hyphen clipping */

/* Minimized pill — floats bottom-left while stream keeps running */
.minimized-hidden { display: none !important; }
#minimized-pill {
  position: fixed; bottom: 1rem; left: 1rem; z-index: 60;
  background: var(--card); border: 1px solid var(--rule); border-radius: 24px;
  padding: 0.5rem 0.4rem 0.5rem 0.9rem; cursor: pointer;
  display: flex; align-items: center; gap: 0.6rem;
  font-family: 'Fraunces', Georgia, serif; font-size: 0.85rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  max-width: min(360px, calc(100vw - 2rem));
  transition: all 0.15s;
  animation: pillIn 0.3s ease-out;
}
@keyframes pillIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
#minimized-pill:hover { border-color: var(--accent); box-shadow: 0 6px 20px rgba(0,0,0,0.15); }
#minimized-pill.pill-done {
  border-color: var(--accent);
  animation: pillIn 0.3s ease-out, doneBounce 0.6s ease-out 0.3s;
}
@keyframes doneBounce {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.05); }
}
.pill-spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--rule); border-top-color: var(--accent);
  animation: pillSpin 0.8s linear infinite;
  flex-shrink: 0;
}
#minimized-pill.pill-done .pill-spinner {
  animation: none; background: var(--accent); border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--accent);
}
@keyframes pillSpin { to { transform: rotate(360deg); } }
.pill-label {
  color: var(--ink); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.pill-close {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0 0.3rem;
  flex-shrink: 0;
}
.pill-close:hover { color: var(--accent); }
@media (max-width: 600px) {
  #minimized-pill { bottom: 0.5rem; left: 0.5rem; font-size: 0.78rem; }
}
.modal-source {
  padding: 0.9rem 1.25rem;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  max-height: 140px; overflow-y: auto;
}
.modal-source .hebrew-text { font-size: 1rem; }
.modal-body {
  padding: 1rem 1.25rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  font-size: 0.95rem;
  line-height: 1.65;
  flex: 1;
  min-height: 120px;
}

/* Body scroll lock when any modal is open (fixes iOS scroll chaining) */
body.modal-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  right: 0;
}
.modal-backdrop { overscroll-behavior: contain; touch-action: none; }
.modal-source { overscroll-behavior: contain; }
.modal-body strong { color: var(--accent); }
.modal-body h3 {
  font-size: 1rem; font-weight: 700; margin: 1rem 0 0.5rem;
  color: var(--accent); letter-spacing: -0.005em;
}
.modal-body h4 {
  font-size: 0.9rem; font-weight: 700; margin: 0.85rem 0 0.4rem;
  color: var(--ink); letter-spacing: -0.005em;
}
.modal-body h3:first-child, .modal-body h4:first-child { margin-top: 0; }
.modal-body p { margin: 0 0 0.55rem; }
.modal-body p:last-child { margin-bottom: 0; }
.modal-body ul { margin: 0 0 0.6rem; padding-left: 1.2rem; }
.modal-body li { margin-bottom: 0.3rem; line-height: 1.55; }
.modal-body code {
  background: var(--bg); padding: 0.1rem 0.35rem; border-radius: 2px;
  font-family: "Menlo", "Consolas", monospace; font-size: 0.85em;
  color: var(--accent);
}
.modal-body em { font-style: italic; }

/* Conversation turns inside the modal */
.turn-user {
  background: var(--bg);
  border-left: 2px solid var(--accent);
  padding: 0.7rem 0.95rem;
  margin: 1rem 0 0.75rem;
  font-style: italic;
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.55;
}
.turn-user::before {
  content: "you asked";
  display: block;
  font-size: 0.6rem; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; font-style: normal;
  color: var(--accent); margin-bottom: 0.3rem;
  font-family: Georgia, serif;
}
.turn-assistant { margin-top: 0.25rem; }
.tool-use-note {
  display: inline-flex; align-items: center; gap: 0.4rem;
  margin: 0.4rem 0; padding: 0.35rem 0.7rem;
  background: var(--bg); border: 1px dashed var(--rule);
  border-radius: 3px; font-size: 0.78rem; color: var(--muted);
  font-style: italic;
}
.tool-use-note .tool-icon { font-style: normal; }
.tool-use-note.tool-use-done { opacity: 0.7; }
.md-content { display: block; }

/* Follow-up input bar */
.followup-form {
  display: flex; gap: 0.5rem; align-items: flex-end;
  padding: 0.65rem 0.85rem; background: var(--bg);
  border-top: 1px solid var(--rule); flex-shrink: 0;
}
#followup-input {
  flex: 1; border: 1px solid var(--rule); border-radius: 4px;
  padding: 0.55rem 0.75rem; font-family: inherit; font-size: 0.9rem;
  background: var(--card); color: var(--ink);
  resize: none; min-height: 36px; max-height: 120px;
  line-height: 1.4; outline: none; transition: border-color 0.12s;
}
#followup-input:focus { border-color: var(--accent); }
#followup-input:disabled { opacity: 0.5; cursor: not-allowed; }
#followup-send {
  background: var(--accent); color: var(--card); border: none;
  width: 36px; height: 36px; border-radius: 4px; cursor: pointer;
  font-size: 1.2rem; line-height: 1; font-weight: 700;
  transition: all 0.12s; flex-shrink: 0;
}
#followup-send:hover { filter: brightness(1.1); transform: translateY(-1px); }
#followup-send:disabled { background: var(--muted); cursor: not-allowed; transform: none; }

/* Free-tier badge (floating, always visible when using free tier) */
.free-tier-badge {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 50;
  background: #fffdf5; border: 1px solid #d9cfb7;
  padding: 0.55rem 0.85rem; border-radius: 4px;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 0.8rem; color: #6b5a47;
  box-shadow: 0 4px 14px rgba(0,0,0,0.10);
  cursor: pointer;
  transition: all 0.15s;
  animation: badgeIn 0.4s ease-out;
  user-select: none;
}
.free-tier-badge:hover {
  border-color: #7a1f2e; color: #1a1410;
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
}
.free-tier-badge .badge-num {
  font-weight: 700; color: #7a1f2e; font-size: 0.95rem;
  margin-right: 0.15rem;
}
.free-tier-badge .badge-iyun {
  color: #3f2a4a; font-weight: 600;
  border-left: 1px solid var(--rule); padding-left: 0.5rem; margin-left: 0.1rem;
}
.free-tier-badge.low { border-color: #b06730; }
.free-tier-badge.low .badge-num { color: #b06730; }
.free-tier-badge.empty { border-color: #8b2a2a; }
.free-tier-badge.empty .badge-num { color: #8b2a2a; }
@keyframes badgeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 600px) {
  .free-tier-badge { bottom: 0.5rem; right: 0.5rem; font-size: 0.72rem; padding: 0.4rem 0.65rem; }
}

/* Settings */
.settings-box { max-width: 500px; }
.settings-body { padding: 1.25rem; }
.settings-label { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.35rem; font-weight: 600; }
.settings-body input {
  width: 100%; padding: 0.5rem 0.7rem; border: 1px solid var(--rule); border-radius: 3px;
  font-family: "Menlo", "Consolas", monospace; font-size: 0.85rem;
  background: var(--bg); color: var(--ink);
}
.settings-body input:focus { outline: none; border-color: var(--accent); }
.settings-help { font-size: 0.8rem; color: var(--muted); line-height: 1.5; margin: 0.75rem 0; }
.settings-help a { color: var(--accent); }
.settings-actions { display: flex; align-items: center; gap: 0.6rem; margin-top: 1rem; }
.settings-actions button {
  background: var(--accent); color: var(--card); border: none;
  padding: 0.4rem 0.85rem; border-radius: 3px; cursor: pointer;
  font-family: inherit; font-size: 0.85rem;
}
.settings-actions button.secondary { background: transparent; color: var(--ink); border: 1px solid var(--rule); }
.settings-actions button.secondary:hover { background: var(--hover); }
.modal-body .cursor {
  display: inline-block; width: 0.5ch; height: 1em;
  background: var(--accent); vertical-align: text-bottom;
  animation: blink 0.9s infinite;
}
@keyframes blink { 50% { opacity: 0; } }
