/* ─── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --text: #0b1220;
  --accent: #168afe;
  --glow: #8fc4ff;
  --border-dark: rgba(11, 18, 32, 0.18);
  --border-dark-strong: rgba(11, 18, 32, 0.22);
  --pill-bg: linear-gradient(180deg, rgba(210, 215, 225, 0.55), rgba(175, 182, 195, 0.45));
  --pill-bg-strong: linear-gradient(180deg, rgba(210, 215, 225, 0.6), rgba(175, 182, 195, 0.5));
  --pill-shadow:
    0 10px 30px -10px rgba(0, 0, 0, 0.5),
    0 0 28px -8px rgba(143, 196, 255, 0.35);
  --swatch-ring:
    0 0 0 1px rgba(11, 18, 32, 0.4),
    inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  --selected-ring:
    0 0 0 2px var(--text),
    0 0 0 3px rgba(255, 255, 255, 0.75);
  --focus-ring: rgba(22, 138, 254, 0.7);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(ellipse 120% 85% at 50% 0%,
      #f6f8fc 0%,
      #e7ecf4 55%,
      #d6dde9 100%);
  font-family: monospace;
}

/* ─── Flex row: canvas on the left, notes sidebar on the right ─────────────── */
body {
  display: flex;
  flex-direction: row;
}

.canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0; /* allow flex child to shrink below its content size */
}

#slides {
  position: absolute;
  width: 100%;
  height: 100%;
}

.slide {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  user-select: none;
}

.slide.active {
  display: block;
}

/* Whiteboard mode: hide the underlying slide and show a blank white page
   sized to the same letterbox the slide would occupy. */
body.whiteboard-mode .slide.active {
  display: none;
}

#whiteboard-page {
  position: absolute;
  display: none;
  background: #ffffff;
  pointer-events: none; /* clicks go through to the canvas below */
}

body.whiteboard-mode #whiteboard-page {
  display: block;
}

/* Make injected SVG fill the slide */
.slide svg {
  display: block;
  width: 100%;
  height: 100%;
}

.drawing-enabled .slide {
  pointer-events: none;
}

canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
}

/* Cursor states applied on #c based on interaction mode */
#c.cursor-pencil {
  cursor: url("./assets/pencil.svg") 8 21, auto;
}

#c.cursor-eraser {
  cursor: url("./assets/eraser.svg") 9 22, auto;
}

/* Laser mode: hide the native cursor — the bright red head dot drawn on
   the canvas stands in for the pointer. */
body.laser-mode #c {
  cursor: none;
}

#tmp {
  pointer-events: none;
}

canvas.drawing-disabled {
  pointer-events: none;
  cursor: default;
}

#size-dot {
  position: absolute;
  border-radius: 50%;
  background: var(--accent);
  pointer-events: none;
  opacity: 0;
}

#size-dot.visible {
  opacity: 1;
}

#size-dot.fade {
  opacity: 0;
  transition: opacity 250ms ease-out;
}

/* ─── Glass pill — shared visual treatment for floating UI chrome ──────────── */
:where(
  #freeze-indicator,
  #loading-indicator,
  #progress-indicator,
  #color-picker,
  #toolbar,
  #empty-deck-cta
) {
  border-radius: 999px;
  background: var(--pill-bg);
  border: 1px solid var(--border-dark);
  box-shadow: var(--pill-shadow);
  backdrop-filter: blur(14px) saturate(160%);
  color: var(--text);
  user-select: none;
}

/* Heavier glass variant */
:where(#loading-indicator, #empty-deck-cta) {
  background: var(--pill-bg-strong);
}

#empty-deck-cta {
  border-color: var(--border-dark-strong);
}

/* ─── Notes sidebar ─────────────────────────────────────────────────────────── */
#notes-panel {
  /* Hidden by default; JS adds .visible.
     Width is driven by --notes-width, set via the drag handle (#notes-resizer). */
  display: none;
  flex: 0 0 var(--notes-width, 300px);
  min-width: 0;
  box-sizing: border-box;
  background:
    linear-gradient(180deg, #eef2f8 0%, #dde4ef 100%);
  padding: 8px 10px;
  overflow-y: auto;       /* scroll long notes; panel height stays 100% */
  overflow-x: hidden;
  line-height: 1.6;
  box-shadow: inset 1px 0 0 rgba(70, 90, 130, 0.28);
}

/* Drag handle between canvas-wrap and notes-panel. Visible only in speaker mode. */
#notes-resizer {
  display: none;
  position: relative;
  flex: 0 0 4px;
  cursor: col-resize;
  background: transparent;
  border-left: 1px solid rgba(70, 90, 130, 0.22);
  user-select: none;
  touch-action: none;     /* prevent scrolling on touch drag */
}

