/* =================================================================
   Layout · stage, slides, chrome (top/bottom), script dock
================================================================= */

/* Stage & slides */
.stage {
  position: fixed;
  top: 0;
  left: var(--source-w);
  right: 0;
  bottom: calc(var(--script-h) + var(--chrome-bot-h));
  overflow: hidden;
  transition: bottom .3s cubic-bezier(.2,.7,.2,1),
              left .3s   cubic-bezier(.2,.7,.2,1);
}
.stage.source-collapsed { left: var(--source-bar-w); }
.stage.source-hidden    { left: 0; }
.stage.script-collapsed { bottom: calc(var(--script-bar-h) + var(--chrome-bot-h)); }
.stage.script-hidden    { bottom: var(--chrome-bot-h); }

.slide {
  position: absolute; inset: 0;
  padding: var(--pad-slide-y) var(--pad-slide-x);
  display: none; flex-direction: column;
  overflow: hidden; background: var(--bg);
}
.slide.active {
  display: flex;
  animation: fadeIn .55s cubic-bezier(.2,.7,.2,1);
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Slide head — shared across most slides */
.slide-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: var(--sp-6); position: relative; z-index: 2;
  gap: var(--sp-4);
}
.slide-head .head-left  { display: flex; flex-direction: column; gap: var(--sp-3); max-width: 80%; }
.slide-head .head-right { display: flex; flex-direction: column; align-items: flex-end; gap: var(--sp-1); }

/* Large decorative section number in corner */
.section-num {
  font-family: var(--display); font-weight: 800;
  font-size: 14vw; line-height: 0.8; color: var(--bg-2);
  position: absolute; right: -2vw; bottom: -3vw;
  letter-spacing: -0.04em; pointer-events: none; z-index: 0;
}

/* ===== Top Chrome ===== */
.chrome-top {
  position: fixed; top: 0;
  left: var(--source-w); right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px var(--pad-slide-x);
  font-size: var(--fs-xs); letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted); z-index: 20; pointer-events: none;
  font-family: var(--mono);
  transition: left .3s cubic-bezier(.2,.7,.2,1);
}
body.source-collapsed .chrome-top { left: var(--source-bar-w); }
.chrome-top .lhs, .chrome-top .rhs {
  display: flex; gap: 18px; align-items: center;
}

/* Auth chip — shows signed-in user + login/logout toggle */
.chrome-top .auth-chip {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 4px 4px 10px;
  border: 1px solid var(--line);
  border-radius: 100px;
  background: var(--paper);
  font-family: var(--mono);
  font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase; font-weight: 600;
  color: var(--ink-2);
  transition: border-color .2s, background .2s;
}
.chrome-top .auth-chip[data-state="loading"] { color: var(--muted); }
.chrome-top .auth-chip[data-state="authed"] {
  border-color: rgba(4, 120, 87, 0.45);
  background: rgba(4, 120, 87, 0.06);
  color: var(--emerald);
}
.chrome-top .auth-chip[data-state="guest"] {
  border-color: rgba(180, 83, 9, 0.45);
  background: rgba(180, 83, 9, 0.06);
  color: var(--amber);
}
.chrome-top .auth-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}
.chrome-top .auth-chip[data-state="loading"] .auth-dot {
  background: var(--muted);
  animation: auth-pulse 1.2s ease-in-out infinite;
}
.chrome-top .auth-name {
  max-width: 14ch;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: var(--sans);
  font-size: 11.5px; letter-spacing: -0.005em;
  text-transform: none; color: var(--ink);
}
.chrome-top .auth-btn {
  cursor: pointer; border: none;
  padding: 4px 10px;
  background: var(--ink); color: var(--paper);
  font-family: var(--mono); font-size: 9.5px;
  letter-spacing: 0.18em; text-transform: uppercase; font-weight: 700;
  border-radius: 100px;
  transition: background .15s, transform .15s;
}
.chrome-top .auth-btn:hover { background: var(--blue-deep); transform: translateY(-1px); }
.chrome-top .auth-chip[data-state="loading"] .auth-btn { display: none; }
.chrome-top .auth-chip[data-state="authed"] .auth-name { display: inline; }
.chrome-top .auth-chip[data-state="guest"] .auth-name  { display: none; }
@keyframes auth-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ===== Auth Gate (full-screen, shown until SSO verified) ===== */
.auth-gate {
  position: fixed; inset: 0;
  z-index: 10000;
  display: none;
  align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 30% 30%, rgba(29, 78, 216, 0.08), transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(4, 120, 87, 0.06), transparent 60%),
    var(--bg);
}
body.auth-pending .auth-gate { display: flex; }
body.auth-pending > *:not(.auth-gate) { visibility: hidden !important; }

