:root {
  --taskbar-h: 48px;
  --accent: #0a84ff;
  --win-bg: #f3f3f3;
  --titlebar-h: 40px;
  --shadow: 0 8px 30px rgba(0,0,0,0.35);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  user-select: none;
}

#desktop {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#wallpaper {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #0b3d91 0%, #1e5799 25%, #2d8fd8 55%, #5ac3ec 80%, #a0e4f7 100%);
  z-index: 0;
}
#wallpaper::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.25), transparent 45%),
              radial-gradient(ellipse at 80% 85%, rgba(0,0,0,0.25), transparent 50%);
}

#iconGrid {
  position: absolute;
  top: 12px;
  left: 12px;
  bottom: calc(var(--taskbar-h) + 12px);
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 4px;
  z-index: 1;
}

.desktop-icon {
  width: 82px;
  height: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  border-radius: 6px;
  padding: 4px;
}
.desktop-icon:hover { background: rgba(255,255,255,0.18); }
.desktop-icon.selected {
  background: rgba(120, 180, 255, 0.45);
  outline: 1px solid rgba(255,255,255,0.5);
}
.desktop-icon .icon {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.4));
}
.desktop-icon .icon svg { width: 100%; height: 100%; }
.desktop-icon .label {
  color: #fff;
  font-size: 12px;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  max-width: 76px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#windowLayer { position: absolute; inset: 0; z-index: 10; }

.window {
  position: absolute;
  min-width: 320px;
  min-height: 220px;
  background: var(--win-bg);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.15);
}
.window.focused { box-shadow: 0 12px 40px rgba(0,0,0,0.5); }
.window.maximized {
  border-radius: 0;
  width: 100% !important;
  height: calc(100% - var(--taskbar-h)) !important;
  left: 0 !important;
  top: 0 !important;
}
.window.minimized { display: none; }

.titlebar {
  height: var(--titlebar-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: #f3f3f3;
  flex-shrink: 0;
}
.window.focused .titlebar { background: #fff; }
.titlebar .win-icon { width: 18px; height: 18px; flex-shrink: 0; }
.titlebar .win-icon svg { width: 100%; height: 100%; }
.titlebar .title {
  font-size: 13px;
  color: #333;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.window-btn-group { display: flex; gap: 2px; }
.win-btn {
  width: 38px;
  height: 30px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
}
.win-btn:hover { background: rgba(0,0,0,0.08); }
.win-btn.close:hover { background: #e81123; color: #fff; }

.window-body {
  flex: 1;
  background: #fff;
  overflow: hidden;
  position: relative;
  border-top: 1px solid rgba(0,0,0,0.06);
}

.win-resize-handle {
  position: absolute;
  z-index: 50;
}
.win-resize-handle.n { top: -3px; left: 8px; right: 8px; height: 6px; cursor: ns-resize; }
.win-resize-handle.s { bottom: -3px; left: 8px; right: 8px; height: 6px; cursor: ns-resize; }
.win-resize-handle.e { right: -3px; top: 8px; bottom: 8px; width: 6px; cursor: ew-resize; }
.win-resize-handle.w { left: -3px; top: 8px; bottom: 8px; width: 6px; cursor: ew-resize; }
.win-resize-handle.ne { top: -3px; right: -3px; width: 10px; height: 10px; cursor: nesw-resize; }
.win-resize-handle.nw { top: -3px; left: -3px; width: 10px; height: 10px; cursor: nwse-resize; }
.win-resize-handle.se { bottom: -3px; right: -3px; width: 10px; height: 10px; cursor: nwse-resize; }
.win-resize-handle.sw { bottom: -3px; left: -3px; width: 10px; height: 10px; cursor: nesw-resize; }

/* ===== 任务栏 ===== */
#taskbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--taskbar-h);
  background: rgba(20, 20, 30, 0.88);
  backdrop-filter: blur(18px);
  z-index: 1000;
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 6px;
}
.taskbar-left, .taskbar-right { display: flex; align-items: center; gap: 4px; }
.taskbar-items {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  height: 100%;
  overflow: hidden;
}
.taskbar-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.taskbar-btn:hover { background: rgba(255,255,255,0.12); }
.taskbar-btn.active { background: rgba(255,255,255,0.18); }

.task-item {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.task-item:hover { background: rgba(255,255,255,0.12); }
.task-item.active { background: rgba(255,255,255,0.18); }
.task-item.active::after {
  content: "";
  position: absolute;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
}
.task-item svg { width: 22px; height: 22px; }

.tray-clock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  padding: 0 10px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  line-height: 1.35;
  cursor: pointer;
}
.tray-clock:hover { background: rgba(255,255,255,0.12); }

/* ===== 开始菜单 ===== */
#startMenu {
  position: fixed;
  left: 50%;
  bottom: calc(var(--taskbar-h) + 10px);
  transform: translateX(-50%);
  width: 560px;
  max-width: calc(100vw - 40px);
  height: 640px;
  max-height: calc(100vh - var(--taskbar-h) - 30px);
  background: rgba(30, 30, 40, 0.95);
  backdrop-filter: blur(24px);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 1100;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  color: #fff;
}
#startMenu.hidden, #powerMenu.hidden, #contextMenu.hidden, #lockScreen.hidden { display: none; }

.start-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 24px;
  padding: 8px 14px;
}
.start-search input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 14px;
}
.start-search input::placeholder { color: #bbb; }

.start-pinned h3, .start-recommended h3 {
  font-size: 13px;
  color: #ccc;
  font-weight: 500;
  margin-bottom: 10px;
}
#pinnedApps, #recommendedApps {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
#recommendedApps { grid-template-columns: repeat(3, 1fr); }
.pin-app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 4px;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 12px;
}
.pin-app:hover { background: rgba(255,255,255,0.1); }
.pin-app .icon { width: 34px; height: 34px; }
.pin-app .icon svg { width: 100%; height: 100%; }