body:not(.is-slideshow).speaker-mode #notes-resizer {
  display: block;
}

#notes-resizer:hover,
#notes-resizer.dragging {
  background: rgba(22, 138, 254, 0.25);
}

#notes-toggle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid rgba(70, 90, 130, 0.28);
  border-radius: 4px;
  background: linear-gradient(180deg, #eef2f8 0%, #dde4ef 100%);
  color: var(--text);
  cursor: pointer;
  z-index: 1;
  box-shadow: 0 2px 6px -3px rgba(0, 0, 0, 0.35);
  transition: background 120ms ease-out;
}

#notes-toggle:hover {
  background: linear-gradient(180deg, #e5ebf4 0%, #ccd6e4 100%);
}

#notes-toggle svg {
  width: 12px;
  height: 12px;
  display: block;
}

body.notes-collapsed #notes-toggle svg {
  transform: rotate(180deg);
}

body:not(.is-slideshow) #notes-panel.visible {
  display: block;
}

body.notes-collapsed #notes-panel {
  display: none !important;
}

#next-preview {
  margin-bottom: 14px;
}

#next-preview.hidden {
  display: none;
}

#next-preview-thumb {
  width: 100%;
  max-width: 240px;
  aspect-ratio: 16 / 9;
  background: #ffffff;
  border: 1px solid rgba(70, 90, 130, 0.28);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 2px 8px -4px rgba(0, 0, 0, 0.35);
}

#next-preview-thumb svg {
  display: block;
  width: 100%;
  height: 100%;
}

#notes-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--accent);
  margin-bottom: 6px;
  user-select: none;
}

#notes-content {
  font-size: 12.5px;
  color: #1a2236;
  white-space: pre-wrap;   /* preserve explicit line breaks */
  word-break: break-word;  /* wrap long words inside the fixed panel width */
}

/* ─── Freeze-mode indicator ─────────────────────────────────────────────────── */
#freeze-indicator {
  position: absolute;
  left: 50%;
  top: 18px;
  transform: translate(-50%, -8px);
  display: none;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 10px;
  pointer-events: none;
  opacity: 0;
  z-index: 10;
  white-space: nowrap;
  transition: opacity 180ms ease-out, transform 180ms ease-out;
}

body.is-frozen:not(.is-slideshow) #freeze-indicator {
  display: inline-flex;
  opacity: 1;
  transform: translate(-50%, 0);
}

#freeze-indicator .freeze-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--glow);
  box-shadow: 0 0 0 0 rgba(143, 196, 255, 0.55);
  animation: freeze-pulse 1.8s ease-out infinite;
  flex: 0 0 auto;
}

#freeze-indicator .freeze-label {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--text);
}

#freeze-indicator .freeze-hint {
  font-size: 11px;
  letter-spacing: 0;
  color: rgba(11, 18, 32, 0.65);
  padding-left: 8px;
  margin-left: 2px;
  border-left: 1px solid var(--border-dark);
}

#freeze-indicator kbd {
  display: inline-block;
  padding: 0 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--border-dark-strong);
  color: var(--text);
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.3;
  vertical-align: 1px;
}

/* ─── Deck loading indicator ────────────────────────────────────────────────── */
#loading-indicator {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  display: none;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 10px;
  pointer-events: none;
  opacity: 0;
  z-index: 20;
  transition: opacity 160ms ease-out, transform 160ms ease-out;
}

body.is-loading #loading-indicator {
  display: inline-flex;
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#loading-indicator .loading-spinner {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid var(--border-dark-strong);
  border-top-color: var(--text);
  animation: loading-spin 0.8s linear infinite;
  flex: 0 0 auto;
}

#loading-indicator .loading-label {
  font-size: 12px;
  letter-spacing: 0;
  color: rgba(11, 18, 32, 0.78);
}

@keyframes loading-spin {
  to { transform: rotate(360deg); }
}

/* ─── Slide progress indicator (slideshow window only) ──────────────────────── */
#progress-indicator {
  position: absolute;
  display: none;
  align-items: baseline;
  gap: 4px;
  padding: 3px 10px;
  pointer-events: none;
  z-index: 10;
  transform: translate(-100%, -100%);
}

body:not(.is-slideshow).speaker-mode #progress-indicator,
body:not(.is-slideshow).whiteboard-mode #progress-indicator {
  display: inline-flex;
}

body:not(.is-slideshow) #progress-indicator.is-empty {
  display: none;
}

