/* r17 · sub-book «اكتشف وتعلّم مع حامد»: the card on the book page + the page viewer + print. Used by both looks:
   Hamed's Window (html.v2: Cairo, navy/ivory tokens) and Book Door (classic: Readex/Markazi, ink/ivory/wood). Her pages are shown
   whole (contain, never cropped), on a sheet with a stack of pages beneath it: the one visual move of the page. Motion = CSS only. */
.sbk, .sbk-card-sec {
  --sbk-ink: var(--ink, #1E2B45); --sbk-text: var(--ink-soft, #4A4339); --sbk-paper: var(--ivory, #FAF4E8); --sbk-ground: var(--ivory-2, #F2E7D2);
  --sbk-line: var(--ivory-3, #E9D9BC); --sbk-accent: var(--wood, #6B3D22); --sbk-accent-hi: var(--wood-deep, #4E2B17); --sbk-gold: var(--gold, #C29A4B);
  --sbk-font: var(--text, system-ui, sans-serif); --sbk-head: var(--display, serif); --sbk-r: 14px;
  color: var(--sbk-text); font-family: var(--sbk-font);
}
html.v2 .sbk, html.v2 .sbk-card-sec {
  --sbk-ink: var(--c-navy); --sbk-text: var(--c-body); --sbk-paper: var(--c-ivory); --sbk-ground: var(--c-sand); --sbk-line: var(--c-line);
  --sbk-accent: var(--c-navy); --sbk-accent-hi: var(--c-hover); --sbk-gold: var(--c-gold); --sbk-font: var(--font); --sbk-head: var(--font); --sbk-r: var(--radius-card);
}
.sbk-mirror { width: 20px; height: 20px; flex: none; }
[dir="rtl"] .sbk-mirror { transform: scaleX(-1); }

/* ---------- buttons (≥ 48 px, one primary per view) ---------- */
.sbk-btn { display: inline-flex; align-items: center; justify-content: center; gap: .5em; min-height: 48px; padding: .55em 1.25em; border-radius: 12px;
  font: 600 1.0625rem/1.3 var(--sbk-font); text-decoration: none; border: 2px solid var(--sbk-accent); cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none; transition: background-color .16s ease, color .16s ease, transform .12s ease; }
.sbk-btn--primary { background: var(--sbk-accent); color: #fff; }
.sbk-btn--ghost { background: transparent; color: var(--sbk-accent); }
@media (hover: hover) and (pointer: fine) { .sbk-btn--primary:hover { background: var(--sbk-accent-hi); border-color: var(--sbk-accent-hi); } .sbk-btn--ghost:hover { background: color-mix(in srgb, var(--sbk-accent) 8%, transparent); } }
.sbk-btn:active { transform: scale(.97); }
.sbk-btn:focus-visible, .sbk-nav:focus-visible, .sbk-track:focus-visible, .sbk-adults summary:focus-visible, .sbk-crumb a:focus-visible { outline: 3px solid var(--sbk-accent-hi); outline-offset: 3px; }
.sbk-btn[aria-busy="true"] { opacity: .7; }
.sbk-size { font-weight: 400; opacity: .85; }

/* ---------- the card on the book page ---------- */
.sbk-card-sec { padding: clamp(24px, 4vw, 48px) var(--gutter, var(--gut, 20px)); }
.sbk-card { max-width: var(--wrap, var(--max, 1200px)); margin-inline: auto; display: grid; grid-template-columns: minmax(96px, 34%) 1fr; gap: clamp(16px, 3vw, 40px); align-items: center;
  background: #fff; border: 1px solid var(--sbk-line); border-radius: var(--sbk-r); padding: clamp(14px, 3vw, 32px); box-shadow: 0 1px 2px rgba(16,28,48,.06), 0 10px 28px -16px rgba(16,28,48,.22); }
@media (min-width: 900px) { .sbk-card { grid-template-columns: 200px 1fr; max-width: 920px; } html:not(.v2) .sbk-card { max-width: 760px; grid-template-columns: 180px 1fr; } html:not(.v2) .sbk-card-line { max-width: none; } }
.sbk-card-cover { display: block; position: relative; }
.sbk-card-cover img { display: block; width: 100%; height: auto; border-radius: 4px; box-shadow: 0 1px 0 #fff, 3px 3px 0 -1px #fff, 3px 3px 0 0 var(--sbk-line), 6px 6px 0 -1px #fff, 6px 6px 0 0 var(--sbk-line), 0 14px 24px -14px rgba(16,28,48,.35); }
[dir="rtl"] .sbk-card-cover img { box-shadow: 0 1px 0 #fff, -3px 3px 0 -1px #fff, -3px 3px 0 0 var(--sbk-line), -6px 6px 0 -1px #fff, -6px 6px 0 0 var(--sbk-line), 0 14px 24px -14px rgba(16,28,48,.35); }
.sbk-kicker { margin: 0 0 .25em; font: 500 .875rem/1.4 var(--sbk-font); color: var(--sbk-accent); letter-spacing: 0; }
.sbk-card-h { margin: 0 0 .35em; font: 700 clamp(1.3rem, 1.15rem + .6vw, 1.6rem)/1.35 var(--sbk-head); color: var(--sbk-ink); text-wrap: balance; }
.sbk-card-line { margin: 0 0 1em; font-size: 1rem; line-height: 1.7; max-width: 46ch; }
.sbk-card-act { margin: 0; }
/* C1 (r17 fix): Book Door headings in the book page heading face, Readex 700 (Arabic and English) */
html:not(.v2) .sbk-card-h, html:not(.v2) .sbk-title { font-family: var(--text, system-ui, sans-serif); font-weight: 700; }
@media (max-width: 420px) { .sbk-card { grid-template-columns: 96px 1fr; align-items: start; } .sbk-card-act .sbk-btn { width: 100%; } }

/* ---------- the viewer page ---------- */
.sbk { max-width: var(--wrap, var(--max, 1200px)); margin-inline: auto; padding: clamp(16px, 3vw, 40px) var(--gutter, var(--gut, 20px)) clamp(40px, 6vw, 80px); }
@media (min-width: 1000px) {
  .sbk { display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); column-gap: clamp(32px, 4vw, 64px); align-items: start; }
  .sbk-head { grid-column: 1; grid-row: 1; align-self: end; }
  .sbk-tools { grid-column: 1; grid-row: 2; align-self: start; }
  .sbk-viewer { grid-column: 2; grid-row: 1 / span 2; }
  .sbk-adults, .sbk-back { grid-column: 2; }
}
.sbk-crumb { margin: 0 0 1rem; }
.sbk-crumb a { display: inline-flex; align-items: center; gap: .35em; min-height: 44px; color: var(--sbk-accent); font-weight: 600; text-decoration: underline; text-underline-offset: .25em; }
.sbk-title { margin: 0 0 .35em; font: 700 clamp(1.875rem, 1.643rem + .952vw, 2.5rem)/1.3 var(--sbk-head); color: var(--sbk-ink); text-wrap: balance; }
.sbk-line { margin: 0 0 1rem; font-size: 1.0625rem; line-height: 1.75; max-width: 40ch; }
.sbk-acts { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 .5rem; }
/* r23 fix round 2: the breadcrumb trail in the sub-book header flows as one inline line that wraps between words (overrides site.css's flex items, which pushed the 3rd and 4th crumbs onto their own lines at 390) */
html .sbk-head .crumbs ol { display: block !important; line-height: 2.2; }
html .sbk-head .crumbs li { display: inline !important; }
html .sbk-head .crumbs a { display: inline; min-height: 0; padding-block: 8px; }
@media (max-width: 599px) { .sbk-line { display: none; } .sbk-crumb { margin-bottom: .25rem; } .sbk-title { font-size: 1.75rem; } }
.sbk-tools { margin-top: 18px; }
.sbk-tools .sbk-acts .sbk-btn { flex: 1 1 auto; }
@media (min-width: 1000px) { .sbk-tools { margin-top: 8px; } .sbk-tools .sbk-acts .sbk-btn { flex: 0 0 auto; } }
.sbk-hint { margin: 0 0 1.5rem; font-size: .9375rem; color: color-mix(in srgb, var(--sbk-text) 85%, transparent); }
.no-js .sbk-hint { display: none; }

/* the sheet: her page, whole, on a stack of pages (the signature move) */
.sbk-viewer { position: relative; }
.sbk-track { position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: 100%; overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding: 10px 0 22px; border-radius: 6px; }
.sbk-track::-webkit-scrollbar { display: none; }
.sbk-page { margin: 0; scroll-snap-align: center; scroll-snap-stop: always; display: grid; place-items: center; padding-inline: 14px; }
.sbk-page img { display: block; width: auto; height: auto; max-width: 100%; max-height: min(calc(100svh - 300px), 1100px); aspect-ratio: 1240 / 1754; object-fit: contain;
  background: #fff; border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(16,28,48,.06), 5px 5px 0 -1px #fff, 5px 5px 0 0 var(--sbk-line), 10px 10px 0 -1px #fff, 10px 10px 0 0 var(--sbk-line), 0 22px 40px -22px rgba(16,28,48,.45); }
[dir="rtl"] .sbk-page img { box-shadow: 0 0 0 1px rgba(16,28,48,.06), -5px 5px 0 -1px #fff, -5px 5px 0 0 var(--sbk-line), -10px 10px 0 -1px #fff, -10px 10px 0 0 var(--sbk-line), 0 22px 40px -22px rgba(16,28,48,.45); }
@media (min-width: 1000px) { .sbk-page img { max-height: min(calc(100svh - 230px), 1100px); } }
/* the page in view settles in; the others rest a touch lower (CSS only; nothing under reduced motion) */
.js .sbk-page img { transition: transform .2s cubic-bezier(.23, 1, .32, 1), opacity .2s cubic-bezier(.23, 1, .32, 1); }
.js .sbk-page:not([data-on]) img { transform: scale(.97); opacity: .8; }
@media (prefers-reduced-motion: reduce) { .js .sbk-page img { transition: none; } .js .sbk-page:not([data-on]) img { transform: none; opacity: 1; } .sbk-btn, .sbk-nav { transition: none; } .sbk-btn:active, .sbk-nav:active { transform: none; } }
/* F2: «حركة أقل» (hw:calm) = the same as reduced motion (subbook.js sets .sbk-calm on <html>) */
html.sbk-calm .sbk-page img { transition: none !important; }
html.sbk-calm .sbk-page:not([data-on]) img { transform: none; opacity: 1; }
html.sbk-calm .sbk-btn, html.sbk-calm .sbk-nav { transition: none; }
html.sbk-calm .sbk-btn:active, html.sbk-calm .sbk-nav:active { transform: none; }

.sbk-ctl { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 560px; margin: 4px auto 0; }
.sbk-nav { display: inline-flex; align-items: center; gap: .35em; min-height: 52px; min-width: 52px; padding: .4em .9em; border-radius: 999px; border: 2px solid var(--sbk-accent);
  background: #fff; color: var(--sbk-accent); font: 600 1rem/1.2 var(--sbk-font); cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none;
  transition: background-color .16s ease, transform .12s ease; }
.sbk-nav:active { transform: scale(.96); }
.sbk-nav:disabled { opacity: .35; cursor: default; transform: none; }
@media (hover: hover) and (pointer: fine) { .sbk-nav:not(:disabled):hover { background: color-mix(in srgb, var(--sbk-accent) 8%, #fff); } }
.sbk-count { margin: 0; font: 600 1rem/1.3 var(--sbk-font); color: var(--sbk-ink); font-variant-numeric: tabular-nums; text-align: center; }
.no-js .sbk-count { display: none; }

/* grown-ups' part */
.sbk-adults { margin-top: clamp(28px, 5vw, 56px); border: 1px solid var(--sbk-line); border-radius: var(--sbk-r); background: #fff; }
.sbk-adults summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25em .75em; min-height: 56px; padding: 14px 20px; cursor: pointer; list-style: none;
  font: 700 1.1875rem/1.4 var(--sbk-head); color: var(--sbk-ink); }
html:not(.v2) .sbk-adults summary { font-family: var(--text, system-ui, sans-serif); }
.sbk-adults summary::-webkit-details-marker { display: none; }
.sbk-adults summary::after { content: "+"; margin-inline-start: auto; font: 600 1.4rem/1 var(--sbk-font); color: var(--sbk-accent); }
.sbk-adults[open] summary::after { content: "−"; }
.sbk-sum-sub { font: 400 .9375rem/1.4 var(--sbk-font); color: var(--sbk-text); }
.sbk-adults-in { padding: 0 20px 20px; }
.sbk-adults-in > p { margin: 0 0 1rem; font-size: 1rem; line-height: 1.7; }
.sbk-guide-page { margin: 0 0 1rem; max-width: 420px; }
.sbk-guide-page img { display: block; width: 100%; height: auto; border: 1px solid var(--sbk-line); border-radius: 3px; }
.sbk-pdf-note { margin: 0 0 .5rem; font-size: .9375rem; line-height: 1.6; }
.sbk-back { margin: clamp(24px, 4vw, 40px) 0 0; }

/* ---------- print: one of her pages per A4 sheet, nothing else ---------- */
.sbk-print { display: none; }
/* @page { size: A4; margin: 0 } is set by the sub-book page itself (lib/subbook.mjs), so the book page that only shows the card prints as before */
@media print {
  html, body { margin: 0 !important; padding: 0 !important; background: #fff !important; }
  html.sbk-printing body > :not(.sbk-print) { display: none !important; }
  html.sbk-printing .sbk-print { display: block; }
  .sbk-sheet { width: 210mm; height: 297mm; overflow: hidden; break-after: page; page-break-after: always; display: flex; align-items: center; justify-content: center; }
  .sbk-sheet:last-child { break-after: auto; page-break-after: auto; }
  .sbk-sheet img { display: block; width: 210mm; height: 297mm; object-fit: contain; }
  /* without the print view (no JS): the child's pages as they are on screen, no chrome */
  html:not(.sbk-printing) body:has([data-sbk]) > :not(main), html:not(.sbk-printing) .sbk-head, html:not(.sbk-printing) .sbk-tools, html:not(.sbk-printing) .sbk-ctl, html:not(.sbk-printing) .sbk-adults, html:not(.sbk-printing) .sbk-back { display: none !important; }
  html:not(.sbk-printing) .sbk-track { display: block; overflow: visible; padding: 0; }
  html:not(.sbk-printing) .sbk-page { break-after: page; padding: 0; }
  html:not(.sbk-printing) .sbk-page img { max-height: none; width: 100%; box-shadow: none; transform: none; opacity: 1; }
}

/* ---------- F5 (r17 fix): a page at full size (1240 px image), native pinch-zoom, no zoom library ---------- */
.js .sbk-page img { cursor: zoom-in; }
.sbk-zoom-open { display: block; margin: 8px auto 0; min-height: 44px; padding: .3em 1em; border: 0; background: none; color: var(--sbk-accent); font: 600 1rem/1.3 var(--sbk-font);
  text-decoration: underline; text-underline-offset: .25em; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; user-select: none; }
.sbk-zoom-open:focus-visible { outline: 3px solid var(--sbk-accent-hi); outline-offset: 3px; }
.sbk-zoom { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #1b1b1b; color: #fff; }
.sbk-zoom::backdrop { background: rgba(0,0,0,.85); }
.sbk-zoom[open] { display: grid; grid-template-rows: auto 1fr; }
.sbk-zoom-bar { display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px; background: #111; }
.sbk-zoom-title { margin: 0; margin-inline-end: auto; font: 600 1rem/1.3 var(--sbk-font); font-variant-numeric: tabular-nums; }
.sbk-zoom-btn { min-height: 44px; min-width: 44px; padding: .3em .9em; border-radius: 999px; border: 2px solid #fff; background: transparent; color: #fff; font: 600 1rem/1.2 var(--sbk-font);
  cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
.sbk-zoom-btn--x { background: #fff; color: #111; }
.sbk-zoom-btn:focus-visible { outline: 3px solid #FFD98A; outline-offset: 2px; }
.sbk-zoom-scroll { overflow: auto; overscroll-behavior: contain; touch-action: pan-x pan-y pinch-zoom; -webkit-overflow-scrolling: touch; padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px)); }
.sbk-zoom-scroll img { display: block; margin-inline: auto; background: #fff; width: 100%; max-width: 1240px; height: auto; }
.sbk-zoom[data-full] .sbk-zoom-scroll img { width: 1240px; max-width: none; }
