:root {
  color-scheme: light;
  --background: 48 30% 96%; --foreground: 30 8% 10%; --card: 45 25% 93%; --secondary: 45 22% 90%;
  --muted-foreground: 40 6% 39%; --accent: 217 84% 46%; --accent-foreground: 0 0% 98%; --border: 45 18% 85%;
  --bg: hsl(var(--background)); --fg: hsl(var(--foreground)); --tile: hsl(var(--card)); --sec: hsl(var(--secondary));
  --muted: hsl(var(--muted-foreground)); --acc: hsl(var(--accent)); --line: hsl(var(--border));
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --display: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --background: 30 8% 8%; --foreground: 45 25% 90%; --card: 30 8% 11%; --secondary: 30 8% 14%;
    --muted-foreground: 40 6% 60%; --accent: 217 90% 64%; --accent-foreground: 30 8% 8%; --border: 30 8% 20%;
  }
}
*, *::before, *::after { border-radius: 0 !important; box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 13.5px/1.5 var(--mono); -webkit-font-smoothing: antialiased; }
button, select, input, textarea { font: inherit; color: inherit; }
kbd { font: inherit; font-size: 11px; border: 1px solid var(--line); padding: 0 4px; background: var(--tile); }
code { font-family: var(--mono); }
.dim { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }
.section-heading { font-family: var(--display); font-size: 1.35rem; letter-spacing: -0.01em; font-weight: 700; margin: 0; }
.section-heading::before { content: "■ "; color: var(--acc); font-weight: 400; }
:focus-visible { outline: 1px solid var(--acc); outline-offset: 1px; }

.app { display: grid; grid-template-rows: auto auto 1fr auto; height: 100dvh; }
.bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); min-width: 0; }
.brand { font-family: var(--display); font-weight: 700; font-size: 17px; letter-spacing: -0.01em; margin-right: 4px; white-space: nowrap; }
.sq { color: var(--acc); font-weight: 400; }
.deck-title { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 30vw; }
.btn { background: transparent; border: 1px solid var(--line); padding: 4px 10px; cursor: pointer; white-space: nowrap; transition: background-color .2s, border-color .2s; }
.btn:hover { background: var(--sec); }
.btn.primary { background: var(--acc); color: hsl(var(--accent-foreground)); border-color: var(--acc); font-weight: 500; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger:hover { border-color: hsl(4 70% 47%); color: hsl(4 70% 52%); }
.sel { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); padding: 0 0 0 8px; }
.sel span { color: var(--muted); font-size: 12.5px; }
.sel select { background: var(--bg); border: 0; border-left: 1px solid var(--line); padding: 4px 6px; cursor: pointer; }

.tabs { display: none; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: 0; padding: 8px; color: var(--muted); cursor: pointer; }
.tabs button.on { color: var(--fg); box-shadow: inset 0 -1px 0 var(--acc); }

.split { display: grid; grid-template-columns: var(--left, 44%) 1px 1fr; min-height: 0; }
.pane { min-height: 0; min-width: 0; position: relative; }
.gutter { background: var(--line); cursor: col-resize; position: relative; }
.gutter::after { content: ""; position: absolute; inset: 0 -4px; }
#src {
  width: 100%; height: 100%; resize: none; border: 0; outline: none; background: var(--bg);
  padding: 18px 20px 40vh; font-size: 13.5px; line-height: 1.65; tab-size: 2; caret-color: var(--acc);
}
.editor-pane.dragging #src { background: var(--tile); }
.drop-hint { position: absolute; inset: 12px; border: 1px dashed var(--acc); display: none; place-items: center; color: var(--acc); pointer-events: none; }
.editor-pane.dragging .drop-hint { display: grid; }
.preview-pane { overflow: auto; background: var(--tile); }
.preview { display: flex; flex-direction: column; gap: 18px; padding: 20px; max-width: 980px; margin: 0 auto; }
.pv-item { display: grid; grid-template-columns: 28px 1fr; gap: 8px; align-items: start; cursor: pointer; }
.pv-item .n { color: var(--muted); font-size: 11px; text-align: right; padding-top: 2px; font-variant-numeric: tabular-nums; }
.pv-item .slide { outline: 1px solid var(--line); transition: outline-color .2s; }
.pv-item.cur .slide { outline: 1px solid var(--acc); }
.pv-item.cur .n { color: var(--acc); }
.pv-item .has-notes { display: block; margin-top: 4px; font-size: 11px; }

.status { display: flex; align-items: center; gap: 8px; padding: 5px 12px; border-top: 1px solid var(--line); font-size: 12px; white-space: nowrap; overflow: hidden; }
#saveState::before { content: "● "; color: hsl(142 55% 42%); }
#saveState.pending::before { color: hsl(38 90% 50%); }

