/* =========================================================================
   Chumasch – Gestaltung
   Farbschema: System / Hell / Pergament / Dunkel (über <meta name=color-scheme>
   und data-theme am <html>-Element).
   ========================================================================= */

:root {
  color-scheme: light dark;
  &:has(> head > meta[name="color-scheme"][content="dark"]) { color-scheme: dark; }
  &:has(> head > meta[name="color-scheme"][content="light"]) { color-scheme: light; }

  --bg:        light-dark(#fbfaf7, #15171a);
  --surface:   light-dark(#ffffff, #1d2024);
  --surface-2: light-dark(#f3f0e9, #24282d);
  --text:      light-dark(#1d1b18, #e9e6df);
  --muted:     light-dark(#6c665c, #a19c92);
  --line:      light-dark(#e3ddd1, #33383e);
  --accent:    light-dark(#1f4e79, #8fb8e0);
  --accent-2:  light-dark(#a0742a, #d7b26b);
  --done:      light-dark(#2e7d4f, #74c795);
  --today:     light-dark(#fff2cc, #3d3520);
  --rashi-bg:  light-dark(#f6f3ec, #1f2226);
  --onk:       light-dark(#5d4a7a, #c2b0e0);
  --danger:    light-dark(#a33a2c, #f08b7d);

  --font-he: "Noto Serif Hebrew", "SBL Hebrew", "Ezra SIL", "Times New Roman", serif;
  --font-rashi: "Noto Rashi Hebrew", var(--font-he);
  --font-de: "Source Serif 4", Georgia, serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", sans-serif;
  --size-he: 34px;
  --size-small: 19px;
  --radius: 10px;
}

:root[data-theme="sepia"] {
  color-scheme: light;
  --bg: #f4ecd8;
  --surface: #faf4e4;
  --surface-2: #ece2c8;
  --text: #3b2f20;
  --muted: #7a6a52;
  --line: #ddcfae;
  --rashi-bg: #efe5cc;
  --today: #f3df9f;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-padding-top: 10rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner, .picker {
  max-width: 1000px; margin: 0 auto; padding: .5rem 1rem;
}
.topbar-inner { display: flex; align-items: center; gap: 1rem; }
.brand { display: flex; align-items: baseline; gap: .5rem; text-decoration: none; color: inherit; margin-inline-end: auto; }
.brand-he { font-family: var(--font-he); font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.brand-de { font-family: var(--font-de); font-size: 1.05rem; color: var(--muted); letter-spacing: .04em; }
.actions { display: flex; gap: .4rem; }

.btn {
  font: inherit; font-size: .95rem;
  display: inline-flex; align-items: center; gap: .35rem; justify-content: center;
  min-height: 2.4rem; padding: .35rem .8rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text); cursor: pointer;
  position: relative;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn.danger { color: var(--danger); }
.btn.icon { padding: .35rem; width: 2.4rem; }
#btn-notes { display: inline-flex; align-items: center; gap: .35rem; }
.btn svg { width: 1.3rem; height: 1.3rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.badge {
  position: absolute; top: -.35rem; inset-inline-end: -.35rem;
  min-width: 1.2rem; height: 1.2rem; padding: 0 .3rem; border-radius: 1rem;
  background: var(--accent-2); color: #fff; font-size: .7rem; line-height: 1.2rem;
}

/* ---------- Auswahl ---------- */
.picker { padding-top: 0; display: grid; gap: .5rem; }
.mode-switch { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; width: max-content; }
.mode-switch button {
  font: inherit; font-size: .85rem; padding: .3rem .8rem; border: 0;
  background: transparent; color: var(--muted); cursor: pointer;
}
.mode-switch button[aria-selected="true"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.picker-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.sel { display: grid; gap: .1rem; font-size: .75rem; color: var(--muted); }
select, input[type="text"], textarea {
  font: inherit; font-size: 1rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  min-height: 2.4rem; padding: .3rem .6rem;
}
#sel-parsha { min-width: 15rem; }

.aliyot { display: flex; flex-wrap: wrap; gap: .3rem; }
.aliya-tab {
  font: inherit; font-size: .9rem; cursor: pointer;
  min-width: 2.6rem; min-height: 2.4rem; padding: .2rem .55rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: .25rem;
}
.aliya-tab .he { font-family: var(--font-he); font-size: 1rem; margin: 0; line-height: 1; text-align: center; text-align-last: center; }
.aliya-tab[aria-selected="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }
.aliya-tab.today { background: var(--today); }
.aliya-tab.done { color: var(--done); }
.aliya-tab.done::after { content: "✓"; font-weight: 700; }

/* ---------- Lesebereich ---------- */
main { max-width: 1000px; margin: 0 auto; padding: 1rem 1rem 6rem; }
.status { color: var(--muted); min-height: 1.5rem; }
.status.error { color: var(--danger); }

.reader-head { text-align: center; margin: 1rem 0 2rem; }
.reader-head h1 { font-family: var(--font-he); font-size: calc(var(--size-he) * 1.1); margin: 0; font-weight: 700; line-height: 1.3; }
.reader-head .sub { font-family: var(--font-de); color: var(--muted); font-size: 1.05rem; }
.reader-head .today-hint { display: inline-block; margin-top: .4rem; padding: .1rem .6rem; border-radius: 1rem; background: var(--today); font-size: .85rem; }

.pasuk {
  position: relative;
  padding: .8rem 0 1rem;
  border-bottom: 1px solid var(--line);
}
.pasuk.flash { animation: flash 2s ease-out; }
@keyframes flash { from { background: var(--today); } to { background: transparent; } }

.pasuk-tools {
  display: flex; align-items: center; gap: .4rem; justify-content: flex-end;
  font-size: .8rem; color: var(--muted);
}
.pasuk-num { font-variant-numeric: tabular-nums; margin-inline-end: auto; }
.note-btn {
  border: 0; background: none; color: var(--muted); cursor: pointer; font: inherit;
  padding: .2rem .4rem; border-radius: 6px; display: inline-flex; gap: .2rem; align-items: center;
}
.note-btn:hover { color: var(--accent); background: var(--surface-2); }
.note-btn.has-note { color: var(--accent-2); }
.note-btn svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 1.8; }

.he {
  font-family: var(--font-he);
  font-size: var(--size-he);
  line-height: 1.85;
  direction: rtl; text-align: justify; text-align-last: right;
  margin: .2rem 0;
}
.he .vnum { font-size: .55em; color: var(--accent); font-weight: 700; margin-inline-end: .3em; vertical-align: .25em; }
.he .mark { font-size: .6em; color: var(--muted); margin-inline-start: .4em; }
.he .ktiv { font-size: .6em; color: var(--muted); }
.he big { font-size: 1.3em; }
.he small { font-size: .75em; }
.he.repeat { color: color-mix(in srgb, var(--text) 82%, var(--bg)); }
.he .times {
  font-family: var(--font-ui); font-size: .4em; color: var(--muted);
  border: 1px solid var(--line); border-radius: 1em; padding: 0 .5em; margin-inline-end: .5em;
  vertical-align: .4em;
}

.onk {
  font-family: var(--font-he); direction: rtl; text-align: justify; text-align-last: right;
  font-size: calc(var(--size-he) * .78); line-height: 1.8;
  color: var(--onk); margin: .2rem 0;
}
.onk .lbl, .rashi .lbl, .de .lbl {
  font-family: var(--font-ui); font-size: .7rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin-inline-end: .5rem;
}
.onk .lbl { font-size: max(.75rem, .35em); }

.translit {
  font-family: var(--font-de); font-style: italic;
  font-size: calc(var(--size-small) * 1.05); color: var(--muted);
  margin: .1rem 0 .5rem;
}
.de {
  font-family: var(--font-de); font-size: var(--size-small); line-height: 1.6;
  margin: .4rem 0;
}
.de .vref { color: var(--accent); font-weight: 600; margin-inline-end: .4rem; font-variant-numeric: tabular-nums; }

.rashi {
  background: var(--rashi-bg); border-radius: var(--radius);
  padding: .6rem .9rem; margin: .6rem 0;
}
.rashi-item { margin: .35rem 0; }
.rashi-he {
  font-family: var(--font-he); direction: rtl; text-align: justify; text-align-last: right;
  font-size: calc(var(--size-small) * 1.15); line-height: 1.75;
}
.rashi-script .rashi-he { font-family: var(--font-rashi); }
.rashi-he b { font-family: var(--font-he); }
.rashi-de { font-family: var(--font-de); font-size: var(--size-small); line-height: 1.6; }
.rashi-de b { font-weight: 600; }
.rashi .vref { color: var(--accent); font-weight: 600; font-family: var(--font-ui); font-size: .8rem; }

.hirsch p { font-family: var(--font-de); font-size: var(--size-small); line-height: 1.65; margin: .4rem 0; }
.hirsch .vref { color: var(--accent); font-weight: 600; font-family: var(--font-ui); font-size: .8rem; margin-top: .8rem; }
button.vref {
  font: inherit; font-weight: 600; color: var(--accent); background: none; border: 0; padding: 0;
  cursor: pointer; text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
  text-underline-offset: .2em;
}
button.vref:hover { text-decoration-color: currentColor; }
.rashi button.vref, .hirsch button.vref { font-family: var(--font-ui); font-size: .8rem; margin-top: .6rem; }
.fold { margin: .6rem 0; border-inline-start: 3px solid var(--accent-2); padding-inline-start: .8rem; }
.fold .rashi { margin: .3rem 0; }
.fold summary {
  cursor: pointer; font-family: var(--font-ui); font-size: .8rem; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}
.lang-tag {
  margin-inline-start: .5rem; font-size: .7rem; text-transform: none; letter-spacing: 0;
  border: 1px solid var(--line); border-radius: 999px; padding: 0 .4rem;
}

.note-inline { margin: .6rem 0; display: grid; gap: .4rem; }
.note-item {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem;
  background: var(--rashi-bg); border-inline-start: 3px solid var(--accent);
  border-radius: var(--radius); padding: .45rem .8rem;
}
.note-item .lbl {
  font-family: var(--font-ui); font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; color: var(--accent);
}
.note-item .n-text { flex: 1 1 12rem; white-space: pre-wrap; font-family: var(--font-de); }
.note-item .n-actions { display: flex; gap: .4rem; }
.note-item .btn { min-height: 2rem; font-size: .8rem; }

.reminder {
  display: flex; flex-wrap: wrap; align-items: center; gap: .6rem;
  margin: 1rem 0 0; padding: .7rem 1rem; border-radius: var(--radius);
  border: 1px solid var(--accent); background: var(--rashi-bg); font-family: var(--font-de);
}
.reminder span { flex: 1 1 14rem; }

.section-title {
  font-family: var(--font-de); font-weight: 600; font-size: 1.2rem;
  margin: 2.2rem 0 .6rem; padding-bottom: .3rem; border-bottom: 2px solid var(--accent-2);
}
.repeat-block { margin-top: 1.5rem; padding: .6rem 1rem; border: 1px dashed var(--line); border-radius: var(--radius); }
.repeat-block .lbl { font-size: .8rem; color: var(--muted); }

/* ---------- Abschluss einer Alija ---------- */
.aliya-end {
  display: flex; flex-wrap: wrap; gap: .8rem; justify-content: center; align-items: center;
  margin: 2.5rem 0 1rem;
}
.done-toggle {
  font: inherit; font-size: 1.1rem; cursor: pointer;
  display: inline-flex; align-items: center; gap: .6rem;
  padding: .7rem 1.4rem; border-radius: 2rem;
  border: 2px solid var(--done); background: var(--surface); color: var(--done);
}
.done-toggle[aria-pressed="true"] { background: var(--done); color: var(--bg); }
.done-toggle .box { width: 1.3rem; height: 1.3rem; border: 2px solid currentColor; border-radius: 4px; display: inline-grid; place-items: center; font-size: .9rem; }

/* ---------- Dialoge ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--text);
  width: min(640px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem);
}
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop { background: rgb(0 0 0 / .4); overflow: hidden; overscroll-behavior: contain; }
.dlg { display: flex; flex-direction: column; max-height: calc(100dvh - 2rem); }
.dlg-head, .dlg-foot { display: flex; align-items: center; gap: .5rem; padding: .8rem 1rem; }
.dlg-head { border-bottom: 1px solid var(--line); justify-content: space-between; }
.dlg-head h2 { margin: 0; font-size: 1.15rem; font-family: var(--font-de); }
.dlg-foot { border-top: 1px solid var(--line); }
.dlg-foot .spacer { flex: 1; }
.dlg-body { padding: 1rem; overflow: auto; }
.settings fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 1rem; padding: .6rem .9rem .9rem; display: grid; gap: .7rem; }
.settings legend { font-weight: 600; padding: 0 .3rem; }
.settings label { display: grid; gap: .25rem; font-size: .92rem; }
.settings label.check { display: flex; align-items: center; gap: .5rem; }
.settings input[type="range"] { width: 100%; accent-color: var(--accent); }
.hint { font-size: .82rem; color: var(--muted); margin: 0; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: .3rem; }
.week label { font-size: .75rem; text-align: center; }
.week input { width: 100%; text-align: center; min-height: 2.2rem; padding: .2rem; }
.btn.file { cursor: pointer; }
textarea { width: 100%; resize: vertical; font-family: var(--font-de); }
.note-ref { margin: 0 0 .5rem; color: var(--muted); }

.notes { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .5rem; }
.notes li { border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .8rem; }
.notes li.done { opacity: .6; }
.notes .n-ref { font-weight: 600; color: var(--accent); }
.notes .n-date { font-size: .8rem; color: var(--muted); margin-inline-start: .4rem; }
.notes .n-text { white-space: pre-wrap; margin: .3rem 0 .5rem; font-family: var(--font-de); }
.notes .n-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.notes .n-actions .btn { min-height: 2rem; font-size: .85rem; }
.empty { color: var(--muted); text-align: center; padding: 1rem; }

@media (max-width: 640px) {
  /* Auf dem Handy scrollt die Auswahl mit, damit der Text Platz hat. */
  html { scroll-padding-top: 1rem; }
  .topbar { position: static; }
  .he, .onk, .rashi-he { text-align: right; }
  .brand-de { display: none; }
  #sel-parsha { min-width: 0; width: 100%; }
  .sel:has(#sel-parsha) { flex: 1 1 100%; }
  .aliya-tab { min-width: 2.3rem; padding: .2rem .4rem; }
  .week { grid-template-columns: repeat(4, 1fr); }
}

@media print {
  .topbar, .pasuk-tools, .aliya-end { display: none; }
  main { max-width: none; }
}
