/* ============================================================
   落沙 · Particle Sandbox — styles
   温暖暗色实验室美学：炭黑底 + 琥珀点缀
============================================================ */

:root {
  --bg:        #0a0c10;
  --bg-soft:   #0e1116;
  --panel:     #141821;
  --panel-2:   #191e28;
  --line:      #262c38;
  --line-soft: #1c212b;
  --text:      #ece9e2;
  --muted:     #8b93a0;
  --faint:     #5b6270;
  --accent:    #ff9b45;
  --accent-2:  #ffb26b;
  --accent-soft: rgba(255, 155, 69, .13);
  --accent-line: rgba(255, 155, 69, .45);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC",
          "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
  --r: 14px;
  --ease: cubic-bezier(.16, 1, .3, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 18% -8%, rgba(255, 155, 69, .055), transparent 60%),
    radial-gradient(900px 600px at 100% 110%, rgba(70, 110, 180, .045), transparent 55%),
    var(--bg);
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased;
}

/* 全屏噪点（固定层，pointer-events 关闭） */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 22px;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line-soft);
  flex: none;
}

.brand { display: flex; align-items: center; gap: 12px; }

.logo { width: 34px; height: 34px; filter: drop-shadow(0 2px 10px rgba(255, 155, 69, .25)); }
.logo rect, .logo circle { animation: floaty 3.4s ease-in-out infinite; }
.logo .l2 { animation-delay: .25s; }
.logo .l3 { animation-delay: .5s; }
.logo .l4 { animation-delay: .75s; }

@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-2.2px); }
}

.brand-text h1 {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: .14em;
  line-height: 1.05;
  background: linear-gradient(180deg, #fff 0%, #d9d5cc 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-sub {
  display: block;
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .3em;
  color: var(--faint);
}

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

.stat {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 9px;
}
.stat-label { font-size: 10px; letter-spacing: .16em; color: var(--faint); }
.stat-value { font-size: 12.5px; color: var(--accent-2); min-width: 34px; text-align: right; }

/* ---------- 主布局 ---------- */
.main {
  display: flex;
  gap: 20px;
  padding: 20px 4px 10px;
  flex: 1;
  min-height: 0;
}

/* ---------- 侧栏 ---------- */
.tools {
  width: 252px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(24, 29, 40, .92), rgba(16, 19, 26, .92));
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: 0 18px 50px -24px rgba(0, 0, 0, .7);
  backdrop-filter: blur(8px);
}

.tool-sec { padding: 8px 0; }
.tool-sec + .tool-sec { border-top: 1px solid var(--line-soft); }

.sec-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--text);
  margin-bottom: 10px;
}
.sec-sub {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: .22em;
  color: var(--faint);
}

/* 笔刷 */
.brush-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }

.brush-row input[type="range"] {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) var(--fill, 23%), var(--line) var(--fill, 23%));
  outline: none;
  cursor: pointer;
}
.brush-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #ffd9b0, var(--accent) 55%, #c96f24);
  border: 1px solid rgba(255, 255, 255, .25);
  box-shadow: 0 0 0 4px rgba(255, 155, 69, .12), 0 2px 6px rgba(0, 0, 0, .5);
  transition: box-shadow .2s var(--ease);
}
.brush-row input[type="range"]::-webkit-slider-thumb:hover { box-shadow: 0 0 0 6px rgba(255, 155, 69, .18), 0 2px 6px rgba(0, 0, 0, .5); }
.brush-row input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #ffd9b0, var(--accent) 55%, #c96f24);
  border: 1px solid rgba(255, 255, 255, .25);
  box-shadow: 0 0 0 4px rgba(255, 155, 69, .12);
}

.size {
  min-width: 34px;
  text-align: center;
  font-size: 13px;
  color: var(--accent-2);
  padding: 4px 6px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

/* 当前元素 */
.current {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 11px;
  background: var(--bg-soft);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  font-size: 13px;
}
.current .dot { width: 12px; height: 12px; border-radius: 50%; box-shadow: 0 0 10px rgba(255, 155, 69, .5); }
.current kbd { margin-left: auto; }

/* 元素面板 */
.palette {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.mat {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-family: var(--sans);
  font-size: 12.5px;
  cursor: pointer;
  transition: background .18s var(--ease), border-color .18s var(--ease), transform .12s var(--ease);
  user-select: none;
  -webkit-user-select: none;
  text-align: left;
}
.mat:hover { background: rgba(255, 255, 255, .05); }
.mat:active { transform: scale(.965); }
.mat .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mat .dot {
  flex: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, .28), 0 1px 3px rgba(0, 0, 0, .45);
}
.mat.glow .dot { box-shadow: inset 0 1px 1px rgba(255, 255, 255, .35), 0 0 9px var(--glow, rgba(255, 150, 50, .6)); }

.mat kbd {
  flex: none;
  min-width: 17px;
  text-align: center;
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1.5px 4px;
}

.mat.on {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
.mat.on .name { color: var(--accent-2); font-weight: 600; }
.mat.on kbd { color: var(--accent-2); border-color: var(--accent-line); }

/* 橡皮擦特殊样式 */
.mat.erase .dot {
  border: 1.5px dashed rgba(255, 120, 105, .8);
  background: transparent;
  box-shadow: none;
}

/* 操作按钮 */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.act {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 4px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 12px;
  cursor: pointer;
  transition: background .18s var(--ease), border-color .18s var(--ease), transform .12s var(--ease);
}
.act svg { width: 15px; height: 15px; }
.act:hover { background: linear-gradient(180deg, #1e2530, #171c26); border-color: #333b4a; }
.act:active { transform: scale(.96); }
.act:focus-visible, .mat:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#btnPause.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-2); }

/* 速度 */
.speed {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}
.speed button {
  padding: 7px 0;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
  transition: all .18s var(--ease);
}
.speed button:hover { color: var(--text); border-color: #333b4a; }
.speed button.on {
  color: var(--accent-2);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

/* ---------- 舞台 ---------- */
.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 1060px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid #2a3140;
  box-shadow:
    0 30px 80px -24px rgba(0, 0, 0, .72),
    0 6px 18px -8px rgba(0, 0, 0, .55);
  transform: translateZ(0);
}
.canvas-wrap::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .12), transparent);
  z-index: 3;
  pointer-events: none;
}

#view {
  display: block;
  width: 100%;
  height: auto;
  background: #0b0e13;
  cursor: crosshair;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.vignette {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .035), transparent 9%),
    radial-gradient(118% 105% at 50% 42%, transparent 58%, rgba(4, 5, 8, .42) 100%);
}

