:root {
  --bg: #111316;
  --bg-grid: rgba(255, 255, 255, 0.032);
  --surface: #191c21;
  --surface-2: #21252c;
  --surface-3: #2a2f38;
  --line: #313742;
  --line-hi: #4a5363;
  --fg: #ebeef2;
  --muted: #98a1b0;
  --accent: #e5a93b;
  --accent-dim: rgba(229, 169, 59, 0.16);
  --ok: #57c785;
  --warn: #f0b357;
  --bad: #f06e6e;
  --taskbar-h: 44px;
  --sans: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); font-variant-ligatures: none; }
.hidden { display: none !important; }

/* ---------------- 开机画面 ---------------- */
.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: radial-gradient(circle at 25% 18%, #1d2129 0%, #0e1013 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  transition: opacity 0.25s ease;
}
.boot-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}
.boot-panel {
  width: min(760px, 100%);
  max-height: min(560px, calc(100vh - 32px));
  background: #14171c;
  border: 1px solid var(--line-hi);
  border-radius: 10px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.boot-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.boot-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.boot-sub { color: var(--muted); font-size: 12px; }
.boot-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  animation: pulse 1.1s infinite;
}
.boot-dot.ok { background: var(--ok); box-shadow: 0 0 10px var(--ok); animation: none; }
.boot-dot.bad { background: var(--bad); box-shadow: 0 0 10px var(--bad); animation: none; }
@keyframes pulse { 50% { opacity: 0.35; } }

.boot-log {
  flex: 1;
  overflow: auto;
  padding: 14px 16px;
  font: 12.5px/1.65 var(--mono);
  background: #0d0f12;
  min-height: 220px;
}
.boot-line { display: flex; gap: 10px; margin-bottom: 3px; word-break: break-word; }
.boot-ts { color: #6f798a; flex: none; min-width: 58px; }
.boot-msg.ok { color: var(--ok); }
.boot-msg.warn { color: var(--warn); }
.boot-msg.bad { color: var(--bad); }
.boot-msg.dim { color: var(--muted); }

.boot-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}
.boot-tag {
  border: 1px solid var(--line-hi);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  color: var(--accent);
}

/* ---------------- 桌面背景与图标 ---------------- */
.desktop {
  position: fixed;
  inset: 0 0 var(--taskbar-h) 0;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse at 72% 24%, rgba(229, 169, 59, 0.08), transparent 55%),
    radial-gradient(ellipse at 20% 80%, rgba(87, 199, 133, 0.06), transparent 50%),
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 32px 32px, 32px 32px;
  overflow: hidden;
  user-select: none;
}

.desktop-icons {
  position: absolute;
  top: 16px;
  left: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 10px;
  z-index: 1;
}
.desk-icon {
  width: 84px;
  padding: 8px 6px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  text-align: center;
  font: inherit;
  transition: background 0.12s, border-color 0.12s;
}
.desk-icon:hover, .desk-icon:focus-visible {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.14);
  outline: none;
}
.desk-icon:active { transform: scale(0.97); }
.desk-glyph {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line-hi);
  display: flex;
  align-items: center;
  justify-content: center;
  font: 600 18px/1 var(--mono);
  color: var(--accent);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}
.desk-label {
  font-size: 12px;
  line-height: 1.25;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

/* ---------------- 窗口系统 ---------------- */
.window-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}
.win {
  position: absolute;
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--line-hi);
  border-radius: 10px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 280px;
  min-height: 200px;
  user-select: text;
}
.win.focused {
  border-color: rgba(229, 169, 59, 0.65);
  box-shadow: 0 22px 58px rgba(0, 0, 0, 0.72);
}
.win.minimized { display: none; }
.win.maximized {
  left: 6px !important;
  top: 6px !important;
  width: calc(100% - 12px) !important;
  height: calc(100% - 12px) !important;
}

