/* =============================================================================
 * 《迷雾迷宫 / Mist Maze》—— 全部样式
 * 主题：潮湿石廊 + 火把暖光 + 迷雾
 *   主色 近黑蓝 #05070d ｜ 石灰 #8a8578 ｜ 出口绿 #33dd88 ｜ 钥匙金 #ffcc33 ｜ 危险 #ff3b52
 * 约定（CONTRACT §3）：.hidden{display:none!important}；section.screen.active{display:flex}
 * ========================================================================== */

:root {
  /* 颜色 */
  --bg: #05070d;
  --bg-soft: #080b13;
  --stone: #8a8578;
  --stone-dim: #6a6559;
  --exit: #33dd88;
  --key: #ffcc33;
  --danger: #ff3b52;
  /* v2：道具 / 增益配色，与小地图标记保持一致 */
  --fuel: #ff9a3c;
  --scroll: #3ce0d0;
  --silence: #b07cff;
  --stamina: #7fb3ff;
  --text: #e9e5da;
  --text-dim: #9b958a;

  --panel-bg: rgba(11, 14, 23, 0.74);
  --panel-bg-solid: rgba(9, 12, 20, 0.95);
  --panel-border: rgba(138, 133, 120, 0.22);
  --hairline: rgba(138, 133, 120, 0.14);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;

  /* 字体 */
  --font-title: Georgia, "Songti SC", "Songti TC", "Times New Roman", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;

  /* 阴影 */
  --shadow-panel: 0 22px 60px rgba(0, 0, 0, 0.62), 0 2px 0 rgba(255, 255, 255, 0.03) inset,
    0 0 70px rgba(51, 221, 136, 0.035) inset;
  --shadow-hud: 0 8px 22px rgba(0, 0, 0, 0.45);
}

/* ------------------------------------------------------------------ 基础 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden; /* 永不出现横向/纵向滚动条 */
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

/* .hidden 为契约约定：必须能压过任何布局声明 */
.hidden {
  display: none !important;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
}

/* 画布铺满视口 */
#scene {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  z-index: 0;
  background: var(--bg);
  touch-action: none;
}

/* ------------------------------------------------------------------ HUD */

#hud {
  position: absolute;
  inset: 0;
  z-index: 3; /* 在暗角之上：HUD 不该被暗角压暗 */
  pointer-events: none; /* HUD 本身不拦截鼠标，以保证 Pointer Lock */
  user-select: none;
}

/* 顶部统计条：小圆角胶囊 */
#hud-top {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-width: calc(100% - 236px); /* 给右上角小地图留位置 */
  z-index: 3;
}

.stat {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  background: rgba(6, 9, 15, 0.55);
  border: 1px solid rgba(138, 133, 120, 0.18);
  box-shadow: var(--shadow-hud), 0 1px 0 rgba(255, 255, 255, 0.04) inset;
  backdrop-filter: blur(6px) saturate(1.05);
  -webkit-backdrop-filter: blur(6px) saturate(1.05);
  font-size: 12px;
  white-space: nowrap;
}

.stat-label {
  color: var(--text-dim);
  font-size: 10.5px;
  letter-spacing: 0.14em;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: #f6f2e8;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.12);
}

#stat-keys {
  color: var(--key);
  text-shadow: 0 0 10px rgba(255, 204, 51, 0.28);
}

#stat-level {
  color: #cfe9dd;
}

/* v3：HUD 层指示（CONTRACT §8.10）。layers<=1 时整块 .hidden（平面模式零回归） */
#stat-layer-wrap {
  border-color: rgba(255, 181, 69, 0.32);
}

#stat-layer {
  color: #ffd9a1;
  text-shadow: 0 0 10px rgba(255, 181, 69, 0.28);
}

/* FPS：刻意更弱，不喧宾夺主 */
.stat-fps {
  background: transparent;
  border-color: rgba(138, 133, 120, 0.1);
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  padding: 5px 8px;
}

.stat-fps .stat-value {
  font-size: 11px;
  color: rgba(233, 229, 218, 0.42);
  text-shadow: none;
}

/* --------------------------------------------------------------- 小地图 */

