/* ============================================================
 * theme.css —— 设计令牌 / 基础重置 / 通用控件
 * 主题：宣纸暖白 + 墨黑 + 朱砂（暗色模式随系统或手动切换）
 * ========================================================== */

:root {
  /* 色板 */
  --paper: #FBF9F4;
  --bg: #F2EFE7;
  --surface: #FFFFFF;
  --surface-2: #F7F4ED;
  --surface-3: #EDE9E0;
  --stage-bg: #E7E2D7;

  --ink: #1A1815;
  --ink-2: #514B42;
  --ink-3: #8A8375;
  --ink-4: #B3AC9E;

  --accent: #B1392C;
  --accent-2: #96302496;
  --accent-soft: #B1392C14;
  --jade: #3F6B54;
  --gold: #B08A45;

  --border: #1A18151A;
  --border-2: #1A18152E;
  --ring: #B1392C40;

  /* 字体 */
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro SC", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  --font-serif: "Songti SC", "STSong", "Source Han Serif SC", "Noto Serif SC",
    "PingFang SC", Georgia, serif;
  --font-mono: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, monospace;

  /* 尺度 */
  --r-xs: 6px;
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 20px;
  --r-xl: 28px;

  --sh-1: 0 1px 2px #1A18150A, 0 2px 8px #1A181508;
  --sh-2: 0 2px 6px #1A18150A, 0 12px 28px #1A18150F;
  --sh-3: 0 8px 20px #1A181514, 0 28px 64px #1A18151C;
  --sh-paper: 0 2px 4px #1A181512, 0 10px 24px #1A181514, 0 30px 60px #1A181512;

  --ease: cubic-bezier(.22, .61, .36, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --topbar-h: 62px;
  --maxw: 1280px;

  color-scheme: light;
}

[data-theme="dark"] {
  --paper: #171613;
  --bg: #100F0C;
  --surface: #1D1B17;
  --surface-2: #232019;
  --surface-3: #2B271F;
  --stage-bg: #0D0C0A;

  --ink: #F2EDE3;
  --ink-2: #C3BBAE;
  --ink-3: #918A7C;
  --ink-4: #6B655A;

  --accent: #DE5B4A;
  --accent-soft: #DE5B4A1F;
  --jade: #6FA98A;
  --gold: #D2AC68;

  --border: #F2EDE31A;
  --border-2: #F2EDE32E;
  --ring: #DE5B4A4D;

  --sh-1: 0 1px 2px #0008, 0 2px 8px #0006;
  --sh-2: 0 2px 6px #0008, 0 12px 28px #000A;
  --sh-3: 0 8px 20px #000A, 0 28px 64px #000C;
  --sh-paper: 0 2px 4px #0006, 0 14px 32px #000A, 0 40px 80px #0009;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 84px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
svg { display: block; }
::selection { background: var(--accent); color: #fff; }

/* 纸纹 */
.paper-grain {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  opacity: .045; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}
[data-theme="dark"] .paper-grain { opacity: .05; mix-blend-mode: screen; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 40px; padding: 0 16px; border-radius: var(--r-sm);
  font-size: 13.5px; font-weight: 550; letter-spacing: .01em;
  border: 1px solid transparent; white-space: nowrap;
  transition: transform .18s var(--ease), background .18s var(--ease),
    border-color .18s var(--ease), box-shadow .18s var(--ease), color .18s var(--ease);
}
.btn:active { transform: scale(.975); }
.btn-ico { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.btn-primary {
  background: var(--accent); color: #fff;
  box-shadow: 0 1px 2px #B1392C40, 0 6px 16px #B1392C26;
}
.btn-primary:hover { background: #9C3126; box-shadow: 0 2px 4px #B1392C4D, 0 10px 24px #B1392C33; transform: translateY(-1px); }

.btn-ghost {
  background: var(--surface); color: var(--ink-2);
  border-color: var(--border-2); box-shadow: var(--sh-1);
}
.btn-ghost:hover { color: var(--ink); border-color: var(--ink-4); background: var(--surface-2); transform: translateY(-1px); }

.btn-lg { height: 48px; padding: 0 22px; font-size: 15px; border-radius: var(--r); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn-xs { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px; color: var(--ink-2);
  border: 1px solid var(--border); background: var(--surface);
  transition: all .18s var(--ease);
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink-4); background: var(--surface-2); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn.sm svg { width: 15px; height: 15px; }

/* 主题按钮图标切换 */
#themeToggle .i-moon { display: none; }
[data-theme="dark"] #themeToggle .i-sun { display: none; }
[data-theme="dark"] #themeToggle .i-moon { display: block; }

/* ---------------- 通用小控件 ---------------- */
.eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 10px; border-radius: 100px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 12px; font-weight: 550; color: var(--ink-2);
  box-shadow: var(--sh-1);
}
.eyebrow .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: pulse 2.4s var(--ease) infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--accent-soft); }
  50% { box-shadow: 0 0 0 6px #B1392C0A; }
}

/* ---------------- Toast ---------------- */
.toasts {
  position: fixed; z-index: 200; bottom: 26px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 16px; border-radius: 100px;
  background: var(--ink); color: var(--paper);
  font-size: 13px; font-weight: 500; box-shadow: var(--sh-3);
  animation: toastIn .32s var(--ease-out) both;
}
.toast svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.toast.out { animation: toastOut .24s var(--ease) both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px) scale(.97); } }

/* ---------------- Modal ---------------- */
.modal { position: fixed; inset: 0; z-index: 150; display: grid; place-items: center; padding: 24px; }
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: #0B0A0880; backdrop-filter: blur(6px); animation: fade .2s var(--ease); }
.modal-panel {
  position: relative; width: min(720px, 100%); max-height: 82vh;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl);
  box-shadow: var(--sh-3); animation: modalIn .28s var(--ease-out);
}
@keyframes fade { from { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.98); } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-family: var(--font-serif); font-size: 17px; font-weight: 600; }
.modal-body { padding: 8px 10px 18px; overflow: auto; }

