/* =========================================================================
   台北夜市大冒險 — UI / HUD / 畫面版面
   規則：深藍夜色 + 暖橘與霓虹粉；像素遊戲感；無框架、無外部字型。
   ========================================================================= */

:root {
  --bg-deep: #030814;
  --bg-navy: #071226;
  --panel: #0a1730;
  --panel-2: #0f2342;
  --panel-line: #2b4066;
  --line-soft: rgba(74, 95, 134, 0.35);
  --ink: #f8e8c8;
  --ink-dim: #a8b8d4;
  --ink-faint: #7488a8;
  --orange: #ff9f45;
  --orange-hi: #ffc46b;
  --orange-deep: #d96a1f;
  --pink: #ff4f9a;
  --pink-hi: #ff8fbe;
  --gold: #ffd36b;
  --shadow: #020610;
  --font-ui: "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

/* -------------------------------------------------------------------------
   0. Reset / page
   ------------------------------------------------------------------------- */

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #030814;
}

body {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

/* 舞台外的夜色氛圍（不影響遊戲畫面） */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(55% 45% at 50% 0%, rgba(255, 122, 60, 0.08), transparent 70%),
    radial-gradient(40% 40% at 8% 100%, rgba(255, 79, 154, 0.07), transparent 70%),
    radial-gradient(40% 40% at 92% 100%, rgba(88, 180, 255, 0.05), transparent 70%),
    #030814;
}

.hidden {
  display: none !important;
}

/* -------------------------------------------------------------------------
   1. Game shell / canvas
   ------------------------------------------------------------------------- */

#game-shell {
  position: relative;
  z-index: 1;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  aspect-ratio: 16 / 9;
  max-width: 100vw;
  max-height: 100vh;
  overflow: hidden;
  background: #000;
  box-shadow:
    0 0 0 1px rgba(255, 160, 80, 0.16),
    0 24px 90px rgba(0, 0, 0, 0.72);
}

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  image-rendering: pixelated;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* -------------------------------------------------------------------------
   2. HUD
   ------------------------------------------------------------------------- */

#hud {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding:
    calc(10px + env(safe-area-inset-top, 0px))
    calc(12px + env(safe-area-inset-right, 0px))
    calc(10px + env(safe-area-inset-bottom, 0px))
    calc(12px + env(safe-area-inset-left, 0px));
  pointer-events: none;
  container-type: inline-size;
}

.hud-cluster {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.hud-left {
  flex-direction: column;
  align-items: flex-start;
}

.hud-right {
  flex-direction: row;
  align-items: center;
}

/* Hearts -------------------------------------------------------------- */

#hud-hearts {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  filter: drop-shadow(0 2px 0 rgba(2, 6, 16, 0.65));
}

.heart {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  background-image: url("assets/game/items/heart.png");
  background-repeat: no-repeat;
  background-size: 96px 24px;
  background-position: 0 0;
  image-rendering: pixelated;
  transition: opacity 0.15s linear, filter 0.15s linear;
}

.heart.empty {
  opacity: 0.25;
  filter: grayscale(1);
}

/* Coins --------------------------------------------------------------- */

#hud-coins {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 4px 10px 4px 8px;
  background: rgba(5, 12, 26, 0.84);
  border: 2px solid #35496c;
  box-shadow: 3px 3px 0 var(--shadow);
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: clamp(13px, 1.5cqw, 16px);
  font-weight: 700;
  letter-spacing: 0.05em;
}

#hud-coin-count {
  min-width: 2ch;
  text-align: right;
}

.coin-icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  background-image: url("assets/game/items/coin.png");
  background-repeat: no-repeat;
  background-size: 64px 16px;
  background-position: 0 0;
  image-rendering: pixelated;
}

/* Power (form) meter -------------------------------------------------- */

#hud-form {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  background: rgba(4, 10, 24, 0.82);
  border: 2px solid #445b80;
  box-shadow: 3px 3px 0 var(--shadow);
}

#hud-form-icon {
  display: grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 3px;
  background: #0a1a31;
  border: 1px solid #334a70;
  color: #ffe0a8;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  image-rendering: pixelated;
}

#hud-form-icon img {
  display: block;
  width: 16px;
  height: 16px;
  image-rendering: pixelated;
}

.bar {
  width: 100%;
  height: 10px;
  background: #040b19;
  border: 2px solid #33486d;
  overflow: hidden;
}

.bar-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #ff7a3c, #ffb84d);
}

#hud-form-bar {
  width: 120px;
  height: 8px;
  border-width: 1px;
  border-color: #2e4568;
}

#hud-form-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #ff7a3c, #ffd06b);
  transition: width 0.1s linear;
}

/* Shield charm -------------------------------------------------------- */

#hud-shield {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  background: rgba(38, 24, 6, 0.82);
  border: 2px solid #a8762a;
  box-shadow: 3px 3px 0 var(--shadow), 0 0 14px rgba(255, 190, 80, 0.18);
  color: #ffe9a8;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.shield-icon {
  width: 12px;
  height: 14px;
  flex: 0 0 auto;
  background: linear-gradient(180deg, #ffd36b, #e8a63a);
  clip-path: polygon(50% 0%, 100% 16%, 88% 70%, 50% 100%, 12% 70%, 0% 16%);
  box-shadow: 0 0 8px rgba(255, 190, 80, 0.5);
}

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

.hud-btn {
  appearance: none;
  -webkit-appearance: none;
  pointer-events: auto;
  flex: 0 0 auto;
  width: 44px;
  width: clamp(44px, 3.2cqw, 52px);
  height: 44px;
  height: clamp(44px, 3.2cqw, 52px);
  display: grid;
  place-items: center;
  padding: 0;
  background: #0c1c36;
  border: 2px solid #3c5278;
  box-shadow: 3px 3px 0 var(--shadow);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.06s ease, box-shadow 0.06s ease;
}

.hud-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--shadow);
  background: #18345a;
  border-color: var(--orange);
}

.hud-btn:focus-visible {
  outline: 3px solid var(--pink-hi);
  outline-offset: 2px;
}

/* Backpack button + item-count badge -------------------------------- */

