:root {
  --taskbar-h: 48px;
  --accent: #0078d4;
  --accent-hover: #106ebe;
  --text: #1b1b1b;
  --text-dim: #616161;
  --stroke: rgba(0, 0, 0, .08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden; /* 防止拖拽产生页面滚动条 */
  position: fixed;
  touch-action: none;
}

body {
  font-family: "Segoe UI Variable", "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei",
               system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  user-select: none;
  -webkit-font-smoothing: antialiased;
  background: #0b1a33;
}

input, textarea { user-select: text; touch-action: auto; }

/* ==================== 桌面 ==================== */
#desktop {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse 55% 45% at 20% 26%, rgba(88, 166, 255, .50), transparent 70%),
    radial-gradient(ellipse 50% 42% at 80% 20%, rgba(168, 120, 255, .42), transparent 70%),
    radial-gradient(ellipse 70% 60% at 52% 100%, rgba(10, 30, 80, .85), transparent 70%),
    linear-gradient(150deg, #0b1a33 0%, #12294d 38%, #2a1b52 74%, #150e2b 100%);
}

#desktop.wall-2 { background: radial-gradient(circle at 50% 50%, #2b5876 0%, #4e4376 100%); }
#desktop.wall-3 {
  background:
    radial-gradient(ellipse 60% 50% at 30% 30%, #ff9a9e 0%, transparent 65%),
    radial-gradient(ellipse 60% 50% at 75% 70%, #a18cd1 0%, transparent 65%),
    linear-gradient(135deg, #1f1c2c, #302b63 55%, #0f0c29);
}

#desktop-icons {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.desk-icon {
  position: absolute;
  width: 86px;
  height: 92px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 6px 4px;
  border-radius: 5px;
  color: #fff;
  text-align: center;
  cursor: default;
  border: 1px solid transparent;
  pointer-events: auto;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden; /* 防止图标或文字溢出 */
}

.desk-icon svg {
  width: 40px;
  height: 40px;
  flex: none;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, .45));
  margin-bottom: 6px;
}

.desk-icon span {
  font-size: 12px;
  line-height: 1.25;
  max-width: 100%;
  padding: 0 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word; /* 防止英文单词被从中间生硬切断 */
  white-space: normal;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .85);
}

.desk-icon:hover { background: rgba(255, 255, 255, .13); border-color: rgba(255, 255, 255, .12); }
.desk-icon.selected { background: rgba(0, 120, 212, .38); border-color: rgba(255, 255, 255, .45); }
.desk-icon.dragging { opacity: 0.7; pointer-events: none; z-index: 9999; }

/* ==================== 窗口层 ==================== */
#windows-layer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: calc(var(--taskbar-h) + var(--safe-bottom));
  left: 0;
  pointer-events: none;
  overflow: hidden;
}

.window {
  position: absolute;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  min-width: 280px;
  min-height: 160px;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .10), 0 24px 64px rgba(0, 0, 0, .38), 0 6px 16px rgba(0, 0, 0, .20);
  animation: winOpen .16s cubic-bezier(.2, .8, .3, 1);
}
@keyframes winOpen { from { opacity: 0; transform: scale(.955); } to { opacity: 1; transform: scale(1); } }
.window.inactive { box-shadow: 0 0 0 1px rgba(0, 0, 0, .10), 0 14px 36px rgba(0, 0, 0, .26), 0 4px 10px rgba(0, 0, 0, .14); }
.window.maximized { border-radius: 0; }