/* ---------------- 表单控件（面板内） ---------------- */
.ctl-select { position: relative; }
.ctl-select select {
  appearance: none; width: 100%; height: 34px; padding: 0 30px 0 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-xs);
  font-size: 13px; cursor: pointer; transition: all .16s var(--ease);
}
.ctl-select select:hover { border-color: var(--ink-4); }
.ctl-select select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.ctl-caret {
  position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; fill: none; stroke: var(--ink-3); stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round; pointer-events: none;
}

.ctl-seg {
  display: flex; gap: 2px; padding: 2px; border-radius: 9px;
  background: var(--surface-3); border: 1px solid var(--border);
}
.seg-btn {
  flex: 1; min-width: 0; height: 28px; padding: 0 6px; border-radius: 7px;
  font-size: 12.5px; color: var(--ink-3); white-space: nowrap;
  transition: all .18s var(--ease);
}
.seg-btn:hover { color: var(--ink-2); }
.seg-btn.is-on {
  background: var(--surface); color: var(--ink); font-weight: 600;
  box-shadow: var(--sh-1);
}

.ctl-range { display: flex; align-items: center; gap: 10px; }
.ctl-range input[type="range"] {
  flex: 1; appearance: none; height: 18px; background: none; cursor: pointer;
}
.ctl-range input[type="range"]::-webkit-slider-runnable-track {
  height: 3px; border-radius: 2px; background: var(--surface-3);
}
.ctl-range input[type="range"]::-webkit-slider-thumb {
  appearance: none; width: 14px; height: 14px; margin-top: -5.5px; border-radius: 50%;
  background: var(--ink); border: 2px solid var(--surface);
  box-shadow: var(--sh-1); transition: transform .16s var(--ease);
}
.ctl-range input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.18); }
.ctl-range input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.05); }
.ctl-range input[type="range"]::-moz-range-track { height: 3px; border-radius: 2px; background: var(--surface-3); }
.ctl-range input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%; background: var(--ink);
  border: 2px solid var(--surface); box-shadow: var(--sh-1);
}
.ctl-out {
  min-width: 48px; text-align: right; font-size: 12px; font-variant-numeric: tabular-nums;
  color: var(--ink-2); font-family: var(--font-mono);
}

.ctl-color { display: flex; align-items: center; gap: 8px; }
.color-well { position: relative; width: 34px; height: 26px; flex: none; }
.color-well input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.color-well span {
  display: block; width: 100%; height: 100%; border-radius: var(--r-xs);
  border: 1px solid var(--border-2); box-shadow: inset 0 1px 2px #0002;
}
.sw-row { display: flex; gap: 5px; }
.sw {
  width: 18px; height: 18px; border-radius: 5px; border: 1px solid var(--border-2);
  transition: transform .16s var(--ease);
}
.sw:hover { transform: scale(1.14); }
.sw.is-on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--accent); }

.ctl-switch { position: relative; display: inline-flex; }
.ctl-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.ctl-switch .track {
  display: block; width: 38px; height: 22px; border-radius: 100px;
  background: var(--surface-3); border: 1px solid var(--border);
  transition: all .22s var(--ease); position: relative;
}
.ctl-switch .knob {
  position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 3px #0003;
  transition: all .22s var(--ease);
}
.ctl-switch input:checked + .track { background: var(--accent); border-color: transparent; }
.ctl-switch input:checked + .track .knob { left: 19px; }
.ctl-switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--ring); }

.ctl-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 4px 10px; border-radius: 100px; font-size: 12px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-3);
  transition: all .16s var(--ease);
}
.chip:hover { border-color: var(--ink-4); color: var(--ink-2); }
.chip.is-on {
  background: var(--accent-soft); border-color: #B1392C40; color: var(--accent); font-weight: 600;
}

.ctl-text input {
  width: 100%; height: 34px; padding: 0 10px; font-size: 13px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-xs);
  transition: all .16s var(--ease);
}
.ctl-text input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