#hud-backpack {
  position: relative;
  border-color: #5a4160;
}

.bag-icon {
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
}

#hud-bag-count {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--pink);
  border: 1px solid #340d20;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
  color: #1b0611;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
}

/* -------------------------------------------------------------------------
   3. Hint
   ------------------------------------------------------------------------- */

#hint {
  position: absolute;
  z-index: 55;
  top: calc(74px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(72%, 560px);
  padding: 7px 14px;
  background: rgba(3, 9, 22, 0.84);
  border: 1px solid rgba(255, 191, 120, 0.45);
  border-left: 3px solid var(--orange);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.4);
  color: #ffeccc;
  font-size: clamp(11px, 2.2vh, 14px);
  letter-spacing: 0.04em;
  line-height: 1.45;
  text-align: center;
  pointer-events: none;
  animation: hint-in 0.22s ease-out;
}

/* -------------------------------------------------------------------------
   3b. Interaction prompt (vending machine / world actions)
   ------------------------------------------------------------------------- */

#interact-prompt {
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  z-index: 35;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  max-width: min(52%, 360px);
  min-height: 40px;
  padding: 7px 16px;
  background: linear-gradient(180deg, #ffb84d, #ff8f2f);
  border: 2px solid #2a1706;
  box-shadow:
    3px 3px 0 var(--shadow),
    0 0 18px rgba(255, 150, 60, 0.18);
  color: #081428;
  font-family: var(--font-ui);
  font-size: clamp(12px, 1.7vh, 15px);
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.3;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  animation: interact-in 0.18s ease-out;
  transition: background-color 0.12s ease, transform 0.06s ease, box-shadow 0.06s ease;
}

#interact-prompt:active {
  transform: translate(-50%, 2px);
  box-shadow: 1px 1px 0 var(--shadow);
}

#interact-prompt:focus-visible {
  outline: 3px solid var(--pink-hi);
  outline-offset: 3px;
}

.interact-key {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  background: #081428;
  border: 1px solid #2a1706;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}

body.touch #interact-prompt {
  bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  max-width: min(34%, 280px);
}

body.touch .interact-key {
  display: none;
}

/* -------------------------------------------------------------------------
   4. Touch controls
   ------------------------------------------------------------------------- */

#touch-controls {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: none;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 12px;
  padding:
    0
    calc(14px + env(safe-area-inset-right, 0px))
    calc(14px + env(safe-area-inset-bottom, 0px))
    calc(14px + env(safe-area-inset-left, 0px));
  pointer-events: none;
  container-type: inline-size;
}

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

/* input.js 判定為觸控裝置後，按鈕一律至少 52px，即使媒體查詢沒命中 */
body.touch .btn {
  min-height: 52px;
  font-size: 16px;
}

body.touch .hud-btn {
  width: 52px;
  height: 52px;
}

body.touch .touch-btn {
  width: clamp(72px, 9.6cqw, 88px);
  height: clamp(72px, 9.6cqw, 88px);
  font-size: 28px;
}

#touch-jump {
  margin-left: auto;
}

.touch-btn {
  appearance: none;
  -webkit-appearance: none;
  pointer-events: auto;
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  width: clamp(64px, 9.6cqw, 88px);
  height: clamp(64px, 9.6cqw, 88px);
  display: grid;
  place-items: center;
  padding: 0;
  background: rgba(8, 20, 40, 0.58);
  border: 2px solid rgba(255, 194, 122, 0.55);
  border-radius: 6px;
  box-shadow:
    0 0 0 2px rgba(3, 8, 20, 0.35),
    0 6px 16px rgba(0, 0, 0, 0.25);
  color: #ffe7bd;
  font-family: var(--font-ui);
  font-size: clamp(20px, 3.2cqw, 28px);
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.08s linear, border-color 0.08s linear, transform 0.06s ease;
}

.touch-btn:active,
.touch-btn.is-active {
  background: rgba(255, 159, 69, 0.4);
  border-color: var(--orange-hi);
  transform: scale(0.95);
}

.touch-btn:focus-visible {
  outline: 3px solid var(--pink-hi);
  outline-offset: 2px;
}

/* 任一選單畫面或美食卡顯示時，收起觸控按鈕，避免重疊 */
#game-shell:has(.screen:not(.hidden)) #touch-controls,
#game-shell:has(#cutin:not(.hidden)) #touch-controls {
  display: none;
}

