/* ==========================================================================
   roroto · 主题层（手写）
   theme.css 负责 178 个原子颜色令牌；本文件负责语义 token、控件、边角补丁。
   三套：dark（站点原有深空蓝，默认）/ mid（雾蓝灰中色）/ light（浅纸淡色）。
   选择器一律带 html[data-theme=...]，特异性高于 app.css 的 :root。
   ========================================================================== */

/* ---------- 淡色 ---------- */
html[data-theme="light"] {
  color-scheme: light;

  --bg: #f6f9fd;
  --bg-2: #eef4fb;
  --surface: #ffffff;
  --surface-2: #f3f8fd;
  --surface-3: #e8f1fa;

  --line: rgba(30, 70, 110, .13);
  --line-2: rgba(30, 70, 110, .22);
  --line-3: rgba(30, 70, 110, .38);

  --text: #17283e;
  --muted: #4c6280;
  --dim: #7387a1;

  --cyan: #0b7fb4;
  --cyan-2: #08628c;
  --blue: #2f5fd0;
  --gold: #a9740a;
  --violet: #6a4fc0;
  --coral: #c25a26;
  --ok: #0f7d58;
  --ok-2: #0b6b4b;
  --violet-2: #5a40ad;
  --warn: #a9740a;
  --danger: #c0392f;

  --brand: var(--cyan);
  --brand-hi: var(--cyan-2);
  --brand-soft: rgba(11, 127, 180, .10);

  --grad: linear-gradient(135deg, #38b4e6 0%, #0b7fb4 48%, #2f5fd0 100%);
  --grad-gold: linear-gradient(135deg, #e2aa34 0%, #b98314 55%, #8a5f06 100%);
  --grad-text: linear-gradient(100deg, #1b3552 0%, #0b6f9c 38%, #1179b0 68%, #3f63c8 100%);

  --shadow: 0 1px 2px rgba(24, 54, 88, .05), 0 18px 40px -26px rgba(24, 54, 88, .30);
  --shadow-lift: 0 26px 60px -30px rgba(24, 54, 88, .34);
}

/* ---------- 中色（雾蓝灰，比暗色亮、比淡色沉，长时间看更松） ---------- */
html[data-theme="mid"] {
  color-scheme: dark;

  --bg: #212b3a;
  --bg-2: #26313f;
  --surface: #2a3648;
  --surface-2: #303d51;
  --surface-3: #38465c;

  --line: rgba(170, 196, 232, .14);
  --line-2: rgba(170, 196, 232, .25);
  --line-3: rgba(170, 196, 232, .38);

  --text: #e9f0fa;
  --muted: #b0c0d4;
  --dim: #8799b1;

  --cyan: #4fbbe6;
  --cyan-2: #8adcf7;
  --blue: #7398f8;
  --gold: #f6c94f;
  --violet: #b1a2f8;
  --coral: #ffae85;
  --ok: #4cd7a5;
  --ok-2: #8ef0c4;
  --violet-2: #c6b9fa;
  --warn: #f5c262;
  --danger: #ff9a9a;

  --brand-soft: rgba(79, 187, 230, .14);

  --grad-text: linear-gradient(100deg, #f0f7ff 0%, #b4e6fb 38%, #7ccfef 68%, #9ab8f8 100%);
  --shadow: 0 1px 2px rgba(0, 0, 0, .22), 0 18px 40px -26px rgba(0, 0, 0, .62);
  --shadow-lift: 0 26px 60px -30px rgba(0, 0, 0, .7);
}

/* ---------- 通用边角补丁 ---------- */
html[data-theme="light"] body::before { opacity: .5; }
html[data-theme="light"] body::after { opacity: .6; }
html[data-theme="mid"] body::before { opacity: .7; }

/* 白→浅蓝的渐变字在浅纸上会消失，换成深墨→品牌青 */
html[data-theme="light"] .brand-tx,
html[data-theme="light"] .stat-i b:not(.gold) {
  background: linear-gradient(180deg, #1b3552, #0b6f9c);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
/* 实心渐变按钮压深后统一白字 */
html[data-theme="light"] .btn-p:not(:disabled),
html[data-theme="light"] .btn-gold:not(:disabled),
html[data-theme="light"] .hs-go { color: #fff; }

/* 抽屉 / 命令面板 / 缩略图放大层的遮罩必须压暗，不能跟着玻璃背景一起变白 */
html[data-theme="light"] .drawer-mask,
html[data-theme="light"] .pal-mask,
html[data-theme="light"] .pv-mask { background: rgba(16, 32, 52, .46); }
html[data-theme="mid"] .drawer-mask,
html[data-theme="mid"] .pal-mask,
html[data-theme="mid"] .pv-mask { background: rgba(10, 16, 26, .62); }

/* 加载圈在浅底上要有深色顶边 */
html[data-theme="light"] .spin,
html[data-theme="light"] .btn-g .spin,
html[data-theme="light"] .spin.on-dark { border-top-color: #0b6f9c; }

/* 签名板永远是白纸（用户签名要导出成白底，不随主题变） */
.sign-pad { color-scheme: light; }

/* 切换瞬间给主要面板一点过渡，平时不干扰各自的 hover 动画 */
html.th-anim body,
html.th-anim .hd,
html.th-anim .tool,
html.th-anim .card,
html.th-anim .wb,
html.th-anim .drawer,
html.th-anim .pal,
html.th-anim .inp,
html.th-anim .sel,
html.th-anim .ta,
html.th-anim .th-menu {
  transition: background-color .28s ease, color .28s ease, border-color .28s ease, box-shadow .28s ease;
}

/* ==========================================================================
   顶栏配色切换器：紧跟 On-device
   ========================================================================== */
.th-wrap { position: relative; flex: none; }
.th-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--brand-soft);
  color: var(--cyan-2);
  transition: border-color .18s, background .18s, color .18s, transform .18s;
}
.th-btn:hover { border-color: var(--line-3); background: var(--surface-3); color: var(--text); }
.th-btn:active { transform: scale(.94); }
.th-btn svg { display: block; }

.th-menu {
  position: absolute; top: calc(100% + 14px); right: 0;
  z-index: 70;
  width: 218px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  box-shadow: var(--shadow-lift);
  opacity: 0; visibility: hidden; transform: translateY(-6px) scale(.98);
  transform-origin: 100% 0;
  transition: opacity .18s, transform .18s, visibility .18s;
}
.th-menu.on { opacity: 1; visibility: visible; transform: none; }
.th-cap {
  padding: 6px 9px 9px;
  font-family: var(--mono); font-size: 10px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--dim);
}
.th-opt {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 7px 8px;
  border-radius: 10px;
  color: var(--muted); font-size: 13px; text-align: left;
  transition: background .16s, color .16s;
}
.th-opt:hover { background: var(--brand-soft); color: var(--text); }
.th-opt[aria-checked="true"] { color: var(--text); }
.th-nm { flex: 1; }
.th-ck { display: grid; place-items: center; width: 16px; color: var(--cyan); opacity: 0; }
.th-opt[aria-checked="true"] .th-ck { opacity: 1; }

/* 三档配色的小色板：底 + 卡片 + 强调点 */
.th-sw {
  position: relative; flex: none;
  width: 38px; height: 25px; border-radius: 6px;
  border: 1px solid rgba(128, 148, 180, .35);
  overflow: hidden;
}
.th-sw i { position: absolute; display: block; }
.th-sw i:nth-child(1) { left: 4px; top: 5px; width: 17px; height: 15px; border-radius: 3px; }
.th-sw i:nth-child(2) { right: 4px; top: 5px; width: 9px; height: 6px; border-radius: 2px; }
.th-sw i:nth-child(3) { right: 4px; bottom: 5px; width: 9px; height: 6px; border-radius: 2px; }
.th-sw-dark  { background: #05080f; }
.th-sw-dark  i:nth-child(1) { background: #111e33; }
.th-sw-dark  i:nth-child(2) { background: #2ea8da; }
.th-sw-dark  i:nth-child(3) { background: #f6c445; }
.th-sw-mid   { background: #212b3a; }
.th-sw-mid   i:nth-child(1) { background: #38465c; }
.th-sw-mid   i:nth-child(2) { background: #4fbbe6; }
.th-sw-mid   i:nth-child(3) { background: #f6c94f; }
.th-sw-light { background: #f6f9fd; }
.th-sw-light i:nth-child(1) { background: #ffffff; border: 1px solid #ccdbea; }
.th-sw-light i:nth-child(2) { background: #0b7fb4; }
.th-sw-light i:nth-child(3) { background: #b98314; }

@media (max-width: 880px) {
  .th-btn { width: 38px; height: 38px; }
  .th-menu { right: -2px; width: min(218px, calc(100vw - 28px)); }
}

/* ==========================================================================
   vramfit 桥接：vramfit.css 由上游同步生成（有 sha1 校验），不能手改，
   所以这里用更高特异性把它的语义变量接到当前主题。
   ========================================================================== */
html[data-theme="light"] .vfit {
  --panel: #ffffff;
  --ink: #17283e;
  --ink-2: #4c6280;
  --ink-3: #7387a1;
  --line: rgba(30, 70, 110, .13);
  --line-2: rgba(30, 70, 110, .22);
  --accent: #0b7fb4;
  --accent-soft: rgba(11, 127, 180, .10);
  --good: #0f7d58;   --good-soft: rgba(15, 125, 88, .10);
  --warn: #a9740a;   --warn-soft: rgba(169, 116, 10, .10);
  --bad: #c0392f;    --bad-soft: rgba(192, 57, 47, .10);
}
/* 只有实心按钮（无 class）是深青底、要白字；.ex / .ghost / .linkbtn
   这些带 class 的按钮是浅底 + 深色字，不能被一起刷成白色。 */
html[data-theme="light"] .vfit button:not([class]) { color: #fff; }
html[data-theme="light"] .vfit button.ghost { color: var(--ink-2); }
html[data-theme="light"] .vfit button.ghost:hover { color: var(--ink); }
html[data-theme="light"] .vfit button.linkbtn { color: var(--accent); }
html[data-theme="light"] .vfit #target,
html[data-theme="light"] .vfit .hwbar select,
html[data-theme="light"] .vfit .hwbar input { background: #f3f8fd; color: var(--ink); }

html[data-theme="mid"] .vfit {
  --panel: #2a3648;
  --ink: #e9f0fa;
  --ink-2: #b0c0d4;
  --ink-3: #8799b1;
  --line: rgba(170, 196, 232, .14);
  --line-2: rgba(170, 196, 232, .25);
  --accent: #4fbbe6;
  --accent-soft: rgba(79, 187, 230, .14);
}
html[data-theme="mid"] .vfit #target,
html[data-theme="mid"] .vfit .hwbar select,
html[data-theme="mid"] .vfit .hwbar input { background: #212b3a; color: var(--ink); }
