/* ═══════════════════════════════════════════════════════════
   HAND GESTURE CONTROLLER — DESIGN SYSTEM
   GitHub Dark Dimmed palette · Cascadia Code + Figtree
   See DESIGN.md for full specification.
   ═══════════════════════════════════════════════════════════ */

/* ── TOKENS ──────────────────────────────────────────────── */
:root {
  /* Canvas stack */
  --canvas-default: oklch(0.21 0.012 245);
  --canvas-subtle:  oklch(0.25 0.012 240);
  --canvas-inset:   oklch(0.18 0.013 245);

  /* Foreground */
  --fg-default: oklch(0.77 0.016 228);
  --fg-muted:   oklch(0.58 0.016 230);
  --fg-subtle:  oklch(0.51 0.014 230);

  /* Border */
  --border-default: oklch(0.35 0.015 240);
  --border-muted:   oklch(0.30 0.013 240);

  /* Gesture-semantic accents */
  --accent-blue:        oklch(0.65 0.175 255);   /* interactive */
  --accent-blue-bright: oklch(0.70 0.17  255);
  --accent-green:       oklch(0.73 0.17  148);   /* grab / left hand */
  --accent-cyan:        oklch(0.75 0.11  204);   /* scale mode */
  --accent-purple:      oklch(0.72 0.16  300);   /* network metric */
  --accent-yellow:      oklch(0.73 0.12   76);   /* minimize / strings */
  --accent-red:         oklch(0.62 0.18   23);   /* close / danger */

  /* Typography */
  --font-mono: 'Cascadia Code', ui-monospace, 'Fira Code', monospace;
  --font-body: 'Figtree', system-ui, sans-serif;

  /* Transitions */
  --t-border: border-color 0.18s cubic-bezier(0.22, 1, 0.36, 1);
  --t-color:  color 0.15s ease, background-color 0.15s ease;
}


/* ── RESET ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }


/* ── BODY ────────────────────────────────────────────────── */
body {
  background: var(--canvas-default);
  font-family: var(--font-body);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
}


/* ── DESKTOP ─────────────────────────────────────────────── */
#desktop {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: var(--canvas-default);
  overflow: hidden;
}


/* ── WINDOWS ─────────────────────────────────────────────── */
.window {
  position: absolute;
  background: var(--canvas-subtle);
  border: 1px solid var(--border-default);
  border-radius: 6px;
  box-shadow: none;
  overflow: hidden;
  min-width: 200px;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  transition:
    var(--t-border),
    opacity 0.22s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: opacity, transform;
}

.window.grabbed {
  border-color: rgba(107, 196, 109, 0.45);
  box-shadow: none;
}

.window.scaling {
  border-color: rgba(57, 197, 207, 0.45);
  box-shadow: none;
}

.window-titlebar {
  display: flex;
  align-items: center;
  padding: 0 10px;
  height: 32px;
  background: var(--canvas-inset);
  border-bottom: 1px solid var(--border-muted);
  flex-shrink: 0;
  gap: 7px;
  cursor: grab;
}
.window-titlebar:active { cursor: grabbing; }
.window-titlebar .win-btn { cursor: pointer; }

.window-icon { font-size: 12px; line-height: 1; }

.window-title {
  flex: 1;
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 11px;
  font-weight: 500;
  color: var(--fg-muted);
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.win-btn {
  width: 11px;
  height: 11px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: filter 0.12s;
  flex-shrink: 0;
}
.win-btn:hover { filter: brightness(1.25); }
.btn-min   { background: var(--accent-yellow); }
.btn-close { background: var(--accent-red); }

.window-body {
  flex: 1;
  padding: 12px;
  overflow: hidden;
  color: var(--fg-muted);
  font-family: var(--font-body);
  font-size: 12px;
  line-height: 1.6;
}

.window.minimized {
  opacity: 0;
  transform: scale(0.88) translateY(18px);
  pointer-events: none;
}


/* ── OVERLAY CANVAS ──────────────────────────────────────── */
#overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  pointer-events: none;
  z-index: 1000;
}


