:root {
  --bg: #eef1f5;
  --bar: #ffffff;
  --ink: #1f2328;
  --muted: #667085;
  --line: #d9dee5;
  --hover: #f1f3f6;
  --accent: #1e66f5;
  --accent-soft: #e3ecff;
  --danger: #e03131;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; }
button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { opacity: .35; cursor: default; }
svg { width: 22px; height: 22px; display: block; flex: none; }
.muted { color: var(--muted); }

.icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  flex: none;
}
.icon.active { background: var(--accent-soft); color: var(--accent); }
.icon.danger { color: var(--danger); }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 600;
  white-space: nowrap;
  flex: none;
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (hover: hover) {
  .icon:not(:disabled):hover, .title:hover, .pagelabel:hover, .menu .item:hover { background: var(--hover); }
  .icon.active:hover { background: var(--accent-soft); }
  .btn:hover { filter: brightness(.97); }
}

/* ---------- home ---------- */
#home {
  max-width: 1100px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 40px max(20px, env(safe-area-inset-left));
}
.home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}
.home-head h1 { display: flex; align-items: center; gap: 12px; font-size: 26px; }
.row { display: flex; gap: 8px; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; font-size: 17px; }
.note { color: var(--muted); font-size: 13px; margin-top: 28px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.card {
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 0 0 1px var(--line);
  display: flex;
  flex-direction: column;
}
.card .thumbbtn { display: block; width: 100%; }
.card .thumb {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #f7f8fa;
  border-bottom: 1px solid var(--line);
}
.card .meta { padding: 10px 12px 0; min-width: 0; }
.card .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .sub { color: var(--muted); font-size: 13px; }
.card .actions { display: flex; justify-content: flex-end; padding: 2px 4px 4px; }
.card .actions .icon { width: 36px; height: 36px; color: var(--muted); }
.card .actions svg { width: 19px; height: 19px; }

/* ---------- board ---------- */
#board { position: fixed; inset: 0; display: flex; flex-direction: column; }
.bar {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bar);
  flex: none;
  padding: 6px max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left));
  overflow-x: auto;
  scrollbar-width: none;
}
.bar::-webkit-scrollbar { display: none; }
.bar.top { border-bottom: 1px solid var(--line); padding-top: max(6px, env(safe-area-inset-top)); }
.bar.bottom { border-top: 1px solid var(--line); padding-bottom: max(6px, env(safe-area-inset-bottom)); }
.tools { display: flex; align-items: center; gap: 2px; margin: 0 auto; }
.spacer { flex: 1; min-width: 8px; }
.sep { width: 1px; height: 26px; background: var(--line); margin: 0 6px; flex: none; }
.title {
  font-weight: 600;
  max-width: 28vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 8px 10px;
  border-radius: 8px;
}
.pagelabel {
  min-width: 60px;
  padding: 8px 6px;
  border-radius: 8px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  flex: none;
}

.rec-btn { color: var(--danger); border-color: #f1c4c4; margin: 0 4px; }
.rec-btn .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); }
.rectime {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  color: var(--danger);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.rectime::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  animation: blink 1s steps(2, start) infinite;
}
body.rec-paused .rectime::before { animation: none; opacity: .3; }
@keyframes blink { to { visibility: hidden; } }
.icon.stop { color: var(--danger); }

#stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: hidden;
}
#paper {
  position: relative;
  background: #fff;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .12);
  touch-action: none;
  cursor: crosshair;
}
#paper[data-tool="select"] { cursor: default; }
#paper[data-tool="hand"] { cursor: grab; }
#paper canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#texteditor {
  position: absolute;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  background: transparent;
  resize: none;
  overflow: hidden;
  white-space: pre;
  font-family: var(--font);
  -webkit-user-select: text;
  user-select: text;
}
.selbar {
  position: absolute;
  z-index: 5;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
  transform: translate(-50%, -100%);
}
.selbar.below { transform: translate(-50%, 0); }
.selbar .icon { width: 38px; height: 38px; }

.palette { display: flex; align-items: center; gap: 4px; }
.swatch {
  position: relative;
  width: 30px;
  height: 30px;
  margin: 0 1px;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid rgba(0, 0, 0, .15);
  flex: none;
  cursor: pointer;
}
.swatch.active { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }
.swatch.custom { background: conic-gradient(#e03131, #fab005, #2f9e44, #1e66f5, #7048e8, #e03131); }
.swatch.custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.sizes { display: flex; align-items: center; }
.sizes.disabled { opacity: .35; pointer-events: none; }
.size { width: 38px; height: 40px; display: grid; place-items: center; border-radius: 8px; }
.size span { display: block; border-radius: 50%; background: var(--ink); }
.size[data-size="0"] span { width: 6px; height: 6px; }
.size[data-size="1"] span { width: 11px; height: 11px; }
.size[data-size="2"] span { width: 18px; height: 18px; }
.size.active { background: var(--accent-soft); }
.size.active span { background: var(--accent); }

/* ---------- menus, drawer, dialog ---------- */
.menu {
  position: fixed;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 230px;
  padding: 6px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .2);
}
.menu.row { flex-direction: row; min-width: 0; }
.menu .item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 8px;
  text-align: left;
}