/* -------------------------------------------------------------------------
   5. Screens / panels / buttons
   ------------------------------------------------------------------------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding:
    calc(12px + env(safe-area-inset-top, 0px))
    calc(16px + env(safe-area-inset-right, 0px))
    calc(12px + env(safe-area-inset-bottom, 0px))
    calc(16px + env(safe-area-inset-left, 0px));
  background: rgba(4, 10, 28, 0.72);
  pointer-events: none;
  container-type: inline-size;
}

.panel {
  pointer-events: auto;
  position: relative;
  width: 90%;
  max-width: 90%;
  max-height: 100%;
  overflow-y: auto;
  padding: clamp(14px, 2.2cqw, 30px) clamp(16px, 2.6cqw, 34px);
  background:
    linear-gradient(180deg, rgba(255, 159, 69, 0.06), rgba(255, 159, 69, 0) 42%),
    linear-gradient(180deg, #0c1d38, #081328);
  border: 2px solid var(--orange);
  box-shadow:
    0 0 0 3px rgba(3, 8, 20, 0.92),
    8px 8px 0 rgba(0, 0, 0, 0.45),
    0 0 36px rgba(255, 144, 64, 0.14);
  text-align: center;
  scrollbar-width: thin;
  scrollbar-color: #3c5478 transparent;
  overscroll-behavior: contain;
}

.panel::-webkit-scrollbar {
  width: 8px;
}

.panel::-webkit-scrollbar-thumb {
  background: #3c5478;
}

.panel::-webkit-scrollbar-track {
  background: transparent;
}

.narrow {
  width: clamp(280px, 38cqw, 430px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--pink-hi);
  font-family: var(--font-mono);
  font-size: clamp(9px, 1.2cqw, 12px);
  font-weight: 700;
  letter-spacing: 0.28em;
  line-height: 1.4;
  text-transform: uppercase;
}

.panel-title {
  margin: 0 0 clamp(8px, 1.2cqw, 12px);
  color: #fff0d2;
  font-size: clamp(22px, 4.4cqw, 34px);
  font-weight: 900;
  letter-spacing: 0.1em;
  line-height: 1.15;
  text-shadow:
    0 2px 0 #6b2a10,
    0 0 18px rgba(255, 150, 70, 0.22);
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: clamp(8px, 1.4cqw, 16px);
}

.menu .btn {
  width: 100%;
}

.btn {
  appearance: none;
  -webkit-appearance: none;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 140px;
  padding: 9px 20px;
  background: var(--orange);
  border: 2px solid #2a1706;
  box-shadow: 3px 3px 0 var(--shadow);
  color: #081428;
  font-family: var(--font-ui);
  font-size: clamp(14px, 1.6cqw, 17px);
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.12s ease, color 0.12s ease, transform 0.06s ease, box-shadow 0.06s ease;
}

.btn.primary {
  background: linear-gradient(180deg, #ffb84d, #ff8f2f);
  box-shadow:
    3px 3px 0 var(--shadow),
    0 0 20px rgba(255, 150, 60, 0.18);
}

.btn.secondary {
  background: #0c1f3c;
  border-color: #3d5579;
  color: var(--ink);
}

.btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--shadow);
  background: var(--orange-deep);
  color: #1a0d03;
}

.btn.secondary:active {
  background: #14305a;
  color: var(--ink);
}

.btn:focus-visible {
  outline: 3px solid var(--pink-hi);
  outline-offset: 3px;
}

.btn.btn-block {
  width: 100%;
  min-width: 0;
}

.btn[disabled],
.btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: 3px 3px 0 var(--shadow);
}

@media (hover: hover) {
  .btn:hover {
    background: var(--orange-hi);
  }

  .btn.secondary:hover {
    background: #14305a;
    border-color: var(--orange);
  }

  .btn.primary:hover {
    background: linear-gradient(180deg, #ffc96b, #ff9f45);
  }

  .hud-btn:hover {
    background: #18345a;
    border-color: #5a7398;
  }

  .touch-btn:hover {
    border-color: var(--orange-hi);
  }

  .shop-card:hover {
    border-color: var(--orange);
    background: #142e50;
    transform: translateY(-2px);
  }

  .skin-card:hover {
    border-color: var(--orange-hi);
  }

  .bag-slot:not(.disabled):not(:disabled):hover {
    border-color: var(--orange);
    background: #142e50;
  }

  #interact-prompt:hover {
    background: linear-gradient(180deg, #ffc96b, #ff9f45);
  }
}

/* -------------------------------------------------------------------------
   6. Title screen
   ------------------------------------------------------------------------- */

#screen-title {
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(255, 126, 60, 0.2), transparent 62%),
    radial-gradient(ellipse at 92% 82%, rgba(255, 79, 154, 0.13), transparent 55%),
    radial-gradient(ellipse at 6% 88%, rgba(88, 180, 255, 0.08), transparent 55%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.016) 0 1px, transparent 1px 3px),
    rgba(4, 10, 28, 0.78);
}

.title-layout {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2.2cqw, 24px);
  width: min(92%, 720px);
  max-height: 100%;
  pointer-events: none;
}

.title-hero {
  flex: 0 0 auto;
  text-align: center;
  pointer-events: none;
}

.title-hero .eyebrow {
  margin-bottom: 2px;
}

.game-title {
  margin: 0 0 clamp(4px, 0.8cqw, 8px);
  color: #fff2d6;
  font-size: clamp(30px, 8.2cqw, 76px);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.08;
  white-space: nowrap;
  text-shadow:
    0 2px 0 #b54a18,
    0 5px 0 #601f0e,
    0 10px 26px rgba(255, 110, 50, 0.34),
    3px 3px 0 rgba(255, 79, 154, 0.45);
}

.subtitle {
  margin: 0;
  color: var(--ink-dim);
  font-size: clamp(13px, 2.2cqw, 21px);
  font-weight: 600;
  letter-spacing: 0.18em;
  line-height: 1.5;
  white-space: nowrap;
}

.subtitle .arrow {
  margin: 0 0.15em;
  color: var(--pink-hi);
  font-family: var(--font-mono);
}

.skin-picker {
  pointer-events: auto;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(6px, 1.2cqw, 12px);
  width: min(100%, 560px);
}

.skin-card {
  --skin-size: 64px;
  --skin-sheet-w: 704px;
  position: relative;
  appearance: none;
  -webkit-appearance: none;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  min-height: 44px;
  padding: 6px 6px 7px;
  background: linear-gradient(180deg, rgba(15, 35, 66, 0.92), rgba(8, 19, 40, 0.94));
  border: 2px solid #3c5478;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.4);
  color: var(--ink-dim);
  font-family: var(--font-ui);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.12s ease, background-color 0.12s ease, transform 0.06s ease, box-shadow 0.06s ease;
}

.skin-thumb {
  width: var(--skin-size);
  height: var(--skin-size);
  flex: 0 0 auto;
  background-repeat: no-repeat;
  background-position: 0 0;
  /* idle sheet is 11 frames wide; show frame 0 only */
  background-size: 704px 64px;
  background-size: var(--skin-sheet-w) var(--skin-size);
  image-rendering: pixelated;
}

#skin-virtual .skin-thumb {
  background-image: url("assets/game/player/virtual_idle.png");
}

#skin-mask .skin-thumb {
  background-image: url("assets/game/player/mask_idle.png");
}

#skin-ninja .skin-thumb {
  background-image: url("assets/game/player/ninja_idle.png");
}

#skin-pink .skin-thumb {
  background-image: url("assets/game/player/pink_idle.png");
}

.skin-name {
  color: var(--ink-dim);
  font-size: clamp(11px, 1.3cqw, 13px);
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.3;
  white-space: nowrap;
}

.skin-card:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4);
}

.skin-card:focus-visible {
  outline: 3px solid var(--pink-hi);
  outline-offset: 2px;
}

