/* 竹知了 · 3D 仿真网页游戏样式(响应式,移动优先) */
:root {
  --card-bg: rgba(255, 255, 255, 0.74);
  --card-border: rgba(255, 255, 255, 0.55);
  --ink: #24401f;
  --ink-soft: #3d5c33;
  --accent: #4a9c3f;
  --accent-2: #e8a33d;
  --shadow: 0 4px 18px rgba(28, 58, 22, 0.18);
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #9fd6f0 0%, #cfe9e0 45%, #b7d694 100%);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* 太阳光晕 */
body::before {
  content: "";
  position: fixed;
  right: -12vmin;
  top: -12vmin;
  width: 62vmin;
  height: 62vmin;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 246, 200, 0.95) 0%, rgba(255, 244, 190, 0.4) 42%, rgba(255, 244, 190, 0) 70%);
  pointer-events: none;
  z-index: 0;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  touch-action: none;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 0;
  pointer-events: none;
}

.hud-card {
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 14px;
}

#rpmWrap { min-width: 168px; }
.rpmwrap .label { font-size: 12px; color: var(--ink-soft); letter-spacing: 2px; }
.rpmline { display: flex; align-items: baseline; gap: 6px; }
#rpmVal {
  font-size: 40px;
  font-weight: 800;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  transition: color 0.35s;
}
.rpmwrap.cool #rpmVal { color: #2f8f3d; }
.rpmwrap.warm #rpmVal { color: #d98e17; }
.rpmwrap.hot #rpmVal { color: #d8432f; }
.rpmwrap .unit { font-size: 12px; color: var(--ink-soft); }

.bar {
  height: 7px;
  border-radius: 4px;
  background: rgba(40, 80, 30, 0.16);
  overflow: hidden;
  margin-top: 6px;
}
#rpmBar {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: linear-gradient(90deg, #58c25f, #ffc93c 55%, #ff6a3d);
  transition: width 0.12s linear;
}

.row2 { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.soundbars { display: flex; align-items: flex-end; gap: 3px; height: 18px; }
.soundbars i {
  display: block;
  width: 5px;
  height: 18px;
  border-radius: 3px;
  background: #b9c4a8;
  transform: scaleY(0.1);
  transform-origin: bottom;
  transition: background 0.2s;
}
.rpmtag { font-size: 12px; color: var(--ink-soft); }

#challengeCard { flex: 1 1 240px; max-width: 420px; transition: box-shadow 0.2s; }
#challengeCard.burst { animation: burst 0.6s ease; }
@keyframes burst {
  0% { box-shadow: 0 0 0 0 rgba(255, 200, 60, 0.85); transform: scale(1); }
  40% { box-shadow: 0 0 0 14px rgba(255, 200, 60, 0); transform: scale(1.04); }
  100% { box-shadow: 0 4px 18px rgba(28, 58, 22, 0.18); transform: scale(1); }
}
.ctitle { font-size: 15px; font-weight: 700; }
.chint { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
#challengeBar {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: linear-gradient(90deg, #4a9c3f, #ffc93c);
  transition: width 0.15s linear;
}
.cprog { font-size: 12px; color: var(--ink-soft); margin-top: 4px; font-variant-numeric: tabular-nums; }
.csub { font-size: 12px; color: var(--ink-soft); margin-top: 3px; }
.csub b { color: var(--ink); }

.scorecard { min-width: 118px; text-align: center; }
.scoreval { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; color: #b0721a; }
.bestline { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

/* ---------- 模式切换 ---------- */
#modebar {
  position: fixed;
  top: calc(120px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}
.modebtn {
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(8px);
  color: var(--ink-soft);
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.18s;
}
.modebtn.active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 3px 10px rgba(56, 130, 48, 0.4);
  font-weight: 700;
}

/* ---------- 底部控制 ---------- */
#controls {
  position: fixed;
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 10;
  display: flex;
  gap: 9px;
  pointer-events: auto;
}
.ctlbtn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(8px);
  font-size: 19px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.ctlbtn:active { transform: scale(0.92); }
.ctlbtn.off { opacity: 0.55; }
.ctlbtn.active { background: #ffd98c; border-color: #e8a33d; }
.ctlbtn.busy { animation: pulse 0.9s infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

#hintBar {
  position: fixed;
  left: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 9;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  max-width: min(66vw, 640px);
  pointer-events: none;
}
.hl {
  font-size: 12px;
  color: rgba(36, 64, 31, 0.85);
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(6px);
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- 摄像头画中画 ---------- */
#camPip {
  position: fixed;
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(72px + env(safe-area-inset-bottom));
  z-index: 11;
  width: 176px;
  display: none;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow);
  background: #22301f;
}
#camPip.on { display: block; }
#camOverlay { display: block; width: 176px; height: 132px; background: #22301f; }
#camStatus {
  font-size: 11px;
  color: #eaf6da;
  padding: 5px 8px;
  background: rgba(20, 32, 18, 0.85);
}
#btnCamClose {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(20, 32, 18, 0.7);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