.win-bar {
  height: 36px;
  flex: none;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  padding: 0 8px 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: move;
  user-select: none;
  touch-action: none;
}
.win-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.win-badge {
  font: 600 11px/1 var(--mono);
  color: var(--accent);
  background: var(--accent-dim);
  padding: 3px 5px;
  border-radius: 4px;
}
.win-controls { display: flex; gap: 4px; flex: none; }
.win-btn {
  width: 26px;
  height: 24px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font: 600 13px/1 var(--mono);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.win-btn:hover { background: var(--surface-3); color: var(--fg); }
.win-btn.close:hover { background: rgba(240, 110, 110, 0.22); color: #ff9c9c; }

.win-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
  background: var(--surface);
}
.win-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  touch-action: none;
}
.win-resize::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--line-hi);
  border-bottom: 2px solid var(--line-hi);
}

/* ---------------- 任务栏与开始菜单 ---------------- */
.taskbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--taskbar-h);
  z-index: 5000;
  background: rgba(20, 23, 28, 0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.start-btn {
  height: 30px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--line-hi);
  background: var(--surface-2);
  color: var(--fg);
  font: 600 13px/1 var(--sans);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  flex: none;
}
.start-btn:hover { border-color: var(--accent); }
.start-mark { color: var(--accent); font-size: 12px; }

.taskbar-wins {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.taskbar-wins::-webkit-scrollbar { display: none; }
.tb-win {
  height: 30px;
  max-width: 168px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font: 500 12.5px/1 var(--sans);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: none;
}
.tb-win.active {
  background: var(--surface-3);
  border-color: rgba(229, 169, 59, 0.55);
  color: var(--fg);
}
.tb-win.minimized { opacity: 0.65; }

.taskbar-tray {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}
.tray-pill {
  height: 28px;
  padding: 0 9px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.tray-pill:hover { border-color: var(--line-hi); }
.tray-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}
.tray-dot.ok { background: var(--ok); }
.tray-dot.busy { background: var(--accent); animation: pulse 0.9s infinite; }
.tray-dot.bad { background: var(--bad); }
.tray-clock { font-size: 12px; color: var(--muted); padding: 0 4px; }

.start-menu {
  position: fixed;
  left: 8px;
  bottom: calc(var(--taskbar-h) + 6px);
  z-index: 6000;
  width: 240px;
  background: var(--surface-2);
  border: 1px solid var(--line-hi);
  border-radius: 10px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.65);
  padding: 6px;
}
.start-item {
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--fg);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.start-item:hover { background: var(--surface-3); }
.start-item small { display: block; font-size: 11px; color: var(--muted); }
.start-item-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--accent);
  font: 600 13px/1 var(--mono);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

/* ---------------- 通用控件 ---------------- */
.btn, .btn-ghost, .btn-danger {
  border-radius: 6px;
  font: 600 13px/1 var(--sans);
  padding: 8px 13px;
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn {
  background: var(--accent);
  color: #161410;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
  background: var(--surface-2);
  color: var(--fg);
  border-color: var(--line-hi);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); }
.btn-danger {
  background: rgba(240, 110, 110, 0.16);
  color: #ff9c9c;
  border-color: rgba(240, 110, 110, 0.4);
}
.btn-danger:hover { background: rgba(240, 110, 110, 0.28); }

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1 1 130px;
}
.field label { font-size: 12px; color: var(--muted); }
select, input[type="text"], input[type="number"], textarea {
  width: 100%;
  background: #101216;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  font: 13px/1.45 var(--sans);
}
textarea.mono, input.mono { font-family: var(--mono); }
select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  background: #12151a;
  border: 1px solid var(--line);
  font-size: 12.5px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.status-bar.busy .status-dot { background: var(--accent); animation: pulse 0.85s infinite; }
.status-bar.ok .status-dot { background: var(--ok); }
.status-bar.bad .status-dot { background: var(--bad); }

/* ---------------- 吟游诗人应用 ---------------- */
.bard-app { display: flex; flex-direction: column; gap: 10px; height: 100%; }
.bard-output {
  background: #0d0f13;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-height: 92px;
  max-height: 200px;
  overflow: auto;
  font: 15px/1.65 Georgia, "Times New Roman", serif;
  white-space: pre-wrap;
  word-break: break-word;
}
.bard-prompt-part { color: var(--muted); }
.bard-gen-part { color: var(--fg); }
.bard-cursor {
  display: inline-block;
  width: 7px;
  height: 1em;
  background: var(--accent);
  vertical-align: -2px;
  margin-left: 2px;
  animation: pulse 0.7s infinite;
}
.bard-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(115px, 1fr));
  gap: 6px;
}
.metric-box {
  background: #12151a;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
}
.metric-box span { display: block; font-size: 11px; color: var(--muted); }
.metric-box b { font: 600 13.5px/1.3 var(--mono); color: var(--fg); }
.metric-box b.acc { color: var(--accent); }

