/* ==========================================================================
   APP CHROME + FIXED 16:9 STAGE
   Stage rules adapted from frontend-slides viewport-base.css:
   slides are authored at 1920×1080 and scaled as a whole — never reflowed.
   ========================================================================== */

* { box-sizing: border-box; }

/* the hidden attribute must always win over display rules below */
[hidden] { display: none !important; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--stage-bg, #000);
}

/* ---------- fixed stage ---------- */

.deck-viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--stage-bg, #000);
}
/* keep the stage clear of the toolbar/progress chrome while editing;
   presenting reclaims the full window */
body:not(.presenting) .deck-viewport { top: 48px; bottom: 10px; }

.deck-stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 1920px;
  height: 1080px;
  overflow: hidden;
  transform-origin: 0 0;
  background: var(--slide-bg, #fff);
}

.slide {
  position: absolute;
  inset: 0;
  width: 1920px;
  height: 1080px;
  overflow: hidden;
  display: block;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  background: var(--slide-bg, #fff);
}

.slide.active,
.slide.visible {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  z-index: 1;
}

img, video, canvas, svg { max-width: 100%; max-height: 100%; }

/* ---------- chrome tokens (template-independent) ---------- */

:root {
  --ch-bg: rgba(16, 16, 18, 0.92);
  --ch-ink: #e8e8ea;
  --ch-muted: #9a9aa2;
  --ch-line: rgba(255, 255, 255, 0.12);
  --ch-accent: #ffd166;
  --ch-font: "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

/* ---------- toolbar ---------- */

.toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 900;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--ch-bg);
  border-bottom: 1px solid var(--ch-line);
  font-family: var(--ch-font);
  color: var(--ch-ink);
  backdrop-filter: blur(8px);
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.tb-group { display: flex; align-items: center; gap: 10px; min-width: 0; }

.tb-decktitle {
  font-size: 13px;
  color: var(--ch-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}

.tb-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ch-muted); }

.tb-btn {
  font: 500 13px/1 var(--ch-font);
  color: var(--ch-ink);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--ch-line);
  border-radius: 7px;
  padding: 7px 12px;
  cursor: pointer;
}
.tb-btn:hover { background: rgba(255, 255, 255, 0.14); }
.tb-primary { background: var(--ch-accent); border-color: var(--ch-accent); color: #1a1a1a; font-weight: 700; }
.tb-primary:hover { filter: brightness(1.08); background: var(--ch-accent); }

/* square icon button — a .tb-btn collapsed to a single Lucide glyph */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--ch-ink);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--ch-line);
  border-radius: 7px;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.14); }
