/* Parallel — M1 scaffold styling
 * Design system: docs/design-system.md
 * The DOM never changes between screen and print — only CSS toggles. */

:root {
  --brand: #1565C0;
  --brand-dark: #0D47A1;
  --brand-tint: #E8F0FE;

  --ink: #1a1a1a;
  --ink-soft: #555;
  --ink-faint: #999;
  --line: #e5e5e5;
  --canvas: #ebe8e2;
  --sidebar: #fafafa;
  --paper: #ffffff;

  --serif: "EB Garamond", Georgia, serif;
  --cjk-tc: "Noto Serif TC", "Songti TC", "Source Han Serif TC", serif;
  --cjk-sc: "Noto Serif SC", "Songti SC", "Source Han Serif SC", serif;
  --cjk: var(--cjk-tc);      /* JS swaps to --cjk-sc when Simplified is picked */
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Type ramp — Chinese is the primary voice (pastor reads it aloud),
     English is the anchor (silent comprehension check). JS updates
     --font-cuv from the Chinese-font-size dropdown; KJV scales at 0.7. */
  --font-cuv: 16pt;
  --font-kjv: 11pt;
  --line-height-cuv: 2.0;    /* leaves room for ruby overhang */
  --line-height-kjv: 1.55;

  /* 33:66 grid — the type shift is reinforced by column width */
  --col-kjv: 1fr;
  --col-cuv: 2fr;
  --col-gap: 12mm;

  /* Page geometry — JS updates these when Paper / Orientation change */
  --page-w: 297mm;
  --page-h: 210mm;
  --page-margin: 15mm;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Screen chrome (header + sidebar + canvas grid) ---------- */

.chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  /* Reset button chrome — the wordmark opens the About dialog but should
     read as text, not a button. Hover reveals the affordance. */
  border: 0;
  padding: 0;
  background: transparent;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
  color: var(--ink);
  cursor: pointer;
  transition: color 0.15s ease;
}
.wordmark:hover { color: var(--ink-soft); }
.wordmark:focus-visible {
  outline: none;
  color: var(--ink-soft);
  box-shadow: 0 2px 0 -1px var(--ink-soft);
}

.passage-input {
  display: flex;
  align-items: center;
  gap: 10px;
}

.passage-input input {
  width: 260px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--sans);
  font-size: 0.95rem;
  color: var(--ink);
  background: #fff;
}

.chrome-main {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: calc(100vh - 57px);
}

/* ---------- Sidebar ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  padding: 24px 20px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.ctrl-group { display: flex; flex-direction: column; gap: 8px; }

.sidebar h3 {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-faint);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 0 0 4px 0;
}

.label {
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.sidebar select {
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.9rem;
}

.sidebar select:disabled { color: var(--ink-soft); opacity: 0.6; cursor: not-allowed; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin-top: 4px;
}

.check input { accent-color: var(--brand); }

/* Segmented radio pill (Portrait / Landscape) */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  background: #fff;
}
.segmented label {
  position: relative;
  text-align: center;
  padding: 7px 8px;
  font-size: 0.85rem;
  color: var(--ink-soft);
  cursor: pointer;
}
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented input:checked + span {
  color: #fff;
}
.segmented label:has(input:checked) {
  background: var(--brand);
  color: #fff;
}

/* Focus states — Deep Blue halo, no default browser blue */
.sidebar input:focus-visible,
.sidebar select:focus-visible,
.passage-input input:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
}

.print-btn {
  margin-top: auto;
  padding: 12px 14px;
  border: none;
  border-radius: 4px;
  background: var(--brand);
  color: #fff;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.15s ease;
}
.print-btn:hover { background: var(--brand-dark); }
.print-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--brand-tint);
}

/* ---------- Canvas + paper ---------- */

.canvas {
  overflow: auto;
  padding: 32px;
  background: var(--canvas);
  /* Center the scaled page horizontally without flex-shrink distorting it */
  text-align: center;
}

.page {
  /* True paper dimensions preserved — scaled visually via --fit-scale so
   * aspect ratio stays honest when the browser is narrower than the paper.
   * min-height (not height) lets long passages flow past one paper page;
   * the browser's print engine paginates at print time via @page rules.
   * `zoom` (vs `transform: scale`) scales the layout box too, so the
   * canvas reserves the correct footprint without slack-margin gymnastics. */
  width: var(--page-w);
  min-height: var(--page-h);
  padding: var(--page-margin);
  background: var(--paper);
  box-shadow:
    0 2px 12px rgba(0,0,0,0.08),
    0 8px 40px rgba(0,0,0,0.06);
  color: var(--ink);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
  display: inline-block;
  text-align: left;
  vertical-align: top;
  zoom: var(--fit-scale, 1);
}

