:root {
  --bg: #08090c;
  --panel: #121419;
  --panel-2: #171a20;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #e9ebef;
  --muted: #8a909c;
  --amber: #ffcf4a;
  --amber-deep: #e7a51e;
  --red: #ff5a5f;
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(255, 207, 74, 0.06), transparent 60%),
    radial-gradient(900px 500px at 80% 110%, rgba(90, 120, 255, 0.05), transparent 65%),
    var(--bg);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

#app {
  width: min(1180px, 100%);
  padding: clamp(10px, 2.2vw, 24px) clamp(10px, 2.4vw, 28px);
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.4vh, 14px);
}

/* ── HUD ── */
#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(28, 31, 38, 0.92), rgba(16, 18, 22, 0.92));
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
}

.hud-left { display: flex; align-items: baseline; gap: 12px; min-width: 0; }

.level-id {
  font-family: var(--mono);
  font-size: clamp(20px, 2.4vw, 28px);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--amber);
  text-shadow: 0 0 24px rgba(255, 207, 74, 0.28);
  white-space: nowrap;
}

.level-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.level-meta #level-name { color: #cfd4dd; font-weight: 600; }
.level-meta .sep { opacity: 0.4; }

.hud-right { display: flex; align-items: center; gap: 8px; }

.death {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.22);
  font-family: var(--mono);
}
.death #death-count { color: var(--red); font-size: 18px; font-weight: 700; }
.death-label { color: var(--muted); font-size: 11px; letter-spacing: 0.08em; }

.hud-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: #d7dbe2;
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 11px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}
.hud-btn:hover { background: rgba(255, 255, 255, 0.09); border-color: var(--line-strong); }
.hud-btn:active { transform: translateY(1px); }
.hud-btn.icon { width: 36px; padding: 8px 0; font-size: 15px; }
.hud-btn kbd { margin-left: 4px; }

kbd {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1;
  padding: 2px 4px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: #9aa1ad;
  background: rgba(0, 0, 0, 0.25);
}

.badge {
  display: none;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #ffdf94;
  border: 1px solid rgba(255, 207, 74, 0.4);
  background: rgba(255, 207, 74, 0.12);
  padding: 6px 9px;
  border-radius: 999px;
  animation: badgePulse 1.6s ease-in-out infinite;
}
.badge.show { display: inline-block; }
@keyframes badgePulse {
  0%, 100% { box-shadow: 0 0 0 rgba(255, 207, 74, 0); }
  50% { box-shadow: 0 0 18px rgba(255, 207, 74, 0.25); }
}

/* ── 舞台 ── */
#stage-wrap { position: relative; display: flex; align-items: center; justify-content: center; }

#stage {
  position: relative;
  width: 100%;
  max-width: calc((100vh - 190px) * 16 / 9);
  max-width: calc((100dvh - 190px) * 16 / 9);
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(0, 0, 0, 0.6) inset,
    0 0 80px rgba(255, 207, 74, 0.045);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; outline: none; }

/* ── 关卡开场字幕 ── */
.caption {
  position: absolute;
  left: 50%;
  top: 9%;
  transform: translate(-50%, -6px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 207, 74, 0.28);
  background: rgba(10, 11, 14, 0.78);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s ease;
  white-space: nowrap;
  max-width: 92%;
  overflow: hidden;
}
.caption.show { opacity: 1; transform: translate(-50%, 0); }
.cap-door {
  font-family: var(--mono);
  color: var(--amber);
  font-weight: 700;
  font-size: 15px;
}
.cap-name { color: #e8eaee; font-size: 14px; font-weight: 600; }
.cap-hint { color: var(--muted); font-size: 12px; border-left: 1px solid var(--line); padding-left: 10px; }

/* ── 底部提示 ── */
#footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 12px;
}
.hint { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hint-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 10px rgba(255, 207, 74, 0.7);
  flex: none;
}
#hint { color: #b7bdc8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.controls-tip { display: flex; gap: 14px; flex: none; }
.controls-tip span { display: inline-flex; align-items: center; gap: 3px; }

