/* ============================================================
   指尖花开 · 样式表
   设计要点：
   1. 全屏沉浸：canvas 铺满视口，UI 用绝对定位浮在上层
   2. 毛玻璃控制面板，桌面右侧抽屉 / 移动端底部抽屉
   3. 所有交互元素保证移动端 44px 触控热区
   ============================================================ */

/* ---------- 主题变量（想换配色改这里即可） ---------- */
:root {
  --bg-0: #05060d;          /* 页面底色 */
  --bg-1: #0b0f1e;          /* 面板底色 */
  --ink: #eaf0ff;           /* 主文字 */
  --ink-dim: #9aa8c7;       /* 次要文字 */
  --line: rgba(255, 255, 255, 0.12);
  --glass: rgba(12, 16, 30, 0.62);
  --accent: #ff7ac6;        /* 花朵主色（与粒子色相呼应） */
  --accent-2: #7ce7ff;      /* 辅助色 */
  --radius: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 10%, #131a33 0%, var(--bg-0) 62%, #02030a 100%);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ============================================================
   画布层
   #gl      —— WebGL 场景（粒子花朵）
   #bg      —— 摄像头背景（3D 里作为纹理的镜像画面，DOM 层不显示，仅作数据源）
   #overlay —— 手部骨架连线（2D）
   #video   —— 原始摄像头流，永远不可见，只喂给 MediaPipe
   ============================================================ */
#gl,
#bg,
#overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#gl       { z-index: 1; }
#overlay  { z-index: 2; pointer-events: none; }

#bg,
#video   { position: fixed; opacity: 0; pointer-events: none; z-index: 0; }

/* ============================================================
   标题
   ============================================================ */
.title {
  position: fixed;
  z-index: 5;
  top: calc(18px + var(--safe-t));
  left: calc(22px + var(--safe-l));
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.title h1 {
  margin: 0;
  font-size: clamp(18px, 2.4vw, 26px);
  font-weight: 600;
  letter-spacing: 0.16em;
  background: linear-gradient(100deg, #fff 10%, var(--accent) 55%, var(--accent-2) 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 32px rgba(255, 122, 198, 0.25);
}
.title p {
  margin: 6px 0 0;
  font-size: 12px;
  letter-spacing: 0.05em;
  color: var(--ink-dim);
}

/* ============================================================
   HUD：张力条
   ============================================================ */
.hud {
  position: fixed;
  z-index: 5;
  left: calc(22px + var(--safe-l));
  bottom: calc(24px + var(--safe-b));
  width: min(300px, 52vw);
  padding: 12px 14px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.hud.hidden { opacity: 0; transform: translateY(10px); pointer-events: none; }

.hud-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
}
.hud-label { color: var(--ink-dim); }
.hud-value {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  color: var(--ink);
}

.hud-bar {
  position: relative;
  height: 8px;
  margin-top: 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.hud-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  /* 绿 → 黄 → 粉，直观表达“闭合 → 绽放” */
  background: linear-gradient(90deg, #6ef2b6 0%, #ffd166 46%, var(--accent) 100%);
  transition: width 0.06s linear;
  box-shadow: 0 0 16px rgba(255, 122, 198, 0.5);
}
/* 阈值刻度：0.32 / 0.66 */
.hud-tick {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: rgba(255, 255, 255, 0.45);
}
.hud-state {
  margin-top: 9px;
  font-size: 12px;
  color: var(--ink-dim);
}

/* HUD 里第二条及以后的指标行，多留一点上间距做分隔 */
.hud-row-2 { margin-top: 11px; }

/* 生长进度条：青绿 → 金黄，和张力条的粉紫区分开 */
.hud-bar-grow { margin-top: 8px; }
.hud-bar-fill-grow {
  background: linear-gradient(90deg, #4be3a8 0%, #b8f06a 55%, #ffd166 100%);
  box-shadow: 0 0 16px rgba(120, 240, 170, 0.45);
}

/* 面板里的小字说明 */
.hint {
  margin: 8px 0 2px;
  font-size: 11px;
  line-height: 1.75;
  color: var(--ink-dim);
  opacity: 0.85;
}

/* 面板里的通栏按钮 */
.wide-btn {
  width: 100%;
  min-height: 38px;
  margin: 4px 0 6px;
  border: 1px solid rgba(124, 231, 255, 0.35);
  border-radius: 10px;
  background: linear-gradient(100deg, rgba(124, 231, 255, 0.18), rgba(255, 122, 198, 0.18));
  color: var(--ink);
  font-size: 13px;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.12s ease;
}
.wide-btn:hover { background: rgba(255, 255, 255, 0.14); }
.wide-btn:active { transform: scale(0.985); }
.wide-btn:disabled { opacity: 0.45; cursor: default; }

/* ============================================================
   交互模式选择器（单手 / 双手）
   用卡片式单选，比复选框更直观地表达"二选一"
   ============================================================ */
.mode-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 2px 0 4px;
}

.mode-option { display: block; cursor: pointer; }
/* 真正的 radio 藏起来，用下面的卡片做视觉 */
.mode-option input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 6px 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.035);
  text-align: center;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.mode-option:hover .mode-card { background: rgba(255, 255, 255, 0.08); }

.mode-icon { font-size: 19px; line-height: 1.1; }
.mode-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.03em;
}
.mode-desc {
  font-size: 10px;
  line-height: 1.45;
  color: var(--ink-dim);
}

/* 选中态：描边 + 辉光，一眼看出当前用哪个 */
.mode-option input:checked + .mode-card {
  border-color: rgba(124, 231, 255, 0.75);
  background: linear-gradient(150deg, rgba(124, 231, 255, 0.20), rgba(255, 122, 198, 0.16));
  box-shadow: 0 0 0 1px rgba(124, 231, 255, 0.25), 0 6px 18px rgba(124, 231, 255, 0.16);
}
.mode-option input:checked + .mode-card .mode-name { color: #ffffff; }

/* 键盘可达性：聚焦时给个明显描边 */
.mode-option input:focus-visible + .mode-card {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

/* 双手模式的子选项：模式切到单手持整块隐藏 */
.sub-options { margin-top: 10px; }
.sub-options[hidden] { display: none; }

/* ============================================================
   控制面板
   ============================================================ */
.panel {
  position: fixed;
  z-index: 6;
  top: calc(16px + var(--safe-t));
  right: calc(16px + var(--safe-r));
  bottom: calc(16px + var(--safe-b));
  width: min(320px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  transform: translateX(calc(100% + 24px));
  transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}
.panel.open { transform: translateX(0); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  letter-spacing: 0.08em;
}
.panel-head button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.panel-head button:hover { background: rgba(255, 255, 255, 0.08); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px 14px 18px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}
.panel-body::-webkit-scrollbar { width: 6px; }
.panel-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 99px;
}

.group { padding: 12px 0; border-bottom: 1px dashed rgba(255, 255, 255, 0.09); }
.group:last-child { border-bottom: none; }
.group h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--accent-2);
  text-transform: uppercase;
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 10px 0 4px;
  font-size: 12px;
  color: var(--ink-dim);
}
.row output {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* 滑块统一样式 */
input[type="range"] {
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.16);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(140deg, #fff, var(--accent));
  box-shadow: 0 0 12px rgba(255, 122, 198, 0.7);
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.16);
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(140deg, #fff, var(--accent));
  box-shadow: 0 0 12px rgba(255, 122, 198, 0.7);
}

/* 开关 */
.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  margin: 6px 0;
  font-size: 13px;
  cursor: pointer;
}
.switch input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

/* 状态输出 */
.status {
  margin: 0;
  padding: 8px 10px;
  max-height: 128px;
  overflow: auto;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.32);
  color: var(--ink-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 抽屉把手按钮 */
.panel-toggle {
  position: fixed;
  z-index: 7;
  top: calc(16px + var(--safe-t));
  right: calc(16px + var(--safe-r));
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s ease, opacity 0.2s ease;
}
.panel-toggle:hover { background: rgba(255, 255, 255, 0.12); }
.panel.open ~ .panel-toggle,
body.panel-open .panel-toggle { opacity: 0; pointer-events: none; }

/* ============================================================
   启动遮罩
   ============================================================ */
.gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(60% 60% at 50% 40%, rgba(30, 20, 50, 0.72), rgba(3, 4, 10, 0.92));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 0.5s ease, visibility 0.5s;
}
.gate.hide { opacity: 0; visibility: hidden; pointer-events: none; }

.gate-card {
  width: min(420px, 92vw);
  padding: 30px 26px 22px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(10, 13, 26, 0.72);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.gate-card h2 {
  margin: 16px 0 10px;
  font-size: 22px;
  letter-spacing: 0.2em;
  background: linear-gradient(100deg, #fff, var(--accent) 60%, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.gate-card p {
  margin: 0 0 20px;
  font-size: 13px;
  line-height: 1.8;
  color: var(--ink-dim);
}
.gate-tip { margin: 14px 0 0 !important; font-size: 11px !important; opacity: 0.7; }

/* 遮罩上的旋转花形装饰（纯 CSS） */
.gate-flower {
  position: relative;
  width: 74px;
  height: 74px;
  margin: 0 auto;
  animation: spin 14s linear infinite;
}
.gate-flower span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 34px;
  margin: -34px 0 0 -10px;
  border-radius: 50% 50% 42% 42% / 62% 62% 38% 38%;
  background: linear-gradient(180deg, rgba(255, 122, 198, 0.95), rgba(124, 231, 255, 0.35));
  transform-origin: 50% 100%;
  filter: blur(0.4px) drop-shadow(0 0 10px rgba(255, 122, 198, 0.6));
}
.gate-flower span:nth-child(1) { transform: rotate(0deg); }
.gate-flower span:nth-child(2) { transform: rotate(60deg); }
.gate-flower span:nth-child(3) { transform: rotate(120deg); }
.gate-flower span:nth-child(4) { transform: rotate(180deg); }
.gate-flower span:nth-child(5) { transform: rotate(240deg); }
.gate-flower span:nth-child(6) { transform: rotate(300deg); }
@keyframes spin { to { transform: rotate(360deg); } }

.primary {
  min-height: 46px;
  padding: 0 32px;
  border: none;
  border-radius: 99px;
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
  color: #10101c;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.12em;
  cursor: pointer;
  box-shadow: 0 12px 34px rgba(255, 122, 198, 0.36);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.primary:hover { transform: translateY(-2px); box-shadow: 0 16px 40px rgba(255, 122, 198, 0.5); }
.primary:active { transform: translateY(0) scale(0.98); }

/* ============================================================
   错误提示条
   ============================================================ */
.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  top: calc(20px + var(--safe-t));
  transform: translate(-50%, -140%);
  max-width: min(560px, 92vw);
  padding: 12px 18px;
  border: 1px solid rgba(255, 120, 120, 0.4);
  border-radius: 12px;
  background: rgba(50, 10, 16, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #ffd9d9;
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
  transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s;
  opacity: 0;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.info {
  border-color: rgba(124, 231, 255, 0.4);
  background: rgba(8, 28, 40, 0.9);
  color: #d6f6ff;
}

/* ============================================================
   响应式：窄屏改为底部抽屉
   ============================================================ */
@media (max-width: 720px) {
  .title { top: calc(12px + var(--safe-t)); left: calc(14px + var(--safe-l)); }
  .title h1 { font-size: 17px; }
  .title p { display: none; }

  .hud {
    left: calc(14px + var(--safe-l));
    right: calc(14px + var(--safe-r));
    bottom: calc(14px + var(--safe-b));
    width: auto;
  }

  .panel {
    top: auto;
    left: calc(10px + var(--safe-l));
    right: calc(10px + var(--safe-r));
    bottom: calc(10px + var(--safe-b));
    width: auto;
    max-height: 68vh;
    transform: translateY(calc(100% + 24px));
  }
  .panel.open { transform: translateY(0); }

  .panel-toggle { top: calc(12px + var(--safe-t)); right: calc(12px + var(--safe-r)); }
}

/* 减少动效偏好：关闭装饰动画 */
@media (prefers-reduced-motion: reduce) {
  .gate-flower { animation: none; }
  .panel { transition: none; }
}
