  /* ============ 主题变量（亮） ============ */
  :root {
    --win-bg: #f4f6fb;
    --win-border: #c3cad6;
    --win-shadow: 0 18px 48px rgba(40,60,110,.25);
    --titlebar-bg: linear-gradient(180deg, #f7f8fa, #e6e9ee);
    --titlebar-border: #d3d6dc;
    --title-color: #3a4152;
    --btn-color: #4a5162;
    --btn-hover: rgba(0,0,0,.09);
    --ctx-bg: #fff;
    --ctx-border: #c9cdd4;
    --ctx-fg: #333;
    --ctx-hover: var(--accent);
    --ctx-hover-fg: #fff;
    --ctx-sep: #e6e8ec;
    --icon-fg: #3a4152;
    --icon-hover: rgba(0,0,0,.08);
    --icon-shadow: 0 1px 3px rgba(0,0,0,.25);
    /* 壁纸遮罩：亮色下不生效 */
    --wallpaper-shade: transparent;
    /* 壁纸模糊程度：0.0 ~ 1.0，默认 0.2，由 JS 按 theme.blur 覆盖 */
    --wallpaper-blur: 0.2;
  }

  /* ============ 主题变量（暗） ============ */
  :root[data-theme="dark"] {
    --win-bg: #2b2f38;
    --win-border: #4a5261;
    --win-shadow: 0 18px 48px rgba(0,0,0,.6);
    --titlebar-bg: linear-gradient(180deg, #383d47, #2c3039);
    --titlebar-border: #1f232b;
    --title-color: #e6e9f0;
    --btn-color: #cdd3de;
    --btn-hover: rgba(255,255,255,.12);
    --ctx-bg: #333842;
    --ctx-border: #4a5261;
    --ctx-fg: #e6e9f0;
    --ctx-hover: var(--accent);
    --ctx-hover-fg: #fff;
    --ctx-sep: #454b57;
    --icon-fg: #ffffff;
    --icon-hover: rgba(255,255,255,.14);
    --icon-shadow: 0 1px 3px rgba(0,0,0,.6);
    /* 暗色主题下压低壁纸亮度，避免亮图刺眼、保证图标对比度 */
    --wallpaper-shade: rgba(0,0,0,.38);
  }

  html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  /* ============ 桌面壁纸 ============ */
  .desktop {
    position: fixed;
    inset: 0;
    background-color: #1d2747;
    overflow: hidden;
    user-select: none;
  }

  /* 独立壁纸层：便于单独应用模糊，四周外扩 30px 避免模糊后露出边缘 */
  .desktop-bg {
    position: absolute;
    inset: -30px;
    background-image: var(--wallpaper);
    background-position: center center;
    background-size: cover;
    background-repeat: no-repeat;
    filter: blur(calc(var(--wallpaper-blur, 0) * 20px));
    pointer-events: none;
    z-index: 0;
  }

  /* 暗色主题低亮度遮罩：铺在壁纸上、图标/窗口之下，不接收指针事件 */
  .desktop::after {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--wallpaper-shade, transparent);
    pointer-events: none;
    z-index: 2;
  }

  /* ============ 桌面图标（左上角） ============ */
  .desktop-icon {
    position: absolute;
    top: 18px;
    left: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 80px;
    max-width: 160px;
    padding: 12px 6px;
    border-radius: 10px;
    cursor: pointer;
    color: var(--icon-fg);
    transition: background .15s ease, transform .15s ease, color .18s ease;
    z-index: 5;
  }
  .desktop-icon:hover { background: var(--icon-hover); }
  .desktop-icon:active { transform: scale(.96); }

  .icon-img {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    font-family: "CryptoLoli Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
    font-size: 40px;
  }
  .desktop-icon span {
    font-size: 13px;
    white-space: nowrap;
    text-shadow: var(--icon-shadow);
  }

  /* ============ 窗口（KDE 风格，无圆角） ============ */
  .window {
    position: absolute;
    width: 780px;
    height: 520px;
    display: flex;
    flex-direction: column;
    background: var(--win-bg);
    box-shadow: var(--win-shadow);
    border: 1px solid var(--win-border);
    border-radius: 0;
    min-width: 360px;
    min-height: 240px;
    opacity: 0;
    pointer-events: none;
    transform: scale(.85);
    transform-origin: center;
    transition: opacity .18s ease, transform .18s ease;
  }
  .window.visible { opacity: 1; transform: scale(1); pointer-events: auto; }

  /* 手机：窗口固定全屏，不提供缩放手柄 */
  .window.mobile {
    min-width: 0;
    min-height: 0;
  }
  .window.mobile .resize-handle { display: none; }

  /* 最大化 / 还原（窗口化）动画：用 transform 过渡（GPU 合成，不重排），元素只做 transform 动画 */
  .window.animating {
    transition: transform .28s cubic-bezier(.2, .7, .3, 1);
    will-change: transform;
  }

  /* ============ 毛玻璃：半透明 + 背景模糊（主题设置中可关闭） ============ */
  /* 窗口自身半透明并模糊背后的壁纸；子页面 body 透明（见 css/app.css），
     模糊后的壁纸透过 iframe 显示，形成毛玻璃效果。 */
  :root[data-glass="true"] {
    --win-glass-bg: rgba(244, 246, 251, .6);
    --titlebar-glass-bg: linear-gradient(180deg, rgba(247, 248, 250, .75), rgba(230, 233, 238, .6));
    --ctx-glass-bg: rgba(255, 255, 255, .72);
  }
  :root[data-glass="true"][data-theme="dark"] {
    --win-glass-bg: rgba(36, 40, 48, .6);
    --titlebar-glass-bg: linear-gradient(180deg, rgba(56, 61, 71, .75), rgba(44, 48, 57, .62));
    --ctx-glass-bg: rgba(51, 56, 66, .72);
  }
  :root[data-glass="true"] .window {
    background: var(--win-glass-bg);
    -webkit-backdrop-filter: blur(18px) saturate(1.3);
    backdrop-filter: blur(18px) saturate(1.3);
  }
  :root[data-glass="true"] .titlebar {
    background: var(--titlebar-glass-bg);
  }
  :root[data-glass="true"] .window-loading,
  :root[data-glass="true"] .window-error {
    background: var(--win-glass-bg);
  }
  :root[data-glass="true"] .window-body iframe {
    background: transparent;
  }

  /* 右键菜单与窗口保持一致的毛玻璃质感 */
  :root[data-glass="true"] .ctx-menu {
    background: var(--ctx-glass-bg);
    -webkit-backdrop-filter: blur(18px) saturate(1.3);
    backdrop-filter: blur(18px) saturate(1.3);
  }

  /* 关闭动画 */
  .window.closing {
    opacity: 0 !important;
    transform: scale(.85);
    transform-origin: center;
    transition: opacity .18s ease, transform .18s ease;
    pointer-events: none !important;
  }

  /* 标题栏：KDE 风格，居中标题，较矮 */
  .titlebar {
    position: relative;
    height: 34px;
    flex: 0 0 34px;
    display: flex;
    align-items: center;
    padding: 0 6px;
    background: var(--titlebar-bg);
    border-bottom: 1px solid var(--titlebar-border);
    cursor: grab;
    user-select: none;
    touch-action: none; /* 移动端：阻止触摸滚动/缩放手势抢走 pointer 事件 */
  }
  .titlebar:active { cursor: grabbing; }
  .titlebar.dragging { cursor: grabbing; }

  .titlebar .title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    color: var(--title-color);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .3px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
    pointer-events: none;
  }
  .controls {
    margin-left: auto;
    display: flex;
    gap: 2px;
    align-items: center;
  }
  .btn {
    width: 34px;
    height: 24px;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--btn-color);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    transition: background .12s ease;
    display: grid;
    place-items: center;
  }
  .btn:hover { background: var(--btn-hover); }
  .btn-close:hover { background: #e81123; color: #fff; }

  /* 内容区：iframe */
  .window-body { flex: 1; display: flex; overflow: hidden; position: relative; }
  .window-body iframe {
    flex: 1;
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
    opacity: 0;
    transition: opacity .25s ease;
  }
  .window.loaded .window-body iframe { opacity: 1; }

  /* 加载动画（圆形进度条），iframe 加载完成前显示，避免白屏 */
  .window-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--win-bg);
    z-index: 1;
  }
  .window.loaded .window-loading { display: none; }
  .window.error .window-loading { display: none; }

  /* ============ 首屏加载框（全屏） ============ */
  .boot-loading {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--win-bg);
    transition: opacity .22s ease;
  }
  .boot-loading.hide {
    opacity: 0;
    pointer-events: none;
  }

  /* ============ 未启用 JavaScript 提示（<noscript>） ============ */
  /* 颜色不引用主题变量：没有 JS 时 data-theme / --accent 都不会被设置 */
  .nojs-notice {
    position: fixed;
    inset: 0;
    z-index: 100001;              /* 覆盖首屏加载框 */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #1d2747;
    color: #e6e9f0;
    text-align: center;
  }
  .nojs-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    max-width: 640px;
  }
  .nojs-icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border: 2px solid #3d6bff;
    color: #7c9dff;
    font-size: 19px;
    font-weight: 700;
    border-radius: 0;
  }
  .nojs-title {
    font-size: 20px;
    font-weight: 700;
  }
  .nojs-desc {
    color: #b8c2dd;
    font-size: 13px;
    line-height: 1.75;
    white-space: nowrap;             /* 说明文字保持单行 */
  }
  /* 窄屏放不下单行时恢复换行，避免横向溢出 */
  @media (max-width: 640px) {
    .nojs-desc { white-space: normal; }
  }
  .nojs-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 4px;
  }
  .nojs-reload,
  .nojs-link {
    display: inline-flex;
    align-items: center;
    height: 30px;
    padding: 0 20px;
    border: 1px solid #3d6bff;
    border-radius: 0;
    font-size: 12px;
    text-decoration: none;
  }
  .nojs-reload {
    background: #3d6bff;
    color: #fff;
  }
  .nojs-reload:hover { filter: brightness(1.12); }
  .nojs-link {
    background: transparent;
    color: #b8c2dd;
  }
  .nojs-link:hover {
    background: rgba(61, 107, 255, .18);
    color: #fff;
  }
  /* 无 JS 时停止首屏 spinner 空转，也避免读屏软件停留在“加载中”
     （.nojs-notice 只在 JS 禁用时进入 DOM，有 JS 时此规则不会命中） */
  .nojs-notice ~ .boot-loading { display: none; }

  /* 页面加载失败提示：覆盖 iframe 内的浏览器原生错误页 */
  .window-error {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 24px;
    text-align: center;
    background: var(--win-bg);
    color: var(--title-color);
    z-index: 3;
  }
  .window.error .window-error { display: flex; }
  .window-error-icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 2px solid var(--accent);
    color: var(--accent);
    font-size: 23px;
    font-weight: 700;
    border-radius: 0;
  }
  .window-error-title {
    font-size: 15px;
    font-weight: 600;
  }
  .window-error-retry {
    height: 28px;
    padding: 0 18px;
    border: 1px solid var(--accent);
    border-radius: 0;
    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
  }
  .window-error-retry:hover { filter: brightness(1.1); }
  .spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--accent-soft);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
  @keyframes spin {
    to { transform: rotate(360deg); }
  }
  /* 拖动过程中屏蔽 iframe，避免吞掉 pointer 事件 */
  .window.dragging .window-body { pointer-events: none; }

  /* 拖拽改变大小 */
  .window.resizing .window-body { pointer-events: none; }
  .window.resizing { user-select: none; }
  .resize-handle {
    position: absolute;
    display: block;
    z-index: 20;
    touch-action: none; /* 移动端：允许 pointer 拖拽 resize */
  }
  .rh-n  { top: -1px;    left: 6px;    right: 6px;  height: 6px; cursor: ns-resize; }
  .rh-s  { bottom: -1px; left: 6px;    right: 6px;  height: 6px; cursor: ns-resize; }
  .rh-e  { right: -1px;  top: 6px;     bottom: 6px; width: 6px;  cursor: ew-resize; }
  .rh-w  { left: -1px;   top: 6px;     bottom: 6px; width: 6px;  cursor: ew-resize; }
  .rh-ne { top: -1px;    right: -1px;  width: 12px; height: 12px; cursor: nesw-resize; }
  .rh-nw { top: -1px;    left: -1px;   width: 12px; height: 12px; cursor: nwse-resize; }
  .rh-se { bottom: -1px; right: -1px;  width: 12px; height: 12px; cursor: nwse-resize; }
  .rh-sw { bottom: -1px; left: -1px;   width: 12px; height: 12px; cursor: nesw-resize; }

  /* ============ 右键菜单 ============ */
  .ctx-menu {
    position: fixed;
    min-width: 150px;
    padding: 4px;
    background: var(--ctx-bg);
    border: 1px solid var(--ctx-border);
    border-radius: 5px;
    box-shadow: 0 8px 24px rgba(0,0,0,.22);
    z-index: 10000;
    display: none;
    font-size: 13px;
    color: var(--ctx-fg);
    user-select: none;
  }
  .ctx-menu.show { display: block; }
  .ctx-menu .ctx-item {
    padding: 7px 12px;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
  }
  .ctx-menu .ctx-item:hover { background: var(--ctx-hover); color: var(--ctx-hover-fg); }
  .ctx-menu .ctx-sep {
    height: 1px;
    margin: 4px 6px;
    background: var(--ctx-sep);
  }