/* ── 触屏按键 ── */
.touch {
  position: absolute;
  inset: 0;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  padding: 16px 18px calc(16px + env(safe-area-inset-bottom));
  pointer-events: none;
  z-index: 5;
}
.touch-pad { display: flex; gap: 12px; pointer-events: auto; }
.touch-btn {
  pointer-events: auto;
  width: clamp(58px, 9.5vw, 76px);
  height: clamp(58px, 9.5vw, 76px);
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(20, 23, 29, 0.58);
  color: #e9ebef;
  font-family: var(--font);
  font-size: 20px;
  font-weight: 700;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  touch-action: none;
  transition: background 0.08s ease, transform 0.08s ease;
}
.touch-btn.jump {
  width: clamp(68px, 11vw, 88px);
  height: clamp(68px, 11vw, 88px);
  border-color: rgba(255, 207, 74, 0.45);
  background: rgba(255, 207, 74, 0.16);
  color: #ffe6a3;
  font-size: 17px;
}
.touch-btn.active, .touch-btn:active {
  background: rgba(255, 207, 74, 0.32);
  transform: scale(0.96);
}
@media (hover: none), (pointer: coarse) {
  .touch { display: flex; }
  .controls-tip { display: none; }
  #app { padding: 10px max(10px, env(safe-area-inset-right)) 10px max(10px, env(safe-area-inset-left)); gap: 8px; }
  #hud { padding: 7px 10px; gap: 8px; }
  .level-meta { display: none; }
  .hud-btn kbd { display: none; }
  #stage { width: calc(100% - 176px); max-width: calc((100dvh - 112px) * 16 / 9); }
  .touch { padding: 8px 6px; }
  .touch-pad { flex-direction: column; gap: 10px; }
  .touch-btn { width: 64px; height: 64px; }
  .touch-btn.jump { width: 76px; height: 76px; }
  #footer { font-size: 11px; }
}
@media (hover: none) and (orientation: portrait), (pointer: coarse) and (orientation: portrait) {
  #stage-wrap { flex-direction: column; gap: 10px; }
  #stage { width: 100%; max-width: 100%; }
  .touch { position: relative; width: 100%; min-height: 86px; padding: 4px 10px calc(4px + env(safe-area-inset-bottom)); }
  .touch-pad { flex-direction: row; gap: 14px; }
}

/* ── 弹层 ── */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 3vw, 34px);
  background: rgba(4, 5, 7, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: fadeIn 0.2s ease;
}
.overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: min(760px, 100%);
  max-height: 100%;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: linear-gradient(180deg, #181b21, #101216);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  padding: clamp(16px, 2.4vw, 26px);
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.eyebrow {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--amber);
  opacity: 0.85;
  margin-bottom: 4px;
}
.panel h2 { margin: 0; font-size: clamp(20px, 2.6vw, 28px); letter-spacing: 0.01em; }
.icon-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: #cfd4dd;
  width: 36px; height: 36px;
  border-radius: 10px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }

.level-groups { display: flex; flex-direction: column; gap: 14px; }
.level-group { border-top: 1px solid var(--line); padding-top: 12px; }
.level-group:first-child { border-top: 0; padding-top: 0; }
.group-label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.group-label strong { font-size: 13px; color: #dfe3ea; }
.group-label span { font-size: 11px; color: var(--muted); }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.level-btn {
  appearance: none;
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
  color: #cfd4dd;
  padding: 10px 6px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.level-btn:hover:not(:disabled) { background: rgba(255, 207, 74, 0.12); border-color: rgba(255, 207, 74, 0.4); color: #ffe7a8; }
.level-btn.completed { border-color: rgba(255, 207, 74, 0.38); color: #ffdf94; }
.level-btn.completed::after {
  content: "";
  position: absolute;
  right: 6px; top: 6px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 6px rgba(255, 207, 74, 0.8);
}
.level-btn.current { background: rgba(255, 207, 74, 0.18); border-color: var(--amber); color: #fff1c4; }
.level-btn:disabled { opacity: 0.32; cursor: not-allowed; }

.panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.panel-actions { display: flex; gap: 8px; }
.panel-actions.center { justify-content: center; margin-top: 18px; }
.primary-btn, .ghost-btn {
  appearance: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  padding: 10px 16px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.primary-btn {
  border: 1px solid rgba(255, 207, 74, 0.55);
  background: linear-gradient(180deg, #ffd45e, #e8a51e);
  color: #241a02;
  font-weight: 700;
}
.primary-btn:hover { filter: brightness(1.06); }
.primary-btn:active, .ghost-btn:active { transform: translateY(1px); }
.ghost-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: #cfd4dd;
}
.ghost-btn:hover { background: rgba(255, 255, 255, 0.09); }

.ending-panel { text-align: center; width: min(520px, 100%); }
.ending-panel h2 { margin: 8px 0 14px; }
.ending-panel p { color: #b8bec9; font-size: 14px; line-height: 1.7; margin: 6px 0; }
.ending-note { color: var(--muted) !important; font-size: 12px !important; margin-top: 12px !important; }

@media (hover: none), (pointer: coarse) {
  .overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    padding:
      max(12px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }
  .overlay .panel {
    touch-action: pan-y;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
}

/* ── 响应式 ── */
@media (max-width: 720px) {
  #hud { flex-wrap: wrap; gap: 8px; padding: 9px 11px; }
  .hud-left { flex: 1 1 auto; }
  .level-meta { display: none; }
  .hud-right { gap: 6px; }
  .hud-btn { padding: 7px 9px; font-size: 12px; }
  .hud-btn kbd { display: none; }
  .death { padding: 5px 8px; }
  .death #death-count { font-size: 15px; }
  #footer { font-size: 11px; }
  .controls-tip { display: none; }
  .caption { top: 6%; padding: 8px 12px; gap: 7px; }
  .cap-hint { display: none; }
  .level-grid { gap: 6px; }
  .level-btn { padding: 8px 3px; font-size: 12px; }
  .panel-foot { flex-direction: column; align-items: stretch; }
  .panel-actions { justify-content: flex-end; }
}

@media (orientation: portrait) and (max-width: 720px) {
  #stage { max-width: 100%; }
}