.skin-card.selected {
  border-color: var(--orange);
  background: linear-gradient(180deg, rgba(255, 159, 69, 0.18), rgba(12, 27, 54, 0.95));
  box-shadow:
    0 0 0 2px rgba(255, 159, 69, 0.28),
    3px 3px 0 rgba(0, 0, 0, 0.4),
    0 0 18px rgba(255, 159, 69, 0.16);
}

.skin-card.selected .skin-name {
  color: #fff0d2;
}

.skin-card.selected::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  background: var(--orange);
  box-shadow: 0 0 8px rgba(255, 159, 69, 0.65);
}

.menu-panel {
  width: clamp(300px, 40cqw, 440px);
  pointer-events: auto;
}

.controls-line {
  margin: 10px 0 12px;
  color: var(--ink-dim);
  font-size: clamp(10px, 1.25cqw, 12px);
  letter-spacing: 0.03em;
  line-height: 1.55;
  text-align: center;
}

/* Decorative lanterns ------------------------------------------------ */

.lantern {
  position: absolute;
  top: 14%;
  z-index: 1;
  width: clamp(26px, 4.4cqw, 44px);
  height: clamp(36px, 6cqw, 60px);
  background: linear-gradient(180deg, #ff7a3c, #ffb45e);
  border: 2px solid #ffd79a;
  border-radius: 45% 45% 38% 38% / 28% 28% 52% 52%;
  box-shadow:
    0 0 30px rgba(255, 120, 50, 0.45),
    inset 0 -8px 0 rgba(150, 40, 10, 0.25);
  opacity: 0.9;
  transform-origin: 50% -6px;
  animation: lantern-sway 6s ease-in-out infinite;
}

.lantern::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 25%;
  width: 50%;
  height: 8px;
  background: #3a2010;
  border: 1px solid #ffcf8a;
}

.lantern::after {
  content: "";
  position: absolute;
  bottom: -18px;
  left: calc(50% - 1px);
  width: 2px;
  height: 18px;
  background: #ffcf6b;
  box-shadow: 0 16px 0 1px #ff9f45;
}

.lantern-a {
  left: 8%;
}

.lantern-b {
  right: 8%;
  animation-delay: -2.6s;
  animation-direction: reverse;
}

/* -------------------------------------------------------------------------
   7. Credits
   ------------------------------------------------------------------------- */

.credits-panel {
  display: flex;
  flex-direction: column;
  width: clamp(320px, 54cqw, 620px);
  overflow: hidden;
}

.credits-panel .panel-title,
.credits-panel > .eyebrow {
  flex: 0 0 auto;
  text-align: center;
}

#credits-content {
  flex: 1 1 auto;
  min-height: 0;
  margin: clamp(8px, 1.2cqw, 14px) 0 clamp(12px, 1.8cqw, 18px);
  padding-right: 4px;
  overflow-y: auto;
  text-align: left;
  scrollbar-width: thin;
  scrollbar-color: #3c5478 transparent;
}

#credits-content::-webkit-scrollbar {
  width: 8px;
}

#credits-content::-webkit-scrollbar-thumb {
  background: #3c5478;
}

.credits-list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.credits-list li {
  position: relative;
  padding: clamp(5px, 0.9cqw, 8px) 0 clamp(5px, 0.9cqw, 8px) 14px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink);
  font-size: clamp(11px, 1.55cqw, 14px);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.credits-list li:last-child {
  border-bottom: 0;
}

.credits-list li::before {
  content: "";
  position: absolute;
  top: 1.05em;
  left: 2px;
  width: 5px;
  height: 5px;
  background: var(--orange);
}

.credits-list li:nth-child(even)::before {
  background: var(--pink);
}

.credits-note {
  margin: 12px 0 0;
  padding: 8px 10px;
  background: rgba(3, 9, 22, 0.5);
  border-left: 2px solid var(--panel-line);
  color: var(--ink-faint);
  font-size: clamp(10px, 1.35cqw, 12px);
  line-height: 1.6;
}

.credits-panel > .btn {
  display: flex;
  flex: 0 0 auto;
  width: 100%;
}

/* -------------------------------------------------------------------------
   8. Stats / shop
   ------------------------------------------------------------------------- */

.stats {
  min-height: 1.6em;
  margin: clamp(8px, 1.4cqw, 14px) 0 clamp(12px, 1.8cqw, 18px);
  color: var(--ink);
  font-size: clamp(12px, 1.6cqw, 15px);
  letter-spacing: 0.03em;
  line-height: 1.8;
}

.stats:empty::before {
  content: "—";
  color: var(--ink-faint);
  opacity: 0.45;
}

.stats p {
  margin: 2px 0;
}

.stats strong {
  color: var(--gold);
  font-family: var(--font-mono);
  font-weight: 700;
}

.shop-panel {
  width: clamp(320px, 56cqw, 640px);
}

.shop-wallet {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 0 clamp(10px, 1.6cqw, 16px);
  color: var(--ink-dim);
  font-size: clamp(12px, 1.6cqw, 15px);
  letter-spacing: 0.05em;
}

.shop-wallet strong {
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 1.45em;
  line-height: 1;
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(10px, 1.6cqw, 16px);
  margin: 0 0 clamp(12px, 1.8cqw, 18px);
}

.shop-card {
  appearance: none;
  -webkit-appearance: none;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: clamp(10px, 1.8cqw, 18px) clamp(8px, 1.4cqw, 14px);
  background: linear-gradient(180deg, #102544, #0a1830);
  border: 2px solid #3c5478;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
  color: var(--ink);
  font-family: var(--font-ui);
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease, border-color 0.12s ease, background-color 0.12s ease;
}

.shop-card:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.45);
}

.shop-card:focus-visible {
  outline: 3px solid var(--pink-hi);
  outline-offset: 3px;
}

.shop-card.disabled,
.shop-card:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
}

