:root {
  --bg: #0a0d13;
  --bg-grid: #0d1119;
  --surface: #12161f;
  --surface-2: #171c28;
  --border: #232a3a;
  --border-soft: #1a2030;
  --text: #e8ebf1;
  --text-muted: #6f7890;
  --text-dim: #4a5268;
  --accent: #34e0a1;      /* 在线 / 存活 */
  --accent-dim: #1d8f68;
  --accent-glow: rgba(52, 224, 161, 0.35);
  --danger: #ff5470;
  --danger-dim: #7a2233;
  --game: #8b9dff;        /* 正在运行游戏 */
  --game-dim: #2c3466;

  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

[data-theme="light"] {
  --bg: #f3f5f9;
  --bg-grid: #e7eaf1;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --border: #dde2ea;
  --border-soft: #e7eaf1;
  --text: #171b26;
  --text-muted: #667085;
  --text-dim: #a2a9b8;
  --accent: #0f9d6e;
  --accent-dim: #0c7d58;
  --accent-glow: rgba(15, 157, 110, 0.22);
  --danger: #e0294f;
  --danger-dim: #f6c2cf;
  --game: #4a5fd9;
  --game-dim: #d6dcfb;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
}

body {
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 42px 42px;
  background-position: center;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  font-family: var(--font-body);
  cursor: pointer;
}

.screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- 登录界面 ---------- */

#login-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px 32px;
  text-align: center;
  box-shadow: 0 40px 80px -30px rgba(0, 0, 0, 0.6);
}

.login-pulse {
  height: 40px;
  margin-bottom: 20px;
}

.pulse-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.pulse-svg path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 6px var(--accent-glow));
  stroke-dasharray: 300;
  stroke-dashoffset: 300;
  animation: pulse-draw 2.4s ease-in-out infinite;
}

@keyframes pulse-draw {
  0%   { stroke-dashoffset: 300; opacity: 0.4; }
  50%  { stroke-dashoffset: 0;   opacity: 1; }
  100% { stroke-dashoffset: -300; opacity: 0.4; }
}

.brand {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 0 0 6px;
}

.brand-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 24px;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#password-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  font-family: var(--font-mono);
}

#password-input:focus {
  border-color: var(--accent-dim);
}

#login-form button[type="submit"] {
  background: var(--accent);
  color: #06130d;
  border: none;
  border-radius: 10px;
  padding: 12px 14px;
  font-weight: 600;
  font-size: 14px;
  transition: filter 0.15s ease;
}

#login-form button[type="submit"]:hover {
  filter: brightness(1.1);
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin: 12px 0 0;
}

/* ---------- 顶栏 ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  background: rgba(10, 13, 19, 0.85);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.1em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.ws-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.ws-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
}

.ws-status.online .ws-dot {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  animation: dot-blink 2s ease-in-out infinite;
}

.ws-status.offline .ws-dot { background: var(--danger); }

@keyframes dot-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  transition: all 0.15s ease;
}

.ghost-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px;
}

html {
  transition: none;
}

body, .device-card, .login-card, .modal-card, .toast, .ghost-btn, .device-actions button {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* ---------- 主体 ---------- */

.main {
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 28px 80px;
  display: flex;
  flex-direction: column;
  gap: 44px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-head h2 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}

.section-sub {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.range-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  border-radius: 8px;
  padding: 6px 10px;
}

.head-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
}

.pill-tabs .pill {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.pill-tabs .pill:hover { color: var(--text); }

.pill-tabs .pill.active {
  background: var(--surface-2);
  color: var(--accent);
}

/* ---------- 设备卡片 ---------- */

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s ease;
}

.device-card.is-online {
  border-color: var(--border);
}

.device-card.is-online::before {
  content: '';
  position: absolute;
  inset: 0;
  padding: 1px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-glow), transparent 40%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.device-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.device-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
}

.device-id {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 20px;
  white-space: nowrap;
}

.status-pill.online {
  color: var(--accent);
  background: rgba(52, 224, 161, 0.1);
}

.status-pill.offline {
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
}

.status-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-pill.online .dot {
  animation: dot-blink 1.6s ease-in-out infinite;
}

/* 心跳波形 */
.heartbeat {
  height: 34px;
  opacity: 0.85;
}

