:root {
  color-scheme: dark;
  --bg: #000;
  --panel: rgba(28, 28, 32, 0.85);
  --panel-border: rgba(255, 255, 255, 0.1);
  --fg: #e8e8ec;
  --muted: #8a8a94;
  --accent: #7fd4ff;
  --danger: #ff6b7a;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  overscroll-behavior: none;
}

#app { height: 100%; }

/* ---- Buttons --------------------------------------------------------- */
.btn {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background 120ms, border-color 120ms, opacity 120ms;
}
.btn:hover { background: rgba(60, 60, 68, 0.9); }
.btn:disabled { opacity: 0.35; cursor: default; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.08); }
.btn.primary { background: var(--accent); color: #000; border-color: transparent; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.icon { width: 34px; height: 34px; padding: 0; font-size: 18px; display: grid; place-items: center; }
.btn.danger { color: var(--danger); }
.btn.clear, .btn.paper-btn { font-size: 13px; padding: 5px 10px; min-width: 56px; }
.btn.paper-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

/* ---- Editor ---------------------------------------------------------- */
.editor {
  position: fixed;
  inset: 0;
  background: var(--bg);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
.layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.layer.live {
  touch-action: none;
  cursor: crosshair;
}
.editor[data-theme="light"] { background: #fff; }
.editor[data-theme="light"] .hud.top .btn.ghost,
.editor[data-theme="light"] .zoom { color: #111; }
.editor[data-theme="light"] .hud.top .btn.ghost:hover { background: rgba(0, 0, 0, 0.06); }
.editor[data-theme="light"] .jot-id,
.editor[data-theme="light"] .save-state { color: #6a6a74; }
.editor[data-theme="light"] .save-state.error { color: #c0392b; }
.editor.erasing-mode .layer.live, .editor.erasing .layer.live { cursor: cell; }
/* Eraser swatch and the mobile color button while erasing: a white disc
   with a red diagonal. */
.eraser-swatch, .pick.erase .dot {
  background: #fff;
  position: relative;
  overflow: hidden;
}
.eraser-swatch::after, .pick.erase .dot::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -15%;
  width: 3px;
  height: 130%;
  background: #e5484d;
  transform: translateX(-50%) rotate(45deg);
  border-radius: 2px;
}
.pick.erase .dot { box-shadow: none; }
.theme-btn { font-size: 16px; }
.export-wrap, .add-wrap, .more-wrap { position: relative; }
.more-wrap { display: none; }
.more-menu {
  display: none;
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  min-width: 200px;
}
.more-wrap.open .more-menu { display: flex; }
.more-menu .btn { text-align: left; font-size: 15px; padding: 10px 14px; }
.drop-hint {
  position: absolute;
  inset: 16px;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 18px;
  pointer-events: none;
  background: rgba(127, 212, 255, 0.06);
}
.snapshot-dialog {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(420px, calc(100% - 32px));
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(14px);
}
.snapshot-dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.snapshot-dialog input, .snapshot-dialog select {
  font: inherit;
  font-size: 15px;
  color: var(--fg);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 10px;
}
.snapshot-dialog .row { display: flex; justify-content: flex-end; gap: 8px; }
.export-menu, .add-menu {
  display: none;
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}
.export-wrap.open .export-menu, .add-wrap.open .add-menu { display: flex; }
.export-menu .btn, .add-menu .btn { min-width: 72px; text-align: center; white-space: nowrap; }
.editor.pan-ready .layer.live { cursor: grab; }
.editor.panning .layer.live { cursor: grabbing; }

.hud {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  padding: max(10px, env(safe-area-inset-top)) 12px 12px;
}
.hud > * { pointer-events: auto; }
.hud.top { top: 0; }
.hud.bottom {
  bottom: 0;
  justify-content: center;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
}
.spacer { flex: 1; pointer-events: none; }
.jot-name {
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 4px 8px;
  min-width: 6ch;
  max-width: 40ch;
  outline: none;
}
.jot-name:hover { border-color: var(--panel-border); color: var(--fg); }
.jot-name:focus { border-color: var(--accent); color: var(--fg); background: rgba(0, 0, 0, 0.4); }
.editor[data-theme="light"] .jot-name:focus { background: rgba(255, 255, 255, 0.8); color: #111; }
.editor[data-theme="light"] .jot-name:hover { color: #111; }
.save-state { font-size: 12px; color: var(--muted); }
.save-state.error { color: var(--danger); }
.zoom { font-variant-numeric: tabular-nums; min-width: 60px; text-align: center; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.divider { width: 1px; height: 22px; background: var(--panel-border); margin: 0 4px; }
.group { display: flex; align-items: center; gap: 6px; }
.swatches, .sizes { display: flex; gap: 6px; }

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--c);
  cursor: pointer;
  padding: 0;
  transition: transform 120ms, border-color 120ms;
}
.swatch:hover { transform: scale(1.1); }
.swatch[aria-checked="true"] {
  border-color: #fff;
  box-shadow: 0 0 0 2px #000 inset;
  transform: scale(1.12);
}

.size {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}
.size span {
  width: var(--d);
  height: var(--d);
  border-radius: 50%;
  background: var(--fg);
}
.size[data-size="highlight"] span { width: 18px; height: 8px; border-radius: 3px; opacity: 0.6; }
.pick-size.highlight .dot { width: 18px; height: 8px; border-radius: 3px; opacity: 0.6; }
.size:hover { background: rgba(255, 255, 255, 0.08); }
.size[aria-checked="true"] { border-color: var(--accent); }

.editor.ui-hidden .hud { display: none; }
.toast {
  position: absolute;
  left: 50%;
  top: 18px;
  transform: translateX(-50%) translateY(-8px);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--fg);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms, transform 180ms;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.electron.platform-darwin .toast { top: 52px; }

.btn.icon.pick { display: none; position: relative; }
.pick .dot {
  display: block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 2px #000 inset;
}
.pick-size .dot { width: var(--d, 8px); height: var(--d, 8px); background: var(--fg); box-shadow: none; }

/* Narrow screens (phones, anything under an iPad mini): the toolbar spans
   the viewport in a single row; color and size become popover pickers. */
@media (max-width: 743px) {
  .hud.bottom { padding: 0; }
  .toolbar {
    width: 100%;
    justify-content: space-between;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding: 8px 10px max(8px, env(safe-area-inset-bottom));
    gap: 6px;
  }
  .toolbar > .divider, .group .divider { display: none; }
  .group { position: relative; gap: 6px; }
  .btn.icon.pick { display: grid; place-items: center; width: 44px; height: 44px; }
  .popover {
    display: none;
    position: absolute;
    bottom: calc(100% + 10px);
    left: 0;
    padding: 10px;
    gap: 10px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }
  .group.open > .popover { display: flex; }
  .swatch { width: 38px; height: 38px; }
  .size { width: 42px; height: 42px; }
  .btn.icon { width: 44px; height: 44px; font-size: 20px; }
  /* Secondary actions fold into the ⋯ menu. */
  .group.actions > .paper-btn, .group.actions > .theme-btn, .group.actions > .add-wrap,
  .group.actions > .export-wrap, .group.actions > .clear { display: none; }
  .more-wrap { display: block; }
  .more-menu { left: auto; right: 0; }
  .group.actions .divider { display: none; }
  .hud.top { gap: 6px; }
  .zoom { min-width: 48px; }
}

.update-banner {
  position: fixed;
  right: 16px;
  bottom: 88px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  font-size: 14px;
  color: var(--fg);
}

/* ---- Home ------------------------------------------------------------ */
.home {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  line-height: 0;
}
.brand-wordmark { height: 28px; width: auto; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}
.empty {
  grid-column: 1 / -1;
  color: var(--muted);
  text-align: center;
  padding: 80px 20px;
  line-height: 1.6;
}
.card {
  background: #111115;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 120ms, transform 120ms;
}
.card:hover { border-color: rgba(255, 255, 255, 0.25); transform: translateY(-2px); }
.thumb { display: block; line-height: 0; }
.thumb canvas { width: 100%; height: auto; display: block; }
.meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 10px 14px;
  border-top: 1px solid var(--panel-border);
}
.meta-text { display: flex; flex-direction: column; gap: 2px; }
.name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.delete { font-size: 13px; color: var(--muted); }
.delete:hover { color: var(--fg); }

/* ---- Electron ---------------------------------------------------------- */
/* macOS uses a hidden-inset title bar. A full-width strip at the top is the
   window drag handle; everything else sits below it. */
.electron.platform-darwin .titlebar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 44px;
  z-index: 10;
  -webkit-app-region: drag;
}
.electron.platform-darwin .hud.top { top: 44px; padding-top: 0; }
.electron.platform-darwin .home { padding-top: 56px; }
