/* ============================================================
   base.css — 重置、设计 token、深浅主题、画布层
   ============================================================ */

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", Roboto, Helvetica, Arial, sans-serif;
  font-size: calc(var(--s) * 14px);
  line-height: 1.5;
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- 设计 token ---------- */
:root {
  /* UI 全局缩放,由 JS 依窗口尺寸设定 */
  --s: 1;

  --radius: calc(var(--s) * 10px);
  --radius-lg: calc(var(--s) * 16px);
  --gap: calc(var(--s) * 12px);

  --accent: #5e9fe8;
  --accent-soft: rgba(94, 159, 232, 0.16);
  --danger: #e97366;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* 深色(默认) */
html[data-theme="dark"] {
  --canvas: #191919;
  --surface: rgba(34, 34, 34, 0.72);
  --surface-solid: #232323;
  --raised: rgba(255, 255, 255, 0.07);
  --raised-strong: rgba(255, 255, 255, 0.12);
  --text: #ffffff;
  --text-dim: rgba(255, 255, 255, 0.62);
  --text-faint: rgba(255, 255, 255, 0.38);
  --border: rgba(255, 255, 255, 0.12);
  --border-soft: rgba(255, 255, 255, 0.07);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 40px rgba(0, 0, 0, 0.45);
  --grid-minor: rgba(255, 255, 255, 0.055);
  --grid-major: rgba(255, 255, 255, 0.11);
  --marquee: #7fb8f2;
  --cursor-ring: rgba(255, 255, 255, 0.9);
  --cursor-ring-alt: rgba(0, 0, 0, 0.55);
}

/* 浅色 */
html[data-theme="light"] {
  --canvas: #ffffff;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --raised: rgba(0, 0, 0, 0.05);
  --raised-strong: rgba(0, 0, 0, 0.09);
  --text: #2c2c2b;
  --text-dim: #7d7a75;
  --text-faint: #a8a5a0;
  --border: rgba(0, 0, 0, 0.1);
  --border-soft: rgba(0, 0, 0, 0.06);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 10px 32px rgba(0, 0, 0, 0.09);
  --grid-minor: rgba(0, 0, 0, 0.055);
  --grid-major: rgba(0, 0, 0, 0.12);
  --accent: #2783de;
  --accent-soft: rgba(39, 131, 222, 0.12);
  --marquee: #2783de;
  --cursor-ring: rgba(0, 0, 0, 0.75);
  --cursor-ring-alt: rgba(255, 255, 255, 0.9);
}

/* ---------- 画布层 ---------- */
#stage {
  position: fixed;
  inset: 0;
  background: var(--canvas);
  transition: background 0.25s var(--ease);
  contain: strict;
}

#stage canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  pointer-events: none;
}

/* 已定稿笔迹层使用超采样缓冲:元素比视口更大,由 JS 定位 */
#layer-static { transform-origin: 0 0; will-change: transform; }

#stage.is-drawing { cursor: none; }
#stage.is-panning { cursor: grabbing; }
#stage.is-zooming { cursor: ew-resize; }
#stage.is-sizing  { cursor: ew-resize; }
#stage.is-picking { cursor: crosshair; }
#stage.is-moving  { cursor: move; }

/* 最左侧唤出热区 */
#edge-hot {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: calc(var(--s) * 14px);
  z-index: 40;
}
body:not(.autofold) #edge-hot { pointer-events: none; }

/* 无障碍 */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
