/* ===== 立体贪吃蛇 样式表（零依赖） ===== */

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #e8e9ff;
  background: radial-gradient(circle at 50% 30%, #171a3a, #0b0e20);
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

/* ===== 顶部栏 ===== */

.topbar {
  flex: 0 0 auto;
  height: 56px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 20;
}

.brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 2px;
  background: linear-gradient(90deg, #7c5cff, #22d3ee);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.back-link {
  color: #c9cbff;
  text-decoration: none;
  font-size: 14px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.back-link:hover {
  color: #22d3ee;
  border-color: rgba(34, 211, 238, 0.55);
  background: rgba(34, 211, 238, 0.08);
}

/* ===== 舞台 ===== */

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

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

/* ===== HUD ===== */

.hud {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  z-index: 8;
}

.hud-chip {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 7px 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.hud-label {
  font-size: 12px;
  color: #9a9ccb;
  letter-spacing: 1px;
}

.hud-value {
  font-size: 17px;
  font-weight: 700;
  color: #ffffff;
  min-width: 20px;
  text-align: center;
}

.hud-chip:nth-child(2) .hud-value {
  color: #22d3ee;
}

.hud-chip:nth-child(3) .hud-value {
  color: #ffb347;
}

.pause-btn {
  margin-left: auto;
  pointer-events: auto;
  font-family: inherit;
  font-size: 13px;
  color: #e8e9ff;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid rgba(124, 92, 255, 0.7);
  background: rgba(124, 92, 255, 0.22);
  cursor: pointer;
  transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.1s ease;
}

.pause-btn:hover {
  background: rgba(124, 92, 255, 0.42);
  box-shadow: 0 0 16px rgba(124, 92, 255, 0.45);
}

.pause-btn:active {
  transform: scale(0.95);
}

/* ===== 遮罩与面板 ===== */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 10, 26, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  z-index: 30;
}

.overlay.show {
  opacity: 1;
  visibility: visible;
}

.panel {
  width: min(460px, 100%);
  padding: 34px 34px 30px;
  text-align: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45), 0 0 40px rgba(124, 92, 255, 0.18);
}

.panel-small {
  width: min(380px, 100%);
}

.panel-title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 4px;
  margin-bottom: 14px;
  background: linear-gradient(90deg, #a78bff, #22d3ee);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.panel-desc {
  font-size: 14px;
  line-height: 1.9;
  color: #b9bce4;
  margin-bottom: 18px;
}

.key-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 24px;
}

.key-hints span {
  font-size: 12px;
  color: #cfd1ff;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.3);
}

.main-btn {
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 3px;
  color: #ffffff;
  padding: 13px 42px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  background: linear-gradient(135deg, #7c5cff, #5b3df0);
  box-shadow: 0 8px 26px rgba(124, 92, 255, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.main-btn:hover {
  filter: brightness(1.12);
  box-shadow: 0 10px 32px rgba(124, 92, 255, 0.65), 0 0 22px rgba(34, 211, 238, 0.35);
}

.main-btn:active {
  transform: scale(0.96);
}

/* ===== 结算 ===== */

.record-tip {
  display: none;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 3px;
  color: #ffb347;
  margin-bottom: 12px;
  text-shadow: 0 0 14px rgba(255, 179, 71, 0.75);
}

.record-tip.show {
  display: block;
  animation: pulse-tip 1.1s ease-in-out infinite;
}

@keyframes pulse-tip {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 6px 0 24px;
}

.result-cell {
  padding: 14px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-wide {
  grid-column: 1 / -1;
}

.result-cell strong {
  font-size: 24px;
  color: #22d3ee;
}

.result-wide strong {
  color: #ffb347;
}

/* ===== 底部说明 ===== */

.foot-tip {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 12px;
  letter-spacing: 1px;
  color: rgba(200, 202, 240, 0.62);
  pointer-events: none;
  z-index: 6;
}

/* ===== 移动端触控 ===== */

.touch-controls {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 34px;
  padding: 0 22px;
  justify-content: space-between;
  align-items: flex-end;
  z-index: 10;
  pointer-events: none;
}

body.touch .touch-controls {
  display: flex;
}

.dpad {
  width: 158px;
  height: 158px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 7px;
  pointer-events: auto;
}

.tbtn {
  border: 1px solid rgba(124, 92, 255, 0.55);
  border-radius: 16px;
  background: rgba(124, 92, 255, 0.18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.tbtn:active {
  background: rgba(34, 211, 238, 0.32);
  transform: scale(0.93);
}

.t-up { grid-column: 2; grid-row: 1; }
.t-left { grid-column: 1; grid-row: 2; }
.t-right { grid-column: 3; grid-row: 2; }
.t-down { grid-column: 2; grid-row: 3; }

.rotate-pad {
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

.rbtn {
  font-family: inherit;
  color: #e8e9ff;
  font-size: 12px;
  letter-spacing: 1px;
  padding: 10px 16px;
  border-radius: 16px;
  border: 1px solid rgba(34, 211, 238, 0.5);
  background: rgba(34, 211, 238, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  gap: 8px;
  touch-action: none;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.rbtn:active {
  background: rgba(34, 211, 238, 0.3);
  transform: scale(0.94);
}

/* 纯 CSS 三角箭头，不使用任何表情符号或图片 */
.arrow {
  width: 0;
  height: 0;
  display: inline-block;
}

.arrow-up {
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 14px solid #c7d8ff;
}

.arrow-down {
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-top: 14px solid #c7d8ff;
}

.arrow-left {
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-right: 14px solid #c7d8ff;
}

.arrow-right {
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-left: 14px solid #c7d8ff;
}

.arrow-ccw,
.arrow-cw {
  position: relative;
  width: 16px;
  height: 16px;
  border: 2px solid #22d3ee;
  border-radius: 50%;
  border-top-color: transparent;
}

.arrow-ccw::after,
.arrow-cw::after {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 8px solid #22d3ee;
}

.arrow-ccw::after {
  top: -5px;
  left: -2px;
  transform: rotate(-35deg);
}

.arrow-cw::after {
  bottom: -5px;
  right: -2px;
  transform: rotate(145deg);
}

/* ===== 小屏适配 ===== */

@media (max-width: 560px) {
  .brand {
    font-size: 17px;
    letter-spacing: 1px;
  }

  .back-link {
    font-size: 12px;
    padding: 7px 10px;
  }

  .hud-chip {
    padding: 6px 10px;
    gap: 5px;
  }

  .hud-value {
    font-size: 15px;
  }

  .panel {
    padding: 26px 20px 24px;
  }

  .panel-title {
    font-size: 25px;
  }

  body.touch .foot-tip {
    opacity: 0.45;
  }
}