#minimap-wrap {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 176px;
  padding: 8px 8px 5px;
  border-radius: var(--radius);
  background: rgba(5, 8, 14, 0.6);
  border: 1px solid rgba(255, 204, 51, 0.26);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.55), 0 0 26px rgba(255, 204, 51, 0.05) inset,
    0 1px 0 rgba(255, 255, 255, 0.05) inset;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 3;
  /* 注意：这里不能给 width 加 transition。setMaze() 切换 .mm-lg/.mm-xl 后会立刻
     resize() 读 clientWidth 算 cellPx，若宽度在过渡中就会读到旧值，导致大迷宫
     前几帧用小格宽绘制。 */
}

/* v2：大迷宫（≥24 格）放大画布，保证 27~31 格时走廊仍看得清。
   宽度仍然由媒体查询决定：窄屏用更小的值，避免与小地图外的 HUD 抢位置。 */
#minimap-wrap.mm-lg {
  width: 232px;
  padding: 6px 6px 4px;
}

#minimap-wrap.mm-xl {
  width: 264px;
  padding: 6px 6px 4px;
}

/* 地图变大后统计条要让出更多宽度（:has 不支持时最多只是提前换行，不会重叠） */
#hud-top:has(~ #minimap-wrap.mm-lg) {
  max-width: calc(100% - 264px);
}

#hud-top:has(~ #minimap-wrap.mm-xl) {
  max-width: calc(100% - 296px);
}

#minimap {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 9px;
  background: var(--bg);
  image-rendering: pixelated;
}

#minimap-hint {
  margin-top: 5px;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: rgba(138, 133, 120, 0.72);
}

/* v3：小地图层号徽标（CONTRACT §8.10）。绝对定位叠在画布右上角，
   不参与布局——这样 layers<=1 隐藏时不会改变 #minimap-wrap 的尺寸（平面模式零回归）。 */
#minimap-layer {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: rgba(6, 9, 15, 0.82);
  border: 1px solid rgba(255, 181, 69, 0.5);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  color: #ffd9a1;
  pointer-events: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* --------------------------------------------------------------- 准星 */

#crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  color: rgba(255, 255, 255, 0.78);
  transition: color 0.2s ease, opacity 0.2s ease;
}

/* 中心点 */
#crosshair::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 3px;
  height: 3px;
  margin: -1.5px 0 0 -1.5px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.9);
}

#crosshair span {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
}

/* 上下 / 左右四条短线，由两个 span 的伪元素拼出 */
#crosshair span::before,
#crosshair span::after {
  content: "";
  position: absolute;
  background: currentColor;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.85);
}

/* 水平两条：span1 */
#crosshair span:nth-child(1)::before {
  width: 7px;
  height: 1.5px;
  left: 5px;
  top: -0.75px;
}

#crosshair span:nth-child(1)::after {
  width: 7px;
  height: 1.5px;
  right: 5px;
  top: -0.75px;
}

/* 垂直两条：span2 */
#crosshair span:nth-child(2)::before {
  width: 1.5px;
  height: 7px;
  top: 5px;
  left: -0.75px;
}

#crosshair span:nth-child(2)::after {
  width: 1.5px;
  height: 7px;
  bottom: 5px;
  left: -0.75px;
}

/* 被追猎：#vignette 加 .danger 时准星变红（ui.js 同时给 #hud 加 .danger，双保险） */
#hud.danger #crosshair,
#app:has(#vignette.danger) #crosshair {
  color: rgba(255, 90, 110, 0.92);
}

/* --------------------------------------------------------- 交互提示条 */

#prompt {
  position: absolute;
  left: 50%;
  bottom: 76px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 40px));
  padding: 9px 18px;
  border-radius: var(--radius-pill);
  background: rgba(6, 9, 15, 0.66);
  border: 1px solid rgba(255, 204, 51, 0.3);
  box-shadow: var(--shadow-hud), 0 0 26px rgba(255, 204, 51, 0.08);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-align: center;
  color: #f4efdf;
  animation: promptIn 0.22s ease-out both;
  z-index: 4;
}

/* --------------------------------------------------------------- 提示条 */

#toast-wrap {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 7px;
  max-width: min(320px, calc(100% - 32px));
  z-index: 4;
}