.auth-gate-card {
  max-width: 520px;
  padding: 56px 60px;
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 4px;
  box-shadow:
    0 40px 100px rgba(10, 15, 30, 0.18),
    0 8px 24px rgba(10, 15, 30, 0.08);
  text-align: center;
  display: flex; flex-direction: column; align-items: center;
  gap: 24px;
  animation: gate-in .5s cubic-bezier(.2,.7,.2,1);
}
@keyframes gate-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}
.auth-gate-brand {
  display: flex; flex-direction: column; gap: 4px;
  line-height: 1;
}
.auth-gate-pre {
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.28em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
}
.auth-gate-main {
  font-family: var(--display); font-weight: 800;
  font-size: 44px; letter-spacing: -0.025em;
  color: var(--ink);
}
.auth-gate-main em {
  font-style: normal; color: var(--blue-deep); font-weight: 800;
}
.auth-gate-spinner {
  width: 36px; height: 36px;
  border: 2px solid rgba(10, 15, 30, 0.1);
  border-top-color: var(--blue-deep);
  border-radius: 50%;
  animation: gate-spin 0.9s linear infinite;
}
@keyframes gate-spin { to { transform: rotate(360deg); } }
.auth-gate-status {
  font-family: var(--sans); font-size: 14px; color: var(--ink-2);
  letter-spacing: -0.003em;
}
.auth-gate-meta {
  display: inline-flex; gap: 8px;
  font-family: var(--mono); font-size: 10.5px;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted);
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  width: 100%; justify-content: center;
}
.auth-gate-tag {
  color: var(--emerald); font-weight: 700;
}
.auth-gate-sep { opacity: 0.4; }

@media (max-width: 560px) {
  .auth-gate-card { margin: 20px; padding: 40px 28px; }
  .auth-gate-main { font-size: 34px; }
}
.chrome-top .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 0 4px rgba(4, 120, 87, 0.12);
}

/* ===== Bottom Chrome (nav + progress) ===== */
.chrome-bot {
  position: fixed; left: 0; right: 0;
  bottom: var(--script-h);
  height: var(--chrome-bot-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 var(--pad-slide-x);
  z-index: 14;
  font-family: var(--mono); font-size: var(--fs-xs);
  letter-spacing: 0.14em; color: var(--muted);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  transition: bottom .3s cubic-bezier(.2,.7,.2,1);
}
.stage.script-collapsed ~ .chrome-bot { bottom: var(--script-bar-h); }
.stage.script-hidden    ~ .chrome-bot { bottom: 0; }

.chrome-bot .cb-left,
.chrome-bot .cb-right {
  display: flex; align-items: center;
  gap: var(--sp-3); min-width: 0;
  text-transform: uppercase;
}
.chrome-bot .cb-left  { justify-self: start; }
.chrome-bot .cb-right { justify-self: end; }
.chrome-bot .cb-left #slide-title {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%;
}
.chrome-bot .cb-center {
  display: flex; align-items: center; gap: 6px;
  justify-self: center;
}
.cb-counter {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: var(--fs-xs);
  letter-spacing: 0.18em; color: var(--ink);
  padding: 0 12px;
  font-variant-numeric: tabular-nums;
}
.cb-counter .cb-divider-sm { color: var(--muted); opacity: 0.5; }

