/* ══════════════════════════════════════════════════════════
   Neon Snake 3D — 设计系统
   设计语言：深空玻璃 / 冷霓虹 / 单色数字 / 大圆角
   ══════════════════════════════════════════════════════════ */

:root {
  /* 底色层次：从最深到最浅 */
  --bg-0: #04060e;
  --bg-1: #0a1120;
  --bg-2: #101a2e;

  /* 玻璃材质 */
  --glass: rgba(14, 24, 44, 0.58);
  --glass-hi: rgba(255, 255, 255, 0.07);
  --glass-line: rgba(140, 190, 255, 0.16);
  --glass-line-hi: rgba(140, 200, 255, 0.34);

  /* 品牌色 */
  --cyan: #45e8ff;
  --cyan-deep: #128fb8;
  --violet: #7b61ff;
  --red: #ff4d6a;
  --green: #3ee27f;
  --blue: #46a6ff;
  --gold: #ffc250;

  /* 文字 */
  --ink: #eaf3ff;
  --ink-2: #9fb4d0;
  --ink-3: #63768f;

  --r-sm: 12px;
  --r-md: 18px;
  --r-lg: 26px;
  --r-xl: 34px;

  --safe-t: max(10px, env(safe-area-inset-top));
  --safe-b: max(12px, env(safe-area-inset-bottom));
  --safe-l: max(12px, env(safe-area-inset-left));
  --safe-r: max(12px, env(safe-area-inset-right));

  --font: "PingFang SC", "HarmonyOS Sans SC", "Hiragino Sans GB", "Microsoft YaHei",
          system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

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

/* 暗角：让 UI 浮起来 */
.vignette {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background:
    radial-gradient(130% 80% at 50% 34%, transparent 34%, rgba(2, 4, 10, 0.5) 78%, rgba(2, 4, 10, 0.82) 100%),
    linear-gradient(180deg, rgba(20, 40, 90, 0.2), transparent 26%);
}

#ui {
  position: fixed; inset: 0; z-index: 2;
  pointer-events: none;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}

/* ══════════════ 顶部 HUD ══════════════ */

.hud { display: flex; align-items: flex-start; gap: 10px; }

.score-block { display: flex; flex-direction: column; gap: 7px; }

/* 分数：一个整体玻璃块，数字是绝对主角 */
.score-main {
  display: flex; align-items: flex-end; gap: 5px;
  padding: 8px 16px 9px;
  border-radius: var(--r-md);
  background: var(--glass);
  border: 1px solid var(--glass-line);
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 var(--glass-hi);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}
.score-num {
  font-family: var(--mono);
  font-size: clamp(30px, 9vw, 40px);
  font-weight: 700;
  line-height: 0.92;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #ffffff 20%, #a9d8ff 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 14px rgba(69, 232, 255, 0.45));
}
.score-unit {
  font-size: 11px; color: var(--ink-3); padding-bottom: 3px; letter-spacing: 0.1em;
}

.score-sub { display: flex; align-items: center; gap: 6px; padding-left: 2px; }
.chip-best, .chip-level {
  display: inline-flex; align-items: center; gap: 3px;
  height: 22px; padding: 0 9px;
  font-size: 11px; color: var(--ink-2);
  border-radius: 999px;
  background: rgba(10, 18, 34, 0.5);
  border: 1px solid rgba(140, 190, 255, 0.12);
}
.chip-best b, .chip-level b { font-family: var(--mono); color: var(--ink); font-weight: 600; }
.chip-level i { font-style: normal; color: var(--cyan); font-size: 10px; opacity: 0.9; }

