/* =====================================================================
   desktop.css — 桌面 / 背景 / CRT / 侧边图标 / 任务栏 / 开始菜单
   结构：.desktop > .desktop__bg / .desktop__stars / .desktop__grid
                   / .crt-overlay / .sidebar / .windows-layer / .taskbar
   与 js/windows.js 契约：
     - 窗口由 JS 以像素 left/top 定位在 .windows-layer 内
     - 任务栏按钮由 JS 生成 .taskbar-item，挂到 #taskbar-items
     - 状态类：is-closed / is-minimized / is-maximized / is-focused / is-dragging
     - <=768px：JS isMobile() 与 body.is-mobile 同口径
   ===================================================================== */

/* ---------------------------------------------------------------------
   桌面容器
   --------------------------------------------------------------------- */
.desktop {
  position: fixed;
  inset: 0;
  /* hidden 兜底 + clip 禁滚动：桌面是一块固定画布 */
  overflow: hidden;
  overflow: clip;
  color: var(--text-light);
  font-family: var(--font-ui);
  background:
    radial-gradient(ellipse at 50% -10%, var(--bg-purple) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 110%, rgba(139, 61, 255, 0.22) 0%, transparent 50%),
    linear-gradient(160deg, var(--bg-purple) 0%, var(--bg-deep) 55%, #05000a 100%);
}

.desktop__bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: var(--z-bg);
  background:
    radial-gradient(ellipse at 20% 30%, rgba(139, 61, 255, 0.18), transparent 55%),
    radial-gradient(ellipse at 80% 70%, rgba(0, 240, 255, 0.10), transparent 55%);
}

.desktop__stars {
  position: absolute;
  inset: -50%;
  pointer-events: none;
  z-index: var(--z-bg);
  background-image:
    radial-gradient(1px 1px at 20px 30px, var(--text-light), transparent),
    radial-gradient(1px 1px at 120px 80px, var(--accent-cyan), transparent),
    radial-gradient(1px 1px at 200px 160px, var(--accent-pink), transparent),
    radial-gradient(1.5px 1.5px at 320px 60px, var(--text-light), transparent),
    radial-gradient(1px 1px at 420px 220px, var(--accent-cyan), transparent),
    radial-gradient(1.5px 1.5px at 260px 260px, rgba(255, 255, 255, 0.75), transparent);
  background-size: 480px 300px;
  opacity: 0.6;
  animation: stars-drift 120s linear infinite;
}

@keyframes stars-drift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-240px, -150px, 0); }
}

.desktop__grid {
  position: absolute;
  inset: 40% -20% -20% -20%;
  pointer-events: none;
  z-index: var(--z-bg);
  background-image:
    linear-gradient(rgba(0, 240, 255, 0.14) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 240, 255, 0.14) 1px, transparent 1px);
  background-size: 48px 48px;
  transform: perspective(320px) rotateX(62deg);
  transform-origin: top center;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 60%);
  mask-image: linear-gradient(to bottom, transparent 0%, #000 60%);
  animation: grid-scroll 6s linear infinite;
}

@keyframes grid-scroll {
  from { background-position: 0 0; }
  to { background-position: 0 48px; }
}

/* CRT 扫描线 + 暗角 + 呼吸 */
.crt-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: var(--z-crt);
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.14) 0px,
    rgba(0, 0, 0, 0.14) 1px,
    transparent 1px,
    transparent 3px
  );
}

.crt-overlay::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.5) 100%);
  animation: crt-flicker 7s steps(60) infinite;
}

@keyframes crt-flicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.92; }
}

/* ---------------------------------------------------------------------
   窗口层
   --------------------------------------------------------------------- */
.windows-layer {
  position: absolute;
  /* 左侧留出图标栏，窗口永远不会压住快捷方式 */
  inset: 0 0 var(--taskbar-h) 112px;
  z-index: var(--z-windows);
  pointer-events: none; /* 只有窗口自身可交互，侧栏不被遮挡 */
}

.windows-layer > .win9x-window {
  position: absolute;
  pointer-events: auto;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  max-height: calc(100vh - var(--taskbar-h) - 24px);
}

.windows-layer > .win9x-window.is-maximized {
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-height: none !important;
  transform: none !important;
}

/* ---------------------------------------------------------------------
   左侧图标栏
   --------------------------------------------------------------------- */
.sidebar {
  position: absolute;
  top: var(--space-4);
  left: var(--space-4);
  bottom: calc(var(--taskbar-h) + var(--space-3));
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: var(--space-1) var(--space-2);
  padding: var(--space-2);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(139, 61, 255, 0.5);
}

.sidebar__icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 78px;
  padding: 4px var(--space-1);
  border: 2px solid transparent;
  border-radius: 2px;
  color: var(--text-light);
  text-align: center;
  cursor: pointer;
  transition: background var(--t-fast) ease, border-color var(--t-fast) ease;
}