.icon-btn svg { width: 18px; height: 18px; display: block; }
.icon-btn.tb-primary { background: var(--ch-accent); border-color: var(--ch-accent); color: #1a1a1a; }
.icon-btn.tb-primary:hover { filter: brightness(1.08); background: var(--ch-accent); }
.icon-btn.lib-danger:hover { color: #ff6b6b; border-color: #ff6b6b; }

.tb-select {
  font: 500 13px/1 var(--ch-font);
  color: var(--ch-ink);
  background-color: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--ch-line);
  border-radius: 7px;
  /* symmetric: 12px of breathing room on the left of the text and on the
     right of the custom chevron (the native arrow is removed below). */
  padding: 7px 32px 7px 12px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 10 7'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239a9aa2' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.tb-select option { color: #111; }

.tb-counter { font: 600 13px/1 var(--ch-font); color: var(--ch-muted); min-width: 64px; text-align: right; }

/* signed-in user chip (cloud mode) */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 5px 4px 12px;
  border: 1px solid var(--ch-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
}
.uc-email {
  font-size: 12px;
  color: var(--ch-muted);
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.uc-signout {
  font: 600 11px/1 var(--ch-font);
  color: var(--ch-ink);
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}
.uc-signout:hover { background: rgba(255, 255, 255, 0.16); }

/* presenting: hide chrome, reveal toolbar when the cursor touches the top edge */
body.presenting .toolbar { transform: translateY(-100%); opacity: 0; }
body.presenting .toolbar:hover,
body.presenting:has(.toolbar:hover) .toolbar { transform: none; opacity: 1; }
.toolbar::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 14px; }

/* ---------- progress ---------- */

.progress {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  z-index: 900;
  background: rgba(255, 255, 255, 0.08);
}
.progress-fill { height: 100%; width: 0; background: var(--ch-accent); transition: width 0.25s ease; }

/* ---------- audience mode (?audience=1): clean stage, driven by presenter.html ---------- */

body.audience .toolbar, body.audience .progress { display: none !important; }
body.audience .deck-viewport { top: 0; bottom: 0; }

/* ---------- speaker notes ---------- */

.notes-panel {
  position: fixed;
  top: 48px;
  right: 0;
  bottom: 4px;
  width: min(420px, 40vw);
  z-index: 850;
  display: flex;
  flex-direction: column;
  background: var(--ch-bg);
  border-left: 1px solid var(--ch-line);
  font-family: var(--ch-font);
  color: var(--ch-ink);
  backdrop-filter: blur(8px);
}
.notes-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ch-muted);
  border-bottom: 1px solid var(--ch-line);
}
.notes-body {
  padding: 16px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
}
.np-close {
  background: none;
  border: none;
  color: var(--ch-muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
}
.np-close:hover { color: var(--ch-ink); }

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

.overview {
  position: fixed;
  inset: 0;
  z-index: 940;
  overflow-y: auto;
  background: rgba(10, 10, 12, 0.96);
  padding: 64px 40px 40px;
}
/* close affordance, pinned to the top-right of the grid overlay */
.ov-close {
  position: fixed;
  top: 16px;
  right: 20px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  color: var(--ch-ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--ch-line);
  border-radius: 8px;
  cursor: pointer;
}
.ov-close:hover { background: rgba(255, 255, 255, 0.18); border-color: var(--ch-accent); }
.ov-close svg { width: 22px; height: 22px; display: block; }
.ov-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 22px;
  max-width: 1600px;
  margin: 0 auto;
}
.ov-cell {
  position: relative;
  border: 1px solid var(--ch-line);
  border-radius: 8px;
  background: #000;
  padding: 0 0 26px;
  cursor: pointer;
  overflow: hidden;
  text-align: left;
}
.ov-cell:hover { border-color: var(--ch-accent); }
.ov-cell.is-hidden { opacity: 0.45; }
.ov-stage { position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden; }
.ov-thumb {
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: none !important;
  transform: scale(calc(1 / 6.4));
  transform-origin: 0 0;
}
/* thumbnails: kill entrance animation so clones render fully */
.ov-thumb .reveal, .ov-thumb .term-line { opacity: 1 !important; transform: none !important; transition: none !important; }
.ov-num {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 5px 10px;
  font: 600 11px/1 var(--ch-font);
  color: var(--ch-muted);
  background: var(--ch-bg);
}

/* the overview thumb is a 1920×1080 slide scaled by 1/6.4 = 300×168.75.
   Cells are fluid; slight crop on wider cells is fine. */

/* ---------- home gallery (no ?deck) ---------- */

/* gallery mode hides the single-deck stage + its progress bar */
body.mode-gallery .deck-viewport,
body.mode-gallery .progress { display: none !important; }

.gallery {
  position: fixed;
  inset: 48px 0 0 0;
  z-index: 100;
  overflow-y: auto;
  padding: 34px 40px 64px;
  background: var(--stage-bg, #0d0d0d);
  font-family: var(--ch-font);
}
.gal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 26px;
  max-width: 1600px;
  margin: 0 auto;
}
.gal-empty { color: var(--ch-muted); text-align: center; margin: 60px auto; font-size: 15px; }
.gal-empty strong { color: var(--ch-ink); }

.gal-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--ch-line);
  border-radius: 12px;
  background: #161619;
  overflow: hidden;
}
/* card body: head (title + meta) → previews (fill) → actions (bottom) */
.gal-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 14px;
  padding: 16px 18px 18px;
}
.gal-head { display: flex; flex-direction: column; gap: 6px; }
.gal-title { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; color: var(--ch-ink); }
.gal-meta { font-size: 12px; color: var(--ch-muted); }

/* two slide thumbnails, centered, filling the gap between head and actions;
   re-skin live when the template changes */
.gal-previews {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 90px;
}
.gthumb {
  position: relative;
  flex: 0 1 46%;
  max-width: 46%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--ch-line);
  border-radius: 6px;
  background: #000;
}
.gthumb .deck-stage { pointer-events: none; }
.gthumb-empty { display: flex; align-items: center; justify-content: center; }
/* entrance animations would leave preview elements invisible — pin them shown */
.gthumb .reveal, .gthumb .term-line {
  opacity: 1 !important; transform: none !important; transition: none !important; animation: none !important;
}

/* actions pinned to the bottom of the card (cards stretch to equal row height) */
.gal-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: auto; }
.gal-manage { display: flex; align-items: center; gap: 6px; margin-left: auto; }

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

.modal {
  position: fixed;
  inset: 0;
  z-index: 950;
  background: rgba(10, 10, 12, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-card {
  width: min(680px, 92vw);
  max-height: 84vh;
  overflow-y: auto;
  background: #17171a;
  border: 1px solid var(--ch-line);
  border-radius: 14px;
  padding: 24px 28px;
  font-family: var(--ch-font);
  color: var(--ch-ink);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h1 { font-size: 18px; margin: 0; }
.lib-import {
  margin: 18px 0;
  padding: 22px;
  border: 2px dashed var(--ch-line);
  border-radius: 10px;
  text-align: center;
  font-size: 14px;
  color: var(--ch-muted);
}
.lib-import.dragging { border-color: var(--ch-accent); color: var(--ch-ink); }
.lib-import p { margin: 0 0 12px; }
.lib-import code { color: var(--ch-accent); }
.lib-listwrap h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ch-muted); }
.lib-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lib-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--ch-line);
  border-radius: 9px;
  padding: 12px 14px;
  color: var(--ch-ink);
  font-family: var(--ch-font);
  cursor: pointer;
}
.lib-item:hover { border-color: var(--ch-accent); }
.lib-name { font-size: 14px; font-weight: 600; }
.lib-badge {
  flex: none;
  margin-left: 8px;
  font: 600 10px/1 var(--ch-font);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  color: var(--ch-accent);
  border: 1px solid var(--ch-accent);
  border-radius: 5px;
  padding: 2px 5px;
  vertical-align: middle;
}
.lib-meta { font-size: 12px; color: var(--ch-muted); }
.lib-empty { color: var(--ch-muted); font-size: 13px; list-style: none; }

