/* 竹知了 · 3D 仿真 — 界面样式（深色竹林夜色风） */

:root {
  --bg: #14100c;
  --panel: rgba(22, 17, 12, 0.78);
  --line: rgba(255, 217, 140, 0.16);
  --gold: #ffd98c;
  --gold-dim: #c9a95f;
  --green: #8fbf6a;
  --red: #e0563f;
  --text: #f3ead8;
  --text-dim: #b7a98c;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
}
#stage canvas {
  display: block;
  touch-action: none;
  cursor: grab;
}
#stage.is-interacting canvas { cursor: grabbing; }

.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.hud.topbar {
  position: fixed;
  top: calc(10px + var(--safe-top));
  left: calc(12px + var(--safe-left));
  right: calc(12px + var(--safe-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 20;
}
.brand {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.brand h1 {
  font-size: 19px;
  letter-spacing: 2px;
  color: var(--gold);
  white-space: nowrap;
}
.brand h1 span { font-size: 12px; color: var(--text-dim); letter-spacing: 0; }
.brand p { font-size: 11px; color: var(--text-dim); margin-top: 1px; }

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  pointer-events: auto;
}

.pill {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform 0.12s, border-color 0.2s, background 0.2s;
  white-space: nowrap;
}
.pill:hover { border-color: var(--gold-dim); transform: translateY(-1px); }
.pill:active { transform: scale(0.95); }
.pill.on { border-color: var(--green); color: #c8f0a8; }
.pill.muted { border-color: var(--red); color: #f0a89c; }

/* ---------- 侧面板 ---------- */
.panel {
  position: fixed;
  left: calc(12px + var(--safe-left));
  top: 50%;
  transform: translateY(-50%);
  width: 232px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 15;
  pointer-events: auto;
}

.modes {
  display: flex;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.mode-btn {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 12.5px;
  padding: 7px 2px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.mode-btn.active { background: var(--gold); color: #3a2c12; font-weight: 700; }

.stat-row { display: flex; align-items: baseline; justify-content: space-between; }
.rev span {
  font-size: 34px;
  font-weight: 800;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: 0 0 18px rgba(255, 217, 140, 0.35);
}
.rev small { font-size: 11px; color: var(--text-dim); margin-left: 4px; }
.rpm span { font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.speedbar {
  position: relative;
  height: 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  overflow: visible;
}
#speedFill {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  background: linear-gradient(90deg, #6a9a48, #ffd98c 55%, #ff9d6a);
  transition: width 0.08s linear;
}
#buzzMark {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--red);
  border-radius: 2px;
  left: calc(12 / 80 * 100%);
  box-shadow: 0 0 6px rgba(224, 86, 63, 0.8);
}
#buzzMark::after {
  content: "鸣叫";
  position: absolute;
  top: -14px;
  left: -9px;
  font-size: 9px;
  color: var(--red);
  white-space: nowrap;
}

.vu {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 6px;
}
.vu div:first-child {
  flex: 1;
  height: 4px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.35);
}
#vuFill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, #4e7d3a, #b9d95f);
  transition: width 0.1s linear;
}
.vu small { font-size: 10px; color: var(--text-dim); }

/* 玩法面板 */
.score { display: none; font-size: 12.5px; }
.panel[data-mode="free"] .s-free { display: block; }
.panel[data-mode="sustain"] .s-sustain { display: block; }
.panel[data-mode="rush"] .s-rush { display: block; }

.score .line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 3px 0;
  border-bottom: 1px dashed rgba(255, 217, 140, 0.1);
}
.score .line label { color: var(--text-dim); }
.score .line b { color: var(--gold); font-size: 15px; font-variant-numeric: tabular-nums; }
.score .line small { color: var(--text-dim); margin-left: 3px; font-size: 10px; }
.score .line.big b { font-size: 22px; }
.score .hint { color: var(--text-dim); font-size: 11px; margin-top: 6px; line-height: 1.5; }
.score p { color: var(--text-dim); font-size: 11.5px; line-height: 1.6; }

.badges { display: flex; gap: 6px; margin-top: 6px; }
.badge {
  flex: 1;
  text-align: center;
  font-size: 10.5px;
  padding: 4px 0;
  border-radius: 6px;
  border: 1px solid var(--line);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.badge.got { border-color: var(--green); color: #c8f0a8; background: rgba(143, 191, 106, 0.12); }

.cta, .ghost {
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.12s;
}
.cta {
  background: linear-gradient(135deg, #ffd98c, #f0b25e);
  color: #3a2c12;
  font-weight: 700;
  margin-top: 4px;
}
.ghost {
  background: rgba(255, 217, 140, 0.08);
  color: var(--gold-dim);
  border: 1px dashed var(--line);
}
.cta:hover, .ghost:hover { transform: translateY(-1px); }
.cta:active, .ghost:active { transform: scale(0.97); }

.panel.buzzing .rev span { color: #ffe9b0; text-shadow: 0 0 24px rgba(255, 217, 140, 0.8); }

/* ---------- 摄像头预览 ---------- */
#cameraBox {
  position: fixed;
  right: calc(14px + var(--safe-right));
  bottom: calc(14px + var(--safe-bottom));
  width: 220px;
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.5);
  z-index: 25;
  background: #000;
}
#cameraBox video, #cameraBox canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
#camStatus {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  font-size: 10.5px;
  padding: 4px 8px;
  color: #d8ecc2;
  background: rgba(0, 0, 0, 0.55);
  text-align: center;
}
#rubBadge {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--red);
  border-radius: 999px;
  padding: 3px 10px;
  opacity: 0;
  transition: opacity 0.2s;
}
#cameraBox.rubbing #rubBadge { opacity: 1; animation: pulse 0.7s infinite alternate; }

@keyframes pulse { from { transform: translateX(-50%) scale(1); } to { transform: translateX(-50%) scale(1.12); } }

/* ---------- 提示 / 弹层 ---------- */
#tip {
  position: fixed;
  bottom: calc(16px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 40;
  display: flex;
  gap: 12px;
  align-items: center;
}
#tip p { font-size: 12.5px; color: var(--text-dim); line-height: 1.6; margin-top: 4px; }
#tip b { color: var(--gold); }
#tip button {
  border: 0;
  background: var(--gold);
  color: #3a2c12;
  font-weight: 700;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}

#toast {
  position: fixed;
  top: calc(70px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: var(--panel);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  border-radius: 999px;
  padding: 9px 20px;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 50;
  pointer-events: none;
  white-space: nowrap;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 5, 3, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  width: min(520px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: #201912;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.modal-card h2 { color: var(--gold); letter-spacing: 2px; margin-bottom: 10px; }
.modal-card h3 { color: var(--green); font-size: 14px; margin: 14px 0 6px; }
.modal-card p { font-size: 13px; color: var(--text-dim); line-height: 1.8; }
.modal-card b { color: var(--text); }

#errOverlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
}
#errOverlay h2 { color: var(--gold); }
#errOverlay p { color: var(--text-dim); line-height: 1.7; max-width: 420px; }

/* ---------- 移动端 ---------- */
@media (max-width: 760px) {
  .brand { padding: 6px 10px; }
  .brand h1 { font-size: 16px; }
  .brand p { display: none; }
  .pill { padding: 7px 11px; font-size: 12px; }

  .panel {
    left: calc(8px + var(--safe-left));
    right: calc(8px + var(--safe-right));
    top: auto;
    bottom: calc(8px + var(--safe-bottom));
    transform: none;
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px;
  }
  .modes { order: 1; flex: 0 0 100%; }
  .stat-row { order: 2; flex: 1 1 40%; flex-direction: column; align-items: flex-start; gap: 2px; }
  .rev span { font-size: 26px; }
  .speedbar { order: 3; flex: 1 1 100%; }
  .vu { order: 4; flex: 0 0 100px; }
  .score { order: 5; flex: 1 1 100%; }
  #btnBoost { order: 6; width: auto; flex: 1; padding: 8px 10px; font-size: 12.5px; }
  .score .hint { display: none; }

  #cameraBox.small { width: 128px; }
  #cameraBox:not(.small) { width: 200px; }
}

@media (max-width: 420px) {
  .actions { gap: 5px; }
  .pill { padding: 6px 9px; font-size: 11.5px; }
  .brand h1 { font-size: 14px; }
}