.heartbeat svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.heartbeat path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 4px var(--accent-glow));
}

.heartbeat.flat path {
  stroke: var(--text-dim);
  filter: none;
}

.heartbeat.animated path {
  stroke-dasharray: 340;
  stroke-dashoffset: 340;
  animation: pulse-draw 2.2s linear infinite;
}

.game-block {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 12px 14px;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}

.game-block .label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.game-block .game-name {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--game);
}

.game-block .game-timer {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0.02em;
}

.game-block.idle .game-name {
  color: var(--text-dim);
  font-weight: 400;
}

.category-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 6px;
  margin-left: 8px;
  vertical-align: middle;
}

.category-badge.game { color: var(--game); background: rgba(139, 157, 255, 0.12); }
.category-badge.app { color: var(--accent); background: rgba(52, 224, 161, 0.1); }

.boot-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.boot-meta .boot-timer {
  color: var(--text);
  font-weight: 500;
}

.device-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.device-ip {
  display: flex;
  gap: 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.device-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
}

.device-actions button {
  flex: 1;
  border-radius: 8px;
  padding: 9px 8px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.device-actions button:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-muted);
}

.device-actions button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.device-actions button.danger:hover:not(:disabled) {
  color: var(--danger);
  border-color: var(--danger-dim);
}

/* ---------- 统计 ---------- */

.stats-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stats-empty {
  color: var(--text-dim);
  font-size: 13px;
  font-family: var(--font-mono);
  padding: 20px 0;
}

.stat-row {
  display: grid;
  grid-template-columns: 140px 1fr 90px;
  align-items: center;
  gap: 14px;
  font-size: 13px;
}

.stat-row .stat-name {
  font-family: var(--font-display);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-row .stat-bar-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}

.stat-row .stat-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--game-dim), var(--game));
  border-radius: 4px;
}

.stat-row .stat-time {
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-align: right;
}

/* ---------- 弹层 ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 11, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  max-width: 340px;
  width: 100%;
}

.modal-card p {
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-actions button {
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
}

.danger-btn {
  background: var(--danger);
  color: #2a0710;
  border: none;
}

.danger-btn:hover { filter: brightness(1.1); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-family: var(--font-mono);
  z-index: 200;
  box-shadow: 0 20px 40px -20px rgba(0,0,0,0.6);
}

.toast.error { border-color: var(--danger-dim); color: #ffb3c0; }
.toast.success { border-color: var(--accent-dim); color: var(--accent); }

/* ---------- 详情页 ---------- */

.back-btn {
  margin-bottom: 18px;
}

.detail-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 28px;
}

.detail-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
}

.detail-name {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
}

.detail-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
}

.detail-meta-grid .label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.detail-meta-grid .mono-value {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

.process-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.process-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
}

.process-name {
  font-weight: 600;
  font-size: 13px;
}

.process-exe {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.process-timer {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
}

.ghost-btn.small {
  padding: 5px 10px;
  font-size: 12px;
}

.ghost-btn.danger {
  color: var(--danger);
  border-color: var(--danger-dim);
}

.ghost-btn.danger:hover {
  background: rgba(255, 84, 112, 0.08);
}

.ghost-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.detail-actions {
  display: flex;
  gap: 10px;
}

.detail-controls {
  margin-bottom: 12px;
}

.range-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.range-picker input[type="date"] {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  border-radius: 8px;
  padding: 6px 10px;
}

.range-sep {
  color: var(--text-dim);
  font-size: 12px;
}

.chart-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-area {
  fill: var(--accent);
  opacity: 0.08;
}

.chart-dot {
  fill: var(--bg);
  stroke: var(--accent);
  stroke-width: 1.5;
}

.chart-axis-line {
  stroke: var(--border);
  stroke-width: 1;
}

.chart-axis-label {
  fill: var(--text-dim);
  font-size: 9px;
  font-family: var(--font-mono);
}

/* ---------- 响应式 ---------- */

@media (max-width: 520px) {
  .topbar { padding: 14px 16px; }
  .main { padding: 24px 16px 60px; gap: 32px; }
  .stat-row { grid-template-columns: 100px 1fr 70px; gap: 8px; }
  .process-row { grid-template-columns: auto 1fr auto; row-gap: 6px; }
  .process-exe { display: none; }
}

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