/* ==========================================================================
   灵境 · KINETIC GESTURE ART STUDIO
   Pure Vanilla CSS Design System — Tactile Glass, Editorial Typography, Fluid Layout
   ========================================================================== */

:root {
  /* Surface & Ink Tokens (Warm Obsidian & Alabaster Ivory — Zero Purple) */
  --bg-canvas: hsl(210, 22%, 5%);
  --surface-glass: hsla(210, 18%, 9%, 0.72);
  --surface-glass-hover: hsla(210, 16%, 14%, 0.84);
  --surface-elevated: hsla(210, 18%, 12%, 0.88);
  --surface-active: hsla(38, 30%, 94%, 0.12);

  /* Neutral Hairline Borders (Subtle Specular, Never Colored Neon Outlines) */
  --border-hairline: hsla(40, 20%, 95%, 0.09);
  --border-strong: hsla(40, 20%, 95%, 0.18);

  /* Typography Ink */
  --ink-primary: hsl(40, 24%, 95%);
  --ink-secondary: hsla(40, 14%, 82%, 0.72);
  --ink-muted: hsla(40, 10%, 68%, 0.50);

  /* Dynamic Artistic Palette Accent (Updated cleanly by Palette Engine) */
  --palette-accent: hsl(38, 90%, 62%);
  --palette-secondary: hsl(16, 84%, 58%);
  --palette-soft: hsla(38, 90%, 62%, 0.16);

  /* Status Semantics */
  --status-live: hsl(156, 72%, 52%);
  --status-warn: hsl(38, 92%, 60%);

  /* Layout & Radius */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --hud-pad: clamp(12px, 2vw, 24px);

  /* Typography Stack */
  --font-sans: "Inter", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Menlo", "Consolas", monospace;

  /* Tactile Micro-Grain SVG Overlay for Glass Depth */
  --grain-svg: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-canvas);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
}

/* ==========================================================================
   Full-Viewport Generative Art Stage
   ========================================================================== */

.stage-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(
    circle at 50% 45%,
    hsl(210, 20%, 8%) 0%,
    hsl(210, 24%, 4%) 100%
  );
}

#art-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: none;
}

.stage-container.cursor-visible #art-canvas {
  cursor: crosshair;
}

/* Subtle Film Vignette & Grain Layer (Non-interactive) */
.stage-grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: var(--grain-svg);
  box-shadow: inset 0 0 140px rgba(0, 0, 0, 0.55);
  z-index: 2;
}

/* ==========================================================================
   Tactile Glass Surface System
   ========================================================================== */

.glass-panel {
  background-color: var(--surface-glass);
  background-image:
    linear-gradient(180deg, hsla(40, 30%, 98%, 0.045) 0%, transparent 100%),
    var(--grain-svg);
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  box-shadow:
    0 16px 40px -12px rgba(0, 0, 0, 0.62),
    inset 0 1px 0 0 hsla(40, 30%, 98%, 0.07);
  transition:
    opacity 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    background-color 0.2s ease;
}

/* Immersive Zen Mode (Hides HUD cleanly) */
body.hud-hidden .hud-collapsible {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}

body.hud-hidden .top-bar.hud-collapsible {
  transform: translateY(-8px);
}

/* ==========================================================================
   Top Editorial Header & Telemetry Strip
   ========================================================================== */

.top-bar {
  position: absolute;
  top: var(--hud-pad);
  left: var(--hud-pad);
  right: var(--hud-pad);
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.top-bar > * {
  pointer-events: auto;
}

.brand-panel {
  padding: 14px 18px;
  max-width: 340px;
}

.brand-title {
  font-size: clamp(16px, 1.35vw, 19px);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink-primary);
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.brand-title-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.brand-desc {
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-secondary);
  line-height: 1.45;
}

/* Top-Right Action Cluster */
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-secondary);
  background-color: var(--surface-glass);
  background-image: var(--grain-svg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.18s ease;
}

.icon-btn:hover {
  color: var(--ink-primary);
  background-color: var(--surface-glass-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(0);
}

.icon-btn.is-active {
  color: var(--ink-primary);
  background-color: var(--surface-active);
  border-color: var(--border-strong);
}

.icon-btn svg {
  width: 15px;
  height: 15px;
  stroke-width: 1.75;
  flex-shrink: 0;
}

.btn-primary-camera {
  color: var(--ink-primary);
  background-color: hsla(38, 88%, 56%, 0.16);
}

.btn-primary-camera.is-live {
  background-color: hsla(156, 72%, 45%, 0.18);
}

.live-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--ink-muted);
  transition: background-color 0.25s ease, box-shadow 0.25s ease;
}

.btn-primary-camera.is-live .live-indicator {
  background-color: var(--status-live);
  box-shadow: 0 0 8px var(--status-live);
}

/* ==========================================================================
   Left Gesture Recognition Telemetry HUD
   ========================================================================== */

.telemetry-panel {
  position: absolute;
  top: calc(var(--hud-pad) + 88px);
  left: var(--hud-pad);
  z-index: 10;
  width: 268px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.telemetry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.source-tag {
  color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
}

.gesture-readout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.gesture-name-zh {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink-primary);
}