.toast {
  padding: 8px 13px 8px 15px;
  border-radius: var(--radius-sm);
  background: rgba(7, 10, 17, 0.82);
  border: 1px solid rgba(138, 133, 120, 0.24);
  border-left: 2px solid var(--stone);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 12.5px;
  line-height: 1.45;
  color: #ece7db;
  animation: toastIn 0.2s ease-out both;
  transition: opacity 0.26s ease, transform 0.26s ease;
}

.toast.out {
  opacity: 0;
  transform: translateX(-10px);
}

.toast-good {
  border-left-color: var(--exit);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5), 0 0 22px rgba(51, 221, 136, 0.1);
}

.toast-bad {
  border-left-color: var(--danger);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5), 0 0 22px rgba(255, 59, 82, 0.12);
}

/* ===================================================== v2：体力 / 火把条 */
/* 位置：统计条下方，左侧。避免和钥匙金（#ffcc33）、出口绿（#33dd88）撞色：
   体力 = 冷钢蓝，火把 = 燃料橙（与 fuel 道具同色，暗示"这桶油补的就是它"）。
   DOM：.meter > .meter-label + .meter-track > .meter-fill */
#meters {
  position: absolute;
  left: 14px;
  top: 52px;
  display: grid;
  gap: 9px;
  width: 178px;
  pointer-events: none;
  z-index: 3;
}

.meter {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.meter-label {
  flex: 0 0 30px;
  font-size: 9.5px;
  letter-spacing: 0.16em;
  color: rgba(155, 149, 138, 0.88);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
}

.meter-track {
  position: relative;
  flex: 1 1 auto;
  height: 9px;
  min-width: 0;
  border-radius: var(--radius-pill);
  background: linear-gradient(180deg, rgba(2, 4, 8, 0.74), rgba(2, 4, 8, 0.5));
  border: 1px solid rgba(138, 133, 120, 0.3);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 1px 3px rgba(0, 0, 0, 0.75) inset;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  border-radius: var(--radius-pill);
  transition: width 0.14s linear, background 0.3s ease, box-shadow 0.3s ease;
}

#stamina-fill {
  background: linear-gradient(90deg, #3f7fd6, #7fb3ff);
  box-shadow: 0 0 10px rgba(127, 179, 255, 0.35);
}

#torch-fill {
  background: linear-gradient(90deg, #c2551a, #ff9a3c);
  box-shadow: 0 0 10px rgba(255, 154, 60, 0.35);
}

/* 火把告警：呼吸 + 泛红（幂等，由 ui.setTorchLow / 数值告警驱动） */
#meter-torch.low {
  animation: torchPulse 1.15s ease-in-out infinite;
}

#meter-torch.low .meter-label {
  color: #ff8f6b;
}

#meter-torch.low .meter-track {
  border-color: rgba(255, 107, 74, 0.6);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.75) inset, 0 0 14px rgba(255, 107, 74, 0.35);
}

#meter-torch.low #torch-fill {
  background: linear-gradient(90deg, #a3220f, #ff6b4a);
  box-shadow: 0 0 12px rgba(255, 107, 74, 0.6);
}

@keyframes torchPulse {
  0%,
  100% {
    opacity: 0.52;
  }
  50% {
    opacity: 1;
  }
}

/* ===================================================== v2：增益 / 减益 */
#buffs {
  position: absolute;
  left: 14px;
  top: 124px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-width: 190px;
  pointer-events: none;
  z-index: 3;
}

#buffs.empty {
  display: none;
}

.buff {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border-radius: var(--radius-pill);
  background: rgba(6, 9, 15, 0.66);
  border: 1px solid rgba(138, 133, 120, 0.24);
  box-shadow: var(--shadow-hud);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: #ece7db;
  white-space: nowrap;
  animation: buffIn 0.18s ease-out both;
}

.buff-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}

.buff-name {
  color: rgba(236, 231, 219, 0.92);
}

.buff-time {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: #fff;
  min-width: 2.2em;
  text-align: right;
}