/* Simplified script — swap the CJK font family */
.page.sc { --cjk: var(--cjk-sc); }

/* ---------- Passage typography ---------- */

.passage-title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 22pt;
  text-align: center;
  letter-spacing: 0.03em;
  margin: 0 0 10mm 0;
  color: var(--ink);
}
.passage-title .zh-title { font-family: var(--cjk); }
.passage-title .dot { color: var(--ink-faint); margin: 0 0.4em; }

.verses {
  display: grid;
  grid-template-columns: var(--col-kjv) var(--col-cuv);
  column-gap: var(--col-gap);
  row-gap: 6pt;
}

/* English toggle: hide KJV column, CUV takes the full width */
.page.no-en .verses {
  grid-template-columns: 1fr;
}
.page.no-en .v-kjv { display: none; }

.v-kjv, .v-cuv {
  break-inside: avoid;
}

.v-kjv {
  font-family: var(--serif);
  font-size: var(--font-kjv);
  line-height: var(--line-height-kjv);
  color: var(--ink);
}

.v-cuv {
  font-family: var(--cjk);
  font-size: var(--font-cuv);
  line-height: var(--line-height-cuv);
  color: var(--ink);
  /* Prefer breaking at CJK punctuation over mid-sequence, so short
     ruby-bearing groups (滅亡, 責備) stay together on one line. */
  word-break: keep-all;
  line-break: strict;
  overflow-wrap: anywhere;
}

.vnum {
  font-family: var(--sans);
  font-size: 0.7em;
  font-weight: 600;
  color: var(--brand);
  vertical-align: 0.15em;
  margin-right: 0.35em;
}

/* Ruby — Jyutping (TC) or Pinyin (SC) over rare / name / theology chars.
 * Grouped-ruby markup (adjacent ruby chars share one <ruby> with a single
 * whole-word <rt>) keeps compound words unbreakable and centers the
 * pronunciation cleanly over the base group. */
ruby {
  ruby-align: center;
  white-space: nowrap;
  padding: 0 0.05em;
}
ruby rt {
  font-family: var(--sans);
  font-size: 0.6em;
  font-weight: 400;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
  line-height: 1.1;
}

/* ---------- About dialog (colophon) ---------- */

.about {
  /* Native <dialog>. Screen-only. Sizing anchored at top-10vh so the modal
     never fights the paper canvas for center-of-attention. */
  border: 0;
  border-radius: 6px;
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  max-height: 80vh;
  margin-top: 10vh;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0,0,0,0.28), 0 4px 12px rgba(0,0,0,0.10);
  font-family: var(--sans);
}
.about::backdrop {
  background: rgba(20,20,20,0.42);
  backdrop-filter: blur(2px);
}

.about-body {
  padding: 22px 26px 20px;
  overflow-y: auto;
  max-height: 80vh;
}

.about-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.about-head h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: 0.02em;
  margin: 0;
  color: var(--ink);
}
.about-close {
  border: 0;
  padding: 4px 10px;
  background: transparent;
  color: var(--ink-faint);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.15s ease, background 0.15s ease;
}
.about-close:hover { color: var(--ink); background: var(--sidebar); }
.about-close:focus-visible { outline: none; color: var(--ink); background: var(--sidebar); }

.about-lede {
  margin: 0 0 2px;
  color: var(--ink);
  font-size: 0.95rem;
}
.about-meta {
  margin: 0 0 18px;
  color: var(--ink-faint);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

.about-section { margin: 0 0 16px; }
.about-section h3 {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-faint);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 0 0 8px;
}
.about-section ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.about-section li {
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--ink);
}
.about-section a {
  color: var(--ink-soft);
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 2px;
}
.about-section a:hover { color: var(--ink); text-decoration-color: var(--ink-soft); }

.about-foot {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 6px;
}
.about-foot p {
  margin: 0;
  font-size: 0.76rem;
  color: var(--ink-faint);
  line-height: 1.45;
}

/* ---------- Print — strip chrome, WYSIWYG ---------- */

@media print {
  html, body { background: #fff; }
  .chrome, .sidebar, .about { display: none !important; }
  .chrome-main { display: block; height: auto; }
  .canvas {
    padding: 0;
    background: #fff;
    overflow: visible;
    display: block;
  }
  .page {
    width: auto;
    height: auto;
    min-height: 0;
    padding: 0;                 /* @page margin owns the margin now */
    box-shadow: none;
    overflow: visible;
    zoom: 1;                    /* reset preview scale for real paper */
    display: block;
  }
}