#progress-indicator .progress-current {
  font-size: 11px;
  letter-spacing: 0;
  color: rgba(11, 18, 32, 0.9);
}

#progress-indicator .progress-sep {
  font-size: 11px;
  color: rgba(11, 18, 32, 0.45);
}

#progress-indicator .progress-total {
  font-size: 11px;
  letter-spacing: 0;
  color: rgba(11, 18, 32, 0.65);
}

/* ─── Color picker ──────────────────────────────────────────────────────────── */
/* Positioning context for the picker, which sits above the color button. */
#toolbar .tb-color-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

#color-picker {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translate(-50%, 8px);
  display: none;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  opacity: 0;
  /* Parent toolbar sets pointer-events: none; re-enable for the picker so
     swatches and the custom-color input stay clickable. */
  pointer-events: auto;
  z-index: 11;
  transition: opacity 180ms ease-out, transform 180ms ease-out;
  white-space: nowrap;
}

body.color-picker-open:not(.is-slideshow) #color-picker {
  display: inline-flex;
  opacity: 1;
  transform: translate(-50%, 0);
}

#color-picker .cp-swatches {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

#color-picker .cp-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 0;
  background: var(--c);
  padding: 0;
  cursor: pointer;
  box-shadow: var(--swatch-ring);
  transition: transform 120ms ease-out;
}

#color-picker .cp-swatch:hover {
  transform: scale(1.12);
}

#color-picker .cp-swatch.selected,
#color-picker .cp-custom.selected .cp-custom-ring {
  box-shadow:
    var(--selected-ring),
    inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

#color-picker .cp-sep {
  width: 1px;
  height: 16px;
  background: rgba(11, 18, 32, 0.25);
}

#color-picker .cp-custom {
  position: relative;
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
}

#color-picker .cp-custom-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
  box-shadow:
    0 0 0 1px rgba(11, 18, 32, 0.4),
    inset 0 0 0 1px rgba(255, 255, 255, 0.25);
  transition: transform 120ms ease-out;
}

#color-picker .cp-custom:hover .cp-custom-ring {
  transform: scale(1.12);
}

#color-picker .cp-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  border: 0;
  padding: 0;
  background: transparent;
  outline: none;
  appearance: none;
}

#color-picker .cp-sizes {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#color-picker .cp-size {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  padding: 0;
  cursor: pointer;
  transition: box-shadow 120ms ease-out;
}

#color-picker .cp-size .cp-size-dot {
  display: block;
  border-radius: 50%;
  background: var(--dot, #0b1220);
  box-shadow: var(--swatch-ring);
  transition: transform 120ms ease-out;
}

#color-picker .cp-size:hover .cp-size-dot {
  transform: scale(1.18);
}

#color-picker .cp-size.selected {
  box-shadow: var(--selected-ring);
}

/* ─── Speaker toolbar (speaker window only) ─────────────────────────────────── */
#toolbar {
  position: absolute;
  left: 18px;
  bottom: 18px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 5px 10px;
  z-index: 12;
  /* Buttons opt-in to pointer events individually so drags between buttons
     pass through to the canvas (drawing/laser keep working). */
  pointer-events: none;
  opacity: 1;
  transition: opacity 400ms ease, transform 400ms ease;
}

#toolbar.tb-hidden {
  opacity: 0;
  transform: translateY(12px);
}

/* opacity:0 elements are still hit-testable — disable clicks while hidden. */
#toolbar.tb-hidden .tb-btn { pointer-events: none; }

body.is-slideshow #toolbar { display: none; }

#toolbar .tb-btn {
  pointer-events: auto;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  margin: 0;
  font-family: inherit;
  transition: background 120ms ease-out, transform 120ms ease-out, opacity 120ms ease-out;
}

#toolbar .tb-btn:hover:not(:disabled) {
  background: rgba(11, 18, 32, 0.12);
}

#toolbar .tb-btn.active {
  background: var(--text);
  color: #f3f5fa;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

#toolbar .tb-btn.active:hover:not(:disabled) {
  background: #3d3d3d;
}

#toolbar .tb-btn[data-action="freeze"] {
  display: none;
  color: #0a2a6b;
}

body.speaker-mode #toolbar .tb-btn[data-action="freeze"] {
  display: inline-flex;
}

#toolbar .tb-btn[data-action="freeze"].active {
  color: var(--glow);
}

#toolbar .tb-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

#toolbar .tb-btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

#toolbar .tb-btn svg,
#toolbar .tb-btn img {
  width: 16px;
  height: 16px;
  display: block;
}