.shop-card-icon {
  display: grid;
  place-items: center;
  width: clamp(34px, 5.2cqw, 48px);
  height: clamp(34px, 5.2cqw, 48px);
  background: linear-gradient(180deg, #ffd08a, #ff9f45);
  border: 2px solid #6a3412;
  box-shadow: inset 0 -6px 0 rgba(140, 60, 10, 0.25);
  color: #3a1a06;
  font-size: clamp(18px, 2.8cqw, 24px);
  font-weight: 900;
  line-height: 1;
}

.shop-card-icon-shield {
  background: linear-gradient(180deg, #ff9fca, #ff4f9a);
  border-color: #6d1f3f;
  color: #34101f;
  box-shadow: inset 0 -6px 0 rgba(110, 20, 55, 0.25);
}

.shop-card-name {
  color: #fff0d2;
  font-size: clamp(16px, 2.2cqw, 20px);
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.3;
}

.shop-card-desc {
  color: var(--ink-dim);
  font-size: clamp(11px, 1.5cqw, 13px);
  line-height: 1.4;
}

.shop-card-price {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  padding: 3px 9px;
  background: rgba(3, 9, 22, 0.55);
  border: 1px solid #3c5478;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: clamp(11px, 1.5cqw, 14px);
  font-weight: 700;
  line-height: 1.4;
}

.shop-card-price .coin-icon {
  vertical-align: -3px;
}

/* Backpack ------------------------------------------------------------ */

#screen-backpack .panel {
  display: flex;
  flex-direction: column;
  width: clamp(320px, 52cqw, 560px);
  overflow: hidden;
}

#screen-backpack .panel > .eyebrow,
#screen-backpack .panel > .panel-title {
  flex: 0 0 auto;
}

#backpack-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-content: start;
  gap: clamp(6px, 1.2cqw, 12px);
  margin: clamp(8px, 1.2cqw, 14px) 0 clamp(12px, 1.8cqw, 18px);
  padding-right: 2px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #3c5478 transparent;
}

#backpack-grid::-webkit-scrollbar {
  width: 8px;
}

#backpack-grid::-webkit-scrollbar-thumb {
  background: #3c5478;
}

#backpack-grid::-webkit-scrollbar-track {
  background: transparent;
}

#backpack-grid:empty::before {
  content: "背包是空的";
  grid-column: 1 / -1;
  padding: clamp(18px, 3.2cqw, 30px) 0;
  color: var(--ink-faint);
  font-size: clamp(11px, 1.5cqw, 14px);
  letter-spacing: 0.08em;
  line-height: 1.5;
}

.bag-slot {
  position: relative;
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  min-height: clamp(66px, 10cqw, 84px);
  padding: 6px 4px;
  background: linear-gradient(180deg, #102544, #0a1830);
  border: 2px solid #3c5478;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.4);
  color: var(--ink);
  font-family: var(--font-ui);
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.12s ease, background-color 0.12s ease, transform 0.06s ease, box-shadow 0.06s ease;
}

.bag-slot:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4);
}

.bag-slot:focus-visible {
  outline: 3px solid var(--pink-hi);
  outline-offset: 2px;
}

.bag-slot.disabled,
.bag-slot:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.4);
}

.bag-slot-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  background-color: rgba(3, 9, 22, 0.45);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  border: 1px solid #2e4568;
  font-size: 20px;
  line-height: 1;
  image-rendering: pixelated;
}

.bag-slot-icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.bag-slot-name {
  color: #fff0d2;
  font-size: clamp(10px, 1.3cqw, 12px);
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.bag-slot-count {
  position: absolute;
  top: 3px;
  right: 3px;
  display: grid;
  place-items: center;
  min-width: 16px;
  height: 15px;
  padding: 0 3px;
  background: var(--gold);
  border: 1px solid #4a2a06;
  color: #241402;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}

.bag-note {
  grid-column: 1 / -1;
  margin: 4px 0 0;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 191, 120, 0.18);
  color: var(--ink-dim);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

#screen-backpack .panel > .btn {
  flex: 0 0 auto;
  width: 100%;
}

/* Game over / victory accents ---------------------------------------- */

.gameover-title {
  color: #ff9db5;
  text-shadow:
    0 2px 0 #5c1030,
    0 0 20px rgba(255, 79, 154, 0.3);
}

.victory-panel {
  border-color: var(--gold);
  box-shadow:
    0 0 0 3px rgba(3, 8, 20, 0.92),
    8px 8px 0 rgba(0, 0, 0, 0.45),
    0 0 44px rgba(255, 200, 90, 0.22);
}

.victory-title {
  color: var(--gold);
  text-shadow:
    0 2px 0 #7a4b06,
    0 0 24px rgba(255, 200, 90, 0.4);
}

/* -------------------------------------------------------------------------
   9. Cut-in (special food card)
   ------------------------------------------------------------------------- */

#cutin {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    radial-gradient(50% 50% at 50% 50%, rgba(255, 140, 60, 0.18), transparent 70%),
    rgba(3, 8, 20, 0.78);
  pointer-events: none;
  container-type: inline-size;
}

#cutin:not(.hidden) {
  animation: fade-in 0.18s ease-out;
}

#cutin-card {
  width: min(78%, 460px);
  padding:
    clamp(14px, 2.2cqw, 26px)
    clamp(16px, 2.4cqw, 30px)
    clamp(12px, 1.8cqw, 20px);
  background: linear-gradient(180deg, #122b4c, #08152b);
  border: 2px solid var(--pink);
  box-shadow:
    0 0 0 3px rgba(3, 8, 20, 0.9),
    0 0 0 5px rgba(255, 159, 69, 0.35),
    10px 10px 0 rgba(0, 0, 0, 0.5),
    0 0 40px rgba(255, 79, 154, 0.3);
  text-align: center;
  animation: cutin-pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

#cutin-icon {
  display: grid;
  place-items: center;
  width: clamp(46px, 7cqw, 64px);
  height: clamp(46px, 7cqw, 64px);
  margin: 0 auto 8px;
  background-color: rgba(255, 159, 69, 0.12);
  border: 2px solid rgba(255, 190, 110, 0.6);
  box-shadow: 0 0 20px rgba(255, 150, 60, 0.25);
  color: #ffe0a8;
  font-size: clamp(26px, 4cqw, 36px);
  line-height: 1;
  image-rendering: pixelated;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

#cutin-icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.cutin-kicker {
  margin: 0;
  color: var(--pink-hi);
  font-family: var(--font-mono);
  font-size: clamp(8px, 1.1cqw, 11px);
  font-weight: 700;
  letter-spacing: 0.3em;
  line-height: 1.4;
}

