/* ---------- tokens ---------- */
:root {
  --ink: #14212B;
  --ink-2: #1C2C38;
  --ink-3: #24404F;
  --ink-border: #2E4A57;
  --accent: #E3A93B;
  --accent-ink: #4A3510;
  --accent-2: #4FB6A8;
  --paper: #FFFFFF;
  --page-bg: #F1F4F6;
  --text-hi: #EDF1F3;
  --text-mid: #9FB0B8;
  --text-dim: #6C808A;
  --danger: #E2665F;
  --font-display: 'Sora', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;
  --shadow-1: 0 1px 2px rgba(20, 33, 43, 0.08), 0 1px 1px rgba(20, 33, 43, 0.04);
  --shadow-2: 0 8px 24px rgba(20, 33, 43, 0.18);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text-hi);
  background: var(--page-bg);
  -webkit-font-smoothing: antialiased;
}
#app { height: 100vh; width: 100vw; overflow: hidden; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- shared buttons ---------- */
.btn {
  border: none;
  border-radius: var(--radius-m);
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-display);
  background: var(--ink-3);
  color: var(--text-hi);
}
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { filter: brightness(1.06); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-s);
  border: none;
  background: transparent;
  color: var(--text-mid);
}
.icon-btn:hover { background: var(--ink-3); color: var(--text-hi); }
.icon-btn--small { width: 26px; height: 26px; }
.icon { display: inline-flex; }

/* ================= HOME / GALLERY ================= */
.home { height: 100%; overflow-y: auto; background: var(--page-bg); }
.home__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 40px;
  background: var(--ink);
}
.home__brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  color: var(--text-hi);
  letter-spacing: -0.01em;
}
.home__brand-mark { color: var(--accent); }
.home__status {
  display: none;
  font-size: 13px;
  color: var(--ink-2);
  background: #FBEBC7;
  padding: 10px 40px;
}
.home__status--visible { display: block; }
.home__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 22px;
  padding: 32px 40px 60px;
  max-width: 1280px;
}
.home__loading, .home__empty { color: var(--text-dim); font-size: 14px; }
.home__empty { max-width: 420px; }
.home__empty-title { font-family: var(--font-display); font-weight: 600; font-size: 17px; color: #2A3A44; margin: 0 0 4px; }
.home__empty-body { margin: 0; color: #6C808A; }

.pres-card {
  position: relative;
  background: var(--paper);
  border-radius: var(--radius-m);
  overflow: hidden;
  box-shadow: var(--shadow-1);
  border: 1px solid #E1E7EA;
  transition: transform .12s ease, box-shadow .12s ease;
}
.pres-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.pres-card__open { display: block; width: 100%; padding: 0; border: none; background: none; }
.pres-card__thumb {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, #EAF0F2, #F7F2E4);
  position: relative;
}
.pres-card__thumb::after {
  content: '';
  position: absolute; left: 14px; top: 14px;
  width: 34%; height: 12%;
  background: rgba(20, 33, 43, .12);
  border-radius: 3px;
}
.pres-card__meta { padding: 10px 14px 14px; text-align: left; }
.pres-card__title {
  display: block;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  color: #21323C;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pres-card__date { display: block; font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.pres-card__delete {
  position: absolute; top: 8px; right: 8px;
  width: 28px; height: 28px;
  border: none; border-radius: 50%;
  background: rgba(20, 33, 43, .55);
  color: #fff;
  display: none;
  align-items: center; justify-content: center;
}
.pres-card:hover .pres-card__delete { display: flex; }
.pres-card__delete:hover { background: var(--danger); }

.loading-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--text-dim); font-size: 14px; background: var(--page-bg);
}

/* ================= EDITOR ================= */
.editor { display: flex; flex-direction: column; height: 100%; background: var(--page-bg); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--ink);
  padding: 8px 16px;
  gap: 16px;
  flex-shrink: 0;
}
.topbar__left, .topbar__center, .topbar__right { display: flex; align-items: center; gap: 6px; }
.topbar__left { flex: 1; min-width: 0; }
.title-input {
  background: transparent; border: 1px solid transparent;
  color: var(--text-hi);
  font-family: var(--font-display); font-weight: 600; font-size: 15px;
  padding: 6px 10px; border-radius: var(--radius-s);
  min-width: 120px; max-width: 360px;
}
.title-input:hover { border-color: var(--ink-border); }
.title-input:focus { border-color: var(--accent-2); background: var(--ink-2); outline: none; }
.save-status { font-size: 12px; color: var(--text-mid); padding: 0 6px; white-space: nowrap; }
.save-status--error { color: var(--danger); }
.save-status--saved, .save-status--offline { color: var(--accent-2); }

.editor__body { flex: 1; display: flex; min-height: 0; }

/* --- sidebar --- */
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--ink-2);
  border-right: 1px solid var(--ink-border);
  padding: 14px 12px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
}
.slide-list { display: flex; flex-direction: column; gap: 10px; }
.slide-thumb {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  border-radius: var(--radius-s);
  padding: 4px;
  border: 2px solid transparent;
  cursor: pointer;
}
.slide-thumb--active { border-color: var(--accent); background: rgba(227, 169, 59, .12); }
.slide-thumb__num { font-family: var(--font-mono); font-size: 11px; color: var(--text-mid); width: 14px; text-align: right; }
.slide-thumb__preview {
  position: relative;
  width: 100%; aspect-ratio: 16/9;
  border-radius: 4px; overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08);
}
.slide-thumb__delete {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border: none; border-radius: 50%;
  background: rgba(20,33,43,.7); color: #fff;
  display: none; align-items: center; justify-content: center;
}
.slide-thumb:hover .slide-thumb__delete { display: flex; }
.slide-thumb__delete:hover { background: var(--danger); }
.mini-el { position: absolute; white-space: pre-wrap; overflow-wrap: break-word; }

