:root {
  --bg: #fff8e9;
  --page-text: #685b4d;
  --page-muted: #776854;
  --panel: #202b46;
  --panel-2: #283452;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f9ecd7;
  --muted: #a5b0c9;
  --amber: #e4bf83;
  --amber-deep: #c19454;
  --red: #ed9170;
  --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 650px at 50% 0%, #fffdf7, transparent 75%),
    linear-gradient(180deg, #fff9ee 0%, #fff1d8 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

#app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding: clamp(8px, 1vh, 12px) clamp(10px, 1vw, 20px);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto auto;
  align-content: start;
  gap: 6px;
  --stage-width: 100%;
}

#hud, #footer, .player-bar {
  width: var(--stage-width);
  max-width: 100%;
  min-width: 0;
  justify-self: center;
}

/* ── HUD ── */
#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(43, 54, 83, 0.96), rgba(27, 35, 59, 0.96));
  box-shadow: 0 8px 24px rgba(119, 87, 47, 0.12);
  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(24px, calc(var(--stage-width) * 0.027), 42px);
  line-height: 1.1;
  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: clamp(13px, calc(var(--stage-width) * 0.014), 20px);
  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: clamp(18px, calc(var(--stage-width) * 0.017), 27px); font-weight: 700; line-height: 1.1; }
.death-label { color: var(--muted); font-size: clamp(11px, calc(var(--stage-width) * 0.009), 14px); 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: clamp(13px, calc(var(--stage-width) * 0.011), 17px);
  line-height: 1.25;
  padding: 8px 13px;
  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: flex-start;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

#stage {
  position: relative;
  width: var(--stage-width);
  max-width: 100%;
  flex: none;
  border-radius: 12px;
  overflow: hidden;
  background: #f9edda;
  border: 1px solid rgba(163, 132, 90, 0.36);
  box-shadow:
    0 14px 38px rgba(136, 99, 56, 0.16),
    0 0 0 1px rgba(255, 255, 255, 0.45) inset;
  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(--page-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: #ba8849;
  box-shadow: 0 0 8px rgba(186, 136, 73, 0.2);
  flex: none;
}
#hint { color: var(--page-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.controls-tip kbd {
  color: #76634f;
  border-color: #d4c1a5;
  background: #fff8eb;
}
.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: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    gap: 5px;
  }
  #hud { padding: 7px 10px; gap: 8px; }
  .level-meta { display: none; }
  .hud-btn kbd { display: none; }
  #stage-wrap { padding-inline: 88px; }
  .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) {
  #app { grid-template-rows: auto auto auto auto; align-content: start; }
  #stage-wrap { flex-direction: column; gap: 10px; padding-inline: 0; }
  .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) {
  #app { grid-template-rows: auto auto auto auto; align-content: start; }
}