#cutin-title {
  margin: 4px 0 2px;
  color: #fff0cf;
  font-size: clamp(22px, 3.8cqw, 30px);
  font-weight: 900;
  letter-spacing: 0.1em;
  line-height: 1.2;
  text-shadow: 0 2px 0 #8a3416;
}

#cutin-desc {
  margin: 0 0 12px;
  color: var(--ink-dim);
  font-size: clamp(11px, 1.5cqw, 14px);
  line-height: 1.5;
}

#cutin-bar {
  height: 10px;
  border-width: 2px;
  border-color: #33486d;
}

#cutin-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--pink), var(--orange), var(--gold));
}

/* -------------------------------------------------------------------------
   10. Rotate overlay (portrait warning)
   ------------------------------------------------------------------------- */

#rotate-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(20px + env(safe-area-inset-top, 0px))
    calc(20px + env(safe-area-inset-right, 0px))
    calc(20px + env(safe-area-inset-bottom, 0px))
    calc(20px + env(safe-area-inset-left, 0px));
  background:
    radial-gradient(50% 50% at 50% 45%, rgba(255, 110, 60, 0.12), transparent 65%),
    #04081a;
  text-align: center;
  pointer-events: auto;
}

.rotate-inner {
  max-width: 320px;
}

.rotate-icon {
  position: relative;
  width: 54px;
  height: 88px;
  margin: 0 auto 18px;
  background:
    linear-gradient(180deg, rgba(255, 159, 69, 0.16), rgba(255, 159, 69, 0.03)),
    #0b1c36;
  border: 2px solid var(--orange);
  box-shadow: 0 0 24px rgba(255, 150, 60, 0.2);
  animation: rotate-hint 2.8s ease-in-out infinite;
}

.rotate-icon::after {
  content: "";
  position: absolute;
  bottom: 6px;
  left: 50%;
  width: 16px;
  height: 2px;
  background: #4a5f86;
  transform: translateX(-50%);
}

.rotate-title {
  margin: 0 0 8px;
  color: #fff0d2;
  font-size: clamp(20px, 5.4vh, 28px);
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1.3;
  text-shadow: 0 2px 0 #6b2a10;
}

.rotate-note {
  margin: 0;
  color: var(--ink-dim);
  font-size: clamp(12px, 2.8vh, 15px);
  letter-spacing: 0.08em;
  line-height: 1.6;
}

/* -------------------------------------------------------------------------
   11. Loading
   ------------------------------------------------------------------------- */

#loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    radial-gradient(50% 60% at 50% 38%, rgba(255, 120, 60, 0.13), transparent 70%),
    radial-gradient(40% 40% at 88% 90%, rgba(255, 79, 154, 0.08), transparent 65%),
    #040a18;
  text-align: center;
  pointer-events: auto;
  container-type: inline-size;
}

.loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(80%, 420px);
}

.loading-lantern {
  display: grid;
  place-items: center;
  width: clamp(34px, 6cqw, 52px);
  height: clamp(46px, 8.2cqw, 70px);
  margin-bottom: 2px;
  background: linear-gradient(180deg, #ff7a3c, #ffb45e);
  border: 2px solid #ffd79a;
  border-radius: 45% 45% 38% 38% / 28% 28% 52% 52%;
  box-shadow: 0 0 34px rgba(255, 120, 50, 0.45);
  color: #4a1a06;
  font-size: clamp(16px, 2.6cqw, 22px);
  font-weight: 900;
  line-height: 1;
}

.loading-eyebrow {
  margin: 0;
  color: var(--pink-hi);
  font-family: var(--font-mono);
  font-size: clamp(8px, 1.2cqw, 11px);
  font-weight: 700;
  letter-spacing: 0.28em;
  line-height: 1.4;
}

.loading-title {
  margin: 0;
  color: var(--ink);
  font-size: clamp(22px, 4.6cqw, 36px);
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1.2;
  text-shadow:
    0 2px 0 #7a2f12,
    0 0 18px rgba(255, 140, 70, 0.35);
}

#loading-bar {
  position: relative;
  width: 60%;
  height: 10px;
  background: #061021;
  border: 2px solid #3c5478;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

#loading-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent 0 10px,
    rgba(255, 255, 255, 0.045) 10px 12px
  );
  pointer-events: none;
}

#loading-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #ff4f9a, #ff9f45, #ffd36b);
  transition: width 0.18s ease-out;
}

.loading-text {
  margin: 0;
  color: var(--ink-dim);
  font-size: clamp(10px, 1.4cqw, 13px);
  letter-spacing: 0.2em;
  line-height: 1.5;
}

/* -------------------------------------------------------------------------
   12. Animations
   ------------------------------------------------------------------------- */

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

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

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes cutin-pop {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes lantern-sway {
  0%,
  100% {
    transform: rotate(-2.5deg);
  }
  50% {
    transform: rotate(2.5deg);
  }
}

@keyframes rotate-hint {
  0%,
  38% {
    transform: rotate(0deg);
  }
  58%,
  86% {
    transform: rotate(90deg);
  }
  100% {
    transform: rotate(90deg);
  }
}

/* -------------------------------------------------------------------------
   13. Responsive / device adjustments
   ------------------------------------------------------------------------- */

/* 手機：放大字體與按鈕；觸控列仍由 body.touch 控制 */
@media (max-width: 700px), (pointer: coarse) {
  .btn {
    min-height: 52px;
    padding: 11px 18px;
    font-size: 16px;
  }

  .hud-btn {
    width: 52px;
    height: 52px;
    font-size: 16px;
  }

  .touch-btn {
    font-size: 28px;
  }

  .controls-line {
    font-size: 11px;
  }

  .skin-name {
    font-size: 12px;
  }

  .bag-slot {
    min-height: 72px;
  }

  .bag-slot-icon {
    width: 30px;
    height: 30px;
  }

  #interact-prompt {
    font-size: 12px;
  }

  .credits-list li {
    font-size: 12px;
  }

  .shop-wallet {
    font-size: 14px;
  }
}