/* 静步：紫（与 silence 道具同色） */
.buff-silence {
  border-color: rgba(176, 124, 255, 0.45);
  color: var(--silence, #b07cff);
  box-shadow: var(--shadow-hud), 0 0 18px rgba(176, 124, 255, 0.14);
}

/* 减速：暗红警告 */
.buff-slow {
  border-color: rgba(255, 107, 107, 0.45);
  color: #ff6b6b;
  box-shadow: var(--shadow-hud), 0 0 18px rgba(255, 107, 107, 0.14);
}

@keyframes buffIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ===================================================== v2：全屏红闪 */
/* 叠在 3D 画面之上、HUD 控件之下（z-index 1 < 统计条/条的 3） */
#flash {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(ellipse 78% 74% at 50% 50%, rgba(255, 59, 82, 0.18) 0%, rgba(255, 30, 48, 0.55) 62%, rgba(150, 10, 26, 0.8) 100%);
}

#flash.on {
  animation: flashHit 240ms ease-out both;
}

@keyframes flashHit {
  0% {
    opacity: 0.9;
  }
  45% {
    opacity: 0.5;
  }
  100% {
    opacity: 0;
  }
}

/* 若这几个 v2 节点被放在 #hud 之外，仍要跟随 HUD 一起隐藏 */
#hud.hidden ~ #meters,
#hud.hidden ~ #buffs {
  display: none !important;
}

/* --------------------------------------------------------- 暗角 / 危险 */

#vignette {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(ellipse 72% 68% at 50% 48%, rgba(0, 0, 0, 0) 46%, rgba(2, 3, 6, 0.42) 82%, rgba(2, 3, 6, 0.72) 100%),
    linear-gradient(180deg, rgba(5, 7, 13, 0.28), rgba(5, 7, 13, 0) 22%, rgba(5, 7, 13, 0) 74%, rgba(5, 7, 13, 0.36));
  opacity: 0.9;
  transition: opacity 0.4s ease;
}

#vignette.danger {
  background:
    radial-gradient(ellipse 70% 66% at 50% 48%, rgba(255, 59, 82, 0) 34%, rgba(255, 59, 82, 0.22) 74%, rgba(255, 59, 82, 0.46) 100%),
    radial-gradient(ellipse 78% 74% at 50% 50%, rgba(0, 0, 0, 0) 40%, rgba(2, 3, 6, 0.5) 84%, rgba(2, 3, 6, 0.78) 100%);
  animation: dangerPulse 1.1s ease-in-out infinite;
}

@keyframes dangerPulse {
  0%,
  100% {
    opacity: 0.42;
  }
  50% {
    opacity: 1;
  }
}

/* ------------------------------------------------------- 覆盖层 / 界面 */

#overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-x: hidden;
  overflow-y: auto;
  background:
    radial-gradient(ellipse 70% 60% at 50% 42%, rgba(51, 221, 136, 0.05), rgba(0, 0, 0, 0) 62%),
    radial-gradient(ellipse 90% 80% at 50% 110%, rgba(255, 204, 51, 0.05), rgba(0, 0, 0, 0) 60%),
    rgba(4, 6, 11, 0.76);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

section.screen {
  display: none;
}

section.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100%;
}

/* --------------------------------------------------------------- 面板 */

.panel {
  position: relative;
  width: min(560px, 100%);
  margin: auto;
  padding: 28px 28px 24px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(16, 20, 32, 0.86), rgba(7, 9, 15, 0.9));
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(8px) saturate(1.08);
  -webkit-backdrop-filter: blur(8px) saturate(1.08);
  animation: panelIn 0.2s ease-out both;
}

/* backdrop-filter 不支持时，改用接近不透明的底，保证可读性（降级） */
@supports not ((backdrop-filter: blur(8px)) or (-webkit-backdrop-filter: blur(8px))) {
  .panel {
    background: var(--panel-bg-solid);
  }
  #overlay {
    background: rgba(4, 6, 11, 0.9);
  }
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 -22px 46px rgba(0, 0, 0, 0.35) inset;
}

.panel-narrow {
  width: min(430px, 100%);
}

.panel-lose {
  border-color: rgba(255, 59, 82, 0.3);
  box-shadow: var(--shadow-panel), 0 0 60px rgba(255, 59, 82, 0.08);
}

/* --------------------------------------------------------------- 标题 */

