:root {
  --paper: #efeae0;
  --bar-bg: rgba(28, 26, 23, 0.5);
  --text: #f3eee2;
  --text-dim: rgba(243, 238, 226, 0.6);
  --accent: #16407a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;   /* 手机上禁止下拉刷新 / 橡皮筋，保持沉浸 */
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;   /* 让手指直接在画上落墨，不触发页面滚动/缩放 */
  cursor: crosshair;
  z-index: 0;
}

/* 沙盒层：叠在墨画布之上，但完全不吃事件（事件落到下面的 #stage） */
#sand-stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  pointer-events: none;
  z-index: 1;
  cursor: crosshair;
}
body.mode-sand #sand-stage { display: block; }

/* 控制条：底部一条，半透明、安静 */
#bar {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  max-width: calc(100vw - 24px);
  flex-wrap: wrap;
  justify-content: center;
  background: var(--bar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 13px;
  color: var(--text);
  font-size: 12px;
  user-select: none;
  z-index: 5;   /* 永远在沙盒层之上，保证可点 */
}

/* 物态切换（墨 / 沙）：分段胶囊 */
#mode-group { gap: 4px; padding: 3px; border-radius: 12px; background: rgba(255,255,255,0.08); }
.mode-btn {
  font: inherit;
  color: var(--text-dim);
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active { background: var(--accent); color: #fff; }

/* 沙元素组：默认隐藏，沙模式才显示 */
#sand-group { display: none; }
body.mode-sand #sand-group { display: flex; }
/* 墨专属控件：沙模式隐藏 */
body.mode-sand .ink-only { display: none; }
/* 墨色板：沙模式隐藏（沙模式只显示材料色，不再叠着墨的 5 色） */
body.mode-sand #ink-group { display: none; }

/* 元素圆点：浅色材料给描边，在深色工具条上才看得清 */
.ink.swatch {
  border: 1px solid rgba(20, 18, 15, 0.35);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.group { display: flex; gap: 8px; }

.ink {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--c);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.ink:hover { transform: scale(1.12); }
.ink.active { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,0.35); }
.ink.white { border-color: rgba(20, 18, 15, 0.4); }  /* 白按钮给深色描边，在浅纸与工具条上都看得清 */

.slider {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  white-space: nowrap;
}
.slider input[type="range"] { width: 72px; accent-color: var(--accent); }
#patience-val { min-width: 26px; color: var(--text); }

button.toggle, button.ghost {
  font: inherit;
  color: var(--text);
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 9px;
  padding: 5px 10px;
  cursor: pointer;
  transition: background 0.12s ease;
}
button.toggle:hover, button.ghost:hover { background: rgba(255,255,255,0.16); }
button.toggle.on { background: var(--accent); border-color: var(--accent); }
button.toggle.off { opacity: 0.7; }

/* 环境音：音量滑块仅在开启音景时显示 */
.sound-only { display: none; }
body.sound-on .sound-only { display: flex; }

#hint {
  position: fixed;
  left: 50%;
  top: max(22px, env(safe-area-inset-top));
  transform: translateX(-50%);
  margin: 0;
  z-index: 5;
  padding: 8px 16px;
  color: rgba(40, 36, 30, 0.55);
  background: rgba(239, 234, 224, 0.6);
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: 0.02em;
  pointer-events: none;
  transition: opacity 1.2s ease;
}
#hint.gone { opacity: 0; }

/* 沉浸模式：按 C 隐藏工具栏，静看 AI 作画；画面空白时给一行淡说明 */
body.bar-hidden #bar { display: none; }
body.bar-hidden #hint { display: none; }
#immersive-note {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  margin: 0;
  z-index: 4;
  padding: 6px 14px;
  color: rgba(40, 36, 30, 0.45);
  font-size: 12px;
  letter-spacing: 0.02em;
  background: rgba(239, 234, 224, 0.45);
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease;
  display: none;
}
body.bar-hidden #immersive-note { display: block; }
#immersive-note.show { opacity: 1; }

/* 录制按钮：录制态显示脉动的红点，直观提示“正在记录” */
#movie.rec { color: #b23b2e; font-weight: 600; }
#movie.rec::after {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 6px;
  border-radius: 50%;
  background: #b23b2e;
  vertical-align: middle;
  animation: movie-pulse 1s ease-in-out infinite;
}
@keyframes movie-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }
#movie:disabled { opacity: 0.6; cursor: default; }