/* 很窄的視窗（多為直向；實際由 rotate overlay 接手） */
@media (max-width: 520px) {
  .shop-grid {
    grid-template-columns: 1fr;
  }

  .skin-picker {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .skin-card {
    --skin-size: 44px;
    --skin-sheet-w: 484px;
    flex-direction: row;
    gap: 6px;
    min-height: 48px;
    padding: 4px 8px;
  }

  .skin-name {
    font-size: 11px;
  }

  #backpack-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .game-title {
    letter-spacing: 0.02em;
  }

  .subtitle {
    letter-spacing: 0.1em;
  }

  .lantern {
    display: none;
  }
}

/* 矮視窗（手機橫向／小型視窗）— 壓縮標題畫面，確保開始按鈕可見 */
@media (max-height: 560px) {
  .lantern {
    display: none;
  }

  .title-layout {
    gap: 8px;
  }

  .title-hero .eyebrow {
    margin-bottom: 1px;
  }

  .game-title {
    margin-bottom: 3px;
    font-size: clamp(26px, 7cqw, 46px);
  }

  .subtitle {
    font-size: clamp(12px, 2cqw, 16px);
  }

  .skin-picker {
    gap: 6px;
    width: min(100%, 460px);
  }

  .skin-card {
    --skin-size: 40px;
    --skin-sheet-w: 440px;
    flex-direction: row;
    gap: 6px;
    min-height: 46px;
    padding: 4px 6px;
  }

  .skin-name {
    font-size: 11px;
  }

  .menu-panel {
    width: clamp(310px, 44cqw, 440px);
  }

  .panel {
    padding: 12px 16px;
  }

  .panel-title {
    margin-bottom: 6px;
    font-size: clamp(20px, 3.6cqw, 26px);
  }

  .controls-line {
    margin: 8px 0 10px;
    font-size: 10px;
  }

  .bag-slot {
    min-height: 62px;
    padding: 4px 3px;
  }

  .bag-slot-icon {
    width: 28px;
    height: 28px;
  }

  .bag-slot-name {
    font-size: 10px;
  }

  #interact-prompt {
    min-height: 38px;
    padding: 6px 14px;
  }

  .stats {
    margin: 6px 0 10px;
  }

  .credits-list li {
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .credits-note {
    margin-top: 8px;
    padding: 6px 8px;
  }

  .shop-card {
    gap: 4px;
    padding: 8px 6px;
  }

  .shop-card-desc {
    font-size: 10px;
  }
}

/* 極矮的橫向視窗（例如 iPhone SE 橫向） */
@media (max-height: 340px) {
  #screen-title .title-hero .eyebrow {
    display: none;
  }

  #screen-title .game-title {
    margin-bottom: 2px;
    font-size: clamp(24px, 6.2cqw, 38px);
  }

  #screen-title .subtitle {
    font-size: 11px;
  }

  #screen-title .title-layout {
    gap: 6px;
  }

  #screen-title .skin-card {
    --skin-size: 32px;
    --skin-sheet-w: 352px;
    gap: 4px;
    padding: 4px 6px;
  }

  #screen-title .skin-name {
    font-size: 10px;
  }

  #screen-title .menu-panel {
    padding: 8px 12px;
  }

  .controls-line {
    margin: 6px 0;
    font-size: 9px;
  }

  #screen-backpack .panel {
    padding: 10px 12px;
  }

  .bag-slot {
    min-height: 56px;
  }

  .bag-slot-icon {
    width: 24px;
    height: 24px;
  }

  .bag-slot-name {
    font-size: 9px;
  }

  #interact-prompt {
    bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    min-height: 32px;
    padding: 4px 12px;
  }

  body.touch #interact-prompt {
    bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* -------------------------------------------------------------------------
   v3: weapon HUD / boss HUD
   ------------------------------------------------------------------------- */

.hud-weapon {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  background: rgba(4, 10, 24, 0.84);
  border: 2px solid #5a6a44;
  box-shadow: 3px 3px 0 var(--shadow);
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}

.weapon-icon {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  background: #1a2a18;
  border: 1px solid #5a6a44;
  color: #ffe0a8;
  font-family: var(--font-ui);
  font-size: 11px;
}

.weapon-name {
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.weapon-hits {
  color: var(--pink-hi);
}

.boss-hud {
  position: absolute;
  z-index: 22;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 50%;
  width: min(52%, 520px);
  transform: translateX(-50%);
  pointer-events: none;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6));
}

.boss-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px;
  color: #ffe7bd;
  font-family: var(--font-ui);
  font-size: clamp(10px, 1.4cqw, 13px);
  letter-spacing: 0.08em;
}

.boss-label span {
  color: var(--pink-hi);
  font-family: var(--font-mono);
  font-size: 0.8em;
  font-weight: 800;
}

.boss-label strong {
  color: #fff3d6;
  font-weight: 800;
}

.boss-bar {
  height: 11px;
  background: #1b0d12;
  border: 2px solid #ff6a4d;
  box-shadow: 0 0 0 2px rgba(3, 8, 20, 0.7), 0 0 16px rgba(255, 80, 60, 0.25);
  overflow: hidden;
}

#boss-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #ff3d3d, #ff8a3c, #ffd08a);
  transition: width 0.15s linear;
}

@media (pointer: coarse) {
  .boss-hud {
    width: min(64%, 420px);
    top: calc(8px + env(safe-area-inset-top, 0px));
  }
}

