:root {
  --bg:           #0b0d12;
  --bg-elevated:  #161922;
  --bg-panel:     #1d2230;
  --fg:           #e7eaf0;
  --fg-muted:     #8a92a6;
  --accent:       #5b8def;
  --accent-warm:  #f2a93b;
  --ok:           #2ecc71;
  --warn:         #f2a93b;
  --err:          #e74c3c;
  --border:       #2a3142;
  --radius:       10px;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Menlo', 'Consolas', monospace;
  --font-serif: 'Playfair Display', 'Georgia', serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  height: 100%;
  overflow: hidden;
}

button { font-family: inherit; }

/* ── Layout shell ─────────────────────────────────────────────────────── */
#speaker-shell {
  display: grid;
  grid-template-rows: 56px 1fr;
  height: 100vh;
}

#speaker-shell[data-state="boot"] #stage,
#speaker-shell[data-state="loading"] #stage { display: none; }

#speaker-shell[data-state="running"] #boot-screen { display: none; }

/* ── Header ───────────────────────────────────────────────────────────── */
#header {
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
#header .brand {
  font-family: var(--font-serif);
  font-size: 18px;
  letter-spacing: 0.5px;
  color: var(--fg-muted);
}
#header .deck-title {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#header .header-nav {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: center;
}
#header .header-nav button {
  background: var(--bg-panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
#header .header-nav button:hover { background: #232838; border-color: var(--accent); }
#header .header-nav button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
#header .header-nav button.primary:hover { background: #4774d4; }
#header .slide-counter {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  background: var(--bg-panel);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
#header .session {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--fg-muted);
}
#header .connection {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
  color: var(--fg-muted);
}
#header .connection .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--err);
  box-shadow: 0 0 0 0 currentColor;
  transition: background 0.2s;
}
#header .connection.state-connecting .dot { background: var(--warn); animation: pulse 1.2s infinite; }
#header .connection.state-connected  .dot { background: var(--ok); }
#header .connection.state-disconnected .dot { background: var(--err); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--warn); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

/* ── Stage (the main content) ─────────────────────────────────────────── */
/* One CSS variable per resizer expresses the size of the FIRST track.
   The second track is always 1fr, so it gets whatever's left after the
   resizer's 6px is subtracted. Predictable, no percentage-vs-pixel math. */
#stage {
  --col-1:       60%;      /* slides column width */
  --left-top:    50%;      /* current slide height */
  --left-mid:    25%;      /* next slide height (TOC takes the remainder) */
  --right-top:   25%;      /* pace tracker height (notes take the remainder) */
  --resizer:     6px;

  display: grid;
  grid-template-columns: var(--col-1) var(--resizer) 1fr;
  padding: 12px;
  overflow: hidden;
}

.left-column {
  display: grid;
  grid-template-rows: var(--left-top) var(--resizer) var(--left-mid) var(--resizer) 1fr;
  min-height: 0;
}

.right-column {
  display: grid;
  grid-template-rows: var(--right-top) var(--resizer) 1fr;
  min-height: 0;
}

.resizer {
  background: transparent;
  position: relative;
  z-index: 5;
  transition: background 0.15s;
}
.resizer:hover, .resizer.dragging { background: var(--accent); }
.resizer-v { cursor: col-resize; }
.resizer-h { cursor: row-resize; }
/* Visible "grip" line in the middle of each resizer */
.resizer::after {
  content: '';
  position: absolute;
  background: var(--border);
  border-radius: 2px;
}
.resizer-v::after { top: 50%; left: 50%; transform: translate(-50%, -50%); width: 2px; height: 32px; }
.resizer-h::after { top: 50%; left: 50%; transform: translate(-50%, -50%); height: 2px; width: 32px; }
.resizer:hover::after, .resizer.dragging::after { background: white; }

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
  min-height: 0;
}

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-muted);
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  flex-shrink: 0;
}

.panel-body { flex: 1; overflow: hidden; min-height: 0; }

/* Slide previews use iframes scaled to fit */
.slide-frame-host {
  position: relative;
  width: 100%;
  height: 100%;
  background: black;
}
.slide-frame-host iframe {
  position: absolute;
  top: 0; left: 0;
  width: 1920px; height: 1080px;
  border: 0;
  transform-origin: 0 0;
}

/* ── Notes ──────────────────────────────────────────────────────────── */
.notes-body {
  padding: 16px 20px;
  overflow-y: auto;
  font-size: 18px;
  line-height: 1.5;
  height: 100%;
}
.font-controls { display: flex; gap: 4px; }
.font-controls button {
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
  letter-spacing: 0.04em;
}
.font-controls button:hover { color: var(--fg); border-color: var(--accent); }
.notes-body p { margin: 0 0 1em; }
.notes-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: rgba(255,255,255,0.06);
  padding: 1px 6px;
  border-radius: 4px;
}

/* ── TOC ─────────────────────────────────────────────────────────────── */
.toc-body {
  overflow-y: auto;
  height: 100%;
  padding: 4px 0;
}
.toc-item {
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}
.toc-item:hover { background: rgba(255, 255, 255, 0.04); }
.toc-item.current {
  background: rgba(91, 141, 239, 0.12);
  border-left-color: var(--accent);
}
.toc-item .num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  text-align: right;
}
.toc-item.current .num { color: var(--accent); }
.toc-item .title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toc-item.untitled .title { color: var(--fg-muted); font-style: italic; }
.toc-item.has-vert {
  grid-template-columns: 32px 12px 1fr;
}
.toc-item.is-vert {
  padding-left: 28px;
  font-size: 12px;
}
.toc-item.is-vert .num { color: var(--fg-muted); }

/* ── Pace tracker ───────────────────────────────────────────────────── */
.pace-body {
  padding: 8px 16px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px 16px;
  align-content: center;
}
.pace-stat { display: flex; flex-direction: column; gap: 2px; }
.pace-stat .label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.pace-stat .value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.1;
}
.pace-stat .value.ahead    { color: var(--ok); }
.pace-stat .value.behind   { color: var(--warn); }
.pace-stat .value.way-behind { color: var(--err); }

/* ── Boot screen ───────────────────────────────────────────────────── */
#boot-screen {
  position: absolute;
  inset: 56px 0 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
#boot-screen h1 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 32px;
  margin: 0 0 24px;
}
#boot-form {
  display: grid;
  gap: 16px;
  width: 360px;
}
#boot-form label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--fg-muted);
}
#boot-form input, #boot-form select {
  background: var(--bg-panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
}
#boot-form button {
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: var(--radius);
  padding: 12px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}
#boot-screen .hint {
  margin-top: 24px;
  font-size: 13px;
  color: var(--fg-muted);
}
