:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-border: #e6e9f2;
  --text: #2b2f3a;
  --muted: #8a90a2;
  --accent: #6c5ce7;
  --accent-soft: #efeaff;
  --shadow: 0 8px 24px rgba(40, 44, 80, 0.10);
  --radius: 18px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* 平板横屏场景：禁止长按选中文字 / 禁止系统右键菜单 / 禁止文本缩放 */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  /* 整屏应用：页面本身永不滚动（避免滚动触发地址栏伸缩 → 画布反复重排缩放），
     各区域内容必须在一屏内排下 */
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  /* manipulation 只去掉双击延迟；全页防捏合由 shared/screen.css 负责 */
  touch-action: manipulation;
  display: flex;
  justify-content: center;
  padding: 0;
}

/* 整屏布局：顶栏 + 左画布铺满 + 右工具栏固定宽度；不使用 max-width 限制，
   以平板横屏（参考 MacBook Air 横屏逻辑尺寸）为基准铺满 */
.app {
  width: 100%;
  max-width: none;
  /* shared/screen.js 把未缩放时的实际可见高度传到 html/body，
     此处沿 100% 高度链填满，地址栏伸缩后仍保留画布内容。 */
  height: 100%;
  box-sizing: border-box;
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr 220px;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header"
    "workspace toolbar";
  gap: 14px;
}

/* ---------- Header ---------- */
.app-header {
  grid-area: header;
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
.app-header h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 1px;
}
.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Workspace / Canvas ---------- */
.workspace {
  grid-area: workspace;
  min-height: 0;
  height: 100%;
}
.canvas-wrap {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
/* 画布填满整个工作区（由 JS 动态设置内部分辨率以匹配显示尺寸，避免拉伸） */
#board {
  width: 100%;
  height: 100%;
  background: #ffffff;
  border-radius: var(--radius-sm);
  border: 2px dashed #d7dbe8;
  cursor: crosshair;
  touch-action: none; /* 画布内仍需禁止默认触摸手势以正常绘画 */
  display: block;
}

/* ---------- Toolbar ---------- */
.toolbar {
  grid-area: toolbar;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0; /* 保证右侧工具栏不撑破 grid 轨道 */
}
.tool-group {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.tool-group h2 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 1px;
}

/* Colors */
.colors {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  justify-content: center;
}
.color-dot {
  /* 宽格子（竖屏底栏）里圆点不能无限撑大：只设宽 + max-width，高度由 aspect-ratio 派生，仍是正圆 */
  width: 100%;
  max-width: 56px;
  justify-self: center;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}
.color-dot:hover { transform: scale(1.08); }
.color-dot.active {
  border-color: var(--accent);
  transform: scale(1.12);
}

/* Sizes */
.sizes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  justify-content: center;
}
.size-dot {
  /* 宽格子里格子本身也不无限撑大，居中显示 */
  width: 100%;
  max-width: 64px;
  justify-self: center;
  padding: 0; /* 清掉 button 默认 padding，否则预览点 % 宽度按更小的内容盒解析，圆点偏小 */
  aspect-ratio: 1;
  border-radius: 14px;
  border: 2px solid var(--panel-border);
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.12s ease, background 0.12s ease;
}
/* 笔画预览圆点：只设一个维度 + aspect-ratio:1，让另一维度自动等于它 → 永远是正圆。
   不能用“宽高分别设值 + 两轴 max-%”的组合（flex 子项下两轴百分比截断不一致，
   大尺寸会被压成椭圆）。
   width 用 min(var(--size), 78%)：小格子里大画笔的预览点按比例缩小，
   始终与格子边框留出空隙，不会溢出或挨着边框（手机竖屏/横屏小格子场景）。 */
.size-dot .dot {
  flex: none; /* 不被 flex 压缩/拉伸，保证尺寸稳定 */
  border-radius: 50%;
  background: var(--text);
  width: min(var(--size, 26px), 78%);
  height: auto;
  aspect-ratio: 1 / 1;
}
.size-dot.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Magic */
.magic-btn {
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, #ff6b6b, #feca57, #48dbfb, #ff9ff3);
  background-size: 300% 300%;
  animation: magicflow 6s ease infinite;
  transition: transform 0.12s ease;
}
.magic-btn:hover { transform: translateY(-1px); }
.magic-btn.active {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.magic-icon { font-size: 18px; }
@keyframes magicflow {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* Actions */
.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.action-btn {
  width: 100%;
  border: 1px solid var(--panel-border);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease;
}
.action-btn:hover { background: var(--accent-soft); transform: translateY(-1px); }
.action-btn:active { transform: translateY(0); }
#clear:hover { background: #ffeaea; color: #e03131; }

/* ---------- Responsive ---------- */

/* 竖屏（手机竖屏 / MacBook Air 竖屏）：画布在上铺满，工具栏用 2×2 网格放在底部，
   所有按钮无需横向滚动即可见，把剩余空间尽量留给画布 */
@media (orientation: portrait) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "header"
      "workspace"
      "toolbar";
    padding: 8px;
    gap: 8px;
  }
  .app-header { gap: 4px; }
  .app-header h1 { font-size: 20px; }
  .subtitle { display: none; }
  .canvas-wrap { padding: 6px; }
  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 8px;
    overflow: visible;
  }
  .tool-group {
    padding: 8px;
    min-width: 0;
  }
  .tool-group h2 { font-size: 11px; margin-bottom: 6px; }
  .colors { grid-template-columns: repeat(4, 1fr); gap: 5px; justify-content: center; }
  .color-dot { aspect-ratio: 1; border-width: 2px; }
  .sizes { grid-template-columns: repeat(4, 1fr); gap: 5px; justify-content: center; }
  .magic-btn { width: 100%; font-size: 13px; padding: 9px; border-radius: 10px; }
  .actions { flex-direction: row; gap: 5px; }
  .action-btn { flex: 1; font-size: 12px; padding: 8px 2px; border-radius: 10px; }
}

/* 小高度横屏：只压缩控件。可见高度由 shared/screen.js 跟随地址栏变化，
   不再用大视口高度制造页面滚动。平板横屏仍优先保留宽画布。 */
@media (orientation: landscape) and (max-height: 500px) {
  html, body { overflow: hidden; }
  .app {
    height: 100%;
    grid-template-columns: 1fr 150px; gap: 6px; padding: 6px;
  }
  .app-header h1 { font-size: 18px; }
  .subtitle { display: none; }
  .canvas-wrap { padding: 6px; }
  .toolbar { display: flex; flex-direction: column; gap: 6px; overflow: visible; }
  .tool-group { padding: 6px; min-width: 0; }
  .tool-group h2 { font-size: 10px; margin-bottom: 4px; }
  .colors { grid-template-columns: repeat(4, 1fr); gap: 3px; }
  .color-dot { border-width: 2px; }
  .sizes { grid-template-columns: repeat(4, 1fr); gap: 3px; }
  .magic-btn { font-size: 11px; padding: 6px; border-radius: 8px; }
  .actions { flex-direction: row; gap: 3px; }
  .action-btn { flex: 1; font-size: 10px; padding: 5px 1px; border-radius: 8px; }
}
