/* 页面与缩略预览共用配色；新皮肤以低亮度表面和柔和文字建立层次。 */
:is(html, .theme-preview)[data-theme="midnight"] {
  --bg: #131a22;
  --bg-card: #222f3d;
  --bg-section: #19232e;
  --text: #dce3eb;
  --text-secondary: #aebcca;
  --text-muted: #95a5b5;
  --border: #344352;
  --accent: #a7bed2;
  --accent-light: #728ca5;
  --accent-hover: #c0d0df;
  --accent-bg: #293b4c;
  --accent-solid: #91acc3;
  --on-accent: #172532;
  --header-base: #19232e;
  --bg-header: linear-gradient(120deg, #141d27, #233344 58%, #1a2531);
  --header-text: #dce3eb;
  --header-muted: #a6b6c5;
  --search-bg: #263544;
  --search-text: #dce3eb;
  --search-placeholder: #a3b3c2;
  --engine-bg: #253442;
  --engine-text: #b9c6d2;
  --engine-active-bg: #364d60;
  --engine-active-text: #dce7ef;
  --theme-shadow: 0, 0, 0;
}

:is(html, .theme-preview)[data-theme="forest"] {
  --bg: #141c19;
  --bg-card: #24332d;
  --bg-section: #1b2622;
  --text: #dbe3dc;
  --text-secondary: #b3c2b7;
  --text-muted: #97aa9d;
  --border: #35483e;
  --accent: #adc4b1;
  --accent-light: #7e9c88;
  --accent-hover: #c4d6c7;
  --accent-bg: #2a3c32;
  --accent-solid: #9db9a6;
  --on-accent: #1a2b21;
  --header-base: #1c2822;
  --bg-header: linear-gradient(120deg, #17221d, #293a2e 58%, #1d2b24);
  --header-text: #dbe3dc;
  --header-muted: #a9bbae;
  --search-bg: #283a30;
  --search-text: #dbe3dc;
  --search-placeholder: #a8bcad;
  --engine-bg: #28392f;
  --engine-text: #bdcec1;
  --engine-active-bg: #3b5143;
  --engine-active-text: #dfe9e0;
  --theme-shadow: 0, 0, 0;
}

:is(html, .theme-preview)[data-theme="walnut"] {
  --bg: #1c1816;
  --bg-card: #342b26;
  --bg-section: #26201d;
  --text: #e4dcd4;
  --text-secondary: #c4b6a9;
  --text-muted: #ad9c8e;
  --border: #4a3e34;
  --accent: #ccb5a0;
  --accent-light: #aa8c70;
  --accent-hover: #e0c9b4;
  --accent-bg: #403229;
  --accent-solid: #bca088;
  --on-accent: #2a211a;
  --header-base: #28211c;
  --bg-header: linear-gradient(120deg, #211b18, #3a2e25 58%, #2a221d);
  --header-text: #e4dcd4;
  --header-muted: #bdad9e;
  --search-bg: #392e27;
  --search-text: #e7ded5;
  --search-placeholder: #bcab9c;
  --engine-bg: #352c25;
  --engine-text: #cfc0b1;
  --engine-active-bg: #554435;
  --engine-active-text: #e8d9c9;
  --theme-shadow: 0, 0, 0;
}

:is(html, .theme-preview)[data-theme="graphite"] {
  --bg: #16191c;
  --bg-card: #22262a;
  --bg-section: #1c2024;
  --text: #e9e6df;
  --text-secondary: #c0c4c5;
  --text-muted: #969fa2;
  --border: #343b3f;
  --accent: #d7ba86;
  --accent-light: #b19a72;
  --accent-hover: #ead1a6;
  --accent-bg: #353328;
  --accent-solid: #d7ba86;
  --on-accent: #25231f;
  --header-base: #1c2023;
  --bg-header: linear-gradient(115deg, #1a1e22, #242827 58%, #202528);
  --header-text: #f0ebe0;
  --header-muted: #a9b0b1;
  --search-bg: #292e32;
  --search-text: #eeebe4;
  --search-placeholder: #aab1b4;
  --engine-bg: #2a3034;
  --engine-text: #c5cbcc;
  --engine-active-bg: #d7ba86;
  --engine-active-text: #25231f;
  --theme-shadow: 0, 0, 0;
}

:is(html, .theme-preview)[data-theme="light"] {
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --bg-section: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #636a78;
  --text-muted: #6e7483;
  --border: #e0e3eb;
  --accent: #5848c9;
  --accent-light: #818cf8;
  --accent-hover: #4938b5;
  --accent-bg: #ecebfa;
  --accent-solid: #5848c9;
  --on-accent: #ffffff;
  --header-base: #232044;
  --bg-header: linear-gradient(115deg, #191632, #302b63 58%, #24243e);
  --header-text: #ffffff;
  --header-muted: #c9c5e5;
  --search-bg: #ffffff;
  --search-text: #1a1a2e;
  --search-placeholder: #6e7483;
  --engine-bg: #363354;
  --engine-text: #f1eff9;
  --engine-active-bg: #edeaff;
  --engine-active-text: #342965;
  --theme-shadow: 35, 32, 68;
}

:is(html, .theme-preview)[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-section: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #b0bdd0;
  --text-muted: #a0acbf;
  --border: #334155;
  --accent: #b7adff;
  --accent-light: #818cf8;
  --accent-hover: #ccc5ff;
  --accent-bg: #343451;
  --accent-solid: #6d5bdd;
  --on-accent: #ffffff;
  --header-base: #141a32;
  --bg-header: linear-gradient(115deg, #0f172a, #242047 58%, #141b30);
  --header-text: #f1f5f9;
  --header-muted: #b8b5d5;
  --search-bg: #1e293b;
  --search-text: #f1f5f9;
  --search-placeholder: #a0acbf;
  --engine-bg: #252c46;
  --engine-text: #e0e3f0;
  --engine-active-bg: #433d77;
  --engine-active-text: #ffffff;
  --theme-shadow: 0, 0, 0;
}

/* 新深色皮肤的选中文本采用深字浅底，避免柔和强调色上出现白字。 */
html:is([data-theme="midnight"], [data-theme="forest"], [data-theme="walnut"]) ::selection {
  background: var(--accent-solid);
  color: var(--on-accent);
}

/* 把原先写死的紫色装饰统一接入皮肤，保留既有布局与编辑交互。 */
html[data-theme] {
  --shadow: 0 1px 3px rgba(var(--theme-shadow), .035);
  --shadow-md: 0 5px 18px rgba(var(--theme-shadow), .055);
  --shadow-lg: 0 18px 48px rgba(var(--theme-shadow), .14);
  --shadow-hover: 0 8px 24px rgba(var(--theme-shadow), .10);
}
.search-header { color: var(--header-text); border-bottom: 1px solid var(--border); }
.search-header::before { background: none; }
.site-title { font-weight: 650; letter-spacing: 4px; text-shadow: none; }
html[data-theme] .search-input-wrap { background: var(--search-bg); border-color: var(--border); box-shadow: 0 8px 28px rgba(var(--theme-shadow), .08); }
html[data-theme] .search-input { min-width: 0; color: var(--search-text); }
.search-input::placeholder { color: var(--search-placeholder); opacity: 1; }
.search-btn, .btn-primary, .admin-fab, .link-card .card-icon-placeholder {
  background: var(--accent-solid);
  color: var(--on-accent);
}
.search-input-wrap:focus-within { outline: 2px solid var(--accent-light); outline-offset: 3px; }
.engine-btn { background: var(--engine-bg); color: var(--engine-text); border-color: transparent; backdrop-filter: none; }
.engine-btn:hover { background: var(--engine-bg); color: var(--engine-text); border-color: var(--accent-light); }
.engine-btn.active { background: var(--engine-active-bg); color: var(--engine-active-text); border-color: transparent; box-shadow: none; }
.engine-sort-drag { background: var(--accent-solid); color: var(--on-accent); }
.category-title::before { background: var(--accent); }
.sub-tab.active, .admin-nav button.active, .admin-nav button:hover { background: var(--accent-solid); color: var(--on-accent); box-shadow: none; }
.link-card::after { background: var(--accent-bg); }
.link-card .card-icon-placeholder, .admin-fab, .admin-fab:hover { box-shadow: var(--shadow-md); }
.sub-tab-chosen { box-shadow: 0 0 0 2px var(--accent-light); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* 入口与选择面板使用同一套配色，缩略图展示真实页面层次。 */
.theme-toggle {
  width: auto;
  height: 36px;
  padding: 0 13px;
  gap: 7px;
  border-radius: 20px;
  background: var(--engine-bg);
  border: 1px solid transparent;
  color: var(--engine-text);
  font-size: 13px;
  font-weight: 500;
  backdrop-filter: none;
}
.theme-toggle:hover { background: var(--engine-bg); border-color: var(--accent-light); transform: none; }
.theme-picker {
  width: min(760px, calc(100% - 40px));
  max-height: calc(100dvh - 40px);
  margin: auto;
  padding: 28px;
  overflow-y: auto;
  color: var(--text);
  background: var(--bg-section);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 28px 100px rgba(0, 0, 0, .22);
}
.theme-picker::backdrop { background: rgba(15, 22, 22, .36); backdrop-filter: blur(8px); }
.theme-picker-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.theme-picker-eyebrow { color: var(--text-muted); font-size: 11px; letter-spacing: 2px; margin-bottom: 6px; }
.theme-picker h2 { font-size: 25px; font-weight: 600; letter-spacing: 1px; }
#themePickerDescription { margin-top: 5px; font-size: 13px; color: var(--text-secondary); }
.theme-close { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; flex-shrink: 0; border-radius: 50%; background: var(--bg); color: var(--text-secondary); }
.theme-close:hover { color: var(--text); background: var(--accent-bg); }
.theme-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.theme-option { position: relative; display: block; min-width: 0; padding: 7px 7px 12px; text-align: left; border: 1px solid var(--border); border-radius: 13px; background: var(--bg-card); color: var(--text); transition: border-color .18s, box-shadow .18s, transform .18s; }
.theme-option:hover { border-color: var(--accent-light); transform: translateY(-2px); }
.theme-option[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.theme-option-name { display: block; padding: 11px 28px 0 6px; font-size: 14px; font-weight: 600; }
.theme-option-note { display: block; padding: 2px 6px 0; font-size: 11px; color: var(--text-muted); }
.theme-option-check { position: absolute; bottom: 27px; right: 13px; display: flex; align-items: center; justify-content: center; width: 19px; height: 19px; border-radius: 50%; background: var(--accent-solid); color: var(--on-accent); font-size: 12px; opacity: 0; }
.theme-option[aria-pressed="true"] .theme-option-check { opacity: 1; }
.theme-preview { display: block; aspect-ratio: 1.9; overflow: hidden; border-radius: 7px; background: var(--bg); border: 1px solid var(--border); }
.preview-header { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; height: 43%; background: var(--bg-header); }
.preview-search { display: block; width: 52%; height: 9px; border-radius: 6px; background: var(--search-bg); border-right: 15px solid var(--accent-solid); }
.preview-pills { display: block; width: 36%; height: 4px; border-radius: 5px; background: repeating-linear-gradient(90deg, var(--engine-active-bg) 0 12px, transparent 12px 16px); opacity: .75; }
.preview-body { display: flex; height: 57%; gap: 6px; padding: 8px; }
.preview-sidebar { display: block; flex: 0 0 19%; border-radius: 3px; background: var(--bg-card); border-top: 5px solid var(--accent-bg); }
.preview-content { display: flex; flex: 1; align-items: center; gap: 4px; padding: 6px; border-radius: 3px; background: var(--bg-section); }
.preview-card { display: block; flex: 1; height: 19px; border-radius: 3px; background: var(--bg-card); border: 1px solid var(--border); border-top: 3px solid var(--accent-light); }
.theme-picker-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 12px; }
.theme-picker-footer strong { color: var(--text-secondary); font-weight: 500; }
#themeStatus { font-size: 11px; }
@media (max-width: 600px) {
  .header-actions { right: 16px; top: 16px; }
  .theme-toggle { height: 32px; padding: 0 10px; font-size: 12px; }
  .theme-picker { width: calc(100% - 24px); max-height: calc(100dvh - 24px); padding: 20px 16px; border-radius: 18px; }
  .theme-picker-heading { margin-bottom: 18px; }
  .theme-picker h2 { font-size: 23px; }
  .theme-options { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .theme-picker-footer { margin-top: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .theme-option { transition: none; }
}