.title {
  margin: 0 0 14px;
  font-family: var(--font-title);
  font-weight: 600;
  letter-spacing: 0.1em;
  line-height: 1.15;
}

.title::after {
  content: "";
  display: block;
  height: 1px;
  margin-top: 13px;
  background: linear-gradient(
    90deg,
    rgba(255, 204, 51, 0.55),
    rgba(51, 221, 136, 0.32) 46%,
    rgba(138, 133, 120, 0) 100%
  );
}

.title-main {
  display: block;
  font-size: clamp(30px, 6vw, 42px);
  color: #f5f1e4;
  text-shadow:
    0 0 26px rgba(51, 221, 136, 0.2),
    0 0 2px rgba(255, 255, 255, 0.32),
    0 2px 0 rgba(0, 0, 0, 0.65);
}

.title-sub {
  display: block;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0.38em;
  text-transform: uppercase;
  color: rgba(138, 133, 120, 0.9);
}

.tagline {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-dim);
}

.tagline-small {
  font-size: 12px;
  margin-bottom: 0;
}

.tagline code,
#loading code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(51, 221, 136, 0.09);
  border: 1px solid rgba(51, 221, 136, 0.22);
  color: #bff0d8;
}

/* --------------------------------------------------------------- 表单 */

.field {
  margin-bottom: 18px;
}

.field-label {
  display: block;
  margin-bottom: 9px;
  font-size: 10.5px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: rgba(138, 133, 120, 0.95);
}

.diff-options,
#mode-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.diff-options button,
#mode-options button {
  display: block;
  width: 100%;
  padding: 11px 13px;
  text-align: left;
  border-radius: 12px;
  border: 1px solid rgba(138, 133, 120, 0.2);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.008));
  color: var(--text);
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.18s ease, background 0.18s ease,
    box-shadow 0.18s ease, color 0.18s ease;
}

.diff-options button strong,
#mode-options button strong {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.diff-options button em,
#mode-options button em {
  display: block;
  margin-top: 3px;
  font-style: normal;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-dim);
}

.diff-options button:hover,
#mode-options button:hover {
  border-color: rgba(255, 204, 51, 0.42);
  background: linear-gradient(180deg, rgba(255, 204, 51, 0.09), rgba(255, 204, 51, 0.02));
  transform: translateY(-1px);
}

.diff-options button:active,
#mode-options button:active {
  transform: translateY(0) scale(0.99);
}

.diff-options button:focus-visible,
#mode-options button:focus-visible {
  outline: 2px solid rgba(51, 221, 136, 0.75);
  outline-offset: 2px;
}

.diff-options button.selected,
#mode-options button.selected {
  border-color: rgba(255, 204, 51, 0.62);
  background: linear-gradient(180deg, rgba(255, 204, 51, 0.16), rgba(255, 204, 51, 0.04));
  box-shadow: 0 0 0 1px rgba(255, 204, 51, 0.16) inset, 0 8px 20px rgba(0, 0, 0, 0.4),
    0 0 22px rgba(255, 204, 51, 0.08);
  color: #ffeab4;
}

.diff-options button.selected em,
#mode-options button.selected em {
  color: rgba(255, 226, 160, 0.78);
}

.diff-options button.selected strong::before,
#mode-options button.selected strong::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--key);
  box-shadow: 0 0 10px rgba(255, 204, 51, 0.8);
  vertical-align: middle;
}

/* v3：模式选择（CONTRACT §8.10 / §8.11）。
   复用 #diff-options 的视觉语言，只是语义更轻：两个按钮、居中排布、
   描述保持单行，避免整块比难度区还抢眼。 */
#mode-options {
  gap: 8px;
}

#mode-options button {
  text-align: center;
  padding: 9px 11px;
}

#mode-options button strong {
  letter-spacing: 0.1em;
}

#mode-options button em {
  margin-top: 2px;
  font-size: 10.5px;
  letter-spacing: 0.02em;
}

/* 种子输入 */
#seed-input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 11px;
  border: 1px solid rgba(138, 133, 120, 0.24);
  background: rgba(3, 5, 9, 0.6);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.12em;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

#seed-input::placeholder {
  color: rgba(138, 133, 120, 0.55);
  letter-spacing: 0.06em;
}