/* left_ptr.svg artwork sits in the upper-left of its 256×256 viewBox, so the
   pointer reads as off-center inside the round button. Scale it up and nudge
   right to optically center the arrow. */
#toolbar .tb-btn-cursor img {
  width: 20px;
  height: 20px;
  transform: translateX(3px);
}

#toolbar .tb-sep {
  pointer-events: none;
  width: 1px;
  height: 16px;
  background: rgba(11, 18, 32, 0.25);
  margin: 0 4px;
}

#toolbar .tb-color-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: var(--swatch-ring);
}

/* ─── Empty-deck CTA ────────────────────────────────────────────────────────
   Standalone button shown in the speaker window when no slides are loaded.
   Positioned absolute inside .canvas-wrap (which has no transform), so it
   genuinely centers on the canvas area — unlike a child of #toolbar, whose
   transform would otherwise act as the containing block. The toolbar's
   own "Load deck" button stays at the bottom so it remains available after
   a deck is loaded. */
#empty-deck-cta {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: none;
  align-items: baseline;
  gap: 10px;
  padding: 14px 22px;
  font-family: monospace;
  font-size: 13px;
  cursor: pointer;
  z-index: 15;
  transition: background 120ms ease-out;
}

body.no-deck:not(.is-slideshow) #empty-deck-cta {
  display: inline-flex;
}

/* Hide while a deck is being imported so the CTA doesn't sit behind the
   centered loading spinner. Specificity must beat the `body.no-deck…`
   show rule above, hence the matching class count. */
body.no-deck.is-loading:not(.is-slideshow) #empty-deck-cta,
body.no-deck.whiteboard-mode:not(.is-slideshow) #empty-deck-cta {
  display: none;
}

#empty-deck-cta svg {
  width: 18px;
  height: 18px;
  display: block;
  transform: translateY(1.75px);
}

#empty-deck-cta:hover {
  background: linear-gradient(
    180deg,
    rgba(210, 215, 225, 0.75),
    rgba(175, 182, 195, 0.65)
  );
}

#empty-deck-cta:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ─── Keybinding cheatsheet overlay ────────────────────────────────────────── */
#help-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  z-index: 30;
  opacity: 0;
  transition: opacity 160ms ease-out;
}

body.help-open:not(.is-slideshow) #help-overlay {
  display: flex;
  opacity: 1;
}

body.is-slideshow #help-overlay { display: none; }

#help-panel {
  min-width: 520px;
  max-width: calc(100vw - 48px);
  padding: 20px 26px 22px;
  border-radius: 14px;
  background: linear-gradient(180deg, #eef2f8 0%, #dde4ef 100%);
  border: 1px solid var(--border-dark-strong);
  box-shadow: var(--pill-shadow);
  color: var(--text);
  user-select: none;
  transform: translateY(6px);
  transition: transform 160ms ease-out;
}

body.help-open:not(.is-slideshow) #help-panel {
  transform: translateY(0);
}

#help-panel .help-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-dark);
}

#help-panel .help-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
}

#help-panel .help-hint {
  font-size: 11px;
  color: rgba(11, 18, 32, 0.65);
}

#help-panel .help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 32px;
}

#help-panel section h3 {
  margin: 0 0 8px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
}

#help-panel dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: baseline;
  column-gap: 14px;
  row-gap: 6px;
  font-size: 12px;
}

/* Navigation (1st) and Drawing (3rd) share the left column of .help-grid; pin
   their dt width so descriptions start at the same x in both sections. Modes
   and Presentation stay auto-sized so their single-letter kbds hug the text. */
#help-panel .help-grid > section:nth-child(1) dl,
#help-panel .help-grid > section:nth-child(3) dl {
  grid-template-columns: 110px 1fr;
}

#help-panel dt {
  white-space: nowrap;
  color: rgba(11, 18, 32, 0.78);
}

#help-panel dt kbd + kbd {
  margin-left: 4px;
}

#help-panel dd {
  margin: 0;
  color: var(--text);
}

#help-panel kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--border-dark-strong);
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
}

@media (prefers-reduced-motion: reduce) {
  #help-overlay, #help-panel { transition: none; }
}

@keyframes freeze-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(143, 196, 255, 0.55); }
  70%  { box-shadow: 0 0 0 10px rgba(143, 196, 255, 0);   }
  100% { box-shadow: 0 0 0 0   rgba(143, 196, 255, 0);   }
}

@media (prefers-reduced-motion: reduce) {
  #freeze-indicator .freeze-dot { animation: none; }
  #freeze-indicator { transition: none; }
  #loading-indicator .loading-spinner { animation: none; }
  #loading-indicator { transition: none; }
}