.bag-ingredients {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  padding: 7px 8px;
  background: rgba(20, 40, 26, 0.55);
  border: 1px solid rgba(150, 255, 150, 0.22);
  color: #d8f5d8;
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

.bag-recipe {
  grid-column: 1 / -1;
  appearance: none;
  -webkit-appearance: none;
  min-height: 38px;
  padding: 6px 10px;
  background: linear-gradient(180deg, #3a6a3a, #244a28);
  border: 2px solid #7bd07b;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.4);
  color: #eaffea;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.bag-recipe:disabled {
  opacity: 0.4;
  cursor: default;
  filter: grayscale(0.5);
}

.hud-skill {
  appearance: none;
  -webkit-appearance: none;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 3px 8px;
  background: #10251f;
  border: 2px solid #4f8b6a;
  color: #d9ffe9;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
}

.hud-skill:active {
  transform: translateY(1px);
}

.hud-skill.cooling {
  opacity: 0.55;
}

#hud-skill-cd {
  color: #9de0b6;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 800;
}

/* -------------------------------------------------------------------------
   v4: 茄芷袋 backpack — paper bag, flat ink, no AI card grid
   ------------------------------------------------------------------------- */

#screen-backpack {
  background: rgba(4, 8, 16, 0.84);
}

#screen-backpack .panel {
  width: min(92%, 820px);
  max-width: 820px;
  max-height: 84%;
  padding: 0;
  overflow: hidden;
  background: #f1e3c8;
  border: 3px solid #241c14;
  border-radius: 0;
  box-shadow: none;
  text-align: left;
  color: #241c14;
}

.bag-stripe {
  height: 13px;
  background: linear-gradient(90deg, #c8402f 0 33.4%, #2f6fb5 33.4% 66.7%, #f1e3c8 66.7% 100%);
}

.bag-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px 4px;
}

.bag-title {
  margin: 0;
  color: #241c14;
  font-family: "Songti TC", "Noto Serif TC", "PMingLiU", serif;
  font-size: clamp(30px, 4.6cqw, 46px);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: 0.02em;
}

.bag-sub {
  margin: 5px 0 0;
  color: #6a5a48;
  font-family: var(--font-ui);
  font-size: 12px;
  letter-spacing: 0.04em;
}

.bag-close {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  min-height: 34px;
  padding: 5px 12px;
  background: transparent;
  border: 2px solid #241c14;
  color: #241c14;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.bag-close:active {
  transform: translateY(2px);
}

#backpack-grid {
  display: block;
  max-height: 62vh;
  padding: 10px 22px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.bag-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 176px;
  gap: 16px;
  align-items: start;
}

.bag-tray {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 16px;
  min-height: 132px;
  padding: 14px;
  background: #e5d3b2;
  border: 2px solid #241c14;
}

.bag-tile {
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 70px;
  padding: 4px 2px 2px;
  background: transparent;
  border: 0;
  color: #241c14;
  font-family: var(--font-ui);
  cursor: pointer;
}

.bag-tile:active {
  transform: translateY(2px);
}

@media (hover: hover) and (pointer: fine) {
  .bag-tile:hover .bag-name {
    text-decoration: underline;
    text-underline-offset: 3px;
  }
}

.bag-icon {
  width: 52px;
  height: 52px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  image-rendering: pixelated;
}

.bag-icon--lantern {
  position: relative;
  background: #c8402f;
  border: 2px solid #241c14;
  border-radius: 46% 46% 38% 38%;
}

.bag-icon--lantern::before,
.bag-icon--lantern::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  height: 2px;
  background: #241c14;
}

.bag-icon--lantern::before { top: 10px; }
.bag-icon--lantern::after { bottom: 10px; }

.bag-name {
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
}

.bag-count {
  color: #8a3416;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 800;
}

.bag-empty {
  align-self: center;
  margin: 0;
  color: #6a5a48;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
}

.bag-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bag-tool {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 7px 8px;
  background: #f7efdd;
  border: 2px solid #241c14;
  font-family: var(--font-ui);
  font-size: 11px;
  line-height: 1.35;
}

.bag-tool-icon {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  image-rendering: pixelated;
}

.bag-tool-icon--pan {
  position: relative;
  width: 30px;
  height: 30px;
  background: #7b8494;
  border: 2px solid #241c14;
  border-radius: 50%;
}

.bag-tool-icon--pan::after {
  content: "";
  position: absolute;
  right: -12px;
  top: 12px;
  width: 14px;
  height: 4px;
  background: #4a2a1a;
  border: 1px solid #241c14;
}

.bag-tool-icon--bat {
  position: relative;
  width: 10px;
  height: 34px;
  background: #8a5a2a;
  border: 2px solid #241c14;
  transform: rotate(18deg);
}

.bag-tool-icon--bat::before {
  content: "";
  position: absolute;
  left: -3px;
  top: -5px;
  width: 12px;
  height: 8px;
  background: #c98a4a;
  border: 2px solid #241c14;
}

.bag-tool-text strong {
  display: block;
  font-size: 12px;
}

.bag-crate {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 8px;
  background: #2f6fb5;
  border: 2px solid #241c14;
  color: #f7efdd;
  font-family: var(--font-ui);
}

.bag-crate-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  font-size: 9px;
  line-height: 1.2;
}

.bag-crate-item img {
  width: 26px;
  height: 26px;
  image-rendering: pixelated;
}

.bag-cook {
  appearance: none;
  -webkit-appearance: none;
  padding: 9px 8px;
  background: #c8402f;
  border: 2px solid #241c14;
  color: #f7efdd;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  transform: rotate(-1.5deg);
}

.bag-cook:active {
  transform: rotate(-1.5deg) translateY(2px);
}

.bag-cook:disabled {
  opacity: 0.35;
  cursor: default;
}

.bag-note {
  grid-column: 1 / -1;
  margin: 4px 0 0;
  padding-top: 0;
  border-top: 0;
  color: #6a5a48;
  font-family: var(--font-ui);
  font-size: 11px;
  line-height: 1.5;
  text-align: left;
}

@media (max-width: 640px) {
  .bag-layout {
    grid-template-columns: 1fr;
  }

  .bag-side {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: end;
  }

  .bag-tool {
    grid-column: 1 / -1;
  }

  .bag-icon {
    width: 44px;
    height: 44px;
  }

  .bag-tile {
    min-width: 60px;
  }
}

.skin-skill {
  color: #8fb4d8;
  font-family: var(--font-ui);
  font-size: clamp(9px, 1.05cqw, 11px);
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.skin-card.selected .skin-skill {
  color: #ffd08a;
}
