/* ════════════════════════════════════════════════════════════
    视觉氛围升级层 — 粒子 / 极光 / 光感按钮 / 悬浮卡片
   纯叠加样式：最后加载，只覆写表现，不改结构与逻辑。
   全部跟随皮肤 CSS 变量自动配色，低功耗模式自动关闭动效。
   ════════════════════════════════════════════════════════════ */

/* ── 粒子画布：钉在视口底层，内容区整体抬升一层 ── */
#fx-particles {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
/* 顶层拖尾根：直接挂在 documentElement，绕开应用内容的 stacking context。 */
#fx-overlay-root {
  position: fixed;
  inset: 0;
  z-index: 2147483646 !important;
  pointer-events: none !important;
  overflow: hidden;
  isolation: isolate;
  contain: strict;
  transform: translateZ(0);
  will-change: transform;
}

/* Ink particles sit above the engraved backdrop but below every page and control. */
html[data-theme="ink"] .main > #fx-particles {
  z-index: 0;
}
#fx-trail {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none !important;
  mix-blend-mode: normal;
}
.layout {
  position: relative;
  z-index: 1;
}

/* ── 环境极光：两层缓慢漂移的彩色光雾，透过玻璃卡片若隐若现 ──
   （sakura / simon-star 自带星空 ::after，让位给皮肤原生氛围；
     低功耗模式下保留静态光雾，仅停止漂移动画，视觉氛围不打折） */
html:not([data-theme="sakura"]):not([data-theme="simon-star"]):not([data-theme="ink"]):not([data-theme="gridnight"]) body::after {
  content: '';
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(38% 42% at 22% 18%,
      color-mix(in srgb, var(--primary) 9%, transparent) 0%, transparent 70%),
    radial-gradient(42% 46% at 82% 78%,
      color-mix(in srgb, var(--info, var(--primary)) 8%, transparent) 0%, transparent 70%),
    radial-gradient(30% 34% at 68% 12%,
      color-mix(in srgb, var(--warning, var(--primary)) 5%, transparent) 0%, transparent 70%);
  animation: fx-aurora-drift 36s ease-in-out infinite alternate;
}
@keyframes fx-aurora-drift {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg) scale(1); }
  50%  { transform: translate3d(-2.5%, 2%, 0) rotate(2deg) scale(1.06); }
  100% { transform: translate3d(2%, -2.5%, 0) rotate(-2deg) scale(1.03); }
}
/* 低功耗：光雾静止常驻，零持续功耗 */
html[data-low-power="true"] body::after { animation: none; }

/* ── 新皮肤上新徽标 ── */
.skin-item { position: relative; }
.skin-new-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fdf6e7;
  background: linear-gradient(135deg, #cd4b31 0%, #c9963c 100%);
  box-shadow: 0 2px 8px rgba(205, 75, 49, 0.45);
  pointer-events: none;
}

/* ═══════════════════════════════════════════════
   按钮：光泽扫过 + 悬浮发光 + 按压回弹
   ═══════════════════════════════════════════════ */
