@font-face {
  font-family: 'FrankRuehl';
  src: url('../fonts/FrankRuehlCLM-Medium.ttf') format('truetype');
  font-weight: 400;
}
@font-face {
  font-family: 'FrankRuehl';
  src: url('../fonts/FrankRuehlCLM-Bold.ttf') format('truetype');
  font-weight: 700;
}
@font-face {
  font-family: 'StamAshkenaz';
  src: url('../fonts/StamAshkenazCLM.ttf') format('truetype');
}

:root {
  --bg: #0f1220;
  --panel: #171b2e;
  --panel-2: #1f2540;
  --text: #e7e9f3;
  --muted: #9aa0bd;
  --accent: #5aa0ff;
  --accent-2: #ff8c5a;
  --good: #37c871;
  --bad: #e0555b;
  --line: rgba(255,255,255,0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #1a2140 0%, var(--bg) 55%);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  line-height: 1.4;
}

header.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(30,36,64,0.6), transparent);
}
.brand { display: flex; flex-direction: column; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: 0.5px; }
.brand .sub { color: var(--muted); font-size: 12px; }

.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-left: auto; }
select, button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 11px; font-size: 13px; cursor: pointer;
}
select:hover, button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #08101f; border-color: transparent; font-weight: 600; }
button.warn { background: var(--accent-2); color: #201007; border-color: transparent; font-weight: 600; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.toggle.on { background: var(--accent); color: #08101f; border-color: transparent; }

/* Offline download button + network badge. */
.offline-btn.on { background: var(--good); color: #04210f; border-color: transparent; }
.offline-btn.working { opacity: 0.85; cursor: progress; }
.offline-btn.flash { animation: offline-flash 0.9s ease; }
@keyframes offline-flash {
  0% { box-shadow: 0 0 0 0 rgba(55,200,113,0.6); }
  100% { box-shadow: 0 0 0 10px rgba(55,200,113,0); }
}
.net-badge {
  font-size: 12px; font-weight: 600; color: #201007;
  background: var(--accent-2); border-radius: 6px; padding: 4px 8px; white-space: nowrap;
}

/* Segmented control (e.g. the score-overlay and aliyah-cycle selectors). */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 7px 11px; background: var(--panel-2);
  border-inline-start: 1px solid var(--line); font-size: 13px; }
.seg button:first-child { border-inline-start: none; }
.seg button:hover { border-color: transparent; background: rgba(255,255,255,0.06); }
.seg button.on { background: var(--accent); color: #08101f; font-weight: 600; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 20px; border-bottom: 1px solid var(--line); }
.toolbar .label { color: var(--muted); font-size: 12px; margin-inline-end: 4px; }

main { display: grid; grid-template-columns: var(--leftw, 360px) 6px 1fr; gap: 0; height: calc(100vh - 118px); }
.splitter { cursor: col-resize; background: var(--line); transition: background .12s; }
.splitter:hover, .splitter.dragging { background: var(--accent); }

/* Optional STA"M Torah-column pane: a third column to the LEFT of the pointed
   verses, shown only in scroll view (desktop). Off-screen it is display:none so
   the two-column grid is unchanged. */
.scrollpane { display: none; overflow-y: auto; padding: 16px 20px; border-inline-end: 1px solid var(--line); }
.splitter2 { display: none; }
body.scroll-view main { grid-template-columns: var(--scrollw, 300px) 6px var(--leftw, 360px) 6px 1fr; }
body.scroll-view .scrollpane { display: block; }
body.scroll-view .splitter2 { display: block; }
/* Compact verse cards when the left pane is dragged narrow. */
main.narrow-left .textpane { padding: 12px 8px; }
main.narrow-left .textpane .pane-title { font-size: 10px; }
main.narrow-left .textpane .verse { padding: 8px; margin-bottom: 6px; }
main.narrow-left .textpane .hebrew { font-size: calc(15px * var(--left-scale, 1)); line-height: 1.5; padding-top: 16px; }
main.narrow-left .textpane .vscore { font-size: 10px; }
/* Off-canvas pasuk drawer controls — hidden on desktop, shown on mobile. */
.pasuk-fab, .drawer-close { display: none; }
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 39; background: rgba(6,8,18,0.55);
  backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity .2s;
}

/* --- Mobile / compact layout ------------------------------------------- */
@media (max-width: 900px) {
  main, body.scroll-view main { grid-template-columns: 1fr; height: auto; }
  .splitter, .splitter2 { display: none; }

  /* One column on a phone: the STA"M column and the pointed verses share the
     same off-canvas drawer slot; only one shows at a time — the pointed verses
     normally, the Torah column when scroll view is on. */
  .scrollpane {
    position: fixed; top: 0; inset-inline-start: 0; height: 100%;
    width: min(86vw, 360px); z-index: 40; margin: 0; padding-top: 48px;
    background: var(--panel); border-inline-end: 1px solid var(--line);
    box-shadow: 8px 0 34px rgba(0,0,0,0.5);
    transform: translateX(-104%); transition: transform .22s ease; display: none;
  }
  body.pasuk-open .scrollpane { transform: translateX(0); }
  body.scroll-view .scrollpane { display: block; }
  body.scroll-view .textpane { display: none; }

  /* Keep every control, but let the busy toolbar wrap onto multiple compact rows
     instead of scrolling sideways (bad touch UX). */
  header.topbar { padding: 10px 14px; gap: 10px; }
  .toolbar { flex-wrap: wrap; padding: 8px 14px; row-gap: 8px; }

  /* Trope-family key adds little on a small screen — hide to save space. */
  .fambar { display: none; }

  /* The pasuk list becomes an off-canvas drawer that overlays the practice pane
     instead of consuming horizontal (or vertical) space. */
  .textpane {
    position: fixed; top: 0; inset-inline-start: 0; height: 100%;
    width: min(86vw, 360px); z-index: 40; margin: 0; padding-top: 48px;
    background: var(--panel); border-inline-end: 1px solid var(--line);
    box-shadow: 8px 0 34px rgba(0,0,0,0.5);
    transform: translateX(-104%); transition: transform .22s ease;
  }
  body.pasuk-open .textpane { transform: translateX(0); }
  body.pasuk-open .drawer-backdrop { opacity: 1; pointer-events: auto; }

  .drawer-close {
    display: flex; align-items: center; justify-content: center;
    position: absolute; top: 8px; inset-inline-end: 10px; width: 34px; height: 34px;
    font-size: 15px; border-radius: 8px; z-index: 2;
  }
  .pasuk-fab {
    display: flex; align-items: center; justify-content: center;
    position: fixed; inset-block-end: 18px; inset-inline-start: 16px; z-index: 41;
    width: 52px; height: 52px; border-radius: 50%; font-size: 21px; padding: 0;
    background: var(--accent); color: #08101f; border-color: transparent;
    box-shadow: 0 6px 18px rgba(0,0,0,0.45);
  }
  body.pasuk-open .pasuk-fab { background: var(--panel-2); color: var(--text); }

  /* Stage selector: a single full-width dropdown replaces the sideways-scrolling
     chip row. The chips are hidden; the <select> (kept in sync by renderStageBar)
     drives stage changes through the same selectStage path. */
  .stagebar { flex-wrap: wrap; padding: 7px 14px; }
  .stagebar .stagebtn { display: none; }
  .stage-select { display: block; flex: 1 1 auto; min-width: 0; max-width: 100%;
    font-size: 13px; padding: 8px 10px; }

  /* Practice pane fills the width; trim its padding a touch. */
  .practice { padding: 14px 14px 84px; }
}

/* Portrait phones: hide progress (accuracy/score panel) to save vertical space;
   it stays available in landscape "practice" mode. */
@media (max-width: 900px) and (orientation: portrait) {
  #accPanel { display: none; }
}

/* Landscape "practice" mode: strip the chrome down so the practice canvases and
   transport get as much of the short viewport height as possible. */
@media (max-width: 900px) and (orientation: landscape) {
  header.topbar { padding: 6px 12px; }
  .brand .sub { display: none; }
  .brand h1 { font-size: 16px; }
  footer.src { display: none; }
  .practice { padding: 10px 14px 72px; }
  canvas.contour { height: 150px; }
  canvas.spectro { height: 90px; }
}

.phead { display: flex; align-items: center; justify-content: flex-start; gap: 6px 10px; flex-wrap: wrap; margin-bottom: 4px; }
.phead h2 { margin: 0; }
.stagetag { font-size: 11px; font-weight: 600; color: var(--muted); margin-inline-start: 6px; padding: 1px 7px;
  background: var(--panel-2); border-radius: 6px; }
.keyshint { font-size: 14px; color: var(--muted); cursor: help; margin-inline-start: auto; }

/* Persistent stage selector (top bar) */
.stagebar { gap: 6px; }
/* The dropdown is a mobile-only alternative to the chip row (see media query). */
.stage-select { display: none; }
.stagebtn { font-size: 12px; padding: 6px 10px; border-radius: 8px; }
.stagebtn.cur { background: var(--accent); color: #08101f; border-color: transparent; font-weight: 700; }
.stagebtn.locked { opacity: 0.5; }
.stagebtn.locked.cur { opacity: 1; background: var(--panel-2); color: var(--text); box-shadow: 0 0 0 2px var(--accent-2) inset; }

/* Locked stage page */
.locked-page { text-align: center; max-width: 460px; margin: 48px auto; color: var(--muted); }
.locked-page .lock-icon { font-size: 44px; opacity: 0.7; }
.locked-page h3 { color: var(--text); margin: 10px 0; }
.locked-page .next { margin: 14px 0 18px; color: var(--text); }

.textpane, .practice { overflow-y: auto; padding: 16px 20px; }
.textpane { border-inline-end: 1px solid var(--line); }
.pane-title { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 0 0 10px; }

/* Left-panel header: pane title + a verse text-size slider. */
.pane-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.pane-head .pane-title { margin: 0; flex: 1; min-width: 0; }
.leftsize { display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto; }
.leftsize .rs-ico { font-family: 'FrankRuehl', 'StamAshkenaz', serif; font-size: 16px; color: var(--muted); line-height: 1; }
.leftsize input[type="range"] { width: 84px; accent-color: var(--accent); cursor: pointer; }

.verse {
  position: relative; padding: 12px 14px; margin-bottom: 10px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line); cursor: pointer;
  transition: border-color .15s, transform .05s;
}
.verse:hover { border-color: var(--accent); }
.verse.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(90,160,255,0.25); }
.verse .vnum {
  position: absolute; top: 8px; inset-inline-start: 10px; font-size: 11px; color: var(--muted);
  background: var(--panel-2); border-radius: 6px; padding: 1px 6px;
}
.verse .vscore-wrap {
  position: absolute; top: 8px; inset-inline-end: 10px; display: flex; align-items: center; gap: 5px;
}
.verse .vscore { font-size: 11px; font-weight: 700; border-radius: 6px; padding: 1px 7px; color: #fff; }
.verse .vpips { display: flex; gap: 3px; }
.verse .vpip { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

/* Bilingual layout: Koren-style English column to the left of the Hebrew. The
   top padding clears the absolutely-positioned verse label / score. */
.vbody.bilingual { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; padding-top: 22px; }
.vbody.bilingual .ventext { flex: 1 1 45%; min-width: 150px; }
.vbody.bilingual .hebrew { flex: 1 1 45%; min-width: 150px; }
.ventext { direction: ltr; text-align: left; font-size: calc(16px * var(--left-scale, 1)); line-height: 1.6; color: #cdd2e6; }

/* Hover-hold word translation popover. */
.wordpop { position: absolute; z-index: 60; max-width: 300px; pointer-events: none;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 11px; box-shadow: 0 8px 24px rgba(0,0,0,0.45); font-size: 12px; color: var(--text); }
.wordpop .wp-head { font-family: 'FrankRuehl', serif; font-size: 17px; font-weight: 700; margin-bottom: 4px; direction: rtl; }
.wordpop .wp-lemma { font-size: 13px; font-weight: 400; color: var(--muted); margin-inline-start: 6px; }
.wordpop .wp-body { direction: ltr; }
.wordpop .wp-body ul { margin: 0; padding-inline-start: 16px; }
.wordpop .wp-body li { margin: 2px 0; }
.wordpop .wp-muted { color: var(--muted); font-style: italic; }
/* Aliyot panel (left pane, above the verse list). */
.aliyot-panel { margin: 0 0 12px; }
.aliyot-panel:empty { display: none; }
.aliyot-head { font-size: 12px; font-weight: 700; margin: 0 0 6px; }
.aliyot-head .hint { font-weight: 400; }
.aliyot-note { margin: 4px 0 0; }
.aliyah { border: 1px solid var(--line); border-inline-start: 3px solid var(--accent-2); border-radius: 9px;
  padding: 7px 9px; margin: 4px 0 12px; background: var(--panel); }
.aliyah.ready { border-inline-start-color: var(--good); }
.aliyah.ready { border-color: rgba(55,200,113,0.4); }
.aliyah.open { box-shadow: 0 0 0 2px var(--accent) inset; }
.aliyah .al-main { display: flex; align-items: center; gap: 8px; }
.aliyah .al-n { font-family: 'FrankRuehl', serif; font-size: 16px; color: var(--accent); min-width: 18px; }
.aliyah .al-label { font-size: 12px; font-weight: 600; flex: 1; }
.aliyah .al-label .hint { font-weight: 400; }
.aliyah .al-score { margin-inline-start: auto; font-size: 11px; font-weight: 700; color: #fff; border-radius: 6px; padding: 1px 7px; }
.aliyah .al-prog { height: 5px; border-radius: 3px; background: rgba(255,255,255,0.08); margin: 6px 0 6px; overflow: hidden; }
.aliyah .al-prog span { display: block; height: 100%; border-radius: 3px; }
.aliyah .al-actions { display: flex; }
.aliyah .al-go { padding: 4px 10px; font-size: 12px; }
.aliyah .al-lock { font-size: 12px; color: var(--muted); }
/* Maftir: the closing repeat, flagged with its own accent so it reads as a
   distinct unit sitting alongside (not another numbered aliyah). */
.aliyah.maftir { border-inline-start-color: var(--accent); }
.aliyah.maftir.ready { border-inline-start-color: var(--good); }
.aliyah.maftir .al-n { font-size: 12px; letter-spacing: -1px; }

/* Aliyah controls pane (the STA"M scroll itself lives in the shared #scrollVerses
   pane; see .aliyah-scroll below). */
#practice.aliyah-fill { height: 100%; display: flex; flex-direction: column; }
.aliyah-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
/* The aliyah scroll + yad, rendered into the shared Torah-column pane. */
.aliyah-scroll { min-height: 140px; overflow: auto; margin: 10px 0; }
.aliyah-scroll .al-verse { }
/* Surrounding context (verses before/after the aliyah): faded, not the focus. */
.aliyah-scroll .al-verse.ctx, .aliyah-scroll .sw.ctx { opacity: 0.38; }
/* Current-spot cue: a grey outline that never reflows the text (outline +
   box-shadow don't take layout space, and we don't auto-scroll). */
.aliyah-scroll .sw { transition: outline-color .12s, box-shadow .12s; border-radius: 5px; padding: 0 1px; }
.aliyah-scroll .sw.yad-cur { outline: 2px solid rgba(150,155,170,0.9); outline-offset: 2px;
  background: rgba(140,145,160,0.14); }
.aliyah-scroll .sw.yad-start { box-shadow: 0 0 0 2px rgba(55,200,113,0.6); animation: yadpulse 1.5s ease-in-out infinite; }
.aliyah-scroll .sw.yad-end { box-shadow: 0 0 0 2px rgba(255,120,90,0.6); }
@keyframes yadpulse { 0%,100% { box-shadow: 0 0 0 2px rgba(55,200,113,0.25); } 50% { box-shadow: 0 0 0 2px rgba(55,200,113,0.7); } }

.al-cuebar { display: flex; align-items: center; gap: 8px; margin: 6px 0 2px; }
.al-cuebar .label { color: var(--muted); font-size: 12px; }

.hebrew {
  direction: rtl; text-align: right; font-family: 'FrankRuehl', serif;
  font-size: calc(30px * var(--left-scale, 1)); line-height: 1.9; padding-top: 14px;
}
.hebrew.scroll { font-family: 'StamAshkenaz', serif; font-size: calc(34px * var(--left-scale, 1)); letter-spacing: 2px; }
.hebrew .w { padding: 0 2px; border-radius: 6px; transition: background .1s, opacity .1s; cursor: pointer; }
.textpane .hebrew .w:hover { outline: 1px dashed rgba(255,255,255,0.35); }
.hebrew .w.cur { background: rgba(255,215,0,0.28); }
.hebrew .w.sel { background: rgba(90,160,255,0.22); }
.hebrew .w.hl { background: rgba(255,255,255,0.14); outline: 1px solid currentColor; }
.hebrew .w.dim { opacity: 0.28; }

/* "Trope only" colour mode: two stacked, fully-shaped copies of the word so the
   cantillation marks can be coloured without isolating (and thus breaking) the
   combining glyphs. Both copies share a single grid cell so they overlay
   exactly: the coloured .tc-mark carries the te'amim, and the grey .tc-base
   (te'amim stripped) sits on top, hiding the coloured letters + vowels so only
   the coloured te'amim show through. */
.tc { display: inline-grid; }
.tc-mark, .tc-base { grid-area: 1 / 1; white-space: nowrap; }
.tc-base { color: inherit; pointer-events: none; }

/* Trope family key bar */
.fambar { gap: 6px; }
.famchip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  padding: 4px 9px; border-radius: 999px;
}
.famchip .sw { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.famchip.active { border-color: var(--c); box-shadow: 0 0 0 2px var(--c) inset; }
.famclear { font-size: 12px; border-radius: 999px; padding: 4px 10px; }
.famhint { margin-inline-start: 4px; }
.markicon { font-family: 'FrankRuehl', serif; direction: rtl; unicode-bidi: isolate; color: var(--text); }
.famchip .markicon { font-size: 17px; line-height: 1; }
.famchip .markicon .mk { margin-inline-start: 3px; }
.markicon.big { font-size: 20px; margin-inline-end: 6px; vertical-align: middle; }
.tname .sw { width: 11px; height: 11px; border-radius: 50%; display: inline-block; margin-inline-end: 5px; vertical-align: middle; }

/* --- Trope guide: one optional vertical panel that unifies the old always-on
   family key (top) and the per-unit vocal-shape legend (bottom). It slides in
   from the side on every screen, lists each family (grouped) with its accents'
   melodic diagrams + meanings, and drives the same highlight-in-the-pesukim. */
.guidepane {
  position: fixed; top: 0; inset-inline-end: 0; height: 100%;
  width: min(92vw, 370px); z-index: 42;
  background: var(--panel); border-inline-start: 1px solid var(--line);
  box-shadow: -10px 0 40px rgba(0,0,0,0.5);
  display: flex; flex-direction: column;
  transform: translateX(104%); transition: transform .22s ease;
}
body.guide-open .guidepane { transform: translateX(0); }
.guidepane .drawer-close {
  display: flex; align-items: center; justify-content: center;
  position: absolute; top: 10px; inset-inline-end: 12px; width: 30px; height: 30px;
  font-size: 14px; border-radius: 8px; z-index: 2;
}
.guide-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.guide-head .pane-title { margin: 0 0 8px; }
.guide-head .hint { margin: 8px 0 0; }
.guide-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.guide-controls .seg .cm { font-size: 12px; padding: 6px 9px; }
.guide-body { flex: 1; overflow-y: auto; padding: 10px 14px 24px; }

.guide-fam { margin: 0 0 14px; }
.guide-fam-head {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: start;
  font-size: 13px; font-weight: 700; padding: 8px 10px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
}
.guide-fam-head.static { cursor: default; }
.guide-fam-head:not(.static):hover { border-color: var(--c); }
.guide-fam-head.active { border-color: var(--c); box-shadow: 0 0 0 2px var(--c) inset; }
.guide-fam-head .sw { width: 13px; height: 13px; border-radius: 50%; flex: 0 0 auto; }
.guide-fam-head .gf-label { flex: 1; }
.guide-fam-head .markicon { font-size: 17px; }
.guide-fam-head .markicon .mk { margin-inline-start: 4px; }
.gf-note { margin: 5px 2px 0; }
.guide-tropes { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; padding-inline-start: 6px; }
.guide-tropes .g-trope { margin: 0; }

.practice { background: rgba(255,255,255,0.01); }
.practice h2 { margin: 0; font-size: 15px; }
.levelrow { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.lvlbtn { padding: 6px 9px; font-size: 12px; border-radius: 8px; }
.lvlbtn.cur { background: var(--accent); color: #08101f; border-color: transparent; font-weight: 700; }
.lvlbtn.locked { opacity: 0.35; }
.leveldesc { color: var(--muted); font-size: 13px; margin: 2px 0 6px; }
.practice-en { direction: ltr; font-size: 17px; line-height: 1.6; color: #cdd2e6; margin: 0 0 12px;
  padding-inline-start: 10px; border-inline-start: 3px solid var(--line); }
.aidchips { display: flex; gap: 5px; flex-wrap: wrap; margin: 0; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.chip.on { color: var(--good); border-color: var(--good); }
.chip.off { color: var(--muted); text-decoration: line-through; }

.unit-nav { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.unit-nav .u-label { color: var(--muted); font-size: 12px; }
.unit-nav button { padding: 2px 8px; font-size: 12px; }

.canvas-wrap { position: relative; background: #0b0e1a; border: 1px solid var(--line); border-radius: 12px; margin: 6px 0; overflow: hidden; }
canvas.contour { width: 100%; height: 210px; display: block; }
canvas.spectro { width: 100%; height: 120px; display: block; }
.spectro-label { font-size: 11px; color: var(--text); margin: 6px 0 2px; }
.cmp-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 11px; color: var(--muted); margin: -2px 0 4px; }
.cmp-legend .swatch { display: inline-block; width: 18px; height: 0; vertical-align: middle; margin-inline-end: 5px; }
.cmp-legend .swatch.coach { border-top: 4px solid var(--accent); }
.cmp-legend .swatch.real { border-top: 3px solid rgb(120,255,180); }
.cmp-legend .swatch.you { border-top: 3px dotted var(--accent-2); }
.tapword { margin: 4px 0 6px; }

/* The scroll column's parents are size containers so the glyphs can scale to
   the available width (see the clamp() below) — this keeps a real-scroll look
   whether the pane is dragged narrow (left) or shown in the aliyah view (right). */
#verses, #scrollVerses, .aliyah-view { container-type: inline-size; }

/* Faithful Torah-scroll column view of the whole reading */
.scroll-column {
  direction: rtl; text-align: justify; text-align-last: right;
  font-family: 'StamAshkenaz', serif;
  /* Scale the letters to the column width so a thin pane shrinks the script
     instead of forcing awkward one-word-per-line justification. */
  font-size: clamp(15px, 7.4cqi, 30px); line-height: 2.15; letter-spacing: 1px;
  color: #2a2016;
  background: #e9d7b0;
  background-image: linear-gradient(180deg, rgba(0,0,0,0.05), rgba(0,0,0,0) 8%),
    radial-gradient(120% 60% at 50% 0%, rgba(120,80,30,0.10), rgba(120,80,30,0) 60%);
  border: 1px solid #c9b38a; border-radius: 8px;
  padding: 22px 26px; box-shadow: inset 0 0 40px rgba(120,80,30,0.18);
  max-width: 42ch; margin: 0 auto;
}
/* Each word is an unbreakable unit: never split a word across lines, however
   thin the column gets. */
.scroll-column .sw { cursor: pointer; border-radius: 4px; padding: 0 1px; white-space: nowrap; }
.scroll-column .sw:hover { background: rgba(120,80,30,0.15); }
.scroll-column .sw.sel { background: rgba(200,150,60,0.35); }
/* Current-word "yad" cue while a pasuk plays / records, so you can read the STA"M
   column and follow the spot (mirrors the pointed-text and timeline highlight). */
.scroll-column .sw.cur { background: rgba(255,190,60,0.5); outline: 2px solid rgba(150,95,20,0.6);
  outline-offset: 1px; border-radius: 4px; }

/* The aliyah-view controls: the transport + live meter sit at the TOP (above the
   scroll) in .aliyah-top; the result panel docks at the foot in .aliyah-dock. On
   desktop both groups are transparent and simply stack their children. */
.aliyah-top { display: flex; flex-direction: column; }
.aliyah-dock { display: flex; flex-direction: column; }

/* --- Mobile: show the real scroll full-screen with a minimal control overlay - */
@media (max-width: 900px) {
  /* Torah-column view: let the STA"M drawer fill the screen so the scroll is
     read edge-to-edge rather than in a narrow rail. */
  body.scroll-view .scrollpane { width: 100vw; max-width: 100vw; }
  body.scroll-view .scrollpane .scroll-column {
    border-inline: none; border-radius: 0; box-shadow: inset 0 0 40px rgba(120,80,30,0.14);
  }

  /* Aliyah (reading) mode on a phone: the STA"M scroll takes over the shared
     "Torah column" pane — dropped in-flow, full width — as the reading surface,
     with the aliyah's controls stacked in the practice pane just below it (so
     the scroll stays in the same place as regular reference, not a separate
     full-screen view). The verses drawer + its FAB step aside meanwhile. */
  body.aliyah-open .scrollpane {
    position: static; transform: none; display: block; z-index: auto;
    width: 100%; max-width: 100%; height: auto; box-shadow: none;
    margin: 0; padding: 8px 12px; border-inline-end: none; background: #e2cfa5;
  }
  body.aliyah-open .textpane,
  body.aliyah-open .pasuk-fab { display: none; }
  body.aliyah-open .scrollpane .pane-title { margin: 0 0 6px; color: #4a3a26; }
  body.aliyah-open .scrollpane .scroll-column {
    max-width: none; border: none; border-radius: 0; margin: 0;
    box-shadow: inset 0 0 40px rgba(120,80,30,0.14);
    max-height: 56vh; overflow: auto;
  }

  /* The practice pane becomes an ordinary in-flow control panel under the scroll
     rather than a fixed full-screen surface. */
  body.aliyah-open #practice.aliyah-fill {
    position: static; inset: auto; z-index: auto; height: auto;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: #e2cfa5;
  }
  .aliyah-view { height: auto; padding: 0; }
  .aliyah-view .leveldesc { display: none; }

  .aliyah-view .phead {
    order: 0; margin: 0 0 6px; gap: 6px 10px; align-items: center;
    padding: 6px 0; flex-wrap: nowrap; background: transparent;
    border-bottom: 1px solid #c9b38a; color: #2a2016;
  }
  .aliyah-view .phead h2 { font-size: 13px; color: #2a2016; flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .aliyah-view .phead .stagetag { display: none; }
  .aliyah-view .phead #alBack { flex: 0 0 auto; background: rgba(42,32,22,0.08);
    color: #2a2016; border-color: #c9b38a; }

  .aliyah-view .al-cuebar {
    margin: 0; padding: 6px 0; gap: 8px;
    background: transparent; border-bottom: 1px solid #c9b38a;
  }
  .aliyah-view .al-cuebar .label { color: #4a3a26; }

  .aliyah-view .aliyah-top { padding: 8px 0; gap: 6px; background: transparent; }
  .aliyah-top .transport { margin: 0; gap: 6px; }
  .aliyah-top .transport button { flex: 1 1 auto; font-size: 12px; padding: 8px 10px; }
  .aliyah-top .livemeter { margin: 6px 0 0; }
  .aliyah-top .livemeter .lm-label { color: #4a3a26; }
  .aliyah-top .livemeter .lm-val { color: #4a3a26; }

  .aliyah-dock {
    padding: 8px 0 0; gap: 6px; background: transparent;
    border-top: 1px solid #c9b38a;
  }
  .aliyah-dock .result { margin: 0; color: #2a2016; }
  .aliyah-dock .result .hint { color: #4a3a26; }
}

/* Guitar-hero zoom: a horizontally scrollable strip of the timeline. */
.tl-scroll { overflow: hidden; }
.tl-scroll.scrolling { overflow-x: auto; overflow-y: hidden; scroll-behavior: auto; }
.tl-inner { width: 100%; }
.tl-inner .spectro-label { position: sticky; left: 4px; width: max-content;
  background: rgba(11,14,26,0.85); padding: 2px 6px; border-radius: 6px; z-index: 3; }
.zoomtoggle { font-size: 12px; border-radius: 8px; padding: 4px 9px; margin-inline-start: 8px; }

/* Aligned practice timeline: RTL words over notes over spectrogram.
   Right margin (34px) holds the scale; left margin (8px) matches the canvases.
   Each word is rendered normally and centered over its note group. */
.timeline { position: relative; }
.timeline-words { position: relative; height: 48px; margin: 6px 34px 2px 8px; }
.tlword {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  direction: rtl; white-space: nowrap; line-height: 1;
  padding: 0 2px; border-radius: 6px;
}
.tlword.cur { background: rgba(255,215,0,0.20); }
.mode-indicator { margin: 0; display: inline-flex; align-items: center; gap: 6px; }
.mode-pill {
  display: inline-block; font-size: 12px; font-weight: 700; color: #08101f;
  background: var(--accent); border-radius: 999px; padding: 3px 10px;
}

/* Reading-size control: enlarges the aligned Hebrew, shrinks the notation. */
.readsize { display: inline-flex; align-items: center; gap: 6px; margin-inline-start: auto; }
.readsize .rs-ico { font-family: 'FrankRuehl', 'StamAshkenaz', serif; font-size: 20px; color: var(--muted); line-height: 1; }
.readsize input[type="range"] { width: 110px; accent-color: var(--accent); cursor: pointer; }

.transport { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.result { font-size: 14px; margin: 8px 0; min-height: 22px; }
.result .scorelabel { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-inline-end: 4px; }
.result .num { font-weight: 800; font-size: 22px; }
.result .ceil { font-weight: 700; font-size: 14px; color: var(--muted); }
.result .stars { color: #ffd23f; font-size: 18px; letter-spacing: 2px; }

/* Sticky top status strip: keeps the score + live meter visible while singing. */
.topstatus { position: sticky; top: 0; z-index: 6; display: flex; align-items: center; gap: 16px;
  flex-wrap: wrap; background: var(--bg); padding: 8px 0; margin: 2px 0 6px; border-bottom: 1px solid var(--line); }
.topstatus .result { flex: 1 1 240px; margin: 0; }
.topstatus .livemeter { flex: 1 1 220px; margin: 0; }

/* Live guitar-hero score meter (during recording). */
.livemeter { display: flex; align-items: center; gap: 10px; margin: 8px 0 2px; }
.livemeter[hidden] { display: none; }
.livemeter .lm-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); min-width: 78px; }
.livemeter .lm-track { position: relative; flex: 1; height: 16px; border-radius: 8px; background: rgba(255,255,255,0.06);
  border: 1px solid var(--line); }
.livemeter .lm-fill { height: 100%; width: 0; border-radius: 8px; transition: width .12s linear, background .2s; }
.livemeter .lm-val { min-width: 46px; text-align: right; color: var(--muted); }
.livemeter .lm-val b { font-size: 18px; font-weight: 800; color: var(--text); }

/* "Beat this" markers over the meter: your best (dashed) + record holder (dotted). */
.lm-mark { position: absolute; top: -3px; bottom: -3px; width: 0; z-index: 2; pointer-events: none; }
.lm-mark-you { border-left: 2px dashed #eaf1ff; }
.lm-mark-top { border-left: 2px dotted var(--accent-2); }
.lm-mark .lm-mark-flag { position: absolute; bottom: 100%; left: 0; transform: translateX(-50%);
  margin-bottom: 3px; font-size: 9px; font-weight: 800; line-height: 1.4; white-space: nowrap;
  padding: 0 4px; border-radius: 999px; color: #08101f; }
.lm-mark-you .lm-mark-flag { background: #eaf1ff; }
.lm-mark-top .lm-mark-flag { background: var(--accent-2); }

/* Accuracy panel: three bar-chart meters (words -> phrases -> whole verse, each
   with fewer divisions) plus a row of independent handicap skill badges. */
.accuracy-panel { margin: 8px 0 2px; display: flex; flex-direction: column; gap: 5px; }
.accuracy-panel:empty { display: none; }

.scorebar-row { }
.scorebar-row.active .sb-label { color: var(--text); }
.scorebar-row.active .section-bar { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.sb-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 0 0 2px; }
.sb-label .hint { text-transform: none; letter-spacing: 0; }

/* Hebrew word row aligned over the bars (same flex geometry as the meters). */
.acc-words { display: flex; direction: rtl; border: 1px solid transparent; margin-bottom: 2px; }
.acc-words .aw { flex-basis: 0; min-width: 0; text-align: center; overflow: hidden; white-space: nowrap;
  font-size: 15px; line-height: 1.3; padding: 1px 0; border-inline-start: 1px solid transparent;
  border-radius: 5px; cursor: pointer; }
.acc-words .aw:first-child { border-inline-start: none; }
.acc-words .aw:hover { background: rgba(255,255,255,0.10); }

/* Clickable bar segments + skill badges jump into the matching practice. */
.section-bar .secseg.clickable { cursor: pointer; }
.section-bar .secseg.clickable:hover { outline: 1px solid var(--accent); outline-offset: -1px; }
.skill.clickable { cursor: pointer; }
.skill.clickable:hover { border-color: var(--accent); }

/* Bar-chart meter: bar height = score, width = time span, color adaptive. */
.section-bar { display: flex; direction: rtl; height: 30px; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line); background: rgba(255,255,255,0.03);
  background-image: repeating-linear-gradient(0deg, transparent, transparent 24%, rgba(255,255,255,0.05) 24%, rgba(255,255,255,0.05) calc(24% + 1px)); }
.section-bar .secseg { position: relative; height: 100%; min-width: 2px; border-inline-start: 1px solid rgba(0,0,0,0.28); }
.section-bar .secseg:first-child { border-inline-start: none; }
.section-bar .secfill { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 2px 2px 0 0; transition: height .18s ease; }
.section-bar .secfill.empty { height: 3px; background: rgba(255,255,255,0.09); }
.section-bar .seclbl { position: absolute; top: 2px; left: 0; right: 0; text-align: center;
  font-size: 9px; font-weight: 700; color: var(--muted); direction: ltr; }

.skills { display: flex; flex-wrap: wrap; gap: 6px; }
.skill { display: flex; align-items: center; gap: 6px; padding: 3px 9px 3px 7px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255,255,255,0.02); font-size: 11px; color: var(--muted); }
.skill.earned { color: var(--text); }
.skill.locked { opacity: 0.55; }
.skill .sk-dot { width: 10px; height: 10px; border-radius: 50%; }
.skill .sk-val { font-weight: 800; font-size: 12px; direction: ltr; }

.legend { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.legend h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 0 0 8px; }
.tropes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.trope { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; }
.trope:hover { border-color: var(--c); }
.trope.active { border-color: var(--c); box-shadow: 0 0 0 2px var(--c) inset; }
.trope .tname { font-size: 12px; font-weight: 700; }
.trope .avgn { font-size: 9px; font-weight: 500; color: var(--muted); }
.trope .tmean { font-size: 10px; color: var(--muted); font-style: italic; margin-top: 1px; }
.trope .trole { font-size: 10px; color: var(--muted); }
.trope canvas { width: 100%; height: 42px; display: block; margin-top: 4px; }
.trope .tnote { font-size: 10px; color: var(--muted); margin-top: 3px; }

.hint { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); text-align: center; margin-top: 40px; }
.legend-scale { display:flex; align-items:center; gap:8px; font-size:11px; color:var(--muted); }
.legend-scale .bar { height:10px; width:120px; border-radius:6px;
  background: linear-gradient(90deg, var(--bad), #e0b34e, var(--good)); }
footer.src { padding: 10px 20px; color: var(--muted); font-size: 11px; border-top: 1px solid var(--line); }
footer.src a { color: var(--accent); }

/* --- Account (Google sign-in) chip in the topbar ------------------------- */
.authbox { display: flex; align-items: center; gap: 8px; margin-inline-start: 6px; }
.auth-note { color: var(--muted); font-size: 12px; cursor: pointer; border: 1px dashed var(--line);
  border-radius: 8px; padding: 6px 9px; text-decoration: none; }
.auth-note:hover { border-color: var(--accent); color: var(--text); }
.auth-btn { font-size: 13px; display: inline-flex; align-items: center; gap: 7px; }
.auth-btn.primary { background: var(--accent); color: #08101f; border-color: transparent; font-weight: 600; }
.auth-btn .g-mark { display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 50%; background: #fff; color: #4285F4;
  font-weight: 800; font-size: 12px; }
.auth-user { display: inline-flex; align-items: center; gap: 7px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px 3px 3px; max-width: 220px;
  cursor: pointer; color: var(--text); }
.auth-user:hover { border-color: var(--accent); }
.auth-user .av-img, .auth-user .av-fallback { width: 24px; height: 24px; border-radius: 50%; flex: 0 0 auto; }
.auth-user .av-fallback { display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #08101f; font-weight: 700; font-size: 12px; }
.auth-user .av-img { object-fit: cover; }
.auth-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.auth-anon { font-size: 9px; text-transform: uppercase; letter-spacing: 0.4px; font-weight: 700;
  background: rgba(255,255,255,0.1); color: var(--muted); border-radius: 999px; padding: 1px 6px; flex: 0 0 auto; }

/* Post-take invitation to submit a full-verse score without an account. */
.submit-anon-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 10px; }
.submit-anon-note { flex: 1 1 200px; }
.submit-anon-btn { flex: 0 0 auto; }

/* --- Modal (leaderboard) ------------------------------------------------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(6,8,18,0.66); backdrop-filter: blur(2px); }
.modal-card { position: relative; z-index: 1; width: min(560px, 92vw); max-height: 84vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-close { background: transparent; border: none; font-size: 15px; color: var(--muted); padding: 4px 8px; }
.modal-close:hover { color: var(--text); border-color: transparent; }
.modal-foot { margin: 12px 0 0; }

/* --- Public identity picker (anonymous nickname + avatar) ---------------- */
.profile-intro { margin: 0 0 14px; }
.profile-field { display: block; }
.profile-label { display: block; font-size: 12px; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 6px; }
.profile-pic-label { margin: 16px 0 8px; }
.profile-name-row { display: flex; gap: 8px; align-items: center; }
.profile-name-row input { flex: 1 1 auto; font-size: 15px; padding: 8px 11px; border-radius: 9px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text); }
.profile-name-row input:focus { outline: none; border-color: var(--accent); }
.profile-name-row .auth-btn { flex: 0 0 auto; font-size: 15px; padding: 8px 10px; }
.av-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 8px; }
.av-opt { padding: 0; border: 2px solid transparent; border-radius: 50%; background: transparent;
  cursor: pointer; line-height: 0; aspect-ratio: 1 / 1; }
.av-opt img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.av-opt:hover { border-color: var(--line); }
.av-opt.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(90,160,255,0.35); }
.profile-actions { display: flex; justify-content: flex-end; gap: 10px; }
.profile-actions .auth-btn[hidden] { display: none; }

.lb-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.lb-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.4px; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.lb-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.lb-table tr.me { background: rgba(90,160,255,0.12); }
.lb-rank { font-size: 15px; width: 34px; text-align: center; }
.lb-who { display: flex; align-items: center; gap: 8px; }
.lb-av { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.lb-av.fallback { display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-2); color: #201007; font-weight: 700; font-size: 12px; }
.lb-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.lb-youtag { font-size: 10px; background: var(--accent); color: #08101f; border-radius: 999px; padding: 1px 6px; font-weight: 700; }
.lb-anon { font-size: 9px; text-transform: uppercase; letter-spacing: 0.4px; background: rgba(255,255,255,0.1);
  color: var(--muted); border-radius: 999px; padding: 1px 6px; font-weight: 700; }
.lb-xp { font-weight: 700; color: var(--accent); }
.lb-num { text-align: center; color: var(--muted); width: 60px; }
.lb-empty { color: var(--muted); text-align: center; padding: 18px 0; }
.lb-signin-note { text-align: center; margin-top: 12px; }
.lb-local { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.lb-local h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.lb-local-stats { display: flex; gap: 18px; }
.lb-local-stats b { color: var(--accent); font-size: 17px; }
.lb-local-stats span { font-size: 12px; color: var(--muted); }

/* Hierarchical leaderboard: tabs + per-scope views */
.lb-tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.lb-tab { font-size: 12px; padding: 5px 10px; border-radius: 999px; background: transparent;
  border: 1px solid var(--line); color: var(--muted); cursor: pointer; }
.lb-tab.on { background: var(--accent); color: #08101f; border-color: transparent; font-weight: 700; }
.lb-tabbody { min-height: 60px; }
.lb-scope { font-size: 13px; color: var(--text); margin: 0 0 10px; }
.lb-star { font-size: 12px; }
.lb-runs { display: flex; gap: 6px; flex-wrap: wrap; }
.lb-run { display: inline-flex; align-items: center; justify-content: center; min-width: 30px;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #fff; }
.lb-aliyah-pick { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.lb-aliyah-pick select { font-size: 13px; }

/* Top-scores browse: aliyot/pesukim grouped by parashah, each row clickable. */
.lb-group { margin-bottom: 16px; }
.lb-group-h { margin: 0 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--accent); font-weight: 700; }
.lb-browserow { cursor: pointer; transition: background .1s; }
.lb-browserow:hover { background: rgba(90,160,255,0.12); }
.lb-scopelbl { white-space: nowrap; }
.lb-scopelbl b { font-weight: 600; }
.lb-cyc-tag { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.lb-you-only { color: var(--muted); font-style: italic; }
.lb-yourbest { margin-inline-start: 8px; font-size: 10px; background: rgba(255,255,255,0.08);
  color: var(--muted); border-radius: 999px; padding: 1px 7px; font-weight: 700; }
.lb-bignum { font-size: 16px; font-weight: 800; }
.lb-go { width: 24px; text-align: center; color: var(--muted); }
.lb-browserow:hover .lb-go { color: var(--accent); }

/* Aliyah boundary editor */
.al-edit-list { display: flex; flex-direction: column; gap: 8px; }
.al-edit-row { display: grid; grid-template-columns: 90px auto 76px 1fr; align-items: center; gap: 8px; }
.al-edit-n { font-weight: 600; font-size: 13px; }
.al-edit-lbl { font-size: 12px; color: var(--muted); text-align: right; }
.al-edit-end { width: 70px; font-size: 13px; padding: 4px 6px; }
.al-edit-ref { font-size: 12px; color: var(--muted); }
.aliyot-edit-actions { display: flex; gap: 10px; justify-content: flex-end; }
