/* ==========================================================================
   Site chrome: library page, viewer controls, overview, presenter, print.
   ========================================================================== */

:root {
  --ui-font: "IBM Plex Sans Arabic", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --text-font: "ET Bembo", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, ui-serif, serif;
  --ui-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --page: #f4f2ed;
  --panel: #ffffff;
  --ink: #1d1c1a;
  --ink-2: #625d54;
  --line: #e1ddd4;
  --brand: #16a34a;
  --focus: #2f6fed;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --page: #111214; --panel: #1a1c1f; --ink: #ecebe7; --ink-2: #a19d95; --line: #2b2e33; --brand: #16a34a; --focus: #7aa2ff;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--ui-font); background: var(--page); color: var(--ink); transition: opacity .2s ease; }
/* Hold the page until fonts and content are in, so it appears in one piece
   (inline script in each page adds the class; a 3s fail-safe removes it). */
html.is-loading body { opacity: 0; transition: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
kbd {
  font-family: var(--ui-mono); font-size: .82em; padding: .1em .45em; border-radius: 5px;
  border: 1px solid currentColor; border-bottom-width: 2px; opacity: .8; white-space: nowrap;
}
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

/* ----------------------------------------------------------- thumbnails */

.thumb { position: relative; overflow: hidden; width: 100%; contain: strict; }
.thumb > .slide { left: 50%; top: 50%; transform-origin: center; pointer-events: none; }

/* ------------------------------------------------------------- library */

.library { min-height: 100dvh; display: flex; flex-direction: column; }
.lib-head { padding: 64px 0 8px; }
.theme-toggle {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; cursor: pointer;
  border: 0; background: none; color: var(--ink-2); padding: 0;
}
.theme-toggle:hover { color: var(--ink); }
.library > .theme-toggle { position: absolute; top: 12px; right: 12px; z-index: 1; }
.theme-toggle .icon-sun, [data-effective-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-effective-theme="dark"] .theme-toggle .icon-sun { display: block; }
.lib-head-inner, .lib-main, .lib-foot { max-width: 1272px; margin: 0 auto; width: 100%; padding-inline: 16px; }
.lib-main { flex: 1; }
.lib-head h1 {
  margin: 0; font-size: clamp(32px, 5vw, 48px); letter-spacing: -.025em; font-weight: 700; line-height: 1.05;
}
.lib-head h1::before {
  content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--brand); margin-bottom: 20px;
}
.lib-desc { margin: 12px 0 0; color: var(--ink-2); font-family: var(--text-font); font-size: 23px; max-width: 640px; line-height: 1.4; }

.toolbar { display: flex; align-items: center; gap: 16px; margin: 32px 0 24px; flex-wrap: wrap; }
.search {
  display: flex; align-items: center; gap: 10px; flex: 1; max-width: 420px; min-width: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; color: var(--ink-2);
}
.search:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.search input {
  flex: 1; min-width: 0; border: 0; background: none; font: inherit; font-size: 16px; color: var(--ink); padding: 11px 0; outline: none;
}
.search input::-webkit-search-cancel-button { display: none; }
.search kbd { font-size: 12px; }
.count { color: var(--ink-2); font-size: 14px; font-variant-numeric: tabular-nums; }

.status {
  background: var(--panel); border: 1px dashed var(--line); border-radius: 12px; padding: 28px; color: var(--ink-2); line-height: 1.5;
  font-family: var(--text-font); font-size: 19px;
}
.status strong { color: var(--ink); display: block; margin-bottom: 4px; font-family: var(--ui-font); font-size: 16px; font-weight: 600; }
.status code, .lib-foot code { font-family: var(--ui-mono); font-size: .9em; }

.grid {
  list-style: none; margin: 0; padding: 0 0 48px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 28px;
}
.card { position: relative; display: flex; flex-direction: column; min-width: 0; }
.card-link { color: inherit; text-decoration: none; display: flex; flex-direction: column; gap: 14px; border-radius: 12px; }
.card-thumb {
  border-radius: 10px; overflow: hidden; background: var(--line);
  box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgb(0 0 0 / .05);
  transition: transform .2s ease, box-shadow .2s ease;
}
.card-link:hover .card-thumb, .card-link:focus-visible .card-thumb {
  transform: translateY(-3px);
  box-shadow: 0 0 0 1px var(--line), 0 14px 32px -14px rgb(0 0 0 / .35);
}
.card-link:focus-visible { outline: none; }
.card-link:focus-visible .card-thumb { outline: 3px solid var(--focus); outline-offset: 3px; }
.card-body { padding: 0 2px; }
.card-title { margin: 0; font-size: 19px; line-height: 1.3; letter-spacing: -.01em; font-weight: 650; }
.card-desc {
  margin: 6px 0 0; color: var(--ink-2); font-family: var(--text-font); font-size: 18px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { margin: 8px 0 0; color: var(--ink-2); font-size: 13px; line-height: 1.8; }
.tag {
  display: inline-block; font-size: 12px; line-height: 1; padding: 4px 8px; border-radius: 99px;
  background: color-mix(in srgb, var(--ink) 8%, transparent); color: var(--ink-2); vertical-align: 1px;
}
.tag-draft { background: color-mix(in srgb, var(--brand) 18%, transparent); color: var(--brand); }
.card-present {
  align-self: flex-start; margin: 8px 2px 0; font-size: 13px; color: var(--ink-2); text-decoration: none;
  border-bottom: 1px dotted currentColor;
}
.card-present:hover { color: var(--brand); }
.card-error .card-body { border: 1px dashed var(--line); border-radius: 10px; padding: 20px; }

.lib-foot { padding-block: 0 40px; color: var(--ink-2); font-size: 14px; }
.lib-foot p { margin: 0; font-family: var(--text-font); font-size: 17px; padding-top: 24px; border-top: 1px solid var(--line); line-height: 1.8; }

/* -------------------------------------------------------------- viewer */

.viewer {
  --chrome-bg: rgb(22 22 24 / .82);
  --chrome-fg: #f1f0ec;
  background: #0c0c0d;
  color: #eee;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}
:root[data-theme="light"] .viewer { background: #d9d6ce; }
#app { height: 100%; }
.loading { display: grid; place-items: center; height: 100%; color: #888; font-size: 15px; }

.stage { position: fixed; inset: 0; overflow: hidden; touch-action: pan-y pinch-zoom; }
.viewport { position: absolute; left: 50%; top: 50%; transform-origin: center; }
body.idle .stage { cursor: none; }

.viewport > .slide {
  opacity: 0;
  visibility: hidden;
  transition: opacity .28s ease, visibility 0s linear .28s;
}
.viewport > .slide.is-current { opacity: 1; visibility: visible; transition: opacity .28s ease; }
.viewport > .slide.no-transition { transition: none; }
.viewport > .slide.no-transition .fragment { transition: none; }

.blackout { position: fixed; inset: 0; background: #000; z-index: 5; }

.progress { position: fixed; left: 0; right: 0; top: 0; height: 3px; z-index: 6; pointer-events: none; }
.progress-bar {
  height: 100%; background: var(--brand); transform-origin: left; transform: scaleX(0);
  transition: transform .3s ease;
}

.controls {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px; padding: 5px; z-index: 10;
  background: var(--chrome-bg); color: var(--chrome-fg); border-radius: 14px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 30px rgb(0 0 0 / .3), inset 0 0 0 1px rgb(255 255 255 / .08);
  transition: opacity .3s ease, transform .3s ease;
  max-width: calc(100vw - 32px);
}
body.idle .controls { opacity: 0; transform: translate(-50%, 8px); pointer-events: none; }
.ctl {
  display: inline-grid; place-items: center; min-width: 40px; height: 40px; padding: 0 8px;
  border: 0; border-radius: 10px; background: none; color: inherit; font: inherit; cursor: pointer; text-decoration: none;
}
.ctl:hover { background: rgb(255 255 255 / .1); }
.ctl.active { background: rgb(255 255 255 / .18); }
.controls .theme-toggle, .p-bar .theme-toggle { width: 40px; height: 40px; border: 0; background: none; color: inherit; }
.controls .theme-toggle:hover, .p-bar .theme-toggle:hover { background: rgb(255 255 255 / .1); }
.ctl-sep { width: 1px; height: 22px; background: rgb(255 255 255 / .14); margin: 0 4px; }
.counter { font-variant-numeric: tabular-nums; font-size: 14px; display: inline-flex; gap: 4px; min-width: 70px; }
.counter .of { opacity: .55; }
@media (max-width: 520px) {
  .controls [data-act="presenter"], .controls .ctl-sep { display: none; }
}

.jump-toast {
  position: fixed; top: 24px; left: 50%; transform: translateX(-50%); z-index: 11;
  background: var(--chrome-bg); color: var(--chrome-fg); padding: 10px 18px; border-radius: 10px; font-size: 18px;
  font-variant-numeric: tabular-nums; backdrop-filter: blur(12px);
}
.dev-flag {
  position: fixed; top: 12px; right: 12px; z-index: 11; max-width: calc(100vw - 24px);
  background: #fbbf24; color: #1a1300; font-size: 13px; font-weight: 600; padding: 6px 10px; border-radius: 8px;
  box-shadow: 0 4px 14px rgb(0 0 0 / .3);
}

.viewer-error { max-width: 560px; margin: 0 auto; padding: 18vh 16px 0; color: #ddd; line-height: 1.6; font-size: 16px; }
.viewer-error h1 { font-size: 28px; margin: 0 0 12px; color: #fff; }
.viewer-error a { color: #16a34a; }
.viewer-error code { font-family: var(--ui-mono); background: #222; padding: 2px 6px; border-radius: 4px; }

/* Capture mode (?capture): bare canvas at 1:1 for screenshots. */
body[data-mode="capture"] .controls,
body[data-mode="capture"] .progress,
body[data-mode="capture"] .dev-flag { display: none !important; }
body[data-mode="capture"] .slide, body[data-mode="capture"] .slide * { transition: none !important; }

/* ------------------------------------------------------------ overview */

.overview {
  position: fixed; inset: 0; z-index: 20; overflow-y: auto; overscroll-behavior: contain;
  background: #0c0c0d; color: #eee; padding: 0 16px 48px;
}
.overview-head {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 16px;
  max-width: 1400px; margin: 0 auto; padding: 18px 0; background: #0c0c0d;
}
.overview-head h2 { margin: 0; font-size: 17px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.overview-hint { font-size: 13px; color: #8d8b86; }
@media (max-width: 640px) { .overview-hint { display: none; } }
.overview-grid {
  list-style: none; margin: 0 auto; padding: 0; max-width: 1400px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); gap: 26px 20px;
}
.ov-item {
  display: flex; flex-direction: column; gap: 8px; width: 100%; padding: 0; border: 0; background: none;
  color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 8px;
}
.ov-item .thumb { border-radius: 6px; box-shadow: 0 0 0 1px rgb(255 255 255 / .1); transition: box-shadow .15s ease; }
.ov-item:hover .thumb { box-shadow: 0 0 0 2px rgb(255 255 255 / .45); }
.ov-item[aria-current="true"] .thumb { box-shadow: 0 0 0 3px #16a34a; }
.ov-item:focus-visible { outline: none; }
.ov-item:focus-visible .thumb { box-shadow: 0 0 0 3px var(--focus, #7aa2ff); }
.ov-cap { display: flex; gap: 8px; font-size: 13px; color: #b9b6b0; min-width: 0; }
.ov-num { font-variant-numeric: tabular-nums; color: #7d7a74; }
.ov-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ov-item.overflowing .thumb { box-shadow: 0 0 0 2px #fbbf24; }
.ov-item.overflowing .ov-cap::after { content: "overflows"; margin-left: auto; color: #fbbf24; font-weight: 600; }
body.overview-open .controls { display: none; }

/* ---------------------------------------------------------------- help */

.help {
  border: 0; border-radius: 16px; padding: 0; max-width: min(560px, calc(100vw - 32px));
  background: #1b1c1f; color: #ecebe7; box-shadow: 0 30px 80px rgb(0 0 0 / .5);
}
.help::backdrop { background: rgb(0 0 0 / .55); }
.help form { padding: 28px 28px 24px; position: relative; }
.help h2 { margin: 0 0 18px; font-size: 18px; }
.help table { border-collapse: collapse; width: 100%; font-size: 14px; }
.help td { padding: 7px 0; border-top: 1px solid #2c2e33; vertical-align: top; }
.help td:first-child { padding-right: 20px; white-space: nowrap; }
.help kbd { font-size: 12px; }
.help-foot { color: #8d8b86; font-size: 13px; margin: 16px 0 0; }
.help-foot code { font-family: var(--ui-mono); }
.help-close { position: absolute; top: 16px; right: 16px; border: 0; background: none; color: inherit; cursor: pointer; padding: 6px; border-radius: 8px; }
.help-close:hover { background: rgb(255 255 255 / .08); }

/* ----------------------------------------------------------- presenter */

body[data-mode="presenter"] { background: #141518; color: #e8e6e1; }
.presenter {
  height: 100dvh; display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr);
  grid-template-rows: minmax(0, 1fr) auto; gap: 16px; padding: 16px;
}
.p-current { position: relative; min-height: 0; }
.p-frame { position: absolute; inset: 0; overflow: hidden; border-radius: 8px; background: #0c0c0d; }
.p-frame .viewport > .slide { transition: none; }
.p-side { display: flex; flex-direction: column; gap: 16px; min-height: 0; }
.p-label {
  display: flex; align-items: center; gap: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .1em;
  color: #8d8b86; margin-bottom: 8px;
}
.p-builds { text-transform: none; letter-spacing: 0; color: #16a34a; }
.p-next .thumb { border-radius: 6px; box-shadow: 0 0 0 1px rgb(255 255 255 / .1); }
.p-end {
  aspect-ratio: 16 / 9; display: grid; place-items: center; border: 1px dashed #3a3c41; border-radius: 6px; color: #8d8b86;
}
.p-notes-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.p-font { margin-left: auto; display: flex; gap: 4px; }
.p-font button {
  border: 1px solid #34363b; background: none; color: #cfccc6; border-radius: 6px; padding: 2px 8px; font: inherit; font-size: 12px; cursor: pointer;
}
.p-notes {
  flex: 1; overflow-y: auto; background: #1c1d21; border-radius: 10px; padding: 18px 22px; line-height: 1.45; font-family: var(--text-font);
}
.p-notes > :first-child { margin-top: 0; }
.p-notes ul, .p-notes ol { padding-left: 1.2em; }
.p-notes code { font-family: var(--ui-mono); font-size: .88em; }
.p-empty { color: #6f6d68; font-style: italic; }
.p-bar {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; background: #1c1d21; border-radius: 12px; padding: 6px 10px;
  color: #e8e6e1;
}
.p-count { font-variant-numeric: tabular-nums; font-size: 15px; min-width: 64px; text-align: center; }
.p-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #9f9c95; font-size: 14px; padding: 0 8px; }
.p-timer {
  font-family: var(--ui-mono); font-size: 26px; font-variant-numeric: tabular-nums; background: none; border: 0; color: inherit;
  cursor: pointer; padding: 2px 10px; border-radius: 8px;
}
.p-timer:hover { background: rgb(255 255 255 / .06); }
.p-timer.paused { color: #fbbf24; }
.p-clock { font-variant-numeric: tabular-nums; color: #8d8b86; font-size: 15px; padding-right: 8px; }
@media (max-width: 800px) {
  .presenter { grid-template-columns: 1fr; grid-template-rows: minmax(200px, 40vh) auto auto; height: auto; min-height: 100dvh; }
  body[data-mode="presenter"] { height: auto; overflow: auto; }
  .p-notes { min-height: 30vh; }
  .p-title, .p-clock { display: none; }
}

/* --------------------------------------------------------------- print */

@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body.viewer { background: none; height: auto; overflow: visible; }
  .controls, .progress, .dev-flag, .overview, .jump-toast, .blackout, dialog, .sr-only, .presenter .p-side, .p-bar { display: none !important; }
  .stage { position: static; }
  .viewport { position: static; transform: none !important; width: auto !important; height: auto !important; }
  .viewport > .slide {
    position: relative; opacity: 1 !important; visibility: visible !important; transition: none !important;
    break-after: page; page-break-after: always;
  }
  .viewport > .slide:last-child { break-after: auto; page-break-after: auto; }
  .slide .fragment { opacity: 1 !important; transform: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
