/*
 * Viewer chrome styles for the Lil’moms Corner web deck.
 * Owns: the purple-tinted dark frame (top bar, stage frame, notes drawer, grid,
 * filmstrip, present mode, progress/HUD). Motion here is transform/opacity only. Does NOT own: styling inside slides (slides.js).
 * Layout uses logical properties so one stylesheet serves LTR and RTL; the only
 * physical-direction rules are the chevron flips and the stage transform.
 */
:root {
  /* Frame is darker and less saturated than the slide purple (#2B0752/#39096C), so the slide is the only light source. */
  --bg: #140b22;
  --panel: #1a1030;
  --panel-2: #241743;
  --line: rgba(255, 255, 255, .08);
  --text: #ece8f5;
  --muted: #a79bc0; /* ~6.3:1 on --panel */
  --accent: #20c7d9;
  --accent-ink: #06333a;
  --top-h: 56px;
  --pad: 24px;
  --tw: 136; /* thumbnail width in px, unitless so it can feed calc() for the scale */
  --strip-pad: 20px; /* vertical padding of #lb-strip; part of its reserved height */
  --film-h: 142px; /* approx. filmstrip height, only used to pre-size the stage before JS measures */
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --ease-drawer: cubic-bezier(.32, .72, 0, 1);
  --dur-fast: 120ms;
  --dur-base: 200ms;
}

/* Collapsed strip (saved preference, set pre-paint by the head script): only the 45px bar remains. */
html[data-film="1"] { --film-h: 45px; }

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

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
html[lang="ar"] body { font-family: "Cairo", "Source Sans 3", system-ui, sans-serif; }

button, a { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Keyboard focus ring on every control (mouse clicks do not show it). */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: 0 0 0 5px rgba(32, 199, 217, .18); }

.lb-sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- app grid ---------- */
#lb-app {
  display: grid;
  grid-template-rows: var(--top-h) minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
}

/* ---------- icons + buttons ---------- */
.lb-i {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}
/* Prev/next chevrons are drawn for LTR; mirror them when the page is RTL. */
[dir="rtl"] .lb-flip { transform: scaleX(-1); }