/* 笔刷指示圈 */
.brush {
  position: absolute;
  z-index: 4;
  display: none;
  border: 1px solid rgba(255, 255, 255, .55);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .4), inset 0 0 6px rgba(0, 0, 0, .25);
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.brush.show { display: block; }
.brush.erase { border: 1.5px dashed rgba(255, 118, 102, .85); }

/* 移动端提示（桌面隐藏） */
.m-hint {
  display: none;
  font-size: 12px;
  color: var(--faint);
  user-select: none;
}

/* 提示条 */
.hints {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
}
.hints .sep { color: var(--faint); margin: 0 3px; }
.hints .dim { color: var(--faint); font-size: 11.5px; }

kbd {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1.5px 6px;
}

/* 页脚 */
.foot {
  flex: none;
  text-align: center;
  padding: 4px 0 16px;
  font-size: 11px;
  letter-spacing: .08em;
  color: var(--faint);
}

/* ---------- 入场动画 ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.topbar { animation: rise .6s var(--ease) both; }
.tools  { animation: rise .6s var(--ease) .08s both; }
.stage  { animation: rise .6s var(--ease) .16s both; }

.act, .mat, .speed button, .brush-row input[type="range"] {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .main {
    flex-direction: column-reverse;
    gap: 12px;
    padding: 12px 0 0;
  }

  /* 底部悬浮工具栏 */
  .tools {
    position: sticky;
    bottom: 0;
    z-index: 20;
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    background: linear-gradient(180deg, rgba(23, 27, 37, .96), rgba(13, 16, 22, .98));
    backdrop-filter: blur(14px);
    box-shadow: 0 -20px 44px -20px rgba(0, 0, 0, .85);
  }
  .tool-sec { padding: 0; }
  .tool-sec + .tool-sec { border-top: none; }
  .sec-title { display: none; }

  /* 第一行：元素横滑条 */
  .sec-palette { order: 1; width: 100%; }
  .palette {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 0 8px;
    scrollbar-width: thin;
    scroll-snap-type: x proximity;
  }
  .palette::-webkit-scrollbar { height: 4px; }
  .mat {
    flex: none;
    min-width: 64px;
    min-height: 44px;
    justify-content: center;
    gap: 7px;
    padding: 9px 13px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, .035);
    scroll-snap-align: start;
  }
  .mat .dot { width: 15px; height: 15px; }
  .mat kbd { display: none; }

  /* 第二行：笔刷 + 速度 */
  .sec-brush { order: 2; flex: 1 1 170px; min-width: 130px; }
  .sec-speed { order: 3; flex: 0 0 auto; }
  .brush-row { margin-bottom: 0; }
  .size { min-width: 30px; font-size: 12px; padding: 6px 4px; }
  .current { display: none; }
  .speed button { padding: 9px 12px; }

  /* 第三行：操作按钮（图标+小字） */
  .sec-actions { order: 4; width: 100%; }
  .actions { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .act { min-height: 44px; padding: 10px 0; }
  .act span { font-size: 11px; }
  .act svg { width: 17px; height: 17px; }

  .hints { display: none; }
  .m-hint { display: flex; }
  .stage { gap: 10px; }
}

@media (max-width: 560px) {
  .app { padding: 0 10px calc(env(safe-area-inset-bottom)); }
  .topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .brand-sub { display: none; }
  .stat { padding: 4px 9px; }
  .stat-label { display: none; }
  .canvas-wrap { border-radius: 14px; }
}

/* 横屏矮屏微调 */
@media (max-height: 500px) and (orientation: landscape) {
  .tools { padding-top: 8px; padding-bottom: 8px; }
  .mat { min-height: 38px; padding: 6px 11px; }
  .act { min-height: 38px; padding: 7px 0; }
  .palette { padding-bottom: 4px; }
}

/* ---------- 无障碍：减少动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .logo rect, .logo circle { animation: none; }
}