.speed-meter {
  height: 3px; width: 100%;
  border-radius: 999px;
  background: rgba(140, 190, 255, 0.14);
  overflow: hidden;
}
.speed-fill {
  height: 100%; width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  box-shadow: 0 0 12px rgba(69, 232, 255, 0.75);
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.hud-spacer { flex: 1; min-width: 8px; }

/* 连击：独立浮层，出现时有弹性 */
.combo {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 7px 13px 8px;
  border-radius: var(--r-md);
  background: linear-gradient(160deg, rgba(255, 194, 80, 0.22), rgba(255, 77, 106, 0.16));
  border: 1px solid rgba(255, 194, 80, 0.42);
  box-shadow: 0 8px 26px rgba(255, 140, 60, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  opacity: 0; transform: translateY(-8px) scale(0.86);
  transition: opacity 0.16s ease, transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.combo.on { opacity: 1; transform: none; }
.combo b {
  font-family: var(--mono); font-size: 19px; font-weight: 800;
  color: var(--gold);
  text-shadow: 0 0 16px rgba(255, 194, 80, 0.85);
}
.combo-track { width: 44px; height: 3px; border-radius: 999px; background: rgba(255, 255, 255, 0.2); overflow: hidden; }
.combo-track i {
  display: block; height: 100%; transform-origin: left center;
  background: linear-gradient(90deg, var(--gold), var(--red));
}

/* 工具按钮：竖排圆形玻璃 */
.tools { display: flex; flex-direction: column; gap: 7px; pointer-events: auto; }
.tool {
  pointer-events: auto;
  position: relative;
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 13px;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4), inset 0 1px 0 var(--glass-hi);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--ink-2);
  cursor: pointer;
  transition: transform 0.12s ease, color 0.2s, border-color 0.2s;
}
.tool svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tool b {
  position: absolute; bottom: 2px; left: 0; right: 0;
  text-align: center;
  font-family: var(--mono); font-size: 8px; font-weight: 600;
  color: var(--ink-3);
}
.tool.off { opacity: 0.42; }
.tool:active { transform: scale(0.9); color: var(--cyan); }
.tool .ico-play { display: none; }
.tool.paused .ico-pause { display: none; }
.tool.paused .ico-play { display: block; }

/* ══════════════ 食物图例 ══════════════ */

.legend {
  position: absolute;
  left: var(--safe-l);
  top: calc(var(--safe-t) + 96px);
  display: flex; gap: 6px;
  pointer-events: none;
}
.lg {
  display: inline-flex; align-items: center; gap: 5px;
  height: 25px; padding: 0 10px 0 8px;
  border-radius: 999px;
  background: rgba(8, 16, 32, 0.55);
  border: 1px solid rgba(140, 190, 255, 0.14);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 11px;
}
.lg i { width: 7px; height: 7px; border-radius: 50%; }
.lg b { font-family: var(--mono); font-weight: 700; color: #fff; }
.lg em { font-style: normal; font-family: var(--mono); font-size: 10px; color: var(--ink-3); }
.lg.red i { background: var(--red); box-shadow: 0 0 10px var(--red); }
.lg.green i { background: var(--green); box-shadow: 0 0 10px var(--green); }
.lg.blue i { background: var(--blue); box-shadow: 0 0 10px var(--blue); }

/* ══════════════ 飘分 ══════════════ */

.floaters { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.floater {
  position: absolute; left: 0; top: 0;
  font-family: var(--mono); font-weight: 800;
  font-size: 17px; color: #fff;
  white-space: nowrap;
  text-shadow: 0 0 16px currentColor, 0 2px 8px rgba(0, 0, 0, 0.9);
  will-change: transform, opacity;
}
.floater.special { font-size: 21px; }

/* ══════════════ 触屏操作：左右两个大按钮 ══════════════ */

.touch-controls { position: absolute; inset: 0; pointer-events: none; }

.steer {
  pointer-events: auto;
  position: absolute;
  bottom: calc(var(--safe-b) + 14px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  width: 108px; height: 108px;
  border-radius: 50%;
  background:
    radial-gradient(120% 120% at 50% 0%, rgba(255, 255, 255, 0.1), transparent 60%),
    rgba(12, 22, 42, 0.62);
  border: 1.5px solid rgba(140, 200, 255, 0.28);
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.45),
    0 0 0 6px rgba(69, 232, 255, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  color: var(--cyan);
  cursor: pointer;
  touch-action: none;
  transition: transform 0.09s ease, background 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}
.steer.left { left: calc(var(--safe-l) + 6px); }
.steer.right { right: calc(var(--safe-r) + 6px); }
.steer svg {
  width: 42px; height: 42px;
  fill: none; stroke: currentColor; stroke-width: 3.4;
  stroke-linecap: round; stroke-linejoin: round;
  filter: drop-shadow(0 0 10px rgba(69, 232, 255, 0.5));
}
.steer b { font-size: 12px; font-weight: 600; letter-spacing: 0.14em; color: var(--ink-2); }
.steer.active, .steer:active {
  transform: scale(0.92);
  border-color: rgba(69, 232, 255, 0.85);
  background:
    radial-gradient(120% 120% at 50% 0%, rgba(69, 232, 255, 0.34), transparent 62%),
    rgba(16, 34, 60, 0.8);
  box-shadow:
    0 8px 22px rgba(0, 0, 0, 0.4),
    0 0 26px rgba(69, 232, 255, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.swipe-hint {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(var(--safe-b) + 128px);
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-3);
  letter-spacing: 0.06em;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.swipe-hint.hide { opacity: 0; }

/* ══════════════ 遮罩与面板 ══════════════ */

.overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: 16px;
  pointer-events: none;
}
.overlay.veil {
  background: radial-gradient(70% 55% at 50% 46%, rgba(4, 8, 20, 0.62), rgba(2, 4, 12, 0.9));
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

.panel {
  pointer-events: auto;
  position: relative;
  width: min(430px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 30px 24px 24px;
  border-radius: var(--r-xl);
  background:
    linear-gradient(180deg, rgba(22, 38, 68, 0.9), rgba(8, 14, 28, 0.94));
  border: 1px solid rgba(140, 200, 255, 0.18);
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.72),
    0 0 0 1px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(26px) saturate(160%);
  -webkit-backdrop-filter: blur(26px) saturate(160%);
  animation: panel-in 0.34s cubic-bezier(0.22, 1.2, 0.36, 1) both;
}
/* 顶部高光描边 */
.panel::before {
  content: '';
  position: absolute; inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(69, 232, 255, 0.55), transparent);
}
.panel.narrow { width: min(330px, 100%); padding: 26px 22px 22px; }
@keyframes panel-in {
  from { opacity: 0; transform: translateY(18px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

/* ── 菜单 ── */
.menu-head { text-align: center; margin-bottom: 20px; }
.kicker {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px; letter-spacing: 0.42em;
  color: var(--cyan); opacity: 0.85;
  margin-bottom: 10px;
}
.title {
  font-size: clamp(32px, 10vw, 44px);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -0.01em;
  background: linear-gradient(180deg, #ffffff 24%, #93c4ea 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 24px rgba(69, 232, 255, 0.32));
}
.title span {
  display: block;
  font-size: 0.62em;
  letter-spacing: 0.2em;
  background: linear-gradient(100deg, var(--cyan), var(--violet));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.tagline { margin-top: 10px; font-size: 12px; color: var(--ink-3); letter-spacing: 0.04em; }

/* 食物卡片：三列 */
.food-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 20px; }
.food-card {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 13px 6px 11px;
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(140, 190, 255, 0.1);
  transition: transform 0.2s;
}
.orb { width: 20px; height: 20px; border-radius: 50%; margin-bottom: 4px; }
.food-card b { font-family: var(--mono); font-size: 20px; font-weight: 800; color: #fff; line-height: 1; }
.food-card span { font-size: 11px; color: var(--ink-2); }
.food-card em { font-style: normal; font-family: var(--mono); font-size: 10px; color: var(--ink-3); }
.food-card.red { box-shadow: inset 0 0 24px rgba(255, 77, 106, 0.1); border-color: rgba(255, 77, 106, 0.28); }
.food-card.red .orb { background: var(--red); box-shadow: 0 0 16px var(--red); }
.food-card.red b { color: var(--red); }
.food-card.green { box-shadow: inset 0 0 24px rgba(62, 226, 127, 0.1); border-color: rgba(62, 226, 127, 0.28); }
.food-card.green .orb { background: var(--green); box-shadow: 0 0 16px var(--green); }
.food-card.green b { color: var(--green); }
.food-card.blue { box-shadow: inset 0 0 24px rgba(70, 166, 255, 0.1); border-color: rgba(70, 166, 255, 0.28); }
.food-card.blue .orb { background: var(--blue); box-shadow: 0 0 16px var(--blue); }
.food-card.blue b { color: var(--blue); }

/* 主按钮 */
.primary {
  pointer-events: auto;
  display: block; width: 100%;
  padding: 17px 20px;
  font-family: inherit; font-size: 17px; font-weight: 700;
  letter-spacing: 0.16em; color: #04141f;
  border: 0; border-radius: var(--r-md);
  background: linear-gradient(100deg, #6ff0ff, #45e8ff 40%, #3f8bff);
  box-shadow:
    0 14px 34px rgba(69, 232, 255, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  cursor: pointer; touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s;
}
.primary:hover { filter: brightness(1.06); }
.primary:active { transform: scale(0.975); box-shadow: 0 8px 20px rgba(69, 232, 255, 0.28); }

.ghost {
  pointer-events: auto;
  display: block; width: 100%;
  margin-top: 9px; padding: 13px 18px;
  font-family: inherit; font-size: 13px; letter-spacing: 0.08em;
  color: var(--ink-2);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(140, 190, 255, 0.14);
  border-radius: var(--r-md);
  cursor: pointer; touch-action: manipulation;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.ghost:active { color: var(--ink); background: rgba(140, 200, 255, 0.12); border-color: var(--glass-line-hi); }

/* 玩法提示网格 */
.hint-grid { display: grid; grid-template-columns: 1fr; gap: 7px; margin-top: 18px; }
.hint {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 13px;
  border-radius: var(--r-sm);
  background: rgba(255, 255, 255, 0.028);
  border: 1px solid rgba(140, 190, 255, 0.08);
  font-size: 12px;
}
.hint b { color: var(--ink); font-weight: 600; }
.hint span { color: var(--ink-3); font-size: 11.5px; }

.footnote {
  margin-top: 16px; padding-top: 14px;
  border-top: 1px solid rgba(140, 190, 255, 0.1);
  font-size: 11.5px; color: var(--ink-3); text-align: center; letter-spacing: 0.03em;
}

/* 结算 */
h2 { font-size: 24px; font-weight: 700; text-align: center; margin-bottom: 6px; color: #fff; }
.reason { text-align: center; font-size: 12.5px; color: var(--red); letter-spacing: 0.08em; margin-bottom: 18px; }
.final { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-bottom: 16px; }
.final > div {
  padding: 14px 10px; text-align: center;
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(140, 190, 255, 0.12);
}
.final span { display: block; font-size: 10px; letter-spacing: 0.16em; color: var(--ink-3); margin-bottom: 5px; }
.final b {
  display: block; font-family: var(--mono); font-size: 28px; font-weight: 700; color: #fff;
  text-shadow: 0 0 22px rgba(69, 232, 255, 0.5);
  font-variant-numeric: tabular-nums;
}
.newbest {
  text-align: center; font-size: 14px; font-weight: 700; letter-spacing: 0.1em;
  color: var(--gold); margin-bottom: 14px;
  text-shadow: 0 0 20px rgba(255, 194, 80, 0.7);
  animation: glow-pulse 1.2s ease-in-out infinite;
}
@keyframes glow-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.42; } }

/* ══════════════ 响应式 ══════════════ */

.mobile-only { display: none; }
.touch-controls, .swipe-hint { display: none; }

@media (hover: none) and (pointer: coarse) {
  .touch-controls { display: block; }
  .swipe-hint { display: block; }
  .desktop-only { display: none; }
  .mobile-only { display: flex; }
  .legend { top: calc(var(--safe-t) + 92px); }
}

@media (max-width: 560px) {
  .score-main { padding: 7px 13px 8px; border-radius: 16px; }
  .score-num { font-size: 32px; }
  .tool { width: 37px; height: 37px; border-radius: 12px; }
  .tool svg { width: 17px; height: 17px; }
  .chip-best, .chip-level { height: 20px; font-size: 10px; padding: 0 8px; }
  .chip-level i { display: none; }
  .steer { width: 96px; height: 96px; }
  .steer svg { width: 38px; height: 38px; }
  .swipe-hint { bottom: calc(var(--safe-b) + 116px); font-size: 11px; }
  .panel { padding: 26px 20px 20px; border-radius: 28px; }
  .hint-grid { grid-template-columns: 1fr 1fr; }
  .hint { flex-direction: column; align-items: flex-start; gap: 2px; padding: 9px 11px; }
}

/* 横屏：按钮移到左右下角两侧，不挡视线 */
@media (max-height: 480px) and (orientation: landscape) {
  .steer {
    width: 84px; height: 84px;
    bottom: 50%; transform: translateY(50%);
  }
  .steer:active { transform: translateY(50%) scale(0.92); }
  .swipe-hint { display: none; }
  .legend { display: none; }
  .panel { max-height: calc(100dvh - 20px); }
  .menu-head { margin-bottom: 14px; }
  .title { font-size: 30px; }
  .food-grid { margin-bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .newbest { animation: none; }
  .primary, .steer, .tool { transition: none; }
}
