:root {
  color-scheme: light dark;
  --bg: #f7f7f5;
  --fg: #1d1d1f;
  --muted: #6b6b70;
  --line: #dcdcd8;
  --card: #ffffff;
  --accent: #2557d6;
  --accent-fg: #ffffff;
  --danger: #c4302b;
  --warn: #8a5300;
  --warn-bg: #fff3d6;
  --error: #a3221d;
  --error-bg: #fde5e3;
  --focus: #2557d6;
  --stage: #000000;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161618;
    --fg: #ececee;
    --muted: #9c9ca3;
    --line: #34343a;
    --card: #202024;
    --accent: #7a9cff;
    --accent-fg: #0b1330;
    --danger: #ff6b63;
    --warn: #ffcf70;
    --warn-bg: #3a2c0c;
    --error: #ff9b94;
    --error-bg: #42191a;
    --focus: #7a9cff;
  }
}

[hidden] { display: none !important; }

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); }
h1 { font-size: 1.75rem; line-height: 1.2; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

nav {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  min-height: 56px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
nav a { display: inline-flex; align-items: center; min-height: 44px; }
nav .brand { font-weight: 700; color: var(--fg); text-decoration: none; }
nav form { display: block; margin-left: auto; }

main { max-width: 760px; margin: 0 auto; padding: 24px 16px; }

form { display: flex; flex-direction: column; gap: 12px; }
form > button { align-self: flex-start; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
label:has(> input[type="checkbox"]) { flex-direction: row; align-items: center; gap: 8px; min-height: 44px; }

input, select, textarea {
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 44px;
}
input[type="checkbox"] { min-height: 0; width: 20px; height: 20px; }
input[type="file"] { padding: 8px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.875rem; color: var(--muted); font-weight: 600; }

button {
  font: inherit;
  font-weight: 500;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  min-height: 44px;
  min-width: 44px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.link { background: none; border: none; color: var(--accent); padding: 0 4px; text-decoration: underline; }

.error { color: var(--error); background: var(--error-bg); padding: 8px 12px; border-radius: 8px; }
.warn { color: var(--warn); background: var(--warn-bg); padding: 8px 12px; border-radius: 8px; }
.muted { color: var(--muted); }
.actions { display: flex; flex-flow: row wrap; align-items: center; gap: 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin: 16px 0; }
.card > :first-child { margin-top: 0; }
.copy { display: flex; flex-direction: row; gap: 8px; }
.copy input { flex: 1; min-width: 0; }

dialog {
  border: none;
  border-radius: 12px;
  padding: 24px;
  background: var(--card);
  color: var(--fg);
  max-width: min(420px, calc(100vw - 32px));
  text-align: center;
}
dialog::backdrop { background: rgb(0 0 0 / 0.6); }
dialog .actions { justify-content: center; }
dialog img, .overlay img { display: block; margin: 0 auto; width: 240px; height: 240px; image-rendering: pixelated; background: #fff; }
.join { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.875rem; user-select: all; overflow-wrap: anywhere; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(0 0 0 / 0.75);
}
.overlay .card { max-width: 420px; text-align: center; }

/* Display: the audience sees the slide only. */
body.display { background: var(--stage); height: 100vh; height: 100dvh; overflow: hidden; }
body.display main { max-width: none; height: 100%; padding: 0; display: grid; place-items: center; }
body.display canvas { display: block; }

/* Slide boxes: render.js puts a PDF canvas or a web page export's iframe in them. The
   iframe is the largest 16:9 box that fits; the export's player scales the slide to it.
   pointer-events: none keeps clicks, swipes and focus out of it, so keys stay ours. */
body.display main, .current, .upcoming .box { container-type: size; }
body.display iframe, .presenter iframe {
  display: block;
  border: 0;
  pointer-events: none;
  width: min(100cqw, 100cqh * 16 / 9);
  height: min(100cqh, 100cqw * 9 / 16);
}
#full {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: rgb(0 0 0 / 0.6);
  color: #fff;
  border-color: rgb(255 255 255 / 0.35);
  transition: opacity 0.4s;
}
body.idle { cursor: none; }
body.idle #full:not(:focus-visible) { opacity: 0; }

/* Presenter view: phone first, laptop from 900px. */
body.presenter {
  display: grid;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  gap: 12px;
  padding: 8px 16px 0;
  grid-template: "bar" auto "next" 35vh "notes" minmax(0, 1fr) "controls" auto / minmax(0, 1fr);
}
/* Rapid Prev/Next taps must not double-tap-zoom; pinch zoom still works. On every
   element, since the scrollable notes would otherwise get their own default. */
.presenter, .presenter * { touch-action: manipulation; }
.bar { grid-area: bar; display: flex; align-items: center; gap: 16px; font-variant-numeric: tabular-nums; }
#elapsed { font-size: 2rem; font-weight: 700; border: none; background: none; padding: 0 8px; }
#clock { font-size: 1.25rem; color: var(--muted); }
#pos { margin-left: auto; font-size: 1.25rem; font-weight: 600; }
.presenter .current { display: none; }
.upcoming { grid-area: next; display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
.upcoming h2 { margin: 0 0 4px; font-size: 0.875rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.current, .upcoming .box {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: 8px;
  background: var(--stage);
}
.presenter canvas { display: block; }
.notes { grid-area: notes; overflow-y: auto; white-space: pre-wrap; font-size: 20px; line-height: 1.5; padding-bottom: 8px; }
.controls {
  grid-area: controls;
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom, 0px));
  background: var(--bg);
}
#prev, #next-btn { flex: 1 1 calc(50% - 4px); min-height: 64px; font-size: 1.25rem; }
.controls .actions { flex: 1 1 100%; }
.controls .actions button { flex: 1; }

@media (min-width: 900px) {
  body.presenter {
    padding-top: 12px;
    grid-template:
      "bar bar" auto
      "current next" 32vh
      "current notes" minmax(0, 1fr)
      "controls controls" auto / minmax(0, 2fr) minmax(0, 1fr);
  }
  .presenter .current { display: grid; grid-area: current; }
  .notes { font-size: 22px; }
  #prev, #next-btn { flex: 0 0 auto; min-width: 140px; min-height: 48px; font-size: 1rem; }
  .controls .actions { flex: 0 0 auto; margin-left: auto; }
  .controls .actions button { flex: 0 0 auto; }
}