/* present */
.stage { position: fixed; inset: 0; background: #000; z-index: 50; display: grid; place-items: center; cursor: none; }
.stage.cursor { cursor: default; }
.stage-frame { width: min(100vw, calc(100vh * 16 / 9)); }
.stage-frame .slide { animation: fade .25s ease-out; }
.stage.black .stage-frame { visibility: hidden; }
@keyframes fade { from { opacity: .4; } to { opacity: 1; } }
.stage-ui { position: fixed; left: 0; right: 0; bottom: 0; pointer-events: none; }
.progress { height: 3px; background: rgba(255,255,255,.08); }
.progress-fill { height: 100%; width: 0; background: hsl(217 90% 60%); transition: width .3s ease; }
.stage-hud { position: absolute; bottom: 10px; left: 14px; right: 14px; display: flex; gap: 14px; font-size: 12px; color: rgba(255,255,255,.75); opacity: 0; transition: opacity .3s; text-shadow: 0 0 4px #000; }
.stage-hud .dim { color: rgba(255,255,255,.5); }
.stage.cursor .stage-hud { opacity: 1; }
.overview { position: fixed; inset: 0; overflow: auto; background: hsl(30 8% 6%); padding: 32px; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; align-content: start; cursor: default; z-index: 2; }
.ov-item { cursor: pointer; color: rgba(255,255,255,.6); font-size: 11px; display: flex; flex-direction: column; gap: 6px; }
.ov-item .slide { outline: 1px solid rgba(255,255,255,.12); }
.ov-item.sel .slide { outline: 2px solid hsl(217 90% 62%); }
.ov-item.sel { color: #fff; }

/* presenter window */
body.presenter-mode .app { display: none; }
.presenter { position: fixed; inset: 0; display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; padding: 20px; background: var(--bg); }
.presenter[hidden] { display: none; }
.pv-label { color: var(--muted); font-size: 11px; margin-bottom: 6px; display: block; }
.pv-main, .pv-side { display: flex; flex-direction: column; min-height: 0; }
.pv-cur .slide, .pv-next .slide { outline: 1px solid var(--line); }
.pv-next { margin-bottom: 18px; }
.pv-timer { display: flex; gap: 18px; align-items: end; border: 1px solid var(--line); background: var(--tile); padding: 12px 14px; margin-bottom: 18px; }
.pv-big { font-family: var(--display); font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; display: block; line-height: 1; }
.pv-timer .btn { margin-left: auto; }
.pv-timer .btn + .btn { margin-left: 0; }
.pv-notes { flex: 1; overflow: auto; font-size: 17px; line-height: 1.55; border-top: 1px solid var(--line); padding-top: 10px; }
.pv-notes p { margin: 0 0 .7em; }
.pv-nav { display: flex; gap: 8px; padding-top: 12px; }
.pv-nav .btn { flex: 1; padding: 10px; }

/* dialogs */
.dlg { border: 1px solid var(--line); background: var(--bg); color: var(--fg); padding: 0; width: min(560px, 94vw); box-shadow: 0 25px 50px -12px rgb(0 0 0 / .35); }
.dlg::backdrop { background: rgb(0 0 0 / .35); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.dlg-foot { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.deck-list { list-style: none; margin: 0; padding: 6px 0; max-height: 55vh; overflow: auto; }
.deck-list li { display: flex; align-items: center; gap: 8px; padding: 8px 16px; cursor: pointer; }
.deck-list li:hover, .deck-list li:focus-visible { background: var(--tile); }
.deck-list li.cur .name::before { content: "▸ "; color: var(--acc); }
.deck-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-list .meta { color: var(--muted); font-size: 11px; white-space: nowrap; }
.deck-list .btn { padding: 1px 7px; font-size: 11px; }
.keys { border-collapse: collapse; margin: 8px 16px; width: calc(100% - 32px); }
.keys td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.keys td:first-child { white-space: nowrap; width: 1%; padding-right: 18px; }
#helpDlg p { margin: 12px 16px 16px; }

.print-deck { display: none; }
.toast { position: fixed; bottom: 40px; left: 50%; transform: translate(-50%, 8px); background: var(--fg); color: var(--bg); padding: 6px 12px; font-size: 12.5px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 100; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .tabs { display: flex; }
  .split { grid-template-columns: 1fr; }
  .gutter { display: none; }
  .split[data-tab="edit"] .preview-pane, .split[data-tab="preview"] .editor-pane { display: none; }
  .hide-sm, .deck-title, .sel span { display: none; }
  .sel { padding: 0; } .sel select { border-left: 0; }
  .bar { flex-wrap: wrap; }
  .presenter { grid-template-columns: 1fr; overflow: auto; }
  .preview { padding: 12px; }
}
@media print {
  .app, .stage, .presenter, dialog, .toast { display: none !important; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