#seed-input:hover {
  border-color: rgba(138, 133, 120, 0.4);
}

#seed-input:focus {
  outline: none;
  border-color: rgba(255, 204, 51, 0.55);
  background: rgba(3, 5, 9, 0.8);
  box-shadow: 0 0 0 3px rgba(255, 204, 51, 0.12);
}

/* --------------------------------------------------------------- 按钮 */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 11px 20px;
  border-radius: 12px;
  border: 1px solid rgba(138, 133, 120, 0.28);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.012));
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, border-color 0.2s ease,
    background 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 204, 51, 0.45);
  background: linear-gradient(180deg, rgba(255, 204, 51, 0.1), rgba(255, 204, 51, 0.025));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
}

.btn:active {
  transform: translateY(0) scale(0.985);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5) inset;
}

.btn:focus-visible {
  outline: 2px solid rgba(51, 221, 136, 0.78);
  outline-offset: 2px;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.36;
  cursor: not-allowed;
  transform: none;
  filter: saturate(0.5);
}

.btn:disabled:hover,
.btn[disabled]:hover {
  border-color: rgba(138, 133, 120, 0.28);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.012));
  box-shadow: none;
  transform: none;
}

.btn-primary {
  color: #e9fff4;
  border-color: rgba(51, 221, 136, 0.5);
  background: linear-gradient(180deg, rgba(51, 221, 136, 0.24), rgba(51, 221, 136, 0.07));
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45), 0 0 26px rgba(51, 221, 136, 0.14),
    0 1px 0 rgba(255, 255, 255, 0.08) inset;
  text-shadow: 0 0 12px rgba(51, 221, 136, 0.35);
}

.btn-primary:hover {
  border-color: rgba(51, 221, 136, 0.8);
  background: linear-gradient(180deg, rgba(51, 221, 136, 0.34), rgba(51, 221, 136, 0.12));
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5), 0 0 34px rgba(51, 221, 136, 0.22);
}

.btn-ghost {
  background: transparent;
  border-color: rgba(138, 133, 120, 0.22);
  color: var(--text-dim);
  font-weight: 500;
}

.btn-ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.btn-lg {
  width: 100%;
  min-height: 50px;
  margin-bottom: 20px;
  font-size: 15px;
  letter-spacing: 0.14em;
}

.btn-lg:disabled {
  margin-bottom: 20px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.btn-row .btn {
  flex: 1 1 130px;
}

/* ------------------------------------------------------- 操作说明网格 */

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
}

.controls-grid > div {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-dim);
}

.controls-grid span {
  margin-left: 3px;
}

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid rgba(138, 133, 120, 0.3);
  border-bottom-width: 2px;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
  font-family: var(--font-mono);
  font-size: 10px;
  color: #ddd8cb;
  text-align: center;
}

/* --------------------------------------------------------- 结算数据表 */

.stats-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 4px 0 20px;
}

.stats-list .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.028);
  border: 1px solid var(--hairline);
  font-size: 12.5px;
  min-width: 0;
}

.stats-list .row > span:first-child {
  color: var(--text-dim);
  font-size: 11px;
  letter-spacing: 0.12em;
  white-space: nowrap;
}

.stats-list .row > span:last-child {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: #f2eee3;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-list .row.accent > span:last-child {
  color: var(--key);
}

.stats-list .row.best {
  grid-column: 1 / -1;
  border-color: rgba(51, 221, 136, 0.34);
  background: linear-gradient(180deg, rgba(51, 221, 136, 0.12), rgba(51, 221, 136, 0.03));
}

.stats-list .row.best > span:last-child {
  color: var(--exit);
  text-shadow: 0 0 12px rgba(51, 221, 136, 0.35);
}

/* --------------------------------------------------------- 兜底提示 */

#loading {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  background: rgba(4, 6, 11, 0.94);
}

#loading .panel {
  animation: none;
}