/* 玩家、存档和排行榜独立于关卡画布 */
.hidden { display: none !important; }
.player-bar { display: flex; align-items: center; gap: 16px; color: var(--page-muted); font-size: 12px; padding: 0 4px; flex-wrap: wrap; }
.player-link { border: 0; background: transparent; color: #996328; cursor: pointer; padding: 4px 0; font: inherit; display: flex; align-items: center; gap: 10px; min-width: 0; }
#player-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-link-note { color: var(--page-muted); font-size: 11px; }
.challenge-hud { font-family: var(--mono); }
.save-status { margin-left: auto; color: #477153; }
.save-status.failed { color: #ae4932; }
.feature-overlay { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); background: rgba(4, 5, 7, 0.8); backdrop-filter: blur(10px); }
.feature-panel { width: min(740px, 100%); max-height: 100%; touch-action: pan-y; overscroll-behavior: contain; }
.feature-panel h3 { margin: 0 0 12px; font-size: 14px; }
.feature-note { font-size: 12px; color: var(--muted); line-height: 1.8; margin: 12px 0; }
.identity-card { display: flex; flex-direction: column; gap: 8px; padding: 16px; border: 1px solid rgba(255, 207, 74, 0.25); border-radius: 12px; background: rgba(255, 207, 74, 0.045); margin: 16px 0; overflow-wrap: anywhere; }
.identity-card strong { font-size: 18px; }
.identity-card code { font-family: var(--mono); font-size: 11px; color: var(--muted); user-select: all; }
.identity-card span { color: #b8bec9; font-size: 12px; }
.feature-section { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 18px; }
.inline-form { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.inline-form label { font-size: 12px; color: var(--muted); flex: none; }
.inline-form input, .ranking-toolbar select { min-width: 0; flex: 1; border: 1px solid var(--line-strong); border-radius: 9px; padding: 10px 12px; background: #0c0e12; color: var(--text); font: 13px var(--font); }
.inline-form button { flex: none; }
button:focus-visible, input:focus-visible, select:focus-visible, .file-label:focus-within { outline: 2px solid var(--amber); outline-offset: 3px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.profile-list { display: flex; flex-direction: column; gap: 8px; }
.profile-choice { display: flex; align-items: center; justify-content: space-between; text-align: left; gap: 12px; padding: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.025); border-radius: 10px; color: var(--text); cursor: pointer; font: 13px var(--font); }
.profile-choice.active { border-color: rgba(255, 207, 74, 0.4); }
.profile-choice span { min-width: 0; overflow-wrap: anywhere; }
.profile-choice small { display: block; color: var(--muted); font: 10px var(--mono); margin-top: 5px; }
.profile-choice em { flex: none; color: var(--amber); font-style: normal; font-size: 12px; }
.feature-message { color: var(--amber); font-size: 12px; line-height: 1.7; min-height: 20px; }
.feature-message.error { color: var(--red); }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.file-label { display: inline-flex; align-items: center; }
.import-preview { padding: 12px; margin-top: 12px; border-radius: 10px; border: 1px solid var(--line-strong); font-size: 12px; overflow-wrap: anywhere; }
.ranking-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 20px 0 16px; }
.ranking-toolbar > label { font-size: 12px; color: var(--muted); }
.ranking-toolbar select { flex: 1 1 190px; }
.ranking-tabs { display: flex; border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.ranking-tabs button { border: 0; background: transparent; border-radius: 7px; padding: 8px 12px; color: var(--muted); font: 12px var(--font); cursor: pointer; }
.ranking-tabs button.selected { background: rgba(255, 207, 74, 0.16); color: var(--amber); }
.ranking-sync { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; color: var(--muted); font-size: 12px; }
.ranking-sync .ghost-btn { flex-shrink: 0; }
.ranking-sync .failed { color: #efaf9b; }
.my-best { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.best-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.best-card span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 8px; }
.best-card strong { display: block; color: var(--amber); font: 18px var(--mono); }
.best-card small { display: block; font-size: 11px; color: var(--muted); margin-top: 7px; }
.table-wrap { overflow-x: auto; }
.ranking-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 13px; }
.ranking-table th { color: var(--muted); font-size: 11px; font-weight: 500; }
.ranking-table th, .ranking-table td { padding: 12px 10px; border-bottom: 1px solid var(--line); }
.ranking-table td:first-child, .ranking-table td:nth-child(n+3) { font-family: var(--mono); white-space: nowrap; }
.ranking-table td:nth-child(2) { max-width: 280px; overflow-wrap: anywhere; }
.ranking-table tr.me { background: rgba(255, 207, 74, 0.055); }
.ranking-table .me-tag { font-size: 10px; color: var(--amber); margin-left: 6px; white-space: nowrap; }
.empty-state { text-align: center; color: var(--muted); font-size: 13px; line-height: 1.8; padding: 28px 12px; border: 1px dashed var(--line-strong); border-radius: 10px; }
@media (max-width: 720px) {
  .player-bar { gap: 8px 12px; font-size: 11px; }
  .save-status { margin-left: auto; }
  .inline-form { flex-wrap: wrap; }
  .inline-form input { flex: 1 1 160px; }
  .my-best { grid-template-columns: 1fr; }
  .feature-section .panel-actions { flex-wrap: wrap; justify-content: flex-start; }
  .ranking-table th, .ranking-table td { padding: 10px 6px; }
}

/* Mobile has its own two-row shell; HUD width never follows canvas width. */
.mobile-only { display: none; }
.touch-btn svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.touch-btn.jump svg { display: block; margin: 0 auto 3px; }
.touch-btn.jump span { font-size: 12px; }
html.touch-device { --touch-size: 64px; overflow: hidden; }
html.touch-device body { overflow: hidden; overscroll-behavior: none; }
html.touch-device #app {
  height: 100vh; height: 100dvh;
  padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  grid-template-rows: 44px minmax(0, 1fr);
  gap: 6px;
  align-content: stretch;
}
html.touch-device #hud {
  width: 100%; min-width: 0; height: 44px;
  flex-wrap: nowrap; padding: 4px 10px; gap: 8px;
  border-radius: 11px; backdrop-filter: none;
  box-shadow: 0 3px 12px rgba(119, 87, 47, .1);
}
html.touch-device .hud-left { flex: 0 1 auto; }
html.touch-device .level-id { font-size: 20px; letter-spacing: .02em; }
html.touch-device .level-meta,
html.touch-device #btn-menu,
html.touch-device #btn-ranking,
html.touch-device #btn-mute,
html.touch-device .hud-btn kbd,
html.touch-device #footer,
html.touch-device .player-bar { display: none; }
html.touch-device .hud-right { gap: 6px; min-width: 0; }
html.touch-device .hud-btn { min-width: 44px; height: 36px; padding: 6px 10px; font-size: 13px; }
html.touch-device .mobile-only { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
html.touch-device #btn-fullscreen { font-size: 23px; line-height: 1; padding: 0 8px; }
html.touch-device #btn-mobile-menu { color: var(--amber); border-color: rgba(228,191,131,.35); }
html.touch-device .death { padding: 5px 8px; gap: 4px; }
html.touch-device .death #death-count { font-size: 16px; }
html.touch-device .death-label { font-size: 10px; }
html.touch-device .badge { font-size: 10px; padding: 5px 7px; }
html.touch-device .save-warning { color: var(--red); font-size: 11px; white-space: nowrap; }
html.touch-device #stage-wrap {
  width: 100%; height: 100%; min-height: 0;
  flex-direction: row; align-items: center; justify-content: center;
  padding: 0 calc(var(--touch-size) + 22px) 0 calc(var(--touch-size) * 2 + 26px);
  gap: 0;
}
html.touch-device #stage { max-height: 100%; border-radius: 9px; box-shadow: 0 5px 20px rgba(136,99,56,.12); }
html.touch-device #touch {
  display: flex; position: absolute; inset: 0; width: 100%; min-height: 0;
  padding: 0 6px 12px; align-items: flex-end; justify-content: space-between;
}
html.touch-device .touch-pad { flex-direction: row; gap: 10px; }
html.touch-device .touch-btn {
  display: flex; align-items: center; justify-content: center;
  width: var(--touch-size); height: var(--touch-size);
  border-radius: 20px; border: 1px solid #526079;
  background: linear-gradient(180deg, #394866, #283650);
  color: #ffefd8; box-shadow: 0 4px 0 #202b40, 0 7px 15px rgba(42,47,60,.17);
  backdrop-filter: none; -webkit-backdrop-filter: none;
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
  touch-action: none; padding: 0;
}
html.touch-device .touch-btn.jump {
  display: block; width: calc(var(--touch-size) + 12px); height: calc(var(--touch-size) + 12px);
  border-radius: 50%; background: linear-gradient(180deg, #f0d4a3, #ddb575);
  border-color: #c59a5c; color: #4a371f;
  box-shadow: 0 4px 0 #b28a52, 0 7px 15px rgba(136,99,56,.17);
}
html.touch-device .touch-btn.active,
html.touch-device .touch-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #202b40; filter: brightness(1.12); }
html.touch-device .caption { top: 9%; padding: 7px 12px; border-radius: 10px; backdrop-filter: none; }
html.touch-device .cap-door { font-size: 12px; }
html.touch-device .cap-name:empty, html.touch-device .cap-hint { display: none; }
html.touch-device .overlay, html.touch-device .feature-overlay { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(23,31,49,.82); }
html.touch-device .panel { background: linear-gradient(160deg, #293750, #1c2940); border-color: rgba(228,191,131,.3); box-shadow: 0 14px 44px rgba(17,25,40,.3); }
html.touch-device .panel-head { position: sticky; top: -1px; z-index: 1; background: #293750; padding: 4px 0 10px; margin-bottom: 8px; }
html.touch-device .panel h2 { font-size: 21px; }
html.touch-device .icon-btn { width: 44px; height: 44px; flex: none; }
html.touch-device .level-btn { min-height: 44px; }
html.touch-device .primary-btn { background: linear-gradient(180deg, #eed0a0, #dcb474); border-color: #dcb474; color: #30281e; }
html.touch-device .primary-btn, html.touch-device .ghost-btn { min-height: 44px; }
html.touch-device .inline-form input, html.touch-device .ranking-toolbar select { font-size: 16px; }
html.touch-device .feature-panel { padding: 14px 18px; }
html.touch-device .ranking-toolbar { gap: 8px; margin: 12px 0; }
html.touch-device .ranking-toolbar select { flex-basis: 120px; }
html.touch-device .ranking-tabs button { min-height: 40px; }
html.touch-device .feature-overlay, html.touch-device .overlay { padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
.mobile-pause-panel { width: min(640px, 100%); }
.mobile-menu-body { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.mobile-session { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; padding: 8px 0; }
.mobile-session strong { color: var(--amber); font: 22px var(--mono); }
.mobile-session p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.mobile-session #mobile-save { color: #b5d0ab; }
.mobile-session #mobile-save.failed { color: var(--red); }
.mobile-session .primary-btn { width: 100%; margin-top: auto; display: flex; justify-content: space-between; gap: 16px; }
.mobile-menu-actions { display: flex; flex-direction: column; gap: 7px; }
.mobile-menu-actions .ghost-btn { display: flex; align-items: center; justify-content: space-between; text-align: left; padding: 9px 12px; }
.mobile-menu-actions .ghost-btn span { color: var(--amber); }
.touch-size-label { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; padding: 7px 1px 0; }
#touch-size { width: 100%; margin: 0; min-height: 34px; accent-color: var(--amber); touch-action: pan-x; }
.rotate-screen { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at top, #fffdf8, #faecd3); padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom)); text-align: center; color: #273452; }
.rotate-card { max-width: 340px; }
.rotate-brand { font-size: 23px; font-weight: 750; letter-spacing: .08em; }
.rotate-brand span { display: block; margin-top: 7px; font-size: 12px; font-weight: 400; letter-spacing: .2em; color: #8c755a; }
.rotate-icon { width: 130px; height: 110px; margin: 35px 0 10px; fill: none; stroke: #b48a4e; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.rotate-card h2 { font-size: 26px; margin: 5px 0 12px; }
.rotate-card p { color: #78664e; font-size: 14px; line-height: 1.8; }
.rotate-card .primary-btn { padding: 13px 36px; min-height: 48px; margin: 14px 0; }
.rotate-card .rotate-help { font-size: 12px; max-width: 260px; margin: 12px auto 0; }
html.mobile-portrait #app { visibility: hidden; }
.mobile-notice { position: fixed; z-index: 80; bottom: max(14px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: max-content; max-width: min(90%, 520px); background: #283650; color: #f9ecd7; padding: 12px 18px; border: 1px solid rgba(228,191,131,.35); border-radius: 12px; font-size: 13px; line-height: 1.6; box-shadow: 0 6px 20px rgba(25,34,49,.2); }
@media (max-width: 600px) {
  html.touch-device .mobile-menu-label { display: none; }
  .mobile-menu-body { gap: 12px; }
}
@media (orientation: portrait) {
  .mobile-menu-body { grid-template-columns: 1fr; }
}

/* Mobile landscape HUD: full-viewport playfield with safe-area overlays. */
.mobile-action-icon { display: none; }
html.touch-device,
html.touch-device body {
  width: 100%;
  height: 100%;
  background: #111829;
}
html.touch-device #app {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding: 0;
  display: block;
  overflow: hidden;
}
html.touch-device #stage-wrap {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding: 0;
  display: block;
  overflow: hidden;
}
html.touch-device #stage {
  width: 100vw;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #111829;
}
html.touch-device #game {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  object-fit: contain;
  background: #182238;
}
html.touch-device #hud {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 15;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding: 0;
  display: block;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
}
html.touch-device #hud .hud-left {
  position: fixed;
  inset: 0 auto auto 0;
  display: block;
  pointer-events: none;
}
html.touch-device #hud .hud-left .level-id,
html.touch-device #hud .hud-left .level-meta,
html.touch-device #hud .death { display: none; }
html.touch-device .mobile-status {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  min-height: 40px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  background: rgba(14, 21, 34, 0.46);
  color: rgba(255, 255, 255, 0.76);
  font-size: 11px;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  pointer-events: none;
}
html.touch-device .mobile-status strong {
  margin-left: 4px;
  color: #fff2d2;
  font: 700 16px/1 var(--mono);
}
html.touch-device .mobile-status-deaths strong { color: #ffb09b; }
html.touch-device .mobile-status-divider {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.18);
}
html.touch-device #mobile-save-warning {
  position: fixed;
  top: calc(max(10px, env(safe-area-inset-top)) + 46px);
  left: max(12px, env(safe-area-inset-left));
  padding: 5px 8px;
  border-radius: 5px;
  background: rgba(94, 28, 25, 0.56);
}
html.touch-device .hud-right {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
html.touch-device .hud-right > * { pointer-events: auto; }
html.touch-device #btn-restart,
html.touch-device #btn-fullscreen,
html.touch-device #btn-mobile-menu {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: rgba(14, 21, 34, 0.44);
  color: rgba(255, 255, 255, 0.88);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.16);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}
html.touch-device #btn-restart:active,
html.touch-device #btn-fullscreen:active,
html.touch-device #btn-mobile-menu:active {
  transform: scale(0.93);
  background: rgba(228, 191, 131, 0.62);
  color: #fff8e9;
}
html.touch-device .desktop-action-label { display: none; }
html.touch-device .mobile-action-icon {
  display: block;
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
html.touch-device .badge.show {
  position: fixed;
  top: calc(max(10px, env(safe-area-inset-top)) + 48px);
  right: max(12px, env(safe-area-inset-right));
  display: inline-block;
  border-radius: 6px;
  background: rgba(103, 70, 16, 0.5);
}
html.touch-device #touch {
  position: fixed;
  inset: 0;
  z-index: 12;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  padding:
    0
    calc(max(18px, env(safe-area-inset-right)) + 2px)
    calc(max(18px, env(safe-area-inset-bottom)) + 2px)
    calc(max(18px, env(safe-area-inset-left)) + 2px);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  pointer-events: none;
}
html.touch-device .touch-pad {
  display: flex;
  flex-direction: row;
  gap: 12px;
  pointer-events: auto;
}
html.touch-device .touch-btn,
html.touch-device .touch-btn.jump {
  width: var(--touch-size);
  height: var(--touch-size);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 50%;
  background: rgba(14, 21, 34, 0.43);
  color: rgba(255, 255, 255, 0.9);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  transition: transform 0.08s ease, background 0.08s ease, border-color 0.08s ease, filter 0.08s ease;
  will-change: transform;
}
html.touch-device .touch-btn.jump {
  width: calc(var(--touch-size) + 10px);
  height: calc(var(--touch-size) + 10px);
  border-color: rgba(255, 220, 155, 0.34);
  background: rgba(74, 53, 29, 0.44);
  color: #fff0cb;
}
html.touch-device .touch-btn.jump svg { margin: 0; }
html.touch-device .touch-btn.jump span { display: none; }
html.touch-device .touch-btn.active,
html.touch-device .touch-btn:active {
  transform: scale(0.93);
  border-color: rgba(255, 235, 194, 0.72);
  background: rgba(228, 191, 131, 0.64);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  filter: brightness(1.12);
}
html.touch-device .caption {
  top: calc(max(10px, env(safe-area-inset-top)) + 56px);
  z-index: 14;
  padding: 7px 12px;
  border-radius: 6px;
  background: rgba(14, 21, 34, 0.56);
  transition: opacity 0.24s ease, transform 0.24s ease;
}

@media (hover: none) and (orientation: portrait), (pointer: coarse) and (orientation: portrait) {
  html.touch-device #stage-wrap { display: block; padding: 0; }
  html.touch-device #touch { position: fixed; min-height: 0; }
}

/* V2 game navigation and stage */
body { background: #111e34; }
#v2-shell { position: fixed; inset: 0; z-index: 30; overflow: auto; color: #fff4d9;
  background: linear-gradient(90deg,rgba(13,28,50,.89),rgba(20,37,64,.12)),url('../assets/cloud-clocktower-background-v2.jpg') center/cover; }
#v2-shell[hidden] { display: none; }
.v2-nav { display:flex; align-items:center; justify-content:space-between; padding: max(20px,env(safe-area-inset-top)) max(24px,env(safe-area-inset-right)); }
#v2-shell button { cursor:pointer; color:inherit; border:1px solid #e6c48d66; background:#162942c9; border-radius:14px; padding:15px 24px; font:600 16px system-ui; min-height:48px; }
#v2-shell button:focus-visible { outline:3px solid #ffdf9b; outline-offset:4px; }
#v2-shell button:disabled { opacity:.45; cursor:default; }
#v2-content { margin: min(9vh,90px) auto 40px; width:min(100% - 48px,1080px); }
#v2-content h1 { margin:0 0 24px; font:900 clamp(34px,6vw,80px)/1.1 system-ui; letter-spacing:.05em; text-shadow:0 4px 0 #26344b; }
#v2-content > button { display:block; margin:14px 0; min-width:260px; }
#v2-content .v2-primary { background:#efd09a; color:#18243b; border:0; box-shadow:0 5px 0 #957049; }
.v2-subtitle { font-size:22px; letter-spacing:.3em; margin:0 0 40px; }
#v2-content .v2-chapter { display:inline-flex; align-items:end; width:30%; min-width:230px; min-height:210px; margin-right:2%; background:linear-gradient(0deg,#14243f,transparent),url('../assets/cloud-clocktower-background-v2.jpg') center/cover; text-align:left; }
.chapter-2 { background-position:70% center !important; }
.chapter-3 { background-position:right center !important; }
.v2-door { display:inline-block; vertical-align:top; padding:16px; margin:8px; border:1px solid #dcb67c66; border-radius:18px; background:#13243ed9; }
.v2-door h2 { font-size:16px; margin:0 0 14px; }
.v2-door button { margin:3px; padding:12px !important; }
#v2-content label { display:block; padding:20px 0; }
#v2-content input { display:block; width:260px; margin-top:20px; }
body:not([data-screen="playing"]) #app { visibility:hidden; }
.feature-overlay { z-index:60; }
#footer, .player-bar, #btn-menu, #btn-ranking, #btn-mute { display:none !important; }
#app { grid-template-rows:auto 1fr; }
#btn-mobile-menu { display:inline-flex !important; }
@media (max-width:600px) {
 #v2-content { margin-top:8vh; }
 #v2-content > button { width:100%; }
 #v2-content .v2-chapter { width:100%; min-height:140px; }
 .v2-nav { padding:16px; }
 .v2-subtitle { font-size:17px; }
}
@media (max-height:480px) {
 #v2-content { margin-top:10px; }
 #v2-content h1 { font-size:38px; margin-bottom:12px; }
 .v2-subtitle { margin-bottom:18px; font-size:16px; }
 #v2-content > button { margin:9px 0; padding:11px 22px; }
 #v2-content .v2-chapter { min-height:150px; margin-right:2%; }
 .v2-nav { padding:10px 24px; }
}

#btn-mobile-menu::after { content:'暂停'; }
html.touch-device #btn-mobile-menu::after { content:none; }
#btn-camera { display:none; }
html.touch-device #btn-camera { display:block; }

.v2-chapter { flex-direction:column; justify-content:flex-end; align-items:flex-start !important; vertical-align:top; gap:8px; }
.v2-chapter span { font-size:13px; color:#f5dfb7; }
#hud .level-meta { display:none; }

body[data-screen=home] .v2-nav > span { visibility:hidden; }
.v2-controls { font-size:13px; color:#f4dfbc; margin:20px 0; }


/* V2 polish: compact game-first navigation, safe touch zones, and scene-backed pause. */
#v2-shell { background:linear-gradient(90deg,rgba(12,22,42,.95) 0%,rgba(15,27,47,.73) 40%,rgba(20,37,64,.08) 100%),url('../assets/cloud-clocktower-background-v2.jpg') 65% center/cover; }
.v2-nav { display:grid; grid-template-columns:1fr auto 1fr; gap:12px; padding: max(16px,env(safe-area-inset-top)) max(20px,env(safe-area-inset-right)) 8px max(20px,env(safe-area-inset-left)); }
#v2-back { grid-column:1; justify-self:start; }
.v2-nav > span { grid-column:2; justify-self:center; font-weight:700; letter-spacing:.1em; }
#v2-settings { grid-column:3; justify-self:end; }
#v2-shell button[hidden] { display:none!important; }
#v2-shell button { border-radius:9px; transition:background .15s,transform .1s; }
#v2-shell button:not(:disabled):active { transform:translateY(2px); }
#v2-shell button:disabled { opacity:.58; }
#v2-content { width:min(calc(100% - 48px),1080px); }
#v2-content h1 { color:#fff0cd; font-size:clamp(34px,5.5vw,70px); letter-spacing:.025em; }
body[data-screen=home] #v2-content { margin:clamp(12px,7vh,76px) auto 24px; }
body[data-screen=home] #v2-content h1 { font-size:clamp(52px,8vw,104px); line-height:1; margin:0 0 12px; text-shadow:0 4px #9a714a,0 8px 32px #08162d; letter-spacing:.04em; }
.v2-kicker { font-size:11px; font-weight:700; color:#e8c58d; letter-spacing:.24em; margin:0 0 14px; }
.v2-subtitle { font-size:clamp(16px,2.2vw,23px); letter-spacing:.21em; margin:0 0 14px; }
.v2-tagline { margin:0 0 28px; color:#efe2ca; font-size:16px; }
#v2-content .v2-start { min-width:280px; width:min(100%,340px); min-height:58px; border:1px solid #fff0c5; background:linear-gradient(180deg,#ffe4aa,#d5a05c); color:#20283c; border-radius:10px; box-shadow:0 4px 0 #946235,0 10px 28px #0b162d88; font-size:22px; letter-spacing:.06em; margin-bottom:8px; }
.v2-play-detail { color:#e9d8b9; font-size:13px; margin:10px 0 18px; }
.v2-secondary { display:flex; flex-wrap:wrap; gap:10px; width:min(100%,340px); }
#v2-shell .v2-secondary button { flex:1; min-width:0; padding:11px 14px; }
.v2-controls { color:#c8cbd1; margin:18px 0 0; font-size:12px; }
.v2-section-detail { margin:-8px 0 22px; color:#e7cfa7; font-size:14px; }
.v2-chapter-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:16px; }
#v2-content .v2-chapter { width:100%; min-width:0; min-height:clamp(160px,31vh,280px); margin:0; padding:20px; border:1px solid #e9c18c88; border-radius:13px; box-shadow:0 12px 30px #09132277; overflow:hidden; }
#v2-content .v2-chapter.chapter-1 { background-position:65% center; }
#v2-content .v2-chapter.chapter-2 { background-image:linear-gradient(0deg,#182638 5%,#1d384a44 100%),url('../assets/cloud-clocktower-background-v2.jpg'); background-position:20% center!important; }
#v2-content .v2-chapter.chapter-3 { background-image:linear-gradient(0deg,#1d213b 5%,#54446555 100%),url('../assets/cloud-clocktower-background-v2.jpg'); background-position:90% center!important; }
.v2-chapter strong { font-size:clamp(18px,2.4vw,26px); }
.v2-chapter .v2-chapter-index { font-size:12px; letter-spacing:.1em; }
.v2-progress-track { display:block; width:100%; height:5px; border-radius:5px; background:#ffffff25; overflow:hidden; }
.v2-progress-track > span { display:block; height:100%; background:#edc47c; border-radius:5px; }
.v2-door-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(235px,1fr)); gap:12px; }
.v2-door { display:block; margin:0; padding:14px; border-radius:10px; background:#172640e8; }
.v2-door h2 { color:#e7cca0; font-size:14px; margin:0 0 10px; }
.v2-stages { display:grid; grid-template-columns:repeat(5,minmax(0,1fr)); gap:5px; }
#v2-shell .v2-stages button { min-width:0; min-height:44px; padding:6px 2px!important; margin:0; font-size:14px; border-radius:7px; }
#v2-shell .v2-stages .is-completed { color:#b7e0c7; border-color:#86c6a47a; }
#v2-shell .v2-stages .is-current { color:#20283c; background:#edc58b; border-color:#fff0cb; }
#v2-shell .v2-stages button:disabled { color:#aeb9ce; opacity:.42; background:#111b2d; border-color:#6d7b943b; }
body[data-screen=pause] #app,body[data-screen=victory] #app { visibility:visible; }
body[data-screen=pause] #v2-shell,body[data-screen=victory] #v2-shell { background:linear-gradient(90deg,#0e1b31ed,#14233baa); }
body[data-screen=pause] #hud,body[data-screen=victory] #hud,body[data-screen=pause] #touch,body[data-screen=victory] #touch,body[data-screen=pause] #caption,body[data-screen=victory] #caption { visibility:hidden; }
body[data-screen=pause] #v2-content,body[data-screen=victory] #v2-content { margin:clamp(10px,3vh,40px) auto 20px; }
html.touch-device #btn-camera:not(.hidden) { min-width:52px; min-height:44px; border:1px solid #ffffff36; background:#152239b3; border-radius:22px; color:#fff0d2; }
html.touch-device .touch-pad { gap:8px; }
html.touch-device .touch-btn,html.touch-device .touch-btn.jump { touch-action:none; -webkit-tap-highlight-color:transparent; }
@media (orientation:portrait) and (max-width:700px) {
  #v2-shell { background:linear-gradient(0deg,#101d34 4%,#14233ba6 46%,#14233b1a 100%),url('../assets/cloud-clocktower-background-v2.jpg') 73% top/cover; }
  body[data-screen=home] #v2-content { margin:clamp(32px,25vh,240px) auto 24px; }
  body[data-screen=home] #v2-content h1 { font-size:clamp(45px,13vw,76px); }
  .v2-chapter-grid { grid-template-columns:1fr; gap:10px; }
  #v2-content .v2-chapter { min-height:128px; padding:14px; }
  .v2-door-grid { grid-template-columns:1fr; }
}
@media (orientation:landscape) and (max-height:480px) {
  .v2-nav { padding-top:max(6px,env(safe-area-inset-top)); padding-bottom:2px; }
  #v2-shell .v2-nav button { min-height:40px; padding:6px 14px; font-size:14px; }
  #v2-content,body[data-screen=home] #v2-content { margin-top:8px; margin-bottom:12px; }
  body[data-screen=home] #v2-content h1 { font-size:clamp(32px,13vh,55px); margin-bottom:6px; }
  #v2-content h1 { font-size:30px; margin-bottom:10px; }
  .v2-kicker { margin-bottom:5px; font-size:9px; }
  .v2-subtitle { margin-bottom:5px; font-size:14px; }
  .v2-tagline { margin-bottom:10px; font-size:13px; }
  #v2-content .v2-start { min-height:46px; font-size:18px; padding:9px 16px; margin-top:6px; }
  .v2-play-detail { margin:7px 0 9px; font-size:12px; }
  #v2-shell .v2-secondary button { min-height:40px; padding:6px 12px; font-size:14px; }
  .v2-controls { margin:9px 0 0; font-size:11px; }
  .v2-section-detail { margin:0 0 12px; }
  #v2-content .v2-chapter { min-height:155px; padding:12px; }
}
@media (orientation:landscape) and (max-height:300px) {
  .v2-kicker,.v2-tagline,.v2-controls { display:none; }
  #v2-content .v2-start { min-height:42px; }
  html.touch-device #touch { padding-bottom:max(8px,env(safe-area-inset-bottom)); }
  html.touch-device .touch-btn { width:min(var(--touch-size),58px); height:min(var(--touch-size),58px); }
  html.touch-device .touch-btn.jump { width:min(calc(var(--touch-size) + 10px),68px); height:min(calc(var(--touch-size) + 10px),68px); }
}


/* V2.3: desktop game composition, not a stretched mobile/web dashboard. */
@media (min-width: 721px) and (pointer: fine) {
  html:not(.touch-device) body { background:radial-gradient(ellipse at 50% 38%,#283953 0%,#111c30 62%,#0e1727 100%); }
  html:not(.touch-device) #app { padding:10px 18px; gap:6px; grid-template-rows:auto minmax(0,1fr); align-content:stretch; }
  html:not(.touch-device) #stage-wrap { align-items:center; justify-content:center; }
  html:not(.touch-device) #stage { border:0; border-radius:6px; background:#182238; box-shadow:0 12px 40px #080f1c66; }
  html:not(.touch-device) #game { aspect-ratio:16/9; width:100%; height:auto; }
  html:not(.touch-device) #hud { min-height:42px; padding:3px 8px; border:0; border-radius:0; background:transparent; box-shadow:none; backdrop-filter:none; }
  html:not(.touch-device) .level-id { font-size:22px; letter-spacing:.05em; color:#f7dfaf; }
  html:not(.touch-device) #hud .level-meta { display:flex; font-size:13px; }
  html:not(.touch-device) .hud-left { align-items:center; gap:12px; }
  html:not(.touch-device) .hud-btn { padding:7px 12px; font-size:13px; min-height:34px; border-radius:6px; }
  html:not(.touch-device) .death { padding:5px 9px; border-color:transparent; background:none; }
  html:not(.touch-device) .death #death-count { font-size:17px; }
  html:not(.touch-device) .death-label { font-size:11px; }
  html:not(.touch-device) .caption { top:4%; }
  html:not(.touch-device) body[data-screen=home] #v2-shell { background:linear-gradient(90deg,#111d35f5 0%,#142742bd 28%,#14274233 57%,#14274200 85%),url('../assets/cloud-clocktower-background-v2.jpg') 70% center/cover; }
  html:not(.touch-device) body[data-screen=home] #v2-content { width:min(calc(100% - 100px),1160px); margin:0 auto; min-height:calc(100dvh - 90px); display:flex; flex-direction:column; align-items:flex-start; justify-content:center; padding:12px 0 60px; }
  html:not(.touch-device) body[data-screen=home] #v2-content h1 { font-size:clamp(54px,7vw,106px); color:#fff0cc; line-height:1.04; letter-spacing:.015em; text-shadow:0 3px #977049,0 8px 32px #101b34; }
  html:not(.touch-device) body[data-screen=home] .v2-subtitle { font-size:clamp(16px,1.7vw,24px); letter-spacing:.12em; color:#e7c68d; margin:0 0 12px; }
  html:not(.touch-device) body[data-screen=home] .v2-tagline { font-size:16px; color:#d8d4cb; margin-bottom:28px; }
  html:not(.touch-device) #v2-content .v2-start { width:300px; min-height:60px; margin-top:0; }
  html:not(.touch-device) .v2-secondary { width:300px; }
  html:not(.touch-device) body[data-screen=pause] #v2-content,html:not(.touch-device) body[data-screen=victory] #v2-content { width:min(100% - 60px,420px); margin:clamp(28px,8vh,90px) auto; text-align:center; padding:24px; border:1px solid #e3c39055; background:#142139e8; border-radius:14px; }
  html:not(.touch-device) body[data-screen=pause] #v2-content > button,html:not(.touch-device) body[data-screen=victory] #v2-content > button { width:100%; min-width:0; }
}
.caption .cap-name:empty,.caption .cap-hint:empty { display:none; }
.caption { pointer-events:none; }
@media(prefers-reduced-motion:reduce) { .caption { transition:none; } }