.drawer {
  position: fixed;
  z-index: 15;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 88vw);
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: -6px 0 30px rgba(0, 0, 0, .18);
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}
.drawer header { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 4px 18px; }
.drawer h2 { font-size: 18px; }
.drawer footer { padding: 12px 16px; border-top: 1px solid var(--line); }
.drawer footer .btn { width: 100%; justify-content: center; }
.bgpick { padding: 6px 16px 12px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chips button { padding: 6px 12px; border-radius: 16px; border: 1px solid var(--line); color: var(--ink); font-size: 14px; }
.chips button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.pagelist { flex: 1; overflow-y: auto; padding: 8px; -webkit-overflow-scrolling: touch; }
.pagecard { display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 10px; }
.pagecard.current { background: var(--accent-soft); }
.pagecard .go { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.pagecard .num { width: 18px; text-align: right; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.pagecard canvas { width: 100%; max-width: 190px; height: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.pagecard .ops { display: grid; grid-template-columns: 1fr 1fr; }
.pagecard .ops .icon { width: 34px; height: 34px; color: var(--muted); }
.pagecard .ops svg { width: 18px; height: 18px; }

dialog {
  border: 0;
  border-radius: 16px;
  padding: 20px;
  width: min(720px, 92vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(15, 20, 30, .5); }
dialog h2 { font-size: 19px; margin-bottom: 12px; }
dialog video { display: block; width: 100%; max-height: 60vh; aspect-ratio: 16 / 9; border-radius: 10px; background: #000; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

#toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 90vw;
  padding: 10px 18px;
  border-radius: 20px;
  background: #1f2328;
  color: #fff;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}
#toast.show { opacity: 1; }

/* Phones in landscape and other short screens */
@media (max-height: 520px) {
  .bar { padding-top: 3px; padding-bottom: 3px; }
  .bar.top { padding-top: max(3px, env(safe-area-inset-top)); }
  .bar.bottom { padding-bottom: max(3px, env(safe-area-inset-bottom)); }
  .icon, .size { width: 36px; height: 36px; }
  .btn { height: 34px; padding: 0 12px; }
  .swatch { width: 26px; height: 26px; }
  #stage { padding: 6px; }
}
@media (max-width: 760px) {
  .title { display: none; }
  .home-head h1 { font-size: 22px; }
}

/* ---------- v2 additions ---------- */
body.drive-off .drive-only { display: none !important; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; margin-top: 10px; }
.btn.small svg { width: 16px; height: 16px; }
.btn.danger-text { color: var(--danger); }

.section-title { font-size: 17px; margin: 32px 0 12px; }
.reclist { display: flex; flex-direction: column; gap: 8px; }
.recrow {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 14px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 0 0 1px var(--line);
}
.recrow > svg { color: var(--muted); }
.recrow .info { flex: 1; min-width: 0; }
.recrow .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recrow .sub { color: var(--muted); font-size: 13px; }
.recrow .badge { color: #b54708; font-weight: 600; }
.recrow .icon { width: 36px; height: 36px; color: var(--muted); }

#stage { position: relative; }
.zoomctl {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: 12px;
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, .94);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
  z-index: 4;
}
.zoomctl .icon { width: 34px; height: 34px; }
.zoomctl svg { width: 18px; height: 18px; }
.zoomlabel { min-width: 52px; height: 34px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.menurow { display: flex; align-items: center; gap: 2px; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }
.menu .item .tick { margin-left: auto; visibility: hidden; color: var(--accent); }
.menu .item.on .tick { visibility: visible; }

.drive-result {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
  font-size: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
}
.drive-result a { color: var(--accent); font-weight: 600; }
.dlg-actions { flex-wrap: wrap; align-items: center; }

dialog.busy { width: auto; min-width: 260px; text-align: center; padding: 28px 32px 20px; }
dialog.busy p { margin: 14px 0 0; }
.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto;
  border-radius: 50%;
  border: 4px solid var(--accent-soft);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Presentation mode: toolbars hidden, a small floating toolbar instead. */
.mini { display: none; }
body.presenting .bar { display: none; }
body.presenting #stage { padding: 0; background: #0e1013; }
body.presenting #paper { box-shadow: none; }
body.presenting .zoomctl { top: 12px; bottom: auto; opacity: .85; }
body.presenting .mini {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  max-width: calc(100vw - 16px);
  padding: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  background: rgba(255, 255, 255, .96);
  border-radius: 16px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .3);
}
body.presenting .mini.top { top: max(14px, env(safe-area-inset-top)); bottom: auto; }
.mini .mini-body { display: flex; align-items: center; gap: 2px; }
.mini.collapsed .mini-body { display: none; }
.mini .swatch { width: 26px; height: 26px; }
.mini .rec-btn { height: 34px; padding: 0 12px; }
.mini-page { min-width: 44px; font-size: 13px; }