.lb-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 0 12px;
  background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: 10px;
  /* 14/600 with no tracking: letter-spacing breaks Arabic (Cairo) joins. */
  font-size: 14px; font-weight: 600; line-height: 1.2; letter-spacing: 0;
}
.lb-btn, .lb-seg button {
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), transform var(--dur-base) var(--ease-out);
}
@media (hover: hover) {
  .lb-btn:hover { background: rgba(255, 255, 255, .06); color: var(--text); }
  .lb-seg button:hover { color: var(--text); background: rgba(255, 255, 255, .06); }
}
.lb-btn:active, .lb-seg button:active { transform: scale(.96); transition-duration: 80ms; }
.lb-btn[aria-pressed="true"] { background: rgba(32, 199, 217, .14); color: #5ee0ec; }
.lb-btn:disabled { opacity: .3; cursor: default; background: transparent; color: var(--muted); }
.lb-icon-btn { padding: 0; min-width: 36px; }
.lb-primary {
  color: var(--accent-ink); background: var(--accent); border-radius: 999px;
  box-shadow: 0 8px 20px -6px rgba(32, 199, 217, .5), inset 0 0 0 1px rgba(255, 255, 255, .16);
}
@media (hover: hover) { .lb-primary:hover { background: #4ad6e4; color: var(--accent-ink); } }

/* Pill segmented control, shared by the EN/AR toggle and the zoom control. */
.lb-seg {
  position: relative; display: inline-flex; align-items: center; gap: 2px; padding: 3px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
}
.lb-seg button {
  position: relative; z-index: 1;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 28px; min-width: 32px; padding: 0 12px;
  background: transparent; color: var(--muted); border: 0; border-radius: 999px;
  font-size: 13px; font-weight: 600; line-height: 1.2; letter-spacing: 0;
}
.lb-seg button:disabled { opacity: .3; cursor: default; background: transparent; }
.lb-zoom button { padding: 0 8px; }
.lb-zoom .lb-zoom-val { min-width: 52px; font-variant-numeric: tabular-nums; }
.lb-zoom .lb-i { width: 16px; height: 16px; }

/* EN/AR toggle: two equal columns and a sliding indicator (transform only). The active
   option's own background stays transparent so the indicator shows through. */
#lb-lang { display: inline-grid; grid-template-columns: 1fr 1fr; gap: 0; }
#lb-lang button, #lb-lang button:hover { background: transparent; }
#lb-lang button[aria-pressed="true"] { color: var(--accent-ink); }
.lb-seg-ind {
  position: absolute; inset-block: 3px; inset-inline-start: 3px; width: calc(50% - 3px);
  border-radius: 999px; background: var(--accent);
  transition: transform 220ms var(--ease-drawer);
}
/* AR is the second DOM option and always RTL, where "second" sits to the left. */
html[lang="ar"] .lb-seg-ind { transform: translateX(-100%); }
html[lang="en"] .lb-seg-ind { transform: none; }

/* ---------- top bar ---------- */
#lb-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: relative; padding: 0 16px; min-width: 0;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
/* Deck progress: a 2px bar on the top bar's bottom edge, scaled from the start side (transform only). */
#lb-progress { position: absolute; inset-inline: 0; bottom: -1px; height: 2px; overflow: hidden; pointer-events: none; }
#lb-progress i {
  display: block; height: 100%; background: var(--accent);
  transform-origin: left; transform: scaleX(var(--p, 0));
  transition: transform 400ms var(--ease-drawer);
}
[dir="rtl"] #lb-progress i { transform-origin: right; }
.lb-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
/* width/height attributes on the <img> give the aspect ratio, so no layout shift when the logo loads. */
#lb-mark { height: 24px; width: auto; display: block; }
.lb-divider { width: 1px; height: 20px; background: var(--line); }
#lb-title {
  margin: 0; font-size: 16px; font-weight: 600; letter-spacing: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lb-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.lb-menu-wrap { position: relative; }
.lb-menu {
  position: absolute; z-index: 30; top: calc(100% + 8px); inset-inline-end: 0;
  min-width: 220px; padding: 6px;
  background: var(--panel); border-radius: 12px;
  box-shadow: 0 16px 40px -8px rgba(8, 3, 16, .7), 0 0 0 1px var(--line);
  animation: lb-pop 160ms var(--ease-out);
}
@keyframes lb-pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.lb-menu a {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 12px;
  color: var(--text); text-decoration: none; border-radius: 8px; font-size: 14px; font-weight: 600;
}
@media (hover: hover) { .lb-menu a:hover { background: rgba(255, 255, 255, .06); } }

/* ---------- main: stage / grid / notes ---------- */
#lb-main { display: flex; min-height: 0; min-width: 0; }

#lb-viewport {
  position: relative; flex: 1 1 auto; min-width: 0; display: flex;
  overflow: auto; padding: var(--pad); background: var(--bg);
}
/* margin:auto centres the stage when it is smaller than the area and still lets it scroll when zoomed past it. */
#lb-sizer {
  position: relative; flex: none; margin: auto;
  /* Pre-JS size approximating the fitted stage (JS overwrites width/height with exact values), avoids a big layout shift on load. */
  aspect-ratio: 16 / 9;
  width: min(100%, calc((100dvh - var(--top-h) - var(--film-h) - 2 * var(--pad)) * 16 / 9));
  z-index: 1; border-radius: 16px; overflow: hidden; background: #000;
  box-shadow: 0 2px 4px rgba(8, 3, 16, .4), 0 28px 64px -16px rgba(8, 3, 16, .75), 0 0 0 1px rgba(255, 255, 255, .07);
}
/* Static ambient glow behind the stage (no animation, so it costs nothing per frame). */
#lb-viewport::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(60% 50% at 50% 45%, rgba(57, 9, 108, .38), transparent 70%);
}
#lb-stage {
  position: absolute; top: 0; left: 0; width: 1920px; height: 1080px;
  transform-origin: 0 0;
  direction: inherit;
}
#lb-loading {
  position: absolute; inset: 0; margin: 0; display: grid; place-items: center;
  color: var(--muted); pointer-events: none;
}
#lb-loading.is-done { display: none; }

#lb-grid {
  flex: 1 1 auto; min-width: 0; overflow: auto; padding: 24px;
  display: grid; grid-template-columns: repeat(auto-fill, calc(var(--tw) * 1px));
  justify-content: center; align-content: start; gap: 24px;
  --tw: 264;
}