.start-recommended { flex: 1; overflow: hidden; }

.start-user {
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 12px;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4facfe, #00f2fe);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
}
.avatar.large {
  width: 64px;
  height: 64px;
  font-size: 26px;
}
.user-name { flex: 1; font-size: 14px; }
.power-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.power-btn:hover { background: rgba(255,255,255,0.12); }

#powerMenu {
  position: fixed;
  right: calc((100vw - 560px) / 2);
  bottom: calc(var(--taskbar-h) + 90px);
  background: rgba(45, 45, 55, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 1200;
  padding: 6px;
  min-width: 180px;
}
#powerMenu button {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 14px;
  text-align: left;
  border-radius: 6px;
  cursor: pointer;
}
#powerMenu button:hover { background: rgba(255,255,255,0.12); }

/* ===== 右键菜单 ===== */
#contextMenu {
  position: fixed;
  min-width: 200px;
  background: rgba(245, 245, 245, 0.98);
  backdrop-filter: blur(16px);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 1500;
  padding: 5px;
  font-size: 13px;
  color: #333;
}
#contextMenu .ctx-item {
  padding: 8px 14px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}
#contextMenu .ctx-item:hover { background: var(--accent); color: #fff; }
#contextMenu .ctx-sep {
  height: 1px;
  background: #e0e0e0;
  margin: 5px 8px;
}

/* ===== 锁屏 ===== */
#lockScreen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: linear-gradient(135deg, #0b3d91 0%, #1e5799 25%, #2d8fd8 55%, #5ac3ec 80%, #a0e4f7 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 80px 0 40px;
  color: #fff;
}
#lockScreen.hidden { display: none; }
.lock-time { text-align: center; }
.lock-time #lockTime { font-size: 72px; font-weight: 200; }
.lock-time #lockDate { font-size: 20px; opacity: 0.9; margin-top: 6px; }
.lock-user { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.lock-user button {
  padding: 8px 32px;
  border-radius: 20px;
  border: none;
  background: rgba(255,255,255,0.85);
  color: #222;
  font-size: 14px;
  cursor: pointer;
}
.lock-user button:hover { background: #fff; }

/* ===== 通用滚动条 ===== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c8c8c8; border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #a8a8a8; background-clip: content-box; }

@media (max-width: 700px) {
  #startMenu { width: calc(100vw - 30px); }
  #pinnedApps { grid-template-columns: repeat(4, 1fr); }
}
