/* Layout: the printed Vilna page on paper with a ruled writing margin beside it; a few large, plainly worded buttons above. */
@font-face { font-family: "Vilna"; src: url("fonts/Mekorot-Vilna.ttf") format("truetype"); font-weight: 400; font-display: block; }
@font-face { font-family: "Vilna"; src: url("fonts/Mekorot-Vilna-Bold.ttf") format("truetype"); font-weight: 700; font-display: block; }
@font-face { font-family: "Rashi"; src: url("fonts/Mekorot-Rashi.ttf") format("truetype"); font-weight: 400; font-display: block; }

:root {
  --bg: #E7E5E0;
  --paper: #FFFFFF;
  --ink: #161616;
  --ink-2: #57544E;
  --rule: #D3CFC6;
  --line: #C3CAD6;
  --chrome: #F7F6F3;
  --chrome-ink: #1C1C1C;
  --accent: #1F3F94;
  --c0: #FFF09E; --c1: #CDEDC6; --c2: #C9E4FA; --c3: #FAD3E2; --c4: #FDDCB4; --c5: #E2D6F8; --c6: #C7EEE8; --c7: #FACFC8;
  --f-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-en: Georgia, "Times New Roman", serif;
  --lh: 24px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #1B1B1C; --chrome: #252527; --chrome-ink: #EDEBE6; --ink-2: #AAA69F; --rule: #3B3B3E; color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #1B1B1C; --chrome: #252527; --chrome-ink: #EDEBE6; --ink-2: #AAA69F; --rule: #3B3B3E; color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--chrome-ink); font: 16px/1.45 var(--f-ui); }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Big, plain buttons */
.big, .tb { min-height: 46px; padding: 8px 16px; border: 1.5px solid #B9B4AA; background: #fff; color: #1C1C1C; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 16px; }
.big:hover, .tb:hover { border-color: #57544E; }
.big:disabled { opacity: .45; cursor: default; }
.big.primary, .tb.primary { background: #1F3F94; border-color: #1F3F94; color: #fff; }
.big.icon { width: 46px; padding: 0; font-size: 20px; }
.big[aria-pressed="true"] { background: #1F3F94; border-color: #1F3F94; color: #fff; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--chrome); border-bottom: 1px solid var(--rule); padding-top: env(safe-area-inset-top, 0px); }
.bar-row { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; justify-content: space-between; }
.daf-btn { display: grid; grid-template-columns: auto auto; column-gap: 10px; align-items: baseline; border: 2px solid #1F3F94; background: #fff; color: #161616; border-radius: 12px; padding: 4px 16px 6px; cursor: pointer; min-height: 56px; direction: rtl; }
.db-m { font: 700 1.35rem "Vilna", serif; }
.db-d { font: 700 1.7rem "Vilna", serif; }
.db-hint { grid-column: 1 / -1; font: 600 12px var(--f-ui); color: #1F3F94; letter-spacing: .04em; text-transform: uppercase; text-align: center; direction: ltr; }
.turn, .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Change-colors bar */
.editbar { background: #FFF8DD; border-top: 1px solid #E8D98F; color: #1C1C1C; }
.eb-row { max-width: 1280px; margin: 0 auto; padding: 10px 16px 4px; display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; }
.eb-tools, .eb-actions, .eb-colors { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.eb-actions { margin-inline-start: auto; }
.sw { width: 44px; height: 44px; border-radius: 50%; border: 2px solid #8D877C; background: var(--c); cursor: pointer; }
.sw[aria-pressed="true"] { outline: 3px solid #1F3F94; outline-offset: 2px; border-color: #1F3F94; }
.sw.none { width: auto; border-radius: 22px; padding: 0 14px; background: #fff; font-weight: 600; font-size: 14px; color: #1C1C1C; }
.eb-help { max-width: 1280px; margin: 0 auto; padding: 2px 16px 10px; font-size: 16px; }

/* The sheet: one amud on paper */
main { padding-inline: 16px; padding-block: 20px 120px; }
.loading { text-align: center; color: var(--ink-2); font-size: 18px; }
.sheet { background: var(--paper); color: var(--ink); max-width: 1080px; margin: 0 auto; padding: 26px 30px 24px; box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 8px 28px rgba(0,0,0,.08); }
.runhead { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-family: "Vilna", serif; border-bottom: 1.5px solid var(--ink); padding-bottom: 4px; margin-bottom: 12px; }
.amud-b .runhead { flex-direction: row-reverse; }
.rh-m { font-size: 1.3rem; }
.rh-p { font-size: 1.3rem; font-weight: 700; }
.rh-d { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.sheet-label { font: 700 .8rem var(--f-ui); letter-spacing: .08em; text-transform: uppercase; color: #57544E; margin: -6px 0 10px; }
.sheet-body { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 24px; align-items: start; }
.sums-left .sheet-body { grid-template-columns: 310px minmax(0, 1fr); }
.sums-left .sums { order: -1; }
.sums-below .sheet-body, .no-boxes .sheet-body { grid-template-columns: minmax(0, 1fr); }
.sums-below .sums { columns: 2 280px; column-gap: 20px; }
.daf-col { min-width: 0; overflow-x: auto; display: flex; flex-direction: column; position: relative; }
.daf { margin: 0 auto; position: relative; flex: none; }

/* Text inside the daf */
.daf big strong { font-size: 1.45em; }
.daf .dh { font-family: "Vilna", serif; font-weight: 700; }
.daf .dh.big { font-size: 1.55em; }
.opening-box { display: block; width: 62%; margin: .2em auto .4em; padding: .3em .3em .15em; text-align: center; font: 700 2.6em/1.05 "Vilna", serif; border: 14px solid transparent; border-image: url("img/frame.svg") 30 round; }
.s { cursor: pointer; border-radius: 2px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.s.hl { background: var(--c); }
.s:hover { text-decoration: underline dotted #1F3F94; text-underline-offset: .25em; }
.s.hot { outline: 2px solid #1F3F94; outline-offset: 1px; }
.s.link { outline: 2px dashed #1F3F94; outline-offset: 1px; }
.s.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 40% { outline: 3px solid #1F3F94; outline-offset: 2px; } 100% { outline-color: transparent; } }
.mk { font: 700 .58em var(--f-ui); color: #1F3F94; vertical-align: super; line-height: 0; margin-inline-end: .12em; direction: ltr; unicode-bidi: isolate; }
.editing .s:hover { text-decoration: none; }
.editing .w { border-radius: 2px; }
.editing .w:hover { background: rgba(31,63,148,.2); }
.editing .w.st::before { content: ""; display: inline-block; width: 2px; height: 1em; background: #1F3F94; margin-inline-end: 2px; vertical-align: -0.1em; }

/* Writing boxes */
.sums { min-width: 0; }
.group-head { font: 700 1.1rem "Vilna", serif; display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid var(--ink); margin: 0 0 8px; padding-bottom: 2px; }
.group-head span:last-child { font: 700 .72rem var(--f-ui); letter-spacing: .08em; text-transform: uppercase; color: #57544E; }
.box-group + .box-group { margin-top: 18px; }
.box { border: 1.5px solid #B1AB9F; border-radius: 6px; margin-bottom: 10px; overflow: hidden; break-inside: avoid; background: #fff; }
.box.hot, .box:focus-within { border-color: #1F3F94; box-shadow: 0 0 0 1px #1F3F94; }
.box-head { display: flex; align-items: center; gap: 6px; padding: 4px 6px 4px 4px; background: var(--c); border-bottom: 1px solid rgba(0,0,0,.14); color: #161616; min-height: 34px; }
.num { flex: none; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 13px; background: #161616; color: #fff; font: 700 13px/26px var(--f-ui); text-align: center; cursor: pointer; border: 0; }
.ttl { font: 700 14px var(--f-ui); border: 0; background: transparent; color: #161616; padding: 3px 6px; border-radius: 4px; text-align: start; }
button.ttl { cursor: pointer; text-decoration: underline dotted rgba(0,0,0,.35); text-underline-offset: 3px; }
button.ttl:hover { background: rgba(255,255,255,.7); }
.box-dh { margin-inline-start: auto; font: 1.05rem "Vilna", serif; direction: rtl; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 58%; }
.part + .part { border-top: 1px dashed #B1AB9F; }
.part-lbl { display: block; font: 700 12px var(--f-ui); color: #4B4842; padding: 4px 8px 0; }
.box textarea { display: block; width: 100%; border: 0; margin: 0; padding: 0 8px; resize: none; overflow: hidden; color: #1F3F94; font: 16px/var(--lh) var(--f-en); background: transparent repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--lh) - 1px), var(--line) calc(var(--lh) - 1px), var(--line) var(--lh)); background-attachment: local; min-height: calc(var(--n) * var(--lh)); }
.box textarea:focus { outline: none; background-color: #FAFBFE; }
/* Printed lines are real lines, so they show up on paper */
.lines { position: relative; min-height: calc(var(--n) * var(--lh)); }
.lines .ln { display: block; height: var(--lh); border-bottom: 1px solid #8C97A7; margin: 0 6px; }
.lines .txt { position: absolute; inset: 0; padding: 0 8px; font: 12.5px/var(--lh) var(--f-en); color: #1F3F94; white-space: pre-wrap; overflow-wrap: anywhere; overflow: hidden; }
.notes-fill { flex: 1; position: relative; margin-top: 14px; min-height: 70px; }
.notes-fill .part-lbl { padding: 4px 0; }
.notes-fill .lines.fill { position: absolute; inset: 26px 0 0 0; min-height: 0; overflow: hidden; }
.notes-fill .lines.fill .ln { margin: 0; }

/* English panel */
.xlate { position: fixed; z-index: 30; right: 16px; bottom: 16px; width: min(440px, calc(100vw - 32px)); max-height: min(64vh, 660px); overflow: auto; background: #fff; color: #161616; border: 1px solid #C9C4BA; border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.22); padding: 12px 16px 16px; }
.x-top { display: flex; align-items: center; gap: 8px; font: 600 14px var(--f-ui); color: #4B4842; position: sticky; top: -12px; background: #fff; padding: 4px 0 6px; }
.x-top .sp { flex: 1; }
.x-top button { min-width: 40px; min-height: 40px; border: 1.5px solid #C9C4BA; background: #fff; color: #1C1C1C; border-radius: 8px; cursor: pointer; font: 600 18px var(--f-ui); }
.x-he { font: 1.3rem/1.75 "Vilna", serif; direction: rtl; text-align: right; margin: 8px 0 6px; }
.x-he.r { font-family: "Rashi", serif; font-size: 1.15rem; }
.x-he .dh { font-family: "Vilna", serif; font-weight: 700; }
.x-he .opening-box { display: inline; border: 0; font-size: 1.2em; padding: 0; margin: 0; }
.x-en { font: 1.05rem/1.6 var(--f-en); margin: 0 0 10px; }
.x-en b, .x-en strong { font-weight: 700; }
.x-none { font: italic 1rem var(--f-en); color: #6A6862; margin: 0 0 10px; }
.x-src { font-size: 12px; color: #6A6862; border-top: 1px solid #E4E1DA; padding-top: 6px; margin: 6px 0 0; }
.x-item + .x-item { border-top: 1px solid #EEEBE5; padding-top: 4px; }

/* Dialogs */
.dlg { border: 1px solid var(--rule); border-radius: 14px; padding: 0; width: min(480px, calc(100vw - 24px)); background: var(--chrome); color: var(--chrome-ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dlg.wide { width: min(900px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(20,20,20,.4); }
.dlg form { padding: 16px 20px 18px; max-height: calc(100vh - 40px); overflow: auto; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.dlg h2 { margin: 0; font-size: 1.35rem; }
.dlg h3 { margin: 16px 0 8px; font-size: 1.05rem; }
.dlg .x { width: 44px; height: 44px; border: 1.5px solid var(--rule); background: #fff; color: #1C1C1C; border-radius: 10px; font-size: 22px; cursor: pointer; }
fieldset { border: 0; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
legend { font-weight: 700; font-size: .85rem; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 6px; padding: 0; }
.dlg label { display: flex; gap: 10px; align-items: center; font-size: 16px; }
.dlg input[type="checkbox"], .dlg input[type="radio"] { width: 22px; height: 22px; flex: none; }
.dlg label.stack { flex-direction: column; align-items: stretch; gap: 4px; }
.dlg label.stack small { color: var(--ink-2); }
.dlg select, .dlg input[type="text"], .dlg input[type="search"] { border: 1.5px solid #B9B4AA; border-radius: 10px; padding: 10px 12px; background: #fff; color: #1C1C1C; width: 100%; min-height: 46px; }
.note { color: var(--ink-2); font-size: .92rem; margin: 4px 0; }
.dlg-foot { display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-wrap: wrap; border-top: 1px solid var(--rule); padding-top: 14px; margin-top: 10px; }
.dlg-foot .note { margin-inline-end: auto; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.file { position: relative; overflow: hidden; display: inline-flex !important; align-items: center; }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 4px 24px; margin-top: 12px; }
.help { margin: 0; padding-inline-start: 22px; display: flex; flex-direction: column; gap: 8px; font-size: 16px; }
.title-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px; margin-bottom: 12px; }
.title-list label { border: 1.5px solid #B9B4AA; border-radius: 10px; padding: 8px 10px; background: #fff; color: #1C1C1C; cursor: pointer; }
.title-list label:has(input:checked) { border-color: #1F3F94; background: #F3F6FD; }

/* Print choices */
.choice { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.choice button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: start; padding: 14px 16px; border: 2px solid #B9B4AA; border-radius: 12px; background: #fff; color: #1C1C1C; cursor: pointer; }
.choice button b { font-size: 17px; }
.choice button span { font-size: 14px; color: #57544E; }
.choice button[aria-pressed="true"] { border-color: #1F3F94; box-shadow: 0 0 0 2px #1F3F94; background: #F3F6FD; }
.layer-choice { display: flex; gap: 10px; flex-wrap: wrap; }
.layer-choice label { border: 2px solid #B9B4AA; border-radius: 12px; padding: 10px 16px; background: #fff; color: #1C1C1C; font-weight: 700; cursor: pointer; }
.layer-choice label:has(input:checked) { border-color: #1F3F94; background: #F3F6FD; }
.more-opts { margin-top: 14px; border-top: 1px solid var(--rule); padding-top: 10px; }
.more-opts summary { cursor: pointer; font-weight: 700; font-size: 16px; padding: 6px 0; }

/* Daf chooser */
.m-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 10px; }
.m-tabs button { min-height: 46px; padding: 6px 16px; border: 2px solid #B9B4AA; border-radius: 10px; background: #fff; color: #1C1C1C; font-weight: 700; cursor: pointer; }
.m-tabs button span { font-family: "Vilna", serif; font-size: 1.2rem; }
.m-tabs button.on { border-color: #1F3F94; background: #1F3F94; color: #fff; }
.search { display: flex !important; flex-direction: column; align-items: stretch !important; gap: 4px; margin-bottom: 10px; font-weight: 600; }
.daf-grid { max-height: 52vh; overflow: auto; border: 1px solid var(--rule); border-radius: 10px; background: #fff; color: #1C1C1C; padding: 6px 12px 12px; }
.perek h3 { margin: 12px 0 8px; font: 700 1.2rem "Vilna", serif; direction: rtl; text-align: right; }
.perek-btn { display: inline-flex; gap: 10px; align-items: baseline; border: 2px solid #B9B4AA; border-radius: 10px; background: #fff; padding: 6px 12px; cursor: pointer; font: inherit; color: inherit; }
.perek-btn small { font: 600 13px var(--f-ui); color: #1F3F94; }
.dafs { display: flex; flex-wrap: wrap; gap: 6px; direction: rtl; }
.dafcell { display: flex; align-items: center; gap: 2px; border: 1px solid #DDD8CE; border-radius: 10px; padding: 3px; }
.dafcell.found { outline: 3px solid #E0A100; }
.dafcell .dn { display: none; }
.side { min-width: 54px; min-height: 44px; border: 0; border-radius: 8px; background: #F2F0EB; color: #161616; font: 700 1.15rem "Vilna", serif; cursor: pointer; }
.side:hover { background: #E3E8F6; }
.side.on { background: #1F3F94; color: #fff; }

.busy { position: fixed; inset: 0; z-index: 50; background: rgba(20,20,20,.45); display: grid; place-items: center; }
.busy div { background: var(--chrome); color: var(--chrome-ink); padding: 20px 26px; border-radius: 12px; min-width: 260px; text-align: center; font-size: 18px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: #161616; color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 60; font-size: 16px; max-width: calc(100vw - 32px); }

/* Print root lives off-screen until printing */
.print-root { position: absolute; left: -100000px; top: 0; --lh: 21px; }
.print-root .box { margin-bottom: 7px; border-radius: 4px; }
.print-root .box-head { padding: 2px 5px 2px 3px; min-height: 0; }
.print-root .num { min-width: 18px; height: 18px; line-height: 18px; font-size: 11px; }
.print-root .ttl { font-size: 11px; padding: 0 4px; }
.print-root .box-dh { font-size: 13px; }
.print-root .group-head { margin-bottom: 6px; }
.print-root .box-group + .box-group { margin-top: 12px; }
.xsheet h2 { font: 700 1.1rem var(--f-ui); margin: 12px 0 8px; }
.xsheet h2 span { font-family: "Vilna", serif; }
.xsheet .xs-item { break-inside: avoid; margin-bottom: 8px; display: grid; grid-template-columns: 28px 1fr; gap: 8px; }
.xsheet .xs-item .num { margin-top: 2px; background: var(--c); color: #161616; border: 1px solid #8D877C; }
.xsheet .x-en { font-size: 10.5pt; margin: 0; }

@media (max-width: 900px) {
  .sheet { padding: 16px 14px 14px; }
  .sheet-body, .sums-left .sheet-body { grid-template-columns: minmax(0, 1fr); }
  .sums-left .sums { order: 0; }
  .sums-below .sums { columns: 1; }
  .xlate { left: 0; right: 0; bottom: 0; width: auto; max-height: 55vh; border-radius: 16px 16px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 640px) {
  .bar-row { gap: 8px; padding: 8px 10px; }
  .turn { order: 3; width: 100%; }
  .turn .big { flex: 1; }
  .actions .big { padding: 8px 12px; }
  main { padding-inline: 8px; }
}
@media (prefers-reduced-motion: reduce) { .s.flash { animation: none; } }

@media print {
  body { background: #fff; }
  .no-print, .topbar, .xlate, dialog, .busy, .toast { display: none !important; }
  .print-root { position: static; left: auto; }
  .sheet { box-shadow: none; max-width: none; margin: 0; padding: 0; break-after: page; }
  .sheet:last-child { break-after: auto; }
  .sheet-body { gap: 16px; }
  .sheet-body.side { grid-template-columns: var(--dafw) minmax(0, 1fr); align-items: stretch; }
  .sums-left .sheet-body.side { grid-template-columns: minmax(0, 1fr) var(--dafw); }
  .s.hl, .box-head, .num, .xs-item .num { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .s:hover { text-decoration: none; }
  .box { border-color: #6F6A60; }
  .bw .box-head { background: #fff; border-bottom-color: #6F6A60; }
}