/* ── STATUS BAR ──────────────────────────────────────────── */
#statusbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 28px;
  background: var(--canvas-inset);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
  z-index: 998;
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 10px;
  color: var(--fg-subtle);
}

#state-badge {
  padding: 2px 8px;
  border-radius: 9999px;
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.06em;
  background: var(--canvas-subtle);
  border: 1px solid var(--border-default);
  color: var(--fg-muted);
  transition: background 0.18s, color 0.18s, border-color 0.18s;
}

#state-badge.grab {
  background: rgba(107, 196, 109, 0.12);
  border-color: rgba(107, 196, 109, 0.35);
  color: var(--accent-green);
}

#state-badge.scale {
  background: rgba(57, 197, 207, 0.12);
  border-color: rgba(57, 197, 207, 0.35);
  color: var(--accent-cyan);
}

#state-window { flex: 1; color: var(--fg-muted); font-size: 10px; }
#fps-counter  { color: var(--fg-subtle); font-size: 10px; }


/* ── LANG SWITCHER ───────────────────────────────────────── */
#lang-switcher {
  position: fixed;
  top: 38px;
  right: 16px;
  display: flex;
  background: var(--canvas-inset);
  border: 1px solid var(--border-default);
  border-radius: 6px;
  overflow: hidden;
  z-index: 999;
}

.lang-opt {
  background: none;
  border: none;
  color: var(--fg-subtle);
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 6px 14px;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.15s, color 0.15s;
}

.lang-opt + .lang-opt { border-left: 1px solid var(--border-muted); }

.lang-opt:hover:not(.active) {
  background: var(--canvas-subtle);
  color: var(--fg-default);
}

.lang-opt.active {
  background: rgba(83, 155, 245, 0.10);
  color: var(--accent-blue);
  cursor: default;
}


/* ── CAMERA PREVIEW ──────────────────────────────────────── */
#cam-preview {
  position: fixed;
  bottom: 16px; right: 16px;
  width: 310px;
  background: var(--canvas-inset);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  overflow: hidden;
  z-index: 999;
}

#cam-canvas { width: 310px; height: 174px; display: block; }

#cam-footer {
  padding: 5px 10px;
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 10px;
  color: var(--fg-subtle);
  text-align: center;
  background: var(--canvas-inset);
  border-top: 1px solid var(--border-muted);
  letter-spacing: 0.04em;
}

@keyframes cam-ready-pulse {
  0%, 100% { border-color: var(--border-default); }
  50%       { border-color: rgba(107, 196, 109, 0.55); }
}

#cam-preview.cam-ready {
  animation: cam-ready-pulse 0.7s ease-in-out 2;
}


/* ── GESTURE GUIDE ───────────────────────────────────────── */
#guide {
  position: fixed;
  bottom: 16px; left: 16px;
  background: var(--canvas-inset);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  padding: 14px 16px;
  z-index: 999;
  min-width: 260px;
}

#guide-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

#guide h4 {
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--fg-subtle);
  text-transform: uppercase;
  margin-bottom: 0;
}

#guide-toggle {
  background: none;
  border: 1px solid var(--border-muted);
  border-radius: 4px;
  color: var(--fg-subtle);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1;
  padding: 4px 10px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
#guide-toggle:hover {
  color: var(--fg-default);
  background: var(--canvas-subtle);
  border-color: var(--border-default);
}

#guide-body {
  overflow: hidden;
  max-height: 600px;
  opacity: 1;
  transition: max-height 0.28s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease;
}

#guide.collapsed #guide-body {
  max-height: 0;
  opacity: 0;
}

#guide.collapsed {
  padding-bottom: 14px;
}

.g-row { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 9px; }
.g-row:last-child { margin-bottom: 0; }
.g-icon { font-size: 17px; width: 28px; text-align: center; line-height: 1.2; flex-shrink: 0; margin-top: 1px; }
.g-icon-pair { display: flex; gap: 1px; width: 32px; justify-content: center; font-size: 15px; }