/* Thumbnail + card share one structure: a button holding a 16:9 frame that scales a 1920x1080 render. */
.lbv-thumb { scroll-snap-align: center; }
.lbv-thumb, .lbv-card {
  position: relative; flex: none; padding: 0; border: 0; background: transparent; border-radius: 8px;
  width: calc(var(--tw) * 1px);
}
.lbv-frame {
  position: relative; display: block;
  width: calc(var(--tw) * 1px); height: calc(var(--tw) * 9 / 16 * 1px);
  background: var(--panel-2); border-radius: 8px;
  box-shadow: 0 0 0 1px var(--line);
  opacity: .7;
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out);
}
/* Not overflow:hidden on the frame, so the ring below can sit outside it; the inner render is clipped instead. */
.lbv-inner {
  position: absolute; top: 0; left: 0; width: 1920px; height: 1080px; overflow: hidden;
  border-radius: calc(8px * 1920 / var(--tw));
  transform-origin: 0 0; transform: scale(calc(var(--tw) / 1920));
  pointer-events: none;
}
/* Current-slide ring and hover shadow fade by opacity (no paint-heavy box-shadow transitions). */
.lbv-frame::after, .lbv-frame::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; opacity: 0; pointer-events: none;
  transition: opacity 180ms var(--ease-out);
}
.lbv-frame::after { z-index: 2; box-shadow: 0 0 0 2px #20c7d9, 0 0 0 5px rgba(32, 199, 217, .18); }
.lbv-frame::before { box-shadow: 0 12px 24px -10px rgba(8, 3, 16, .8); }
.lbv-thumb[aria-current="true"] .lbv-frame::after, .lbv-card[aria-current="true"] .lbv-frame::after { opacity: 1; }
.lbv-thumb[aria-current="true"] .lbv-frame, .lbv-card[aria-current="true"] .lbv-frame { opacity: 1; }
@media (hover: hover) {
  .lbv-thumb:hover .lbv-frame, .lbv-card:hover .lbv-frame { opacity: 1; transform: translateY(-3px); }
  .lbv-thumb:hover .lbv-frame::before, .lbv-card:hover .lbv-frame::before { opacity: 1; }
}
.lbv-num {
  position: absolute; z-index: 3; inset-block-end: 5px; inset-inline-start: 5px;
  min-width: 20px; padding: 1px 6px; border-radius: 999px;
  background: rgba(20, 11, 34, .7); color: var(--text);
  font-size: 11px; font-weight: 600; line-height: 16px; text-align: center;
}
.lbv-thumb[aria-current="true"] .lbv-num, .lbv-card[aria-current="true"] .lbv-num { background: var(--accent); color: var(--accent-ink); }
.lbv-thumb:focus-visible, .lbv-card:focus-visible { outline-offset: 3px; box-shadow: none; }

/* Notes: right-hand drawer (left in RTL, since it is the last flex child). */
#lb-notes {
  display: none; flex: none; width: 340px; flex-direction: column; min-height: 0;
  background: var(--panel); border-inline-start: 1px solid var(--line);
}
#lb-notes.is-open, html[data-notes="1"] #lb-notes { display: flex; }
.lb-notes-head {
  display: flex; align-items: center; justify-content: space-between; padding: 8px; padding-inline: 16px 8px; border-bottom: 1px solid var(--line);
}
.lb-notes-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
#lb-notes-body {
  flex: 1 1 auto; overflow: auto; padding: 16px; white-space: pre-wrap;
  font-size: 15px; line-height: 1.65;
}
#lb-notes-body.is-empty { color: var(--muted); }

/* ---------- filmstrip ---------- */
#lb-film { background: var(--panel); border-top: 1px solid var(--line); min-width: 0; }
.lb-film-bar { display: flex; align-items: center; justify-content: space-between; padding: 4px 12px; }
.lb-pager, .lb-film-tools { display: flex; align-items: center; gap: 4px; }
/* Counter: current number rolls (see viewer.js), total stays put. */
#lb-counter { min-width: 56px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 600; }
.lb-cur { position: relative; display: inline-block; color: var(--text); }
.lb-cur b { display: inline-block; font-weight: 600; }
.lb-cur b.is-leaving { position: absolute; top: 0; left: 0; }
#lb-collapse .lb-i { transition: transform .2s var(--ease-out); }
#lb-collapse[aria-expanded="false"] .lb-i { transform: rotate(180deg); }
#lb-strip {
  display: flex; gap: 12px; overflow-x: auto; overflow-y: hidden;
  /* Symmetric edge fade (correct in LTR and RTL) and gentle snapping while swiping through thumbnails. */
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
  scroll-snap-type: x proximity;
  padding: 6px 14px 14px; scrollbar-width: thin;
  /* Reserve the thumbnail row height before thumbnails are built, so the stage does not jump. */
  min-height: calc(var(--tw) * 9 / 16 * 1px + var(--strip-pad)); scrollbar-color: var(--line) transparent;
}
#lb-film.is-collapsed #lb-strip, html[data-film="1"] #lb-strip, body.is-grid #lb-strip { display: none; }