.cb-btn {
  width:  clamp(32px, 3.4vh, 42px);
  height: clamp(32px, 3.4vh, 42px);
  border: 1px solid var(--line);
  background: var(--paper); color: var(--ink-2);
  cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  transition: border-color .18s, background .18s, color .18s, transform .18s;
}
.cb-btn:hover { border-color: var(--ink); color: var(--ink); transform: translateY(-1px); }
.cb-btn:active { transform: translateY(0); }
.cb-btn:focus-visible { outline: 2px solid var(--blue-deep); outline-offset: 2px; }
.cb-btn svg { width: 50%; height: 50%; }

.progress-track {
  position: absolute; left: 0; right: 0; top: -1px;
  height: 1px; background: transparent;
}
.progress-bar {
  position: absolute; inset: 0 auto 0 0;
  height: 1px; background: var(--ink);
  transition: width .45s ease;
}

/* ===== Script Dock ===== */
.bottom-script {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: var(--script-h);
  background: var(--paper);
  border-top: 1px solid var(--ink);
  z-index: 15;
  display: flex; flex-direction: column;
  transition: height .3s cubic-bezier(.2,.7,.2,1);
  box-shadow: 0 -12px 40px rgba(10, 15, 30, 0.04);
}
.bottom-script.collapsed { height: var(--script-bar-h); }
.bottom-script.hidden    { height: 0; border-top: none; }

.bs-head {
  flex-shrink: 0;
  height: var(--script-bar-h);
  padding: 0 var(--pad-slide-x);
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  gap: var(--sp-4);
}
.bs-head .bs-label {
  font-family: var(--mono); font-size: var(--fs-xs);
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted); flex-shrink: 0;
}
.bs-head .bs-title {
  font-family: var(--display); font-weight: 700;
  font-size: var(--fs-md); letter-spacing: -0.012em;
  line-height: 1.25; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bs-head .bs-actions { display: flex; gap: 8px; flex-shrink: 0; }
.bs-head .bs-btn {
  width: 30px; height: 30px;
  border: 1px solid var(--line); background: var(--paper);
  color: var(--ink-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border-radius: 2px;
  transition: border-color .15s, background .15s;
}
.bs-head .bs-btn:hover { border-color: var(--ink); background: var(--bg); }
.bs-head .bs-btn svg { width: 14px; height: 14px; }
.bs-head .bs-btn.primary {
  background: var(--ink); color: var(--paper); border-color: var(--ink);
  padding: 0 12px; width: auto; gap: 6px;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.18em;
  text-transform: uppercase; font-weight: 600;
}
.bs-head .bs-btn.primary:hover { background: var(--blue-deep); border-color: var(--blue-deep); }
.bs-head .bs-btn.ghost {
  padding: 0 10px; width: auto;
  font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.18em; text-transform: uppercase;
}
.bs-head .bs-badge {
  font-family: var(--mono); font-size: 9.5px;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--emerald); padding: 3px 8px;
  border: 1px solid rgba(4, 120, 87, 0.3);
  border-radius: 100px; flex-shrink: 0;
  background: rgba(4, 120, 87, 0.06);
}
.bs-head .bs-badge.hidden { display: none; }

/* Sync status indicator — live MongoDB connection state */
.bs-sync {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px;
  border: 1px solid var(--line);
  border-radius: 100px;
  background: var(--paper);
  font-family: var(--mono);
  font-size: 10px; letter-spacing: 0.16em;
  text-transform: uppercase; font-weight: 600;
  color: var(--ink-2);
  flex-shrink: 0;
  transition: background .2s, color .2s, border-color .2s;
}
.bs-sync .bs-sync-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 0 currentColor;
  transition: background .2s, box-shadow .2s;
}
.bs-sync[data-state="loading"] { color: var(--muted); }
.bs-sync[data-state="loading"] .bs-sync-dot {
  background: var(--muted);
  animation: sync-pulse 1.2s ease-in-out infinite;
}
.bs-sync[data-state="online"] {
  color: var(--emerald);
  border-color: rgba(4, 120, 87, 0.35);
  background: rgba(4, 120, 87, 0.06);
}
.bs-sync[data-state="online"] .bs-sync-dot {
  background: var(--emerald);
  box-shadow: 0 0 0 3px rgba(4, 120, 87, 0.15);
}
.bs-sync[data-state="saving"] {
  color: var(--blue-deep);
  border-color: rgba(15, 42, 107, 0.35);
  background: rgba(15, 42, 107, 0.06);
}
.bs-sync[data-state="saving"] .bs-sync-dot {
  background: var(--blue-deep);
  animation: sync-pulse 0.9s ease-in-out infinite;
}
.bs-sync[data-state="saved"] {
  color: var(--emerald);
  border-color: rgba(4, 120, 87, 0.35);
}
.bs-sync[data-state="saved"] .bs-sync-dot { background: var(--emerald); }
.bs-sync[data-state="offline"] {
  color: var(--amber);
  border-color: rgba(180, 83, 9, 0.35);
  background: rgba(180, 83, 9, 0.06);
}
.bs-sync[data-state="offline"] .bs-sync-dot { background: var(--amber); }
.bs-sync[data-state="error"] {
  color: var(--red);
  border-color: rgba(185, 28, 28, 0.35);
  background: rgba(185, 28, 28, 0.06);
}
.bs-sync[data-state="error"] .bs-sync-dot { background: var(--red); }
@keyframes sync-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