.tok-table-wrap {
  flex: 1;
  min-height: 110px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0f1116;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font: 12px/1.4 var(--mono);
}
.data-table th, .data-table td {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  text-align: left;
  white-space: nowrap;
}
.data-table th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
}
.pill {
  display: inline-block;
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-3);
  color: var(--muted);
}
.pill.w8 { background: var(--accent-dim); color: var(--accent); }
.pill.ok { background: rgba(87, 199, 133, 0.16); color: var(--ok); }
.pill.bad { background: rgba(240, 110, 110, 0.18); color: var(--bad); }

/* ---------------- 链上计算机应用 ---------------- */
.cpc-app { display: flex; flex-direction: column; gap: 9px; height: 100%; }
.cpc-editor {
  flex: 1;
  min-height: 140px;
  resize: vertical;
  font-size: 12.5px;
  line-height: 1.5;
  tab-size: 2;
}
.cpc-detail {
  background: #0d0f13;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 130px;
  overflow: auto;
  color: var(--muted);
}

/* ---------------- 终端应用 ---------------- */
.term-app { display: flex; flex-direction: column; gap: 8px; height: 100%; }
.term-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.q-chip {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 5px;
  padding: 3px 8px;
  font: 12px/1.3 var(--mono);
  cursor: pointer;
}
.q-chip:hover { border-color: var(--accent); color: var(--fg); }
.term-out {
  flex: 1;
  min-height: 140px;
  overflow: auto;
  background: #0b0d10;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  font-size: 12.5px;
  line-height: 1.55;
}
.term-line { white-space: pre-wrap; word-break: break-word; margin-bottom: 3px; }
.term-line.cmd { color: var(--accent); margin-top: 6px; }
.term-line.ok { color: var(--ok); }
.term-line.warn { color: var(--warn); }
.term-line.bad { color: var(--bad); }
.term-line.dim { color: var(--muted); }
.term-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #0d0f13;
  border: 1px solid var(--line-hi);
  border-radius: 6px;
  padding: 4px 8px;
}
.term-prompt { color: var(--accent); font-size: 13px; flex: none; }
.term-input-row input {
  border: 0;
  background: transparent;
  padding: 4px 2px;
  font-size: 13px;
}

/* ---------------- 资源监视应用 ---------------- */
.mon-app { display: flex; flex-direction: column; gap: 10px; height: 100%; }
.mon-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.mon-chip {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--fg);
}

/* ---------------- 关于应用 ---------------- */
.about-app { font-size: 13.5px; line-height: 1.65; }
.about-app h3 { margin: 0 0 8px; font-size: 16px; color: var(--accent); }
.about-app h4 { margin: 12px 0 6px; font-size: 13.5px; color: var(--fg); }
.about-app p { margin: 0 0 8px; color: var(--fg); }
.about-app ul { margin: 0 0 8px; padding-left: 18px; color: var(--muted); }
.about-app li { margin-bottom: 5px; }
.about-app li strong { color: var(--fg); }
.about-app code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 12px;
}
.about-warn {
  background: var(--accent-dim);
  border: 1px solid rgba(229, 169, 59, 0.35);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
}
.about-note {
  background: #101216;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------------- 移动端适配（390px 等窄屏） ---------------- */
@media (max-width: 640px) {
  .desktop-icons {
    left: 10px;
    right: 10px;
    top: 10px;
    bottom: auto;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .desk-icon { width: 78px; padding: 6px 4px; }
  .win {
    left: 4px !important;
    top: 4px !important;
    width: calc(100% - 8px) !important;
    height: calc(100% - 8px) !important;
    min-width: 0;
    border-radius: 8px;
  }
  .win-resize { display: none; }
  .tray-clock { display: none; }
  #tray-gas { display: none; }
  .tb-win { max-width: 110px; padding: 0 7px; font-size: 12px; }
  .win-body { padding: 10px; }
  .bard-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