.btn {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
html:not([data-low-power="true"]):not([data-theme="ink"]) .btn::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(105deg,
    transparent 30%,
    rgba(255, 255, 255, 0.38) 50%,
    transparent 70%);
  transform: translateX(-160%) skewX(-12deg);
  transition: transform 0.01s;
  pointer-events: none;
}
html:not([data-low-power="true"]):not([data-theme="ink"]) .btn:hover::after {
  transform: translateX(160%) skewX(-12deg);
  transition: transform 0.75s cubic-bezier(0.22, 1, 0.36, 1);
}
.btn:hover {
  box-shadow:
    0 8px 28px color-mix(in srgb, var(--primary) 22%, transparent),
    0 2px 10px rgba(15, 23, 42, 0.10),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.btn:active {
  transform: translateY(0) scale(0.965) !important;
  transition-duration: 0.08s;
}

/* 主按钮：常驻微光，悬浮时光晕绽放 */
.btn.primary {
  box-shadow:
    0 4px 18px color-mix(in srgb, var(--primary) 30%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
html:not([data-low-power="true"]) .btn.primary:hover {
  box-shadow:
    0 10px 36px color-mix(in srgb, var(--primary) 45%, transparent),
    0 0 0 1px color-mix(in srgb, var(--primary) 30%, transparent),
    0 0 24px color-mix(in srgb, var(--primary) 35%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

/* 危险按钮保持红色光晕，不被主色覆盖 */
.btn.danger:hover {
  box-shadow:
    0 8px 28px color-mix(in srgb, var(--danger, #ef4444) 30%, transparent),
    0 2px 10px rgba(15, 23, 42, 0.10),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

/* ═══════════════════════════════════════════════
   卡片：悬浮抬升 + 主题色边缘光
   ═══════════════════════════════════════════════ */
.card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--primary) 28%, transparent);
  box-shadow:
    0 18px 48px rgba(15, 23, 42, 0.12),
    0 4px 16px color-mix(in srgb, var(--primary) 14%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

/* ═══════════════════════════════════════════════
   侧边栏：导航悬浮滑移 + 激活光晕 + 品牌流光
   ═══════════════════════════════════════════════ */
.menu-item {
  transition: all 0.26s cubic-bezier(0.16, 1, 0.3, 1);
}
.menu-item:hover {
  transform: translateX(4px);
  background: color-mix(in srgb, var(--primary) 8%, transparent);
  color: var(--primary-deep, var(--primary));
}
.menu-item.active {
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--primary) 26%, transparent),
    0 6px 24px color-mix(in srgb, var(--primary) 18%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.menu-item.active .menu-icon {
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--primary) 55%, transparent));
}

/* 品牌名流光：渐变背景缓慢流动 */
html:not([data-low-power="true"]):not([data-theme="ink"]) .brand {
  background-size: 220% 220%;
  animation: fx-brand-flow 7s ease-in-out infinite alternate;
}
@keyframes fx-brand-flow {
  0%   { background-position: 0% 40%; }
  100% { background-position: 100% 60%; }
}

/* ═══════════════════════════════════════════════
   页面切换：淡入上浮，每次切页都有一次呼吸感
   ═══════════════════════════════════════════════ */
html:not([data-low-power="true"]) .page.active {
  animation: fx-page-in 0.52s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes fx-page-in {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════
   输入框：聚焦光环
   ═══════════════════════════════════════════════ */
input, textarea, select {
  transition: border-color 0.25s ease, box-shadow 0.25s ease, background-color 0.25s ease;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--primary) 16%, transparent),
    0 2px 14px color-mix(in srgb, var(--primary) 12%, transparent);
  outline: none;
}

/* ═══════════════════════════════════════════════
   滚动条：纤细圆润，主题色渐变
   ═══════════════════════════════════════════════ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--primary) 38%, transparent),
    color-mix(in srgb, var(--info, var(--primary)) 30%, transparent));
  border-radius: 8px;
  border: 2.5px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--primary) 60%, transparent),
    color-mix(in srgb, var(--info, var(--primary)) 48%, transparent));
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* 选中文本染色 */
::selection {
  background: color-mix(in srgb, var(--primary) 26%, transparent);
  color: inherit;
}

/* 键盘可达性光环 */
:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--primary) 65%, transparent);
  outline-offset: 2px;
  border-radius: var(--radius-md, 10px);
}

/* ═══════════════════════════════════════════════
   卡密门禁页保持静态：动效进入主界面后再启用
   ═══════════════════════════════════════════════ */
html:not([data-low-power="true"]) .license-card {
  animation: none;
}
html:not([data-low-power="true"]) .license-gate::after {
  content: none;
  display: none;
}

/* ═══════════════════════════════════════════════
   降级与无障碍
   ═══════════════════════════════════════════════ */
html[data-low-power="true"] #fx-particles,
html[data-low-power="true"] #fx-overlay-root { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  #fx-particles, #fx-overlay-root { display: none !important; }
  body::after, .brand, .license-card, .license-gate::after,
  .page.active, .btn::after {
    animation: none !important;
  }
}

/* Ink runtime parity v14: motion may change, but typography and masks must not. */
html[data-theme="ink"] :is(.brand, .dashboard-intel-head h2, .model-rankings-identity h2) {
  animation: none !important;
  filter: none !important;
  text-shadow: none !important;
}