/* --------------------------------------------------------------- 动画 */

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes promptIn {
  from {
    opacity: 0;
    transform: translate(-50%, 6px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* 窄屏下提示条改为左下角定位，位移动画里不能再带 -50% 水平居中 */
@keyframes promptInY {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ----------------------------------------------------------- 响应式 */

/* 窄屏：统计条换行缩小、菜单单列、小地图挪到右下角避免与统计条打架 */
@media (max-width: 720px) {
  #hud-top {
    left: 8px;
    right: 8px;
    top: 8px;
    max-width: none;
    justify-content: center;
    gap: 5px;
  }

  .stat {
    padding: 4px 9px;
    font-size: 11px;
  }

  .stat-label {
    font-size: 9.5px;
    letter-spacing: 0.08em;
  }

  .stat-value {
    font-size: 12px;
  }

  #minimap-wrap {
    top: auto;
    bottom: 12px;
    right: 12px;
    width: 116px;
    padding: 6px 6px 3px;
    border-radius: 12px;
  }

  /* v2：窄屏也要放大，但幅度小一些，避免挤占提示条与 toast 的空间 */
  #minimap-wrap.mm-lg {
    width: 144px;
  }

  #minimap-wrap.mm-xl {
    width: 156px;
  }

  #minimap-hint {
    font-size: 9px;
    letter-spacing: 0.04em;
  }

  /* v3：窄屏小地图更小，徽标跟着收紧 */
  #minimap-layer {
    top: 8px;
    right: 8px;
    padding: 1px 6px;
    font-size: 9.5px;
  }

  /* v2：条挪到统计条下方左侧，增益区紧跟其后；toast 再往下排 */
  #meters {
    top: 42px;
    left: 12px;
    width: 140px;
    gap: 7px;
  }

  .meter-label {
    flex-basis: 26px;
    font-size: 9px;
    letter-spacing: 0.1em;
  }

  .meter-track {
    height: 8px;
  }

  #buffs {
    top: 82px;
    left: 12px;
    gap: 6px;
    max-width: calc(100% - 24px);
  }

  .buff {
    padding: 3px 9px 3px 7px;
    font-size: 10.5px;
  }

  /* 竖屏窄机：底部右侧被小地图占用，因此提示条靠左下、toast 挪到顶部（条与增益区下方），
     避免持久显示的提示与其它 HUD 互相遮挡 */
  #prompt {
    left: 12px;
    bottom: 14px;
    transform: none;
    max-width: calc(100% - 184px);
    padding: 8px 13px;
    font-size: 12px;
    text-align: left;
    animation-name: promptInY;
  }

  #toast-wrap {
    top: 112px;
    bottom: auto;
    left: 12px;
    right: auto;
    max-width: min(240px, calc(100% - 24px));
    justify-content: flex-start;
  }

  #overlay {
    padding: 14px;
    align-items: flex-start;
  }

  section.screen.active {
    min-height: auto;
  }

  /* 手机上收紧纵向节奏，让「开始游戏」和操作说明尽量落在一屏内 */
  .panel {
    width: 100%;
    padding: 18px 14px 14px;
    border-radius: 12px;
  }

  .title {
    margin-bottom: 10px;
  }

  .title::after {
    margin-top: 9px;
  }

  .title-main {
    font-size: clamp(22px, 7.5vw, 28px);
  }

  .title-sub {
    margin-top: 6px;
    font-size: 9.5px;
    letter-spacing: 0.24em;
  }

  .tagline {
    margin-bottom: 12px;
    font-size: 12px;
    line-height: 1.6;
  }

  .field {
    margin-bottom: 12px;
  }

  .field-label {
    margin-bottom: 7px;
  }

  .diff-options,
  #mode-options {
    grid-template-columns: minmax(0, 1fr); /* 单列 */
    gap: 7px;
  }

  .diff-options button,
  #mode-options button {
    padding: 9px 12px;
  }

  .diff-options button em,
  #mode-options button em {
    margin-top: 2px;
    font-size: 10.5px;
  }

  #seed-input {
    padding: 9px 12px;
  }

  .btn-lg {
    min-height: 46px;
    margin-bottom: 14px;
  }

  .controls-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding-top: 12px;
    gap: 6px;
    font-size: 10.5px;
  }

  .btn-row .btn {
    flex: 1 1 100%;
  }

  .stats-list {
    grid-template-columns: minmax(0, 1fr);
  }

  .stats-list .row.best {
    grid-column: auto;
  }
}