/* ---------- Toast ---------- */
#toasts {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: rgba(28, 48, 24, 0.88);
  color: #f2f8e4;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-12px);
  transition: all 0.35s;
  max-width: 86vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.win { background: rgba(224, 138, 22, 0.95); }
.toast.record { background: rgba(46, 122, 60, 0.95); }

/* ---------- 帮助卡片 ---------- */
#helpCard {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(20, 34, 16, 0.4);
  backdrop-filter: blur(3px);
  pointer-events: auto;
}
#helpCard.open { display: flex; }
.hcard {
  background: #fdfcf3;
  border-radius: 18px;
  max-width: min(92vw, 460px);
  max-height: 84vh;
  overflow-y: auto;
  padding: 22px 24px;
  box-shadow: 0 14px 40px rgba(10, 30, 8, 0.35);
}
.hcard h2 { font-size: 20px; margin-bottom: 12px; color: var(--ink); }
.hcard ul { list-style: none; }
.hcard li { font-size: 14px; line-height: 1.7; margin-bottom: 9px; color: #3a4a34; }
.hcard b { color: var(--ink); }

/* ---------- 开始界面 ---------- */
#startOverlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 30%, rgba(255, 250, 220, 0.92) 0%, rgba(175, 216, 158, 0.9) 62%, rgba(90, 140, 80, 0.92) 100%);
  transition: opacity 0.5s;
}
#startOverlay.hidden { opacity: 0; pointer-events: none; }
.scard {
  background: rgba(255, 255, 252, 0.9);
  border-radius: 22px;
  padding: 30px 34px;
  max-width: min(92vw, 430px);
  text-align: center;
  box-shadow: 0 18px 50px rgba(20, 50, 14, 0.35);
  backdrop-filter: blur(8px);
}
.scard h1 {
  font-family: "STKaiti", "KaiTi", "SimSun", serif;
  font-size: 44px;
  letter-spacing: 4px;
  color: #2e5a24;
}
.scard h1 .en { display: block; font-size: 13px; letter-spacing: 3px; color: #6c8a58; font-family: inherit; margin-top: 2px; }
.scard .sub { font-size: 14px; color: #4c6b3c; margin: 10px 0 16px; }
.how { list-style: none; text-align: left; margin: 0 auto 20px; max-width: 320px; }
.how li { font-size: 14px; padding: 6px 0; color: #37512c; border-bottom: 1px dashed rgba(90, 120, 70, 0.25); }
.bigbtn {
  display: inline-block;
  border: none;
  background: linear-gradient(180deg, #ffd36b, #f5a93b);
  color: #5c3a08;
  font-size: 18px;
  font-weight: 800;
  padding: 13px 40px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(210, 130, 20, 0.45);
  transition: transform 0.15s;
}
.bigbtn:active { transform: scale(0.95); }
.note { font-size: 12px; color: #7a8f66; margin-top: 14px; }

/* ---------- 自检模式 ---------- */
body.selftest #scene, body.selftest #hud, body.selftest #modebar,
body.selftest #controls, body.selftest #hintBar, body.selftest #startOverlay,
body.selftest #camPip, body.selftest #toasts, body.selftest #helpCard { display: none; }
#selftest {
  position: fixed;
  inset: 0;
  margin: 0;
  padding: 16px;
  overflow: auto;
  background: #10180e;
  color: #b8e6a8;
  font: 12px/1.6 Consolas, monospace;
  z-index: 99;
}

/* ---------- 小屏适配 ---------- */
@media (max-width: 700px) {
  #hud { gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 8px 0; }
  .hud-card { padding: 8px 10px; }
  #rpmWrap { min-width: 132px; }
  #rpmVal { font-size: 32px; }
  #challengeCard { flex-basis: 100%; order: 3; }
  .scorecard { min-width: 96px; }
  .scoreval { font-size: 22px; }
  #modebar { top: calc(88px + env(safe-area-inset-top)); gap: 6px; }
  .modebtn { font-size: 12px; padding: 6px 10px; }
  .hl { font-size: 11px; }
  #hintBar { max-width: calc(100vw - 150px); bottom: calc(10px + env(safe-area-inset-bottom)); }
  .ctlbtn { width: 42px; height: 42px; font-size: 17px; }
  #camPip { width: 132px; }
  #camOverlay { width: 132px; height: 99px; }
  .scard h1 { font-size: 36px; }
}
