* { box-sizing: border-box; }

:root {
  --z-bg: 0;
  --z-icons: 10;
  --z-window: 100;
  --z-menu: 200;
  --desktop-rail: 0px;
  --taskbar-height: 0px;
}

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas,
               'Liberation Mono', 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.6;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

::selection { background: var(--selection); }

/* ---- background layer (z-index: 0, never receives pointer events) ---- */
#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-bg);
  pointer-events: none;
  display: block;
}
.bg-static {
  position: fixed;
  inset: 0;
  z-index: var(--z-bg);
  pointer-events: none;
  display: none;
  background-image:
    linear-gradient(to right, rgba(139, 148, 158, 0.055) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(139, 148, 158, 0.055) 1px, transparent 1px);
  background-size: 48px 48px;
}
body[data-bg="static"] .bg-static { display: block; }
body[data-bg="static"] #bg-canvas,
body[data-bg="gradient"] #bg-canvas { display: none; }
body[data-bg="gradient"] {
  background-image: radial-gradient(1100px 700px at 50% 28%, rgba(139, 148, 158, 0.10), transparent 70%);
}

/* ---- terminal window ---- */
.terminal-window {
  position: relative;
  z-index: var(--z-window);
  width: min(1200px, 92vw);
  height: min(800px, 86vh);
  height: min(800px, 86dvh);
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

/* ---- status bar ---- */
.statusbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  user-select: none;
  cursor: grab;
}
.traffic-lights { display: flex; gap: 6px; }
.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: none;
  padding: 0;
  cursor: pointer;
  transition: filter 0.12s ease;
}
.dot:hover { filter: brightness(1.25); }
.dot:focus-visible { outline: 2px solid var(--input); outline-offset: 2px; }
.dot-red { background: #ff5f56; }
.dot-yellow { background: #ffbd2e; }
.dot-green { background: #27c93f; }
.statusbar-title { font-weight: 700; color: var(--text); }
.statusbar-status { color: var(--success); }
.statusbar-clock { margin-left: auto; }

/* ---- output area ---- */
.output {
  flex: 1 1 auto;
  overflow: auto;
  padding: 16px;
  cursor: text;
}
.output::-webkit-scrollbar { width: 10px; height: 10px; }
.output::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
.output::-webkit-scrollbar-track { background: transparent; }

.line,
.line-error,
.line-success,
.line-muted,
.line-command {
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 1.6em;
}
.line-command .prompt { color: var(--prompt); }
.line-command .cmd { color: var(--input); }
.line-error { color: var(--error); }
.line-success { color: var(--success); }
.line-muted { color: var(--text-muted); }
.muted { color: var(--text-muted); }

.logo {
  white-space: pre;
  color: var(--text);
  /* 立体感：向右下两层挤出投影 */
  text-shadow: 1px 1px 0 var(--logo-depth), 2px 2px 0 var(--logo-depth);
}

/* ---- 站点字标（与 og 分享图一致：粗体大字，27 用强调蓝）---- */
.line-wordmark {
  white-space: nowrap;
  font-size: clamp(34px, 7.5vw, 64px);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.01em;
  margin: 4px 0 2px;
  /* 立体感与旧 ASCII logo 保持一致 */
  text-shadow: 2px 2px 0 var(--logo-depth);
}
.wm-name { color: var(--text); }
.wm-num { color: var(--dir); }
.line-wordmark-note { opacity: 0.85; }

.output pre {
  font-family: inherit;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.dir { color: var(--dir); }
.link { color: var(--link); text-decoration: underline; }
a.link { color: var(--link); text-decoration: underline; cursor: pointer; }
a.link:hover { text-decoration: none; }

/* ---- neofetch ---- */
.neofetch {
  display: flex;
  gap: 28px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.neofetch-art,
.neofetch-info {
  margin: 0;
  font-family: inherit;
  white-space: pre;
  line-height: 1.35;
}
.neofetch-art { color: var(--prompt); }
.neofetch-info { color: var(--text); }
.neofetch-info::first-line { color: var(--input); font-weight: 700; }

/* ---- input line ---- */
.input-line {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}
.prompt {
  color: var(--prompt);
  margin-right: 8px;
  user-select: none;
  flex: 0 0 auto;
}
.cmd-input {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  outline: none;
  color: var(--input);
  font: inherit;
  caret-color: transparent;
  min-width: 1ch;
  padding: 0;
}
.cursor {
  flex: 0 0 auto;
  color: var(--cursor);
  animation: blink 1.1s step-end infinite;
  user-select: none;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

/* ---- desktop shortcuts (desktop-only — hard rule docs 1.3.1) ---- */
.desktop {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: var(--z-icons);
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 4px;
  max-height: calc(100dvh - 36px);
}
.desktop-icon {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 150px;
  padding: 6px 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.desktop-icon-glyph { display: inline-flex; flex: 0 0 auto; color: var(--dir); }
.desktop-icon-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.desktop-icon:hover { background: rgba(139, 148, 158, 0.12); color: var(--text); }
.desktop-icon.selected {
  background: rgba(88, 166, 255, 0.16);
  border-color: var(--input);
  color: var(--text);
}
.desktop-icon:focus-visible { outline: 2px solid var(--input); outline-offset: 1px; }

/* 桌面端为图标列留出左侧栏，并为任务栏留出底部空间（docs 1.3.1） */
@media (min-width: 641px) {
  :root { --desktop-rail: 190px; --taskbar-height: 34px; }
  body {
    padding-left: var(--desktop-rail);
    padding-bottom: var(--taskbar-height);
  }
}

/* 拖动/缩放中降低合成成本 */
.terminal-window.window-moving {
  will-change: transform, left, top, width, height;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
}

/* ---- window management (desktop) ---- */
.terminal-window.floating { position: fixed; margin: 0; }
.terminal-window.minimized { display: none; }
.terminal-window.closed { display: none; }
.terminal-window.maximized {
  border: none;
  border-radius: 0;
  box-shadow: none;
}

/* ---- terminal arcade: game session window ---- */
.game-window {
  z-index: calc(var(--z-window) + 10);
  min-width: 320px;
}
.game-screen {
  flex: 1 1 auto;
  margin: 0;
  padding: 8px 10px;
  overflow: auto;
  font-family: inherit;
  font-size: inherit;
  line-height: 1.2;
  color: var(--text);
  background: var(--bg);
  white-space: pre;
  tab-size: 1;
  outline: none;
}
.game-row { white-space: pre; }
.game-footer {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.game-touch { display: none; }
.game-touch[hidden] { display: none; }

/* ≤640px：窗口规则已由 .terminal-window 通配成全屏；这里只打开触摸控制 */
@media (max-width: 640px) {
  .game-touch {
    display: flex;
    gap: 10px;
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    background: var(--bg-elevated);
  }
  .game-touch-btn {
    flex: 1 1 0;
    min-height: 48px;
    font: inherit;
    font-size: 18px;
    color: var(--text);
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: 8px;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .game-touch-btn:active,
  .game-touch[data-active] .game-touch-btn[data-active] { color: var(--dir); }
  .game-footer { font-size: 12px; }
}
body.no-select { user-select: none; }

/* force the right cursor over the whole window while hovering edges / dragging */
.terminal-window.cursor-n, .terminal-window.cursor-n *,
.terminal-window.cursor-s, .terminal-window.cursor-s * { cursor: ns-resize; }
.terminal-window.cursor-e, .terminal-window.cursor-e *,
.terminal-window.cursor-w, .terminal-window.cursor-w * { cursor: ew-resize; }
.terminal-window.cursor-ne, .terminal-window.cursor-ne *,
.terminal-window.cursor-sw, .terminal-window.cursor-sw * { cursor: nesw-resize; }
.terminal-window.cursor-nw, .terminal-window.cursor-nw *,
.terminal-window.cursor-se, .terminal-window.cursor-se * { cursor: nwse-resize; }
.terminal-window.window-drag, .terminal-window.window-drag * { cursor: grabbing; }

/* ---- taskbar + start menu (desktop-only — hard rule docs 1.3.1) ---- */
.taskbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-menu);
  height: var(--taskbar-height);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.taskbar-start,
.taskbar-window {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.taskbar-start { color: var(--prompt); }
.taskbar-start:hover,
.taskbar-window:hover { border-color: var(--input); }
.taskbar-window.is-minimized { color: var(--text-muted); border-style: dashed; }
.taskbar-cwd { margin-left: auto; color: var(--dir); }
.taskbar-start:focus-visible,
.taskbar-window:focus-visible,
.start-menu-item:focus-visible { outline: 2px solid var(--input); outline-offset: 1px; }

.start-menu {
  position: fixed;
  left: 10px;
  bottom: calc(var(--taskbar-height) + 6px);
  z-index: var(--z-menu);
  min-width: 220px;
  max-height: 70dvh;
  overflow: auto;
  padding: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.start-menu[hidden] { display: none; }
.start-menu-group + .start-menu-group {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.start-menu-title {
  padding: 2px 8px 6px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.start-menu-item {
  display: block;
  width: 100%;
  padding: 7px 10px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.start-menu-item:hover { background: rgba(139, 148, 158, 0.12); }

/* ---- mobile quick toolbar (hidden on desktop) ---- */
.mobile-toolbar { display: none; }

/* ---- responsive: mobile ---- */
@media (max-width: 640px) {
  .cmd-input { font-size: 16px; }
  body { font-size: 13px; align-items: stretch; }
  .terminal-window {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }
  .output { padding: 12px; }
  .logo { font-size: min(10px, calc((100vw - 24px) / 36)); }
  .line-wordmark { font-size: clamp(30px, 12vw, 46px); margin: 6px 0 2px; }
  .input-line {
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }
  .mobile-toolbar {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    background: var(--bg-elevated);
  }
  .mobile-toolbar button {
    flex: 1 1 0;
    background: var(--bg-elevated);
    color: var(--input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 9px 0;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
  }
  .mobile-toolbar button:active { background: var(--border); }
  .window-dock { display: none !important; }
  .desktop { display: none !important; }
  .taskbar,
  .start-menu { display: none !important; }
}

/* ---- reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  .cursor { animation: none; }
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