.sidebar__icon:hover {
  background: rgba(139, 61, 255, 0.22);
  border-color: rgba(0, 240, 255, 0.4);
}

.sidebar__icon:active {
  background: rgba(139, 61, 255, 0.4);
}

.sidebar__glyph {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.45));
}

.sidebar__label {
  font-family: var(--font-cjk-label);
  font-size: 11px;
  line-height: 1.25;
  word-break: break-word;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

.sidebar__label--en {
  font-family: var(--font-pixel-ui);
  font-size: 13px;
  letter-spacing: 0.02em;
}

/* =====================================================================
   任务栏
   ===================================================================== */
.taskbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-taskbar);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  height: var(--taskbar-h);
  padding: 3px var(--space-1);
  background: var(--win-gray);
  border-top: 1px solid var(--win-light);
  box-shadow: 0 -1px 0 var(--text-dark), inset 0 1px 0 var(--win-gray-light);
  color: var(--text-dark);
  font-family: var(--font-ui);
  font-size: 11px;
}

.taskbar__start {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 8px 0 5px;
  background: var(--win-gray);
  border: var(--border-outline);
  box-shadow: var(--bevel-raised);
  font-weight: 700;
  font-size: 12px;
  color: var(--text-dark);
  flex-shrink: 0;
}

.taskbar__start:hover {
  background: var(--win-gray-light);
}

.taskbar__start[aria-expanded="true"] {
  box-shadow: var(--bevel-pressed);
  padding-top: 1px;
}

.taskbar__start-logo {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  background: linear-gradient(135deg, var(--accent-pink), var(--accent-purple) 60%, var(--accent-cyan));
  color: #fff;
  font-size: 11px;
  line-height: 1;
}

.taskbar__items {
  display: flex;
  align-items: center;
  gap: 3px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.taskbar-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 160px;
  min-width: 0;
  height: 24px;
  padding: 0 6px;
  background: var(--win-gray);
  border: var(--border-outline);
  box-shadow: var(--bevel-raised);
  color: var(--text-dark);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

.taskbar-item.is-active {
  box-shadow: var(--bevel-pressed);
  background:
    repeating-conic-gradient(var(--win-gray-light) 0% 25%, var(--win-light) 0% 50%) 0 0 / 2px 2px;
  font-weight: 700;
}

.taskbar-item__label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.taskbar__tray {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 24px;
  padding: 0 6px;
  border: var(--border-outline);
  box-shadow: var(--bevel-inset);
  background: var(--win-gray);
  flex-shrink: 0;
}

.taskbar__tray-icon {
  font-size: 11px;
  opacity: 0.75;
}

.taskbar__clock {
  font-family: var(--font-pixel-ui);
  font-size: 14px;
  letter-spacing: 0.04em;
  min-width: 62px;
  text-align: center;
}

/* 语言切换键 */
.lang-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 18px;
  padding: 0 4px;
  background: var(--win-gray-light);
  border: var(--border-outline);
  box-shadow: var(--bevel-raised);
  font-family: var(--font-pixel-ui);
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--text-dark);
}

.lang-toggle:hover {
  background: var(--win-light);
}

.lang-toggle:active {
  box-shadow: var(--bevel-pressed);
}

/* =====================================================================
   开始菜单
   ===================================================================== */
.start-menu {
  position: absolute;
  left: var(--space-1);
  bottom: calc(var(--taskbar-h) + 1px);
  z-index: var(--z-startmenu);
  display: flex;
  background: var(--win-gray);
  border: var(--border-outline);
  box-shadow: var(--bevel-window), 6px -6px 0 rgba(0, 0, 0, 0.45);
  animation: start-open 140ms var(--ease-out-back) both;
}

@keyframes start-open {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.start-menu__banner {
  width: 26px;
  background: linear-gradient(180deg, var(--accent-pink) 0%, var(--accent-purple) 45%, var(--text-dark) 100%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: var(--space-3);
}

.start-menu__banner-text {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: var(--font-pixel);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--win-light);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}

.start-menu__body {
  display: flex;
  flex-direction: column;
  min-width: 208px;
  padding: 3px;
}

.start-menu__search {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 2px 2px 4px;
  padding: 2px 4px;
  background: var(--win-light);
  border: var(--border-outline);
  box-shadow: var(--bevel-inset);
}

.start-menu__search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--text-dark);
  outline: none;
}

.start-menu__search input::placeholder {
  color: #8a8a96;
}

.start-menu__list {
  display: flex;
  flex-direction: column;
  max-height: 60vh;
  overflow-y: auto;
}

.start-menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: 4px 10px 4px 6px;
  color: var(--text-dark);
  font-family: var(--font-ui);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