.add-slide-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px dashed var(--ink-border);
  border-radius: var(--radius-s);
  background: transparent; color: var(--text-mid);
  padding: 10px; font-size: 13px; font-weight: 600;
}
.add-slide-btn:hover { color: var(--text-hi); border-color: var(--accent-2); }

/* --- main column --- */
.editor__main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.insertbar {
  display: flex; align-items: center; gap: 4px;
  background: var(--ink-2);
  border-bottom: 1px solid var(--ink-border);
  padding: 6px 12px;
  flex-shrink: 0;
}
.insertbar__spacer { flex: 1; }
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: none; background: transparent; color: var(--text-mid);
  padding: 6px 10px; border-radius: var(--radius-s);
  position: relative;
}
.tool-btn:hover { background: var(--ink-3); color: var(--text-hi); }
.tool-btn__label { font-size: 9.5px; letter-spacing: .01em; }

.zoom-controls { display: flex; align-items: center; gap: 2px; color: var(--text-mid); }
.zoom-label { font-family: var(--font-mono); font-size: 12px; width: 42px; text-align: center; }

.contextbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--ink-2);
  border-bottom: 1px solid var(--ink-border);
  padding: 8px 12px;
  min-height: 20px;
  flex-shrink: 0;
}
.contextbar__hint { font-size: 12px; color: var(--text-dim); }
.contextbar__divider { width: 1px; align-self: stretch; background: var(--ink-border); margin: 0 4px; }
.font-select {
  background: var(--ink-3); color: var(--text-hi); border: 1px solid var(--ink-border);
  border-radius: var(--radius-s); padding: 6px 8px; font-size: 13px; max-width: 150px;
}
.num-input {
  width: 56px; background: var(--ink-3); color: var(--text-hi); border: 1px solid var(--ink-border);
  border-radius: var(--radius-s); padding: 6px 6px; font-size: 13px; font-family: var(--font-mono);
}
.color-input {
  width: 30px; height: 30px; padding: 2px; border: 1px solid var(--ink-border);
  border-radius: 50%; background: none; overflow: hidden;
}
.color-input::-webkit-color-swatch-wrapper { padding: 0; border-radius: 50%; }
.color-input::-webkit-color-swatch { border: none; border-radius: 50%; }
.labeled-color { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-mid); }
.toggle-btn {
  width: 30px; height: 30px; border-radius: var(--radius-s);
  border: 1px solid var(--ink-border); background: var(--ink-3); color: var(--text-hi);
  font-size: 13px; font-weight: 700;
}
.toggle-btn--active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* --- stage --- */
.stage-wrap {
  flex: 1;
  overflow: auto;
  display: flex; align-items: center; justify-content: center;
  background: repeating-linear-gradient(45deg, #E7ECEF 0 12px, #EDF1F3 12px 24px);
  padding: 24px;
}
.stage {
  position: relative;
  background: #fff;
  transform-origin: top left;
  box-shadow: var(--shadow-2);
}

.el {
  position: absolute;
  cursor: move;
}
.el--selected { outline: 2px solid var(--accent-2); }
.el--editing { cursor: text; outline: 2px solid var(--accent); }
.el__text {
  width: 100%; height: 100%;
  padding: 4px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  cursor: text;
}
.el__text:focus { outline: none; }
.el__shape { pointer-events: none; }
.el__image { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }

.handle {
  position: absolute;
  width: 10px; height: 10px;
  background: #fff;
  border: 2px solid var(--accent-2);
  border-radius: 2px;
  z-index: 10;
}
.handle--nw { left: -6px; top: -6px; cursor: nwse-resize; }
.handle--n  { left: 50%; top: -6px; margin-left: -5px; cursor: ns-resize; }
.handle--ne { right: -6px; top: -6px; cursor: nesw-resize; }
.handle--e  { right: -6px; top: 50%; margin-top: -5px; cursor: ew-resize; }
.handle--se { right: -6px; bottom: -6px; cursor: nwse-resize; }
.handle--s  { left: 50%; bottom: -6px; margin-left: -5px; cursor: ns-resize; }
.handle--sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.handle--w  { left: -6px; top: 50%; margin-top: -5px; cursor: ew-resize; }
.handle--rotate {
  left: 50%; top: -32px; margin-left: -10px;
  width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent-2); cursor: grab;
}

/* ================= PRESENT MODE ================= */
.present-overlay {
  position: fixed; inset: 0; background: #000;
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; cursor: pointer;
}
.present-frame {
  position: relative;
  width: min(96vw, calc(96vh * 16 / 9));
  aspect-ratio: 16 / 9;
  background: #fff;
  cursor: default;
  box-shadow: 0 0 60px rgba(0,0,0,.4);
}
.present-frame .el { cursor: default; }

/* ================= responsive ================= */
@media (max-width: 860px) {
  .sidebar { width: 150px; }
  .tool-btn__label { display: none; }
  .home__grid { padding: 24px 20px 48px; }
  .home__header { padding: 18px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .pres-card { transition: none; }
}