.gesture-name-en {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--palette-accent);
  text-transform: uppercase;
  margin-top: 2px;
}

.confidence-badge {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-primary);
  padding: 4px 8px;
  background: hsla(40, 20%, 95%, 0.06);
  border-radius: 6px;
}

.confidence-track {
  width: 100%;
  height: 3px;
  background: hsla(40, 20%, 95%, 0.08);
  border-radius: 2px;
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  width: 92%;
  background: var(--palette-accent);
  border-radius: 2px;
  transition: width 0.16s ease-out, background-color 0.3s ease;
}

/* 5-Finger Anatomical Curl / Extension Meters */
.finger-meters {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--border-hairline);
}

.finger-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.finger-bar-wrap {
  width: 6px;
  height: 34px;
  background: hsla(40, 20%, 95%, 0.08);
  border-radius: 3px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}

.finger-bar-fill {
  width: 100%;
  height: 100%;
  background: var(--palette-accent);
  border-radius: 3px;
  transition: height 0.08s linear, background-color 0.3s ease;
}

.finger-label {
  font-size: 11px;
  color: var(--ink-muted);
  font-family: var(--font-mono);
}

/* Live Physics Metrics Row */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border-hairline);
}

.metric-item {
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 10px;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}

.metric-val {
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-secondary);
}

/* ==========================================================================
   Mirrored Camera Picture-in-Picture (PiP) Monitor
   ========================================================================== */

.camera-pip {
  position: absolute;
  top: calc(var(--hud-pad) + 52px);
  right: var(--hud-pad);
  z-index: 10;
  width: 220px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: var(--radius-md);
  display: none;
}

.camera-pip.is-visible {
  display: block;
}

.camera-pip video,
.camera-pip canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.camera-pip video {
  opacity: 0.58;
  filter: contrast(1.06) saturate(0.85);
}

.pip-caption {
  position: absolute;
  bottom: 6px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-primary);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
  z-index: 2;
}

/* ==========================================================================
   Center Toast Notification (For Stroke Recognition & Camera Feedback)
   ========================================================================== */

.gesture-toast {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translate(-50%, -10px);
  z-index: 12;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink-primary);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.gesture-toast.is-shown {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ==========================================================================
   Bottom Floating Interactive Control Dock
   ========================================================================== */

.bottom-dock {
  position: absolute;
  bottom: var(--hud-pad);
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  max-width: calc(100vw - 24px);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

body.hud-hidden .bottom-dock.hud-collapsible {
  transform: translate(-50%, 12px);
}

.dock-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dock-divider {
  width: 1px;
  height: 24px;
  background-color: var(--border-hairline);
}

.dock-label {
  font-size: 11px;
  color: var(--ink-muted);
  margin-right: 4px;
  white-space: nowrap;
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.16s ease;
}

.seg-btn:hover {
  color: var(--ink-primary);
  background: hsla(40, 20%, 95%, 0.06);
}

.seg-btn.is-active {
  color: var(--ink-primary);
  background: var(--surface-active);
  border-color: var(--border-strong);
}

.seg-key {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-muted);
  opacity: 0.75;
}

/* Curated Palette Swatches */
.swatch-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid hsla(40, 20%, 95%, 0.22);
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.swatch-btn:hover {
  transform: scale(1.12);
}

.swatch-btn.is-active {
  border-color: var(--ink-primary);
  transform: scale(1.15);
}

/* ==========================================================================
   Collapsible Gesture Guide Drawer
   ========================================================================== */

.guide-modal {
  position: absolute;
  bottom: calc(var(--hud-pad) + 68px);
  right: var(--hud-pad);
  z-index: 15;
  width: min(340px, calc(100vw - 24px));
  padding: 16px 18px;
  display: none;
  flex-direction: column;
  gap: 10px;
}

.guide-modal.is-open {
  display: flex;
}

.guide-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.guide-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 12px;
  color: var(--ink-secondary);
}

.guide-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.guide-kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--palette-accent);
  white-space: nowrap;
}

/* ==========================================================================
   Responsive Mobile & Tablet Breakpoints
   ========================================================================== */

@media (max-width: 900px) {
  .telemetry-panel {
    width: 232px;
    padding: 11px 13px;
    top: calc(var(--hud-pad) + 80px);
  }

  .bottom-dock {
    width: calc(100vw - 20px);
    justify-content: flex-start;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  .bottom-dock::-webkit-scrollbar {
    display: none;
  }
}

@media (max-width: 640px) {
  .brand-desc {
    display: none;
  }

  .brand-panel {
    padding: 10px 14px;
  }

  .telemetry-panel {
    top: auto;
    bottom: calc(var(--hud-pad) + 62px);
    left: var(--hud-pad);
    width: 205px;
    gap: 8px;
  }

  .finger-meters,
  .metrics-grid {
    display: none;
  }

  .camera-pip {
    width: 132px;
    top: calc(var(--hud-pad) + 52px);
  }

  .icon-btn span.btn-text-hide-sm {
    display: none;
  }
}