.g-text {
  color: var(--fg-muted);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.3;
}

.g-text strong {
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  color: var(--fg-default);
  font-weight: 600;
  display: block;
  font-size: 13px;
}

.g-sub {
  display: block;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--fg-muted);
  margin-top: 3px;
  line-height: 1.5;
}

.g-separator {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 7px;
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--fg-subtle);
  text-transform: uppercase;
}

.g-separator::before,
.g-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-muted);
}


/* ── WELCOME BACKGROUND ──────────────────────────────────── */
#welcome {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}


#welcome-content {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(860px, 90vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

#welcome-tagline {
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: clamp(14px, 1.6vw, 20px);
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--fg-default);
  text-transform: uppercase;
  text-align: center;
}

#welcome-desc {
  font-family: var(--font-body);
  font-size: clamp(13px, 1.3vw, 15px);
  color: var(--fg-muted);
  text-align: center;
  text-wrap: balance;
  line-height: 1.75;
  max-width: 600px;
  width: 100%;
}

#welcome-divider {
  width: 48px;
  height: 1px;
  background: var(--border-default);
}

#welcome-hints {
  display: flex;
  gap: 16px;
  width: 100%;
  transition: opacity 0.4s ease;
}

#welcome-hints.dismissed {
  opacity: 0;
  pointer-events: none;
}

.w-hint {
  flex: 1;
  background: var(--canvas-subtle);
  border: 1px solid var(--border-default);
  border-radius: 6px;
  padding: 20px 22px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.wh-arrow {
  font-size: 20px;
  color: var(--fg-subtle);
  line-height: 1;
  flex-shrink: 0;
  margin-top: 2px;
}

.wh-title {
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--fg-default);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.wh-body p {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--fg-muted);
  line-height: 1.7;
}

.wh-body p .col-green { color: var(--accent-green); }
.wh-body p .col-blue  { color: var(--accent-blue); }


/* ── LOADING ─────────────────────────────────────────────── */
#loading {
  position: fixed;
  inset: 0;
  background: var(--canvas-default);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

#loading h1 {
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 16px;
  letter-spacing: 0.12em;
  color: var(--fg-muted);
  font-weight: 600;
  text-transform: uppercase;
}

#loading-sub {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--fg-subtle);
}

#loading-err {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--accent-red);
  display: none;
  max-width: 420px;
  text-align: center;
  line-height: 1.7;
}

#loading-retry {
  display: none;
  margin-top: 4px;
  padding: 7px 20px;
  background: var(--canvas-subtle);
  border: 1px solid var(--border-default);
  border-radius: 6px;
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
#loading-retry:hover {
  background: rgba(83, 155, 245, 0.08);
  border-color: rgba(83, 155, 245, 0.4);
  color: var(--accent-blue);
}

.dots span { animation: blink 1.4s infinite; }
.dots span:nth-child(2) { animation-delay: 0.46s; }
.dots span:nth-child(3) { animation-delay: 0.92s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.1; }
  40%            { opacity: 1;   }
}


/* ── RESIZE HANDLES ──────────────────────────────────────── */
.resize-handle { position: absolute; z-index: 20; }
.resize-e  { top: 0; right: 0; width: 5px; height: 100%; cursor: e-resize; }
.resize-s  { bottom: 0; left: 0; width: 100%; height: 5px; cursor: s-resize; }
.resize-e:hover, .resize-s:hover { background: rgba(68, 76, 86, 0.35); }
.resize-se {
  bottom: 0; right: 0;
  width: 14px; height: 14px;
  cursor: se-resize;
  background: radial-gradient(circle at 70% 70%, var(--border-default) 0%, transparent 70%);
  opacity: 0.35;
}


/* ── WINDOW COUNTER ──────────────────────────────────────── */
#win-counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

#wc-label {
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--fg-subtle);
  text-transform: uppercase;
}