.start-menu__item:hover,
.start-menu__item:focus-visible {
  background: var(--select-blue);
  color: var(--win-light);
  outline: none;
}

.start-menu__item--danger:hover {
  background: #b3231c;
}

.start-menu__item[hidden] {
  display: none !important;
}

.start-menu__item .pixel-icon {
  width: 16px;
  height: 16px;
}

.start-menu__separator {
  height: 2px;
  margin: 4px 2px;
  border-top: 1px solid var(--win-dark);
  border-bottom: 1px solid var(--win-light);
}

.start-menu__hint {
  margin: 2px 6px 4px;
  color: var(--win-dark);
  font-family: var(--font-pixel-ui);
  font-size: 11px;
  letter-spacing: 0.04em;
}

/* =====================================================================
   开机自检 / 关机屏
   ===================================================================== */
.boot {
  position: fixed;
  inset: 0;
  z-index: var(--z-boot);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-5);
  background: #05000a;
  color: var(--text-light);
  font-family: var(--font-pixel-ui);
  transition: opacity 320ms ease, visibility 320ms;
}

.boot.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot__logo {
  width: 48px;
  height: 48px;
  filter: drop-shadow(0 0 12px rgba(139, 61, 255, 0.8));
  animation: boot-float 2.4s steps(3, end) infinite;
}

@keyframes boot-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.boot__title {
  font-family: var(--font-pixel);
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--accent-cyan);
  text-shadow: var(--neon-glow-cyan);
  text-align: center;
  line-height: 1.9;
}

.boot__log {
  min-height: 96px;
  width: min(420px, 100%);
  font-size: 15px;
  line-height: 1.5;
  color: var(--muted);
  text-align: left;
  white-space: pre-wrap;
}

.boot__bar {
  display: flex;
  gap: 3px;
  width: min(320px, 100%);
  height: 14px;
  padding: 2px;
  border: 1px solid var(--accent-purple);
  background: rgba(139, 61, 255, 0.12);
}

.boot__cell {
  flex: 1;
  background: rgba(139, 61, 255, 0.25);
}

.boot__cell.is-on {
  background: var(--accent-cyan);
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.7);
}

.boot__skip {
  margin-top: var(--space-2);
  color: var(--win-dark);
  font-family: var(--font-ui);
  font-size: 11px;
}

.shutdown {
  position: fixed;
  inset: 0;
  z-index: var(--z-boot);
  display: grid;
  place-items: center;
  padding: var(--space-6);
  background: #000;
  color: #ffb44d;
  font-family: var(--font-pixel);
  font-size: 13px;
  line-height: 2.2;
  text-align: center;
  text-shadow: 0 0 12px rgba(255, 180, 77, 0.7);
}

.shutdown__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-5);
  max-width: 460px;
}

.shutdown__btn {
  min-height: 28px;
  padding: 4px 16px;
  background: var(--win-gray);
  color: var(--text-dark);
  border: var(--border-outline);
  box-shadow: var(--bevel-raised);
  font-family: var(--font-ui);
  font-size: 12px;
  text-shadow: none;
}

/* =====================================================================
   桌宠助手（HR bot）
   ===================================================================== */
.barkley {
  position: absolute;
  right: var(--space-4);
  bottom: calc(var(--taskbar-h) + var(--space-3));
  z-index: var(--z-barkley);
  width: 280px;
  max-width: calc(100vw - 24px);
  padding: 3px;
  background: var(--win-gray);
  border: var(--border-outline);
  box-shadow: var(--bevel-window), var(--window-shadow);
  color: var(--text-dark);
  font-family: var(--font-ui);
  animation: win-appear var(--t-base) var(--ease-out-back) both;
}

.barkley[hidden] {
  display: none !important;
}

.barkley__header {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 3px;
  background: var(--barkley-header);
  color: var(--text-dark);
  font-size: 11px;
}

.barkley__avatar {
  width: 16px;
  height: 16px;
}

.barkley__name {
  font-weight: 700;
}

.barkley__meta {
  flex: 1;
  text-align: right;
  font-family: var(--font-pixel-ui);
  font-size: 12px;
  color: #7a5a00;
}

.barkley__close {
  width: 15px;
  height: 13px;
  font-size: 10px;
}

.barkley__body {
  padding: var(--space-2);
  background: #fffdf2;
  border-top: 1px solid var(--win-dark);
}

.barkley__bubble {
  padding: var(--space-2);
  background: var(--win-light);
  border: 1px solid var(--win-dark);
  box-shadow: var(--bevel-inset);
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-dark);
}

.barkley__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-2);
}

.barkley__actions .win9x-button {
  min-height: 22px;
  padding: 2px 8px;
  font-size: 11px;
}