/* 矮屏（横屏手机 / 小窗）：整体收紧间距，保证不出现横向滚动条。
   此时小地图回到右上角，统计条靠左，避免两者互相遮挡。 */
@media (max-height: 620px) {
  #hud-top {
    top: 8px;
    left: 8px;
    right: auto;
    justify-content: flex-start;
    max-width: calc(100% - 164px);
  }

  #minimap-wrap {
    top: 8px;
    right: 8px;
    bottom: auto; /* 覆盖窄屏的 bottom 定位，否则会被纵向拉伸 */
    width: 124px;
  }

  /* v2：矮屏时小地图在右上，条与增益区跟在统计条下方（统计条此时靠左） */
  #meters {
    top: 42px;
    left: 8px;
    width: 148px;
    gap: 6px;
  }

  .meter-track {
    height: 8px;
  }

  #buffs {
    top: 86px; /* 与 #meters（top 42 + 两行 ≈ 78）留出净空，别贴在一起 */
    left: 8px;
    max-width: min(230px, calc(100% - 16px));
  }

  #overlay {
    align-items: flex-start;
    padding: 12px;
  }

  section.screen.active {
    min-height: auto;
  }

  .panel {
    padding: 18px 18px 15px;
    margin: 0 auto;
  }

  .title {
    margin-bottom: 10px;
  }

  .title::after {
    margin-top: 9px;
  }

  .title-main {
    font-size: clamp(22px, 4.6vw, 30px);
  }

  .tagline {
    margin-bottom: 12px;
    font-size: 12px;
  }

  .field {
    margin-bottom: 12px;
  }

  .diff-options button,
  #mode-options button {
    padding: 8px 11px;
  }

  .diff-options button em,
  #mode-options button em {
    display: none; /* 矮屏下隐藏描述，只留难度名 */
  }

  .btn {
    min-height: 38px;
    padding: 9px 16px;
  }

  .btn-lg {
    min-height: 42px;
    margin-bottom: 14px;
  }

  .controls-grid {
    padding-top: 12px;
    gap: 6px;
  }

  .stats-list {
    gap: 6px;
    margin-bottom: 14px;
  }

  .stats-list .row {
    padding: 7px 10px;
  }

  #prompt {
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    max-width: min(340px, calc(100% - 300px));
    text-align: center;
    animation-name: promptIn;
  }
}

/* 极窄屏兜底：进一步缩小统计胶囊，避免溢出 */
@media (max-width: 380px) {
  .stat {
    padding: 3px 8px;
    font-size: 10px;
  }

  .stat-label {
    display: none; /* 只留数值，靠 title 提示 */
  }

  .stat-fps {
    display: none;
  }

  #minimap-wrap {
    width: 96px;
  }

  /* v2：极窄屏下大迷宫地图不能再宽，否则会挤掉提示条 */
  #minimap-wrap.mm-lg {
    width: 112px;
  }

  #minimap-wrap.mm-xl {
    width: 122px;
  }

  #meters {
    width: 116px;
  }

  .meter-label {
    flex-basis: 22px;
    font-size: 8.5px;
    letter-spacing: 0.04em;
  }

  #buffs {
    max-width: calc(100% - 16px);
  }

  #prompt {
    max-width: calc(100% - 150px);
  }
}

/* 又窄又矮（横屏小机）：统计条要和小地图并排，给它留出地图宽度，
   否则会被挤成两行并与提示条重叠 */
@media (max-width: 380px) and (max-height: 620px) {
  #hud-top {
    max-width: calc(100% - 116px);
  }
}

/* 降低动效偏好：关掉入场/脉冲动画，保留颜色区分 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  #vignette.danger {
    opacity: 0.95;
  }

  .panel,
  .toast,
  #prompt {
    animation: none;
  }
}

/* 高对比度偏好：加强描边 */
@media (prefers-contrast: more) {
  .panel,
  .stat,
  #minimap-wrap {
    border-color: rgba(233, 229, 218, 0.6);
  }

  .stat-value {
    color: #fff;
  }

  #minimap-layer {
    border-color: rgba(233, 229, 218, 0.6);
    color: #fff;
  }
}