#wc-dots { display: flex; gap: 8px; }

.wc-dot {
  background: var(--canvas-inset);
  border: 1px solid var(--border-muted);
  border-radius: 6px;
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition:
    background 0.18s cubic-bezier(0.22, 1, 0.36, 1),
    var(--t-border),
    opacity 0.2s;
  font-family: var(--font-body);
  outline: none;
  min-width: 60px;
}

.wc-dot:hover:not(.state-removed) {
  background: var(--canvas-subtle);
  border-color: var(--border-default);
}

.wc-dot .wd-icon { font-size: 18px; line-height: 1; }

.wc-dot .wd-name {
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 10px;
  color: var(--fg-muted);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.wc-dot.state-visible {
  border-color: rgba(83, 155, 245, 0.35);
  background: rgba(83, 155, 245, 0.06);
  opacity: 1;
}

.wc-dot.state-minimized { opacity: 0.38; }


/* ── MUSIC PLAYER ────────────────────────────────────────── */
.player-meta { margin-bottom: 10px; }

.player-track {
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-default);
}

.player-artist {
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--fg-subtle);
  margin-top: 2px;
}

.prog-track {
  height: 2px;
  background: var(--border-muted);
  border-radius: 1px;
  margin: 8px 0 3px;
}

.prog-fill {
  height: 100%;
  width: 42%;
  background: var(--accent-blue);
  border-radius: 1px;
}

.prog-times {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 10px;
  color: var(--fg-subtle);
}

.p-controls {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin: 8px 0;
  font-size: 16px;
  color: var(--fg-subtle);
  cursor: pointer;
}
.p-controls span:hover { color: var(--fg-default); }

.vol-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 2px;
  font-size: 12px;
  color: var(--fg-subtle);
}

.vol-bar {
  flex: 1;
  height: 2px;
  background: var(--border-muted);
  border-radius: 1px;
}

.vol-fill {
  height: 100%;
  width: 68%;
  background: var(--border-default);
  border-radius: 1px;
}


/* ── FILE EXPLORER ───────────────────────────────────────── */
.file-list { list-style: none; }

.file-list li {
  padding: 4px 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: default;
}

.file-list li:hover { background: var(--canvas-default); }

.f-icon { font-size: 12px; }

.f-name {
  font-family: var(--font-body);
  color: var(--fg-muted);
  flex: 1;
  font-size: 12px;
}

.f-size {
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 10px;
  color: var(--fg-subtle);
}


/* ── CODE EDITOR ─────────────────────────────────────────── */
.code {
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 11.5px;
  line-height: 1.7;
}

.code .ln {
  color: var(--fg-subtle);
  margin-right: 14px;
  display: inline-block;
  width: 18px;
  text-align: right;
  user-select: none;
}

.code .kw  { color: var(--accent-blue); }
.code .fn  { color: var(--accent-green); }
.code .str { color: var(--accent-yellow); }
.code .num { color: var(--accent-cyan); }
.code .cm  { color: var(--fg-subtle); font-style: italic; }


/* ── SYSTEM MONITOR ──────────────────────────────────────── */
.mon-row { margin-bottom: 10px; }

.mon-hdr {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-feature-settings: "calt" 1;
  font-size: 10.5px;
  margin-bottom: 4px;
}

.mon-lbl { color: var(--fg-muted); }
.mon-val { color: var(--fg-default); }

.mon-bar {
  height: 4px;
  background: var(--canvas-inset);
  border: 1px solid var(--border-muted);
  border-radius: 2px;
  overflow: hidden;
}

.mon-fill { height: 100%; border-radius: 2px; transition: width 1.4s ease; }
.fill-cpu  { background: var(--accent-blue); }
.fill-ram  { background: var(--accent-green); }
.fill-disk { background: var(--accent-red); }
.fill-net  { background: var(--accent-purple); }


/* ── REDUCED MOTION ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .window.minimized { transform: none; }
}