/* ---------- present mode ---------- */
/* Fixed overlay is also the fallback where element fullscreen is unavailable (iPhone Safari). */
body.is-presenting #lb-top, body.is-presenting #lb-film,
body.is-presenting #lb-notes, body.is-presenting #lb-grid { display: none !important; }
body.is-presenting #lb-viewport {
  position: fixed; inset: 0; z-index: 50; padding: 0; background: #000; overflow: hidden;
}
body.is-presenting #lb-sizer { border-radius: 0; box-shadow: none; }
body.is-presenting #lb-viewport::before { display: none; }
#lb-hud, #lb-hud-progress { display: none; }
/* HUD is one pill (counter + Exit) so it reads as a single control on any slide colour. */
body.is-presenting #lb-hud {
  display: flex; align-items: center; gap: 4px; position: absolute; z-index: 5;
  height: 36px; padding: 3px; border-radius: 999px;
  background: rgba(20, 11, 34, .72); box-shadow: 0 0 0 1px rgba(255, 255, 255, .1);
  inset-block-start: 16px; inset-inline-end: 16px;
  transition: opacity 200ms var(--ease-out);
}
#lb-hud-count { padding: 0 10px; color: var(--text); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
#lb-exit-btn { min-height: 30px; padding: 0 12px 0 8px; border-radius: 999px; background: transparent; color: var(--text); font-size: 13px; }
#lb-exit-btn .lb-i { width: 16px; height: 16px; }
/* Bottom hairline progress, same scaleX technique as the top bar. */
body.is-presenting #lb-hud-progress {
  display: block; position: absolute; z-index: 5; inset-inline: 0; inset-block-end: 0; height: 3px;
  background: rgba(255, 255, 255, .08); overflow: hidden; pointer-events: none;
  transition: opacity 200ms var(--ease-out);
}
#lb-hud-progress i {
  display: block; height: 100%; background: rgba(32, 199, 217, .9);
  transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform 400ms var(--ease-drawer);
}
[dir="rtl"] #lb-hud-progress i { transform-origin: right; }
body.is-presenting.is-idle #lb-hud, body.is-presenting.is-idle #lb-hud-progress { opacity: 0; pointer-events: none; }
/* Idle-hidden HUD must reappear when keyboard focus lands on its Exit button. */
body.is-presenting.is-idle #lb-hud:focus-within { opacity: 1; pointer-events: auto; }
body.is-presenting.is-idle #lb-viewport { cursor: none; }

/* ---------- narrow screens ---------- */
@media (max-width: 960px) {
  .lb-label { display: none; }
  .lb-actions .lb-btn { padding: 0; min-width: 40px; }
}

@media (max-width: 768px) {
  :root { --top-h: 60px; --pad: 8px; --tw: 112; --strip-pad: 18px; --film-h: 140px; }
  html[data-film="1"] { --film-h: 53px; }
  #lb-top { padding: 0 10px; gap: 8px; }
  .lb-actions { gap: 4px; }
  .lb-zoom, .lb-divider { display: none; }
  /* Touch targets: every control is at least 44x44 on small screens. */
  .lb-btn, .lb-icon-btn, .lb-actions .lb-btn { min-height: 44px; min-width: 44px; }
  .lb-seg { padding: 2px; }
  .lb-seg button { min-height: 44px; min-width: 44px; padding: 0 10px; }
  #lb-grid { --tw: 164; padding: 16px 12px; gap: 14px 12px; }
  #lb-strip { padding: 6px 12px 12px; -webkit-overflow-scrolling: touch; }
  .lb-menu { min-width: 200px; }
  .lb-menu a { min-height: 48px; }

  /* Notes become a bottom sheet over the filmstrip. */
  #lb-notes {
    display: flex; position: fixed; z-index: 40; inset-inline: 0; inset-block-end: 0;
    /* Fixed height (body scrolls): content filled in by JS must not resize the sheet and shift layout. */
    width: auto; height: min(44dvh, 340px);
    border-inline-start: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -12px 32px rgba(0, 0, 0, .5);
    visibility: hidden; transform: translateY(100%);
    transition: transform .22s var(--ease-out), visibility 0s linear .22s;
  }
  #lb-notes.is-open, html[data-notes="1"] #lb-notes { visibility: visible; transform: none; transition: transform .22s var(--ease-out); }
}

/* Phone landscape: the strip would leave the stage a thumbnail; the pager/grid controls remain. */
@media (max-height: 500px) {
  #lb-strip { display: none; }
  :root { --film-h: 45px; }
}

@media (max-width: 480px) {
  /* Mark alone is enough; the title stays available to assistive tech. */
  #lb-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

@media (prefers-reduced-motion: reduce) {
  /* Blanket rule: every chrome transition/animation off; JS also checks the query for its WAAPI motion. */
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