/* Keep the tools workspace equally translucent in normal and low-power modes. */
html[data-theme="ink"] .tools-layout {
  background: linear-gradient(145deg, rgba(22,19,14,0.48), rgba(9,8,7,0.42)) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  box-shadow:
    inset 0 0 0 1px rgba(248,226,163,0.04),
    inset 0 1px 0 rgba(255,239,192,0.055),
    0 9px 26px rgba(0,0,0,0.20) !important;
}

html[data-theme="ink"] :is(.tools-stage, .tools-catalog) {
  background: rgba(10,9,7,0.22) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  box-shadow: none !important;
}

html[data-theme="ink"] .url-tool-head {
  background: rgba(27,23,16,0.32) !important;
}

html[data-theme="ink"] :is(
  .url-converter-zone.input-zone,
  .url-converter-zone.output-zone,
  .url-converter-flow
) {
  background: rgba(8,7,6,0.18) !important;
}

html[data-theme="ink"] .tools-recent-strip {
  background: linear-gradient(145deg, rgba(22,19,14,0.52), rgba(9,8,7,0.46)) !important;
  box-shadow: inset 0 1px 0 rgba(255,239,192,0.04) !important;
}

/* Re-apply approved operational glass after the low-power stylesheet. */
html[data-theme="ink"] :is(
  .news-hero,
  .news-control-panel,
  .model-source-strip,
  .model-insight-cell,
  .model-board-panel,
  .model-api-panel,
  .work-api-console,
  .account-card,
  .account-row,
  .settings-box,
  .about-box
) {
  background: linear-gradient(145deg, rgba(24,21,15,0.82), rgba(10,9,7,0.76)) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

html[data-theme="ink"] .model-board-panel .model-ranking-table {
  background: rgba(8,7,6,0.30) !important;
}

/* Modal depth: dim the page, then give the dialog an almost-opaque reading surface. */
html[data-theme="ink"] .modal {
  background: rgba(3,3,2,0.78) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

html[data-theme="ink"] .modal-box {
  background: linear-gradient(145deg, rgba(24,21,15,0.985), rgba(8,7,6,0.975)) !important;
  background-image: linear-gradient(145deg, rgba(24,21,15,0.985), rgba(8,7,6,0.975)) !important;
  border-color: rgba(235,207,137,0.38) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  box-shadow:
    0 30px 88px rgba(0,0,0,0.62),
    inset 0 0 0 1px rgba(248,226,163,0.045),
    inset 0 1px 0 rgba(255,239,192,0.08) !important;
}

html[data-theme="ink"] .api-link-modal-box :is(
  .api-link-paste-input,
  .api-link-input,
  .api-link-mode-section,
  .api-link-mode-switch
) {
  background: rgba(7,6,5,0.90) !important;
  border-color: rgba(216,185,106,0.24) !important;
}

html[data-theme="ink"] .api-link-modal-box :is(.modal-header, .modal-actions) {
  background: rgba(20,17,12,0.72) !important;
  border-color: rgba(216,185,106,0.20) !important;
}

/* The model picker reuses the API-link dialog palette in every power mode. */
html[data-theme="ink"] :is(.api-model-picker-toolbar, .api-model-picker-list) {
  background: rgba(7,6,5,0.76) !important;
  border-color: rgba(216,185,106,0.24) !important;
  box-shadow: none !important;
}

html[data-theme="ink"] .api-model-picker-search input {
  background: rgba(7,6,5,0.90) !important;
  border-color: rgba(216,185,106,0.24) !important;
}

html[data-theme="ink"] .api-model-picker-item {
  background: rgba(10,9,7,0.78) !important;
  border-color: rgba(216,185,106,0.18) !important;
  color: rgba(232,220,190,0.62) !important;
  box-shadow: none !important;
}

html[data-theme="ink"] .api-model-picker-item:has(input:checked) {
  background: rgba(39,31,17,0.56) !important;
  border-color: rgba(216,185,106,0.42) !important;
  color: #f0dfb5 !important;
  box-shadow: inset 3px 0 0 rgba(225,184,82,0.88) !important;
}

html[data-theme="ink"] .api-model-picker-item:not(:has(input:checked)) {
  opacity: 0.48 !important;
}

/* Model board identity uses the same crisp carved-gold treatment as the approved dashboard title. */
html[data-theme="ink"] .model-rankings-identity h2 {
  font-family: "STXinwei", "FZShuTi", "Source Han Serif SC Heavy", "Noto Serif SC", serif;
  font-size: 34px;
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: 0;
  color: transparent;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: 0.95px #edcb73;
  paint-order: stroke fill;
  background-image:
    radial-gradient(circle at 14% 28%, rgba(244,217,132,0.90) 0 0.8px, transparent 1.2px),
    radial-gradient(circle at 68% 72%, rgba(183,133,34,0.76) 0 0.9px, transparent 1.3px),
    linear-gradient(180deg, #282111 0%, #0c0a06 100%);
  background-size: 31px 27px, 43px 35px, 100% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  text-shadow: none !important;
  filter: none !important;
  animation: none !important;
}

/* WebView native select popup must stay inside the Ink Realm palette. */
html[data-theme="ink"] .model-organization-filter {
  color-scheme: dark;
  forced-color-adjust: none;
  color: #ead9ae !important;
  background-color: #15120d !important;
  border-color: rgba(216,185,106,0.34) !important;
}

html[data-theme="ink"] .model-organization-filter option,
html[data-theme="ink"] .model-organization-filter optgroup {
  color: #ead9ae !important;
  background-color: #15120d !important;
}

html[data-theme="ink"] .model-organization-filter option:checked {
  color: #fff2c6 !important;
  background-color: #6f531d !important;
}

/* Dark skins: keep native select popups on a deep surface instead of system gray. */
:is(html[data-theme="midnight"], html[data-theme="cyber"], html[data-theme="sakura"], html[data-theme="simon-star"]) :is(
  select,
  .settings-select,
  .model-organization-filter,
  .add-tag-select,
  .codx-select,
  .codx-mini-select
) {
  color-scheme: dark;
  forced-color-adjust: none;
}

:is(html[data-theme="midnight"], html[data-theme="cyber"], html[data-theme="sakura"], html[data-theme="simon-star"]) :is(
  select option,
  select optgroup,
  .settings-select option,
  .model-organization-filter option,
  .add-tag-select option,
  .codx-select option,
  .codx-mini-select option
) {
  color: #e8eef8 !important;
  background-color: #12161f !important;
}

:is(html[data-theme="midnight"], html[data-theme="cyber"], html[data-theme="sakura"], html[data-theme="simon-star"]) :is(
  select option:checked,
  .settings-select option:checked,
  .model-organization-filter option:checked,
  .add-tag-select option:checked,
  .codx-select option:checked,
  .codx-mini-select option:checked
) {
  color: #ffffff !important;
  background-color: color-mix(in srgb, var(--primary) 70%, #111) !important;
}

/* Ink title system v16: one crisp, readable inscription across page-level headings. */
html[data-theme="ink"] :is(
  .brand,
  .dashboard-intel-head h2,
  #pageTitle,
  .page-header h1,
  .model-rankings-identity h2,
  .workspace-page-title-row h1,
  .workspace-page-title-row h2
) {
  font-family: "STXinwei", "FZShuTi", "STKaiti", "KaiTi", "Noto Serif SC", serif !important;
  font-synthesis: none;
  font-weight: 400 !important;
  line-height: 1.08;
  letter-spacing: 0;
  color: #ead18a !important;
  -webkit-text-fill-color: #ead18a !important;
  -webkit-text-stroke: 0 !important;
  background: none !important;
  background-image: none !important;
  text-shadow: 0 1px 0 rgba(65,45,13,0.72), 0 0 10px rgba(226,197,113,0.10) !important;
  filter: none !important;
  animation: none !important;
  text-rendering: geometricPrecision;
}

html[data-theme="ink"] :is(#pageTitle, .page-header h1) {
  font-size: 34px;
}

html[data-theme="ink"] .model-rankings-identity h2 {
  font-size: 32px;
}

html[data-theme="ink"] .dashboard-intel-head h2 {
  font-size: 40px;
}

html[data-theme="ink"] .model-board-heading {
  border-bottom-color: rgba(216,185,106,0.22);
  background: linear-gradient(90deg, rgba(216,185,106,0.045), rgba(216,185,106,0.012) 58%, transparent);
  box-shadow: inset 3px 0 0 rgba(216,185,106,0.38);
}

html[data-theme="ink"] .model-board-heading span {
  border-color: rgba(216,185,106,0.28);
  color: #e5c970;
  background: rgba(15,13,9,0.50);
}

html[data-theme="ink"] .model-board-heading h3 {
  font-family: "STKaiti", "KaiTi", "Noto Serif SC", serif;
  font-weight: 600;
  color: #ead7a2;
  text-shadow: none;
}

html[data-theme="ink"] .model-board-heading p {
  color: rgba(235,225,199,0.78);
}

@media (max-width: 700px) {
  html[data-theme="ink"] :is(#pageTitle, .page-header h1) { font-size: 29px; }
  html[data-theme="ink"] .model-rankings-identity h2 { font-size: 27px; }
}

/* ═══════════════════════════════════════════════
   定制标题栏（仅 Windows：body.platform-windows）
   全皮肤联动：底色 / 文字 / 悬停全部走皮肤变量
   ═══════════════════════════════════════════════ */
.app-titlebar { display: none; }
body.platform-windows .app-titlebar {
  display: flex;
  align-items: stretch;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 38px;
  z-index: 10100;
  padding-left: 14px;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line, rgba(148, 163, 184, 0.10));
  color: var(--text);
  user-select: none;
  -webkit-app-region: drag;
  app-region: drag;
  cursor: default;
}
body.platform-windows .layout { padding-top: 38px; }
body.platform-windows .license-gate { padding-top: 58px; }
body.platform-windows .sidebar,
body.platform-windows .main {
  height: calc(100vh - 38px);
}
html[data-active-page="codx"] body.platform-windows .main {
  height: calc(100vh - 38px) !important;
}
.titlebar-brand {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 0 0 auto;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  pointer-events: auto;
  -webkit-app-region: drag;
  app-region: drag;
}
.titlebar-title {
  -webkit-app-region: drag;
  app-region: drag;
}
.titlebar-drag-spacer {
  flex: 1 1 auto;
  min-width: 32px;
  height: 100%;
  -webkit-app-region: drag;
  app-region: drag;
}
.titlebar-seal {
  display: none !important;
  width: 17px;
  height: 17px;
  place-items: center;
  font-family: "Noto Serif SC", "STSong", "SimSun", serif;
  font-size: 10px;
  font-weight: 700;
  color: #f8eeda;
  background: linear-gradient(135deg, #c1442e, #9e3220);
  border-radius: 3.5px;
  transform: rotate(4deg);
  box-shadow: 0 1px 5px rgba(193, 68, 46, 0.35), inset 0 0 0 1px rgba(248, 238, 218, 0.28);
}
.titlebar-actions {
  display: flex;
  align-items: stretch;
  flex: 0 0 auto;
  -webkit-app-region: no-drag;
  app-region: no-drag;
}
.titlebar-btn {
  width: 46px;
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text-secondary);
  transition: background 0.15s ease, color 0.15s ease;
  -webkit-app-region: no-drag;
  app-region: no-drag;
}
.titlebar-btn:hover {
  background: color-mix(in srgb, var(--text) 10%, transparent);
  color: var(--text);
}
.titlebar-btn svg { width: 12px; height: 12px; }
.titlebar-btn.titlebar-close:hover { background: #e81123; color: #fff; }

@media (max-height: 860px) {
  .sidebar {
    padding-top: 18px;
    padding-bottom: 12px;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .brand {
    padding-bottom: 14px;
    margin-bottom: 4px;
  }

  .menu-item {
    min-height: 36px;
    margin-bottom: 2px;
    padding-block: 7px;
  }

  .sidebar-power-mode {
    min-height: 42px;
    margin-bottom: 7px;
    padding-block: 6px;
  }

  .sidebar-status-panel {
    min-height: 58px;
    padding: 8px 10px;
  }

  .sidebar-status-panel .expire-box {
    margin-top: 6px;
    padding: 3px 8px;
  }
}