/* cloud library: sectioned lists with per-row actions */
.lib-import .lib-hint { margin: 12px 0 0; font-size: 12px; }
.lib-listwrap ul + h2 { margin-top: 24px; }
.lib-row { display: flex; align-items: stretch; gap: 8px; }
.lib-row .lib-item { flex: 1; min-width: 0; }
.lib-actions { display: flex; align-items: center; gap: 6px; }
.lib-act {
  font: 600 11px/1 var(--ch-font);
  color: var(--ch-muted);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--ch-line);
  border-radius: 7px;
  padding: 8px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.lib-act:hover { color: var(--ch-ink); border-color: var(--ch-accent); }
.lib-act.is-on { color: #1a1a1a; background: var(--ch-accent); border-color: var(--ch-accent); }
.lib-danger:hover { color: #ff6b6b; border-color: #ff6b6b; }

/* ---------- template picker modal ---------- */

.tpl-sub { margin: 6px 0 16px; font-size: 13px; color: var(--ch-muted); }
.tpl-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.tpl-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--ch-line);
  border-radius: 10px;
  padding: 13px 15px;
  color: var(--ch-ink);
  font-family: var(--ch-font);
  cursor: pointer;
}
.tpl-item:hover { border-color: var(--ch-accent); background: rgba(255, 255, 255, 0.07); }
.tpl-item.is-selected { border-color: var(--ch-accent); box-shadow: inset 0 0 0 1px var(--ch-accent); }
.tpl-item-head { display: flex; align-items: center; gap: 10px; }
.tpl-name { font-size: 15px; font-weight: 700; }
.tpl-scheme {
  font: 600 10px/1 var(--ch-font);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--ch-line);
  color: var(--ch-muted);
}
.tpl-scheme-dark { background: #1a1a1e; color: #cfcfd6; }
.tpl-scheme-light { background: #ece7d8; color: #3a3a34; border-color: #d8d2c2; }
.tpl-current {
  margin-left: auto;
  font: 600 10px/1 var(--ch-font);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #1a1a1a;
  background: var(--ch-accent);
  border-radius: 5px;
  padding: 3px 7px;
}
.tpl-tagline { font-size: 13px; color: var(--ch-ink); opacity: 0.85; line-height: 1.45; }
.tpl-mood { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ch-accent); }
.tpl-bestfor { font-size: 12px; color: var(--ch-muted); line-height: 1.45; }
.tpl-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- auth gate (cloud mode) ---------- */

.gate {
  position: fixed;
  inset: 0;
  z-index: 970;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(10, 10, 12, 0.97);
  font-family: var(--ch-font);
  color: var(--ch-ink);
}
.gate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  max-width: 460px;
  padding: 40px 44px;
  text-align: center;
  background: #17171a;
  border: 1px solid var(--ch-line);
  border-radius: 14px;
}
.gate-title { font-size: 22px; font-weight: 700; }
.gate-msg { margin: 0; font-size: 14px; line-height: 1.55; color: var(--ch-muted); }
.gate-btn { font-size: 14px; padding: 10px 18px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 990;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--ch-bg);
  border: 1px solid var(--ch-line);
  color: var(--ch-ink);
  font: 500 13px/1.4 var(--ch-font);
  padding: 10px 18px;
  border-radius: 9px;
  max-width: 80vw;
}
/* cancel affordance inside a progress toast (e.g. PDF export) */
.toast-cancel { width: 26px; height: 26px; border-radius: 6px; }
.toast-cancel svg { width: 15px; height: 15px; }

/* ---------- print: one slide per page, no chrome ---------- */

@media print {
  html, body { width: 1920px; height: auto; overflow: visible; background: #fff; }
  .deck-viewport { position: static; overflow: visible; background: #fff; }
  .deck-stage { position: static; width: auto; height: auto; transform: none !important; background: none; }
  .slide {
    position: relative;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    width: 1920px;
    height: 1080px;
    break-after: page;
    page-break-after: always;
  }
  .slide:last-child { break-after: auto; page-break-after: auto; }
  .slide .reveal, .slide .term-line { opacity: 1 !important; transform: none !important; }
  .toolbar, .progress, .notes-panel, .overview, .modal, .gate, .toast, .gallery { display: none !important; }
  @page { size: 1920px 1080px; margin: 0; }
}

/* ---------- PDF export: offscreen render host (pdf-export.js) ---------- */

.pdf-host .slide { visibility: visible !important; opacity: 1 !important; }
.pdf-host .reveal, .pdf-host .term-line {
  opacity: 1 !important; transform: none !important; animation: none !important; transition: none !important;
}

/* ---------- reduced motion ---------- */

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