.titlebar {
  flex: none;
  height: 36px;
  display: flex;
  align-items: center;
  padding-left: 12px;
  background: #f7f7f7;
  border-bottom: 1px solid rgba(0, 0, 0, .07);
  cursor: default;
  touch-action: none;
}
.window.inactive .titlebar { background: #fbfbfb; }

.titlebar-left { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.win-icon { display: flex; flex: none; }
.win-icon svg { width: 16px; height: 16px; }
.win-title { font-size: 12px; color: #3a3a3a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.window.inactive .win-title { color: #9a9a9a; }

.win-controls { display: flex; height: 100%; flex: none; }
.wc {
  position: relative;
  width: 46px; height: 100%;
  display: grid; place-items: center;
  transition: background .12s, color .12s;
}
.wc span { display: block; font-size: 10px; line-height: 1; color: #333; }
.wc.min span, .wc.max span { width: 10px; height: 10px; font-size: 0; }
.wc.min span::before { content: ""; display: block; width: 10px; height: 1px; background: currentColor; margin-top: 4px; }
.wc.max span::before { content: ""; display: block; width: 10px; height: 10px; border: 1px solid currentColor; border-radius: 1px; }
.wc.close span::before { content: "✕"; font-size: 11px; }
.wc:hover { background: rgba(0, 0, 0, .07); }
.wc.close:hover { background: #e81123; }
.wc.close:hover span::before { color: #fff; }

.window-body { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; overflow: hidden; background: #fff; }

.resizer { position: absolute; z-index: 20; }
.resizer[data-dir="n"]  { top: -3px; left: 10px; right: 10px; height: 6px; cursor: ns-resize; }
.resizer[data-dir="s"]  { bottom: -3px; left: 10px; right: 10px; height: 6px; cursor: ns-resize; }
.resizer[data-dir="w"]  { left: -3px; top: 10px; bottom: 10px; width: 6px; cursor: ew-resize; }
.resizer[data-dir="e"]  { right: -3px; top: 10px; bottom: 10px; width: 6px; cursor: ew-resize; }
.resizer[data-dir="nw"] { top: -3px; left: -3px; width: 14px; height: 14px; cursor: nwse-resize; }
.resizer[data-dir="ne"] { top: -3px; right: -3px; width: 14px; height: 14px; cursor: nesw-resize; }
.resizer[data-dir="sw"] { bottom: -3px; left: -3px; width: 14px; height: 14px; cursor: nesw-resize; }
.resizer[data-dir="se"] { bottom: -3px; right: -3px; width: 14px; height: 14px; cursor: nwse-resize; }

body.dragging, body.dragging * { cursor: default !important; }

/* ==================== 任务栏 ==================== */
#taskbar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--taskbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex; align-items: center;
  padding-left: 6px; padding-right: 6px;
  z-index: 9500;
  background: rgba(243, 243, 243, .84);
  -webkit-backdrop-filter: blur(26px) saturate(1.7);
  backdrop-filter: blur(26px) saturate(1.7);
  border-top: 1px solid rgba(0, 0, 0, .07);
  box-shadow: 0 -1px 12px rgba(0, 0, 0, .10);
}

.tb-center {
  position: absolute; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px;
  height: var(--taskbar-h);
}
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 2px; height: var(--taskbar-h); }
#taskbar-apps { display: flex; align-items: center; gap: 2px; }

.tb-btn {
  position: relative; width: 42px; height: 42px;
  display: grid; place-items: center; border-radius: 6px;
  color: #1b1b1b; transition: background .12s;
}
.tb-btn:hover { background: rgba(0, 0, 0, .07); }
.tb-btn:active { background: rgba(0, 0, 0, .12); }
.tb-btn svg { width: 22px; height: 22px; }
.tb-btn::after {
  content: ""; position: absolute; bottom: 3px; left: 50%;
  width: 5px; height: 3px; border-radius: 2px; background: #0078d4;
  transform: translateX(-50%); opacity: 0; transition: width .16s, opacity .16s;
}
.tb-btn.running::after { opacity: 1; }
.tb-btn.active::after { width: 16px; }
.tb-btn.active { background: rgba(0, 0, 0, .10); }
.tb-start svg { color: #0a7bd6; }

.tray {
  display: flex; align-items: center; gap: 12px;
  height: 38px; padding: 0 10px; border-radius: 6px; color: #2b2b2b;
  transition: background .12s; cursor: pointer;
}
.tray:hover { background: rgba(0, 0, 0, .07); }
.tray-icon { display: flex; }

.tray-clock {
  display: flex; flex-direction: column; justify-content: center; align-items: flex-end; gap: 1px;
  padding: 0 10px; height: 38px; border-radius: 6px; font-size: 12px; line-height: 1.25; color: #1b1b1b;
  transition: background .12s; cursor: pointer;
}
.tray-clock:hover { background: rgba(0, 0, 0, .07); }

/* ==================== 控制中心 (托盘面板) ==================== */
.tray-panel {
  position: absolute;
  right: 12px;
  bottom: calc(var(--taskbar-h) + var(--safe-bottom) + 8px);
  width: 340px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - var(--taskbar-h) - var(--safe-bottom) - 24px);
  background: rgba(249, 249, 249, .95);
  -webkit-backdrop-filter: blur(30px) saturate(1.6);
  backdrop-filter: blur(30px) saturate(1.6);
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .08), 0 16px 40px rgba(0, 0, 0, .25);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 9400;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(.98);
  transition: opacity .16s, transform .16s;
  overflow-y: auto;
}
.tray-panel.open { opacity: 1; pointer-events: auto; transform: translateY(0) scale(1); }

.tr-top { display: flex; align-items: baseline; gap: 8px; flex: none; }
.tr-time { font-size: 26px; font-weight: 600; }
.tr-date { font-size: 13px; color: #555; }

.tr-toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; flex: none; }
.tr-toggle {
  background: #fff; border: 1px solid rgba(0, 0, 0, .08);
  border-radius: 6px; padding: 10px; font-size: 12.5px; text-align: center; cursor: pointer; transition: background .12s;
}
.tr-toggle[data-on="true"] { background: var(--accent); color: #fff; border-color: transparent; }
.tr-toggle:hover { opacity: 0.9; }

.tr-sliders { display: flex; flex-direction: column; gap: 10px; flex: none; }
.tr-slider { display: flex; align-items: center; gap: 12px; }
.tr-slider input { flex: 1; width: 100%; min-width: 0; accent-color: var(--accent); }

.tr-calendar {
  background: #fff; border: 1px solid rgba(0, 0, 0, .08); border-radius: 8px; padding: 12px; flex: none;
}
.tr-cal-header { font-size: 13px; font-weight: 600; margin-bottom: 8px; text-align: center; }
.tr-cal-week { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; font-size: 11px; color: #888; margin-bottom: 4px; }
.tr-cal-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; font-size: 12px; }
.tr-cal-days span { padding: 4px 0; border-radius: 4px; cursor: default; }
.tr-cal-days span:hover { background: rgba(0,0,0,.05); }
.tr-cal-days span.today { background: var(--accent); color: #fff; }

/* ==================== 开始菜单 ==================== */
.start-menu {
  position: absolute; left: 50%; bottom: calc(var(--taskbar-h) + var(--safe-bottom) + 8px);
  width: 620px; height: 640px; max-height: calc(100vh - var(--taskbar-h) - var(--safe-bottom) - 24px);
  z-index: 9400; display: flex; flex-direction: column;
  padding: 34px 42px 0; border-radius: 10px;
  background: rgba(243, 243, 243, .93);
  -webkit-backdrop-filter: blur(34px) saturate(1.7);
  backdrop-filter: blur(34px) saturate(1.7);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .09), 0 26px 64px rgba(0, 0, 0, .38);
  color: #1b1b1b;
  transform: translateX(-50%) translateY(18px) scale(.985);
  opacity: 0; pointer-events: none;
  transition: opacity .18s ease, transform .18s cubic-bezier(.2, .8, .3, 1);
}
.start-menu.open { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0) scale(1); }

.sm-search {
  flex: none; display: flex; align-items: center; gap: 9px;
  height: 36px; padding: 0 12px; border-radius: 18px;
  background: #fff; border: 1px solid rgba(0, 0, 0, .12);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05); margin-bottom: 26px;
}
.sm-search-icon { color: #5a5a5a; flex: none; }
.sm-search input { flex: 1; border: 0; outline: 0; background: transparent; font-size: 13px; }
.sm-search input::placeholder { color: #8a8a8a; }

.sm-pinned { flex: none; }
.sm-head { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.sm-more {
  font-size: 12px; font-weight: 400; padding: 5px 10px; border-radius: 5px;
  color: #1b1b1b; background: rgba(255, 255, 255, .7); border: 1px solid rgba(0, 0, 0, .08);
}
.sm-more:hover { background: #fff; }

.sm-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px 2px; min-height: 190px; align-content: start; }
.sm-app {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 4px 10px; border-radius: 6px; transition: background .12s;
}
.sm-app:hover { background: rgba(255, 255, 255, .85); }
.sm-app svg { width: 32px; height: 32px; }
.sm-app-label { font-size: 12px; line-height: 1.2; text-align: center; max-width: 78px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sm-recommend { flex: 1; min-height: 0; margin-top: 24px; overflow: hidden; }
.sm-rec-list { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px; overflow: auto; }
.sm-rec {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 6px; transition: background .12s;
}
.sm-rec:hover { background: rgba(255, 255, 255, .85); }
.sm-rec svg { width: 26px; height: 26px; flex: none; }
.sm-rec-txt { display: flex; flex-direction: column; min-width: 0; }
.sm-rec-name { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sm-rec-sub { font-size: 11px; color: #6d6d6d; }

.sm-footer {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  height: 60px; margin: 0 -42px; padding: 0 42px;
  border-top: 1px solid rgba(0, 0, 0, .09);
  background: rgba(230, 230, 230, .6); border-radius: 0 0 10px 10px;
}
.sm-user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, #4facfe, #6a5af9); color: #fff; font-size: 13px; font-weight: 600;
}
.sm-power { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; color: #1b1b1b; }
.sm-power:hover { background: rgba(0, 0, 0, .08); }

/* ==================== 电源菜单 ==================== */
.power-menu {
  position: absolute;
  bottom: calc(var(--taskbar-h) + var(--safe-bottom) + 76px);
  left: 50%;
  transform: translateX(-10px);
  background: #fff; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  padding: 4px; display: none; flex-direction: column; z-index: 9600; min-width: 100px;
}
.power-menu.open { display: flex; }
.pm-item { padding: 8px 16px; font-size: 13px; border-radius: 4px; cursor: pointer; }
.pm-item:hover { background: rgba(0,0,0,.06); }

/* ==================== 电源覆盖层 ==================== */
.power-layer {
  position: fixed; inset: 0; background: #000; z-index: 99999;
  display: none; flex-direction: column; align-items: center; justify-content: center; color: #fff;
}
.power-layer.show { display: flex; }
.pl-content { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.pl-content svg { width: 64px; height: 64px; color: #fff; }
.pl-text { font-size: 20px; font-weight: 300; letter-spacing: 1px; }
.pl-spinner {
  width: 30px; height: 30px; border: 3px solid rgba(255,255,255,.2);
  border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.pl-btn {
  background: transparent; border: 2px solid #fff; color: #fff;
  padding: 12px 32px; border-radius: 30px; font-size: 16px;
  cursor: pointer; display: flex; align-items: center; gap: 10px;
  transition: background .2s; margin-top: 20px;
}
.pl-btn:hover { background: rgba(255,255,255,.15); }

/* ==================== 右键菜单 ==================== */
.ctx-menu {
  position: absolute; min-width: 230px; padding: 6px; border-radius: 8px; z-index: 10000; display: none;
  font-size: 13px; background: rgba(249, 249, 249, .96);
  -webkit-backdrop-filter: blur(22px); backdrop-filter: blur(22px);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .09), 0 14px 38px rgba(0, 0, 0, .28);
}
.ctx-menu.open { display: block; animation: ctxIn .12s ease-out; }
@keyframes ctxIn { from { opacity: 0; transform: scale(.97) translateY(-4px); } to { opacity: 1; } }

.ctx-item { display: flex; align-items: center; gap: 11px; padding: 8px 12px; border-radius: 5px; cursor: default; white-space: nowrap; }
.ctx-item:hover { background: rgba(0, 0, 0, .065); }
.ctx-item svg { width: 17px; height: 17px; flex: none; }
.ctx-item .ctx-shortcut { margin-left: auto; font-size: 11.5px; color: #8a8a8a; }
.ctx-sep { height: 1px; margin: 5px 8px; background: rgba(0, 0, 0, .09); }

/* ==================== 滚动条 ==================== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, .22); border: 2px solid transparent; background-clip: content-box; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, .38); background-clip: content-box; }

/* ==================== 移动端适配 ==================== */
@media (max-width: 768px) {
  input, textarea, select { font-size: 16px !important; }

  .desk-icon { width: 76px; height: 84px; padding: 4px 2px; }
  .desk-icon svg { width: 34px; height: 34px; margin-bottom: 4px; }
  .desk-icon span { font-size: 11px; }

  .tb-btn { width: 38px; height: 38px; }
  .tb-btn svg { width: 20px; height: 20px; }
  .tray { display: none; }
  .tray-clock { font-size: 11px; padding: 0 8px; }
  #clock-date { display: none; }
  .tb-center {
    left: 6px; right: 76px; transform: none; justify-content: flex-start;
    overflow-x: auto; scrollbar-width: none;
  }
  .tb-center::-webkit-scrollbar { display: none; }
  .tb-center > * { flex: none; }

  .wc.max { display: none; }
  .wc { width: 44px; }

  .start-menu {
    left: 50%; width: calc(100vw - 16px); height: calc(100vh - var(--taskbar-h) - var(--safe-bottom) - 16px);
    height: calc(100dvh - var(--taskbar-h) - var(--safe-bottom) - 16px);
    max-height: none; padding: 22px 18px 0;
    transform: translateX(-50%) translateY(18px) scale(.985);
  }
  .start-menu.open { transform: translateX(-50%) translateY(0) scale(1); }
  .sm-search { margin-bottom: 18px; }
  .sm-grid { grid-template-columns: repeat(4, 1fr); gap: 2px; min-height: 0; }
  .sm-app { padding: 10px 2px 8px; }
  .sm-app svg { width: 28px; height: 28px; }
  .sm-app-label { font-size: 11px; max-width: 100%; }
  .sm-recommend { margin-top: 16px; }
  .sm-rec-list { grid-template-columns: 1fr; }
  .sm-footer { margin: 0 -18px; padding: 0 18px; height: 56px; }

  .ctx-menu { min-width: 200px; font-size: 13.5px; }
  .ctx-item { padding: 10px 14px; }

  .tray-panel {
    left: 8px; right: 8px; width: auto; max-width: none;
    max-height: calc(100vh - var(--taskbar-h) - var(--safe-bottom) - 24px);
    overflow-y: auto;
    padding: 12px;
    gap: 12px;
  }
  .tr-time { font-size: 22px; }
  .tr-toggle { padding: 8px; font-size: 12px; }
}

@media (max-width: 380px) {
  .sm-grid { grid-template-columns: repeat(3, 1fr); }
  .desk-icon { width: 70px; height: 80px; }
  .desk-icon span { font-size: 10.5px; }
}