.bs-head .edit-only { display: none; }
.bottom-script.editing .bs-head .edit-only { display: inline-flex; }
.bottom-script.editing .bs-head .idle-only { display: none; }
.bottom-script.editing .bs-body {
  outline: 2px solid var(--blue-deep);
  outline-offset: -2px;
  background: #fdfcf4;
}
.bs-body[contenteditable="true"] { cursor: text; }
.bs-body[contenteditable="true"]:focus { outline: none; }
.bs-body[contenteditable="true"] p { min-height: 1.2em; }

.bs-body {
  flex: 1;
  padding: var(--sp-2) var(--pad-slide-x) var(--sp-3);
  overflow: hidden;
  column-count: 2;
  column-gap: var(--sp-5);
  column-rule: 1px dashed var(--line);
  column-fill: balance;
  font-size: var(--bs-fs, var(--fs-md));
  line-height: var(--bs-lh, 1.5);
}
.bs-body > * { break-inside: avoid-column; }
.bs-body > *:first-child { margin-top: 0; }

/* Fallback when 2-column can't hold content even at minimum sizing:
   single column + vertical scroll (no horizontal overflow) */
.bs-body.bs-single {
  column-count: 1;
  column-rule: none;
  overflow-x: hidden; overflow-y: auto;
}
.bs-body.bs-single > * { break-inside: auto; }
.bs-body::-webkit-scrollbar { width: 6px; }
.bs-body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.bs-body::-webkit-scrollbar-track { background: transparent; }

.bs-body p {
  font-size: inherit; line-height: inherit; color: var(--ink-2);
  margin: 0 0 var(--bs-pm, 0.55em);
  break-inside: avoid;
}
.bs-body p:last-child { margin-bottom: 0; }
.bs-body p.beat {
  color: var(--blue-deep); font-weight: 600;
  font-family: var(--mono); font-size: 0.78em;
  letter-spacing: 0.05em; text-transform: uppercase;
  margin-bottom: 0.3em;
}
.bs-body hr {
  border: none; border-top: 1px dashed var(--line);
  margin: 0.6em 0;
}
.bs-body .note {
  font-size: 0.88em; color: var(--muted);
  font-family: var(--mono); letter-spacing: 0.02em;
  line-height: 1.55;
}
