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

:root {
  --fe-ink: #050a16;
  --fe-panel-top: #173866;
  --fe-panel-mid: #0b2448;
  --fe-panel-bottom: #06142d;
  --fe-panel-soft: rgba(9, 28, 57, 0.94);
  --fe-gold: #d8b45f;
  --fe-gold-bright: #f4dc91;
  --fe-silver: #8fa8c4;
  --fe-blue: #63a9ff;
  --fe-blue-soft: #b9dcff;
  --fe-red: #ee7777;
  --fe-green: #75dda6;
  --fe-muted: #91a1b8;
  --fe-line: rgba(184, 211, 240, 0.2);
  --fe-shadow: rgba(0, 0, 0, 0.72);
}

.fe-overlay {
  background:
    radial-gradient(circle at 50% 42%, rgba(40, 75, 125, 0.2), transparent 48%),
    rgba(1, 5, 15, 0.82) !important;
  backdrop-filter: blur(2px);
}

.fe-panel {
  position: relative;
  color: #f4f7ff;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.07), transparent 18%),
    repeating-linear-gradient(135deg, rgba(255,255,255,0.018) 0 2px, transparent 2px 7px),
    linear-gradient(155deg, var(--fe-panel-top) 0%, var(--fe-panel-mid) 46%, var(--fe-panel-bottom) 100%) !important;
  border: 2px solid var(--fe-gold) !important;
  border-radius: 6px !important;
  box-shadow:
    inset 0 0 0 1px rgba(225, 239, 255, 0.34),
    inset 0 0 0 3px rgba(2, 9, 24, 0.62),
    inset 0 10px 18px rgba(117, 170, 230, 0.08),
    0 4px 0 rgba(2, 6, 16, 0.72),
    0 9px 24px var(--fe-shadow) !important;
}

.fe-panel::before,
.fe-panel::after {
  content: '';
  position: absolute;
  top: 4px;
  width: 10px;
  height: 10px;
  border-top: 2px solid var(--fe-gold-bright);
  pointer-events: none;
  opacity: 0.88;
}

.fe-panel::before {
  left: 4px;
  border-left: 2px solid var(--fe-gold-bright);
}

.fe-panel::after {
  right: 4px;
  border-right: 2px solid var(--fe-gold-bright);
}

.fe-panel--enemy {
  border-color: #d47777 !important;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.06), transparent 18%),
    repeating-linear-gradient(135deg, rgba(255,255,255,0.015) 0 2px, transparent 2px 7px),
    linear-gradient(155deg, #5b2431 0%, #351426 48%, #170919 100%) !important;
}

.fe-heading {
  color: var(--fe-gold-bright) !important;
  font-weight: bold;
  letter-spacing: 2px;
  text-align: center;
  text-shadow: 0 2px 0 #1d1304, 0 0 8px rgba(255, 216, 105, 0.24);
}

.fe-button {
  min-height: 30px;
  padding: 6px 16px;
  border: 1px solid var(--fe-gold) !important;
  border-radius: 4px !important;
  background: linear-gradient(180deg, #315f91, #173b68 52%, #0d274b) !important;
  color: #f4f8ff !important;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.2),
    inset 0 -2px 0 rgba(0,0,0,0.3),
    0 2px 4px rgba(0,0,0,0.45);
  text-shadow: 0 1px 1px #000;
}

.fe-button:hover,
.fe-button:focus-visible,
.fe-button.is-active {
  color: #fff !important;
  border-color: var(--fe-gold-bright) !important;
  background: linear-gradient(180deg, #4a83bd, #23578f 52%, #153865) !important;
  outline: none;
  filter: brightness(1.08);
}

.fe-button:active {
  transform: translateY(1px);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.45);
}

.fe-button:disabled,
.fe-button.disabled {
  opacity: 0.42;
  cursor: not-allowed;
  filter: grayscale(0.45);
}

.fe-button--danger {
  border-color: #e58b81 !important;
  background: linear-gradient(180deg, #8f4343, #65272d 55%, #3d1720) !important;
}

.fe-button--gold {
  border-color: #ffe095 !important;
  background: linear-gradient(180deg, #92702c, #674819 55%, #3f290c) !important;
  color: #fff1ba !important;
}

.fe-button--muted {
  border-color: #718096 !important;
  background: linear-gradient(180deg, #46536a, #2b3549 55%, #171e2d) !important;
  color: #d5dce8 !important;
}

.fe-menu-row {
  border: 1px solid transparent;
  border-bottom-color: var(--fe-line);
  background: rgba(3, 13, 31, 0.18);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.fe-menu-row:hover,
.fe-menu-row.selected {
  border-color: rgba(244, 220, 145, 0.7);
  background: linear-gradient(90deg, rgba(76, 137, 201, 0.68), rgba(30, 76, 127, 0.58));
}

.fe-screen-title {
  color: var(--fe-gold-bright) !important;
  font-weight: bold;
  letter-spacing: 3px;
  text-shadow: 0 2px 0 #241604, 0 0 10px rgba(244, 220, 145, 0.28);
}

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

body {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.008) 0 3px, transparent 3px 9px),
    radial-gradient(ellipse at 50% 42%, #262c4e 0%, #171a36 48%, #0d0e22 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  font-family: 'MS Gothic', 'SimHei', monospace;
  color: #fff;
  overflow: hidden;
}

#game-container {
  position: relative;
  /* 視野解鎖: on desktop the game viewport fills the window (capped at
     1920×1080) and main.js grows the canvas logical size to match. The
     mobile media queries below override this with the fitted 4:3 viewport. */
  width: 100vw;
  height: 100vh;
  max-width: 1920px;
  max-height: 1080px;
  /* body flex already centers in normal flow; margin:auto also centers the
     container inside the fullscreen top layer when capped below screen size. */
  margin: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  /* UI-chrome scale factor — main.js sets it on desktop (1 at 800×600 up to
     1.75 at 1920×1080); mobile/touch keeps this default, which makes every
     calc()/zoom rule below an identity transform. */
  --ui-scale: 1;
}

#gameCanvas {
  display: block;
  background: #000;
  width: 100%;
  height: 100%;
}

/* CSS Pixelation fix removed. 
   Reason: Source images were too high-res/detailed. 
   Solution: Fix the generation prompt to enforce 16-bit style at source. */

#ui-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

#ui-overlay > * { pointer-events: auto; }

/* Top bar */
#top-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 28px;
  background:
    linear-gradient(180deg, rgba(39,75,119,0.97), rgba(9,27,56,0.97));
  border-bottom: 2px solid var(--fe-gold);
  box-shadow: inset 0 -1px 0 rgba(220,235,255,0.24), 0 3px 8px rgba(0,0,0,0.48);
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 13px;
  gap: 20px;
  z-index: 10;
}

#phase-indicator {
  margin-left: auto;
  font-weight: bold;
}

.phase-player { color: #4a9eff; }
.phase-enemy { color: #ff4a4a; }

/* Unit panel */
#unit-panel {
  position: absolute;
  top: 36px;
  right: 8px;
  width: 180px;
  padding: 8px;
  font-size: 11px;
  z-index: 10;
}

#unit-panel.hidden { display: none; }

#unit-portrait {
  width: 48px;
  height: 48px;
  margin: 0 auto 6px;
}

#unit-portrait canvas {
  width: 48px;
  height: 48px;
}

#unit-info { line-height: 1.5; }
.stat-row { display: flex; justify-content: space-between; }
.stat-label { color: #aaa; }
.stat-val { color: #fff; font-weight: bold; }
.stat-hp { color: #4f4; }
.stat-name { color: #4a9eff; font-size: 13px; font-weight: bold; margin-bottom: 4px; }
.stat-class { color: #aaa; font-size: 10px; margin-bottom: 4px; }

/* Action menu */
#action-menu {
  position: absolute;
  min-width: 100px;
  z-index: 20;
  font-size: 14px;
}

#action-menu.hidden { display: none; }

.menu-item {
  padding: 6px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--fe-line);
  background: rgba(2, 10, 26, 0.12);
}

.menu-item:last-child { border-bottom: none; }
.menu-item:hover, .menu-item.selected {
  background: linear-gradient(90deg, rgba(76,137,201,0.9), rgba(29,79,134,0.9));
  color: #fff;
  box-shadow: inset 3px 0 0 var(--fe-gold-bright);
}

.menu-item.disabled {
  color: #666;
  pointer-events: none;
}

/* Rich action menu rows — icon + label + description (matches the map menu style) */
#action-menu.rich-menu .menu-item {
  gap: 8px;
  padding-top: 5px;
  padding-bottom: 5px;
}
#action-menu .menu-icon {
  width: 22px;
  text-align: center;
  font-size: 15px;
  flex-shrink: 0;
  opacity: 0.92;
  color: var(--fe-gold-bright);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.fe-icon {
  display: inline-block;
  vertical-align: -0.18em;
  flex-shrink: 0;
}

/* Minimap legend colour key */
.mm-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  vertical-align: baseline;
}
#action-menu .menu-text { flex: 1; line-height: 1.3; }
#action-menu .menu-label { font-weight: bold; }
#action-menu .menu-desc {
  font-size: 10px;
  color: #93a5c0;
  margin-top: 1px;
}
#action-menu .menu-item.disabled .menu-desc { color: #4c586e; }

/* Combat forecast */
#combat-forecast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 12px 20px;
  z-index: 25;
  font-size: 12px;
  min-width: 320px;
}

#combat-forecast.hidden { display: none; }

.forecast-header {
  text-align: center;
  color: var(--fe-gold-bright);
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(244, 220, 145, 0.55);
  padding-bottom: 4px;
}

.forecast-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 4px 0;
}

.forecast-attacker { color: #4a9eff; flex: 1; text-align: left; }
.forecast-defender { color: #ff4a4a; flex: 1; text-align: right; }
.forecast-vs { color: #888; margin: 0 8px; }
.forecast-label { color: #aaa; width: 60px; text-align: center; flex-shrink: 0; }

/* Forecast HP bars — remaining HP fills from the left, predicted loss is a
   translucent red segment on top of the old value. */
.fc-hp-num { font-weight: bold; }
.fc-hp-arrow { color: #ffb04a; font-size: 10px; margin-left: 1px; }
.fc-hpbar {
  display: inline-block;
  width: 52px;
  height: 7px;
  margin: 0 5px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(160, 190, 230, 0.28);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
}
.fc-hpbar-remain {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: linear-gradient(180deg, #6fe3a0, #35a862);
  border-radius: 3px 0 0 3px;
}
.fc-hpbar-remain--dead { background: #7a2b2b; }
.fc-hpbar-loss {
  position: absolute;
  top: 0; bottom: 0;
  background: repeating-linear-gradient(135deg, rgba(255, 96, 80, 0.55) 0 3px, rgba(255, 96, 80, 0.25) 3px 6px);
}
.fc-dmg { font-weight: bold; font-size: 13px; }
.fc-sub { opacity: 0.92; }
.fc-crit { color: #ffd88a; }

/* Dialogue box */
#dialogue-box {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 120px;
  background:
    linear-gradient(180deg, rgba(28,65,112,0.98), rgba(5,18,43,0.98)) !important;
  border: 2px solid var(--fe-gold) !important;
  border-radius: 6px 6px 0 0 !important;
  box-shadow: inset 0 0 0 1px rgba(220,238,255,0.28), inset 0 0 0 3px rgba(1,8,20,0.6), 0 -4px 18px rgba(0,0,0,0.5) !important;
  display: flex;
  align-items: flex-start;
  padding: 12px 16px;
  gap: 12px;
  z-index: 30;
}

#dialogue-box.hidden { display: none; }

/* Portrait rises above the dialogue box like an FE bust shot. The canvas
   backing store scales with --ui-scale (see DialogueSystem._drawPortraitHiRes)
   while CSS keeps the display size. */
#portrait-canvas {
  width: 132px;
  height: 132px;
  margin-top: -46px;
  border: 2px solid var(--fe-gold);
  border-radius: 3px;
  box-shadow: 0 0 0 1px #142a4a, 0 6px 20px rgba(0,0,0,0.6);
  flex-shrink: 0;
  background: #0d1524;
}

#dialogue-name {
  position: absolute;
  top: -50px;
  left: 30px;
  background: linear-gradient(180deg, #e7c671, #9c7427);
  border: 1px solid #ffe4a0;
  color: #07152b;
  padding: 2px 12px;
  font-size: 13px;
  font-weight: bold;
  z-index: 2;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

#dialogue-text {
  font-size: 14px;
  line-height: 1.6;
  padding-top: 4px;
  max-width: 640px;
}

/* Blinking ▼ prompt — appears once the line has finished typing */
#dialogue-next {
  position: absolute;
  right: 14px;
  bottom: 8px;
  font-size: 12px;
  color: var(--fe-gold-bright);
  text-shadow: 0 0 6px rgba(255, 216, 105, 0.6);
  opacity: 0;
  pointer-events: none;
  animation: dialogueNext 0.7s ease-in-out infinite alternate;
}

#dialogue-box.ready #dialogue-next { opacity: 1; }

@keyframes dialogueNext {
  from { transform: translateY(0); }
  to   { transform: translateY(3px); }
}

/* Phase banner */
#phase-banner {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-size: 26px;
  font-weight: bold;
  letter-spacing: 4px;
  padding: 12px 42px;
  border-radius: 999px;              /* capsule */
  z-index: 50;
  animation: phaseBanner 1.5s ease-in-out forwards;
  pointer-events: none; /* decorative — must never swallow map clicks */
  backdrop-filter: blur(2px);
  box-shadow: 0 6px 24px rgba(0,0,0,0.45);
}

#phase-banner.hidden { display: none; }

@keyframes phaseBanner {
  0% { opacity: 0; transform: translateX(-100%) translateY(-50%); }
  15% { opacity: 1; transform: translateX(0%) translateY(-50%); }
  75% { opacity: 1; transform: translateX(0%) translateY(-50%); }
  100% { opacity: 0; transform: translateX(100%) translateY(-50%); }
}

.banner-player {
  background: linear-gradient(135deg, rgba(30,90,210,0.94), rgba(20,60,150,0.94));
  border: 1px solid rgba(120,180,255,0.7);
  color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
}

.banner-enemy {
  background: linear-gradient(135deg, rgba(200,40,40,0.94), rgba(150,20,30,0.94));
  border: 1px solid rgba(255,140,140,0.7);
  color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
}

/* Level up screen */
#level-up-screen {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 20px 30px;
  z-index: 40;
  text-align: center;
  min-width: 250px;
  overflow: hidden;
  animation: lvupPop 0.35s ease-out;
}

#level-up-screen.hidden { display: none; }

@keyframes lvupPop {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.82); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* One-shot gold shimmer sweeping across the panel on entry */
.lvup-sweep {
  position: absolute;
  top: 0; bottom: 0;
  left: -30%;
  width: 26%;
  background: linear-gradient(100deg, transparent, rgba(255, 224, 138, 0.22), transparent);
  transform: skewX(-14deg);
  pointer-events: none;
  animation: lvupSweep 1.1s ease-out 0.15s both;
}

@keyframes lvupSweep {
  from { left: -30%; }
  to   { left: 110%; }
}

/* ▲+N pill badge */
.lvbadge {
  border-radius: 999px;
  background: rgba(255, 215, 0, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 215, 0, 0.35);
}

#item-get-screen {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 20px 30px;
  z-index: 40;
  text-align: center;
  min-width: 250px;
  box-shadow: inset 0 0 0 1px rgba(225,239,255,0.34), inset 0 0 0 3px rgba(2,9,24,0.62), 0 0 28px rgba(79,214,200,0.28) !important;
  animation: itemGetPop 0.3s ease-out;
}
#item-get-screen.hidden { display: none; }
@keyframes itemGetPop {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.lvup-title {
  color: #ffd700;
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 12px;
}

.lvup-stat { margin: 3px 0; font-size: 13px; }
.lvup-stat.increased { color: #4f4; }
.lvup-stat.same { color: #666; }

.lvup-title {
  color: var(--fe-gold-bright);
  text-shadow: 0 2px 0 #241604, 0 0 10px rgba(244,220,145,0.25);
  letter-spacing: 1px;
}

.fe-result-panel {
  min-width: 330px;
  max-width: min(620px, 90%);
  padding: 28px 34px;
  text-align: center;
}

/* Victory panel — entrance pop + gold ornamentation */
.victory-panel {
  position: relative;
  overflow: hidden;
  animation: lvupPop 0.4s ease-out;
}

.victory-ornament {
  color: var(--fe-gold);
  opacity: 0.75;
  font-size: 11px;
  letter-spacing: 4px;
  margin-bottom: 8px;
}

.victory-title {
  font-size: 30px !important;
  letter-spacing: 6px;
}

.victory-divider {
  height: 1px;
  margin: 12px 0 14px;
  background: linear-gradient(90deg, transparent, rgba(244, 220, 145, 0.6), transparent);
}

.victory-gold-line {
  font-size: 17px;
  color: #ffd700;
  text-shadow: 0 0 12px rgba(255, 215, 0, 0.35);
}

.victory-speed-line {
  font-size: 14px;
  color: #7fe07f;
  margin-top: 8px;
  animation: speedPulse 1.1s ease-in-out infinite alternate;
}

@keyframes speedPulse {
  from { text-shadow: none; }
  to   { text-shadow: 0 0 12px rgba(127, 224, 127, 0.75); }
}

.fe-result-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

#status-screen > .fe-panel,
#map-menu-box,
#unit-list-box,
#trade-overlay > .fe-panel,
#settings-overlay > .fe-panel,
#confirm-overlay > .fe-panel,
#minimap-overlay > .fe-panel {
  scrollbar-color: #94763c #08172d;
}

#status-screen table,
#unit-list-box table {
  color: #edf4ff;
}

#unit-list-box tbody tr:nth-child(even) {
  background: rgba(112, 159, 211, 0.06);
}

#unit-list-box tbody tr:hover {
  background: rgba(112, 159, 211, 0.13);
}

#unit-list-box thead {
  color: var(--fe-gold-bright);
  background: rgba(2, 11, 28, 0.42);
}

#trade-overlay [id^="trade-list-"] > div {
  border-bottom-color: var(--fe-line) !important;
}

#camp-overlay {
  background:
    radial-gradient(circle at 18% 10%, rgba(45, 88, 140, 0.26), transparent 34%),
    linear-gradient(160deg, #0c2347 0%, #07162f 48%, #030a18 100%) !important;
}

#camp-header,
#camp-menu {
  background:
    linear-gradient(180deg, rgba(37,75,119,0.96), rgba(8,25,52,0.97)) !important;
  border-color: var(--fe-gold) !important;
  box-shadow: inset 0 1px 0 rgba(230,240,255,0.18);
}

#camp-body {
  background:
    repeating-linear-gradient(135deg, rgba(255,255,255,0.012) 0 2px, transparent 2px 8px),
    rgba(3, 12, 29, 0.3);
}

/* Camp roster strip — every unit as a clickable portrait chip */
#camp-roster {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 14px;
}

.camp-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 78px;
  padding: 6px 4px 5px;
  background: rgba(10, 25, 50, 0.55);
  border: 1px solid #2c4a70;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  color: #cde;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.camp-chip:hover {
  border-color: #6fa8e8;
  transform: translateY(-1px);
}

.camp-chip--sel {
  border-color: var(--fe-gold-bright);
  background: rgba(42, 62, 102, 0.65);
  box-shadow: 0 0 12px rgba(244, 220, 145, 0.32);
}

.camp-chip img {
  width: 40px;
  height: 40px;
  border: 1px solid #4a9eff;
  border-radius: 4px;
  object-fit: cover;
  object-position: center 30%;
}

.camp-chip--sel img { border-color: var(--fe-gold-bright); }
.camp-chip__name { font-size: 11px; font-weight: bold; }
.camp-chip__sub { font-size: 9px; color: #8aa3c0; }

/* Hero card — the selected unit's large display, between roster and content */
#camp-hero {
  max-width: 760px;
  margin: 0 auto 16px;
}

.camp-hero-card {
  display: flex;
  gap: 18px;
  padding: 16px 20px;
  background:
    linear-gradient(135deg, rgba(28, 48, 84, 0.55), rgba(10, 22, 44, 0.78)),
    rgba(6, 14, 30, 0.82);
  border: 1px solid var(--fe-gold);
  border-radius: 10px;
  box-shadow:
    inset 0 1px 0 rgba(255, 240, 200, 0.08),
    0 4px 14px rgba(0, 0, 0, 0.45),
    0 0 18px rgba(244, 220, 145, 0.06);
}

.camp-hero-card__portrait {
  position: relative;
  flex: 0 0 auto;
  width: 132px;
  height: 132px;
  border: 2px solid var(--fe-gold-bright);
  border-radius: 8px;
  overflow: hidden;
  background: linear-gradient(180deg, #1a2c48, #060d1c);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), inset 0 0 12px rgba(0, 0, 0, 0.4);
}

.camp-hero-card__portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 28%;
  display: block;
}

.camp-hero-card__lv {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 2px 8px;
  background: rgba(10, 18, 34, 0.88);
  border: 1px solid var(--fe-gold);
  border-radius: 3px;
  color: var(--fe-gold-bright);
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 0.5px;
}

.camp-hero-card__info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.camp-hero-card__name {
  font-family: "Noto Serif TC", "Noto Serif CJK TC", "Songti TC", serif;
  font-size: 22px;
  font-weight: bold;
  color: #f4ead0;
  letter-spacing: 1px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.camp-hero-card__class {
  color: var(--fe-gold-bright);
  font-size: 13px;
  letter-spacing: 0.5px;
  margin-top: -4px;
}

.camp-hero-card__hp {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.camp-hero-card__hp-label {
  color: #9ab;
  font-size: 11px;
  letter-spacing: 0.5px;
}

.camp-hero-card__hp-bar {
  flex: 0 0 180px;
  height: 10px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid #3d5a80;
  border-radius: 5px;
  overflow: hidden;
}

.camp-hero-card__hp-bar > div {
  height: 100%;
  background: linear-gradient(180deg, #6ee08a, #2f8f4e 55%, #1b5c33);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.camp-hero-card__hp-num {
  color: #f4ead0;
  font-weight: bold;
  font-size: 13px;
}

.camp-hero-card__stats {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(244, 220, 145, 0.14);
}

.camp-hero-card__stats > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.camp-hero-card__stats span {
  color: #9ab;
  font-size: 10px;
  letter-spacing: 0.5px;
}

.camp-hero-card__stats b {
  color: #f4ead0;
  font-size: 16px;
  font-family: "Noto Serif TC", serif;
}

.camp-hero-card__weapon {
  margin-top: 4px;
  padding: 5px 10px;
  background: rgba(15, 28, 50, 0.6);
  border-left: 3px solid var(--fe-gold);
  color: #d5dce8;
  font-size: 12px;
  border-radius: 3px;
}

#camp-content {
  max-width: 760px;
  margin: 0 auto;
}

#camp-toast {
  border-color: var(--fe-gold-bright) !important;
  background: linear-gradient(180deg, #27563a, #113421) !important;
  color: #ddffe9 !important;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
}

#map-menu-msg,
#map-browse-hint,
#terrain-info,
#exp-gain-overlay {
  color: #e8f2ff !important;
}

#objective-display {
  color: #e7d59d !important;
}

#chapter-name {
  color: #fff2bd;
  font-weight: bold;
  text-shadow: 0 1px 0 #000;
}

#turn-count {
  color: #d7e8fb;
}

#bgm-controls button {
  border-color: rgba(216,180,95,0.58) !important;
  color: #dceaff !important;
}

/* Volume details live in the settings menu; the top bar keeps only the mute toggle */
#bgm-controls > :not(#btn-mute-inner) {
  display: none !important;
}

/* Title screen */
#title-screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #050916;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  z-index: 100;
  overflow: hidden;
}

/* vignette/legibility gradients sit above the artwork, below the particles */
#title-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(2,7,18,0.78) 0%, rgba(2,7,18,0.52) 38%, rgba(2,7,18,0.06) 70%),
    linear-gradient(180deg, rgba(3,5,16,0.14) 50%, rgba(3,5,16,0.76) 100%);
  z-index: 1;
  pointer-events: none;
}

/* Slow Ken-Burns drift on the title artwork */
.title-bg-anim {
  position: absolute;
  inset: -4%;
  background: url('../assets/title/title-bg.webp') center top/cover no-repeat;
  z-index: 0;
  animation: titleDrift 26s ease-in-out infinite alternate;
  will-change: transform;
}

@keyframes titleDrift {
  from { transform: scale(1) translate(0, 0); }
  to   { transform: scale(1.09) translate(-1.2%, 1.5%); }
}

#title-particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

#title-screen.hidden { display: none; }

#title-content {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  padding-top: 12vh;
  padding-left: 10vw;
}

#title-logo {
  position: relative;
  width: min(400px, 55vw);
  margin: 0 0 8vh;
  line-height: 0;
  filter: drop-shadow(0 0 30px rgba(88, 214, 164, 0.35)) drop-shadow(0 4px 20px rgba(0, 0, 0, 0.8));
  animation: logoEmerge 1.2s ease-out forwards;
  opacity: 0;
  transform: translateY(-20px);
}

@keyframes logoEmerge {
  0% { opacity: 0; transform: translateY(-20px) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

#title-logo img {
  display: block;
  width: 100%;
  height: auto;
}

#title-menu {
  margin-bottom: 0;
}

/* Two-level title menu: #title-links is the second level (遊戲資料), shown in
   place of the main menu after tapping 遊戲資料. */
#title-menu.hidden,
#title-menu button.hidden,
#title-links.hidden {
  display: none;
}

#title-links {
  margin-top: 0;
  gap: 8px;
}

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

#title-version { opacity: 0; animation: titleMenuIn 0.5s ease-out 1.1s forwards; }

@media (prefers-reduced-motion: reduce) {
  .title-bg-anim, #title-logo,
  #title-menu button, #title-version,
  #title-links a, #title-links button {
    animation: none !important;
    opacity: 1 !important;
  }
}

#title-menu button:hover {
  background: rgba(216, 180, 95, 0.15);
  border-color: rgba(248, 226, 164, 0.85);
  color: #fffbe8;
}

#btn-install.hidden { display: none; }

#pwa-install-help {
  position: absolute;
  inset: 0;
  z-index: 260;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top))
           max(20px, env(safe-area-inset-right))
           max(20px, env(safe-area-inset-bottom))
           max(20px, env(safe-area-inset-left));
  background: rgba(0, 0, 10, 0.86);
}

#orientation-notice {
  display: none;
}

.pwa-install-card {
  width: min(420px, 92vw);
  padding: 24px;
  border: 2px solid #67dfa2;
  border-radius: 10px;
  background: linear-gradient(180deg, #102a2c, #090d1b);
  text-align: center;
  box-shadow: 0 0 30px rgba(58, 226, 145, 0.28);
}

.pwa-install-title {
  color: #f3cf69;
  font-size: 21px;
  font-weight: bold;
  margin-bottom: 14px;
}

.pwa-install-text {
  color: #d8e8e1;
  font-size: 14px;
  line-height: 1.8;
}

.pwa-install-card button {
  margin-top: 20px;
  padding: 8px 30px;
  border: 1px solid #e2bd58;
  border-radius: 5px;
  background: #17483d;
  color: #fff1b3;
  font: inherit;
  cursor: pointer;
}

#title-version {
  margin-top: 24px;
  color: #a89c78;
  font-size: 11px;
  text-shadow: 0 1px 3px #000;
}

/* Unified menu: buttons and links share the same style */
#title-menu,
#title-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#title-links {
  flex-direction: column;
}

#title-menu button,
#title-links a,
#title-links button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 180px;
  padding: 10px 20px;
  background: rgba(5, 12, 18, 0.5);
  border: 1px solid rgba(216, 180, 95, 0.35);
  border-radius: 2px;
  color: #c8b888;
  font-size: 14px;
  letter-spacing: 3px;
  text-decoration: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  transition: all 0.25s;
  opacity: 0;
  animation: titleMenuIn 0.5s ease-out forwards;
}

/* Second-level entries: same shape as the main buttons, quieter palette */
#title-links a,
#title-links button {
  width: 180px;
  padding: 9px 20px;
  font-size: 13px;
  letter-spacing: 2px;
  background: rgba(5, 12, 18, 0.45);
  border-color: rgba(216, 180, 95, 0.28);
  color: #b3a381;
}

#title-links button {
  font-family: inherit;
}

/* 返回 is the quietest — outline-only feel */
#btn-extras-back {
  background: transparent;
  border-color: rgba(216, 180, 95, 0.18);
  color: #8f8266;
}

#title-menu button {
  font-family: inherit;
}

#title-menu button:nth-child(1) { animation-delay: 0.50s; }
#title-menu button:nth-child(2) { animation-delay: 0.62s; }
#title-menu button:nth-child(3) { animation-delay: 0.74s; }
#title-menu button:nth-child(4) { animation-delay: 0.86s; }

/* Second level staggers too; the delays re-run whenever the layer re-shows
   (JS restarts the animations on swap). */
#title-links > :nth-child(1) { animation-delay: 0.10s; }
#title-links > :nth-child(2) { animation-delay: 0.20s; }
#title-links > :nth-child(3) { animation-delay: 0.30s; }
#title-links > :nth-child(4) { animation-delay: 0.40s; }
#title-links > :nth-child(5) { animation-delay: 0.50s; }

#title-menu button:hover,
#title-links a:hover,
#title-links button:hover {
  background: linear-gradient(180deg, rgba(40, 60, 90, 0.8), rgba(20, 35, 60, 0.9));
  border-color: rgba(88, 214, 164, 0.6);
  color: #fff;
  box-shadow: 0 0 16px rgba(88, 214, 164, 0.2), 0 4px 12px rgba(0, 0, 0, 0.5);
}

.title-link-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25em;
  line-height: 1;
  opacity: 0.7;
}

@media (display-mode: standalone) {
  body {
    min-height: 100dvh;
    background: #000;
  }

  #mobile-toggle {
    display: none !important;
  }
}

/* Chapter title card */
#chapter-title-card {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #000;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 90;
  animation: fadeChapter 3.5s ease-in-out forwards;
}

#chapter-title-card.hidden { display: none; }

@keyframes fadeChapter {
  0% { opacity: 0; transform: scale(1.05); }
  15% { opacity: 1; transform: scale(1); }
  85% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}

#chapter-title-text {
  font-size: 32px;
  font-weight: bold;
  color: #ffc44d;
  margin-bottom: 12px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.9), 0 2px 2px #000;
  letter-spacing: 2px;
}

#chapter-title-sub {
  font-size: 18px;
  color: #f0f0f0;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9), 0 1px 2px #000;
  letter-spacing: 1px;
}

/* Story scenes — unified portrait, CG and live-map interludes */
.story-scene,
.story-map-ui {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  overflow: hidden;
  color: #f5f1e7;
  font-family: 'Noto Serif TC', 'Songti TC', 'PMingLiU', serif;
}

.story-scene {
  z-index: 270;
  cursor: pointer;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 22%, rgba(48, 64, 82, 0.54), transparent 44%),
    linear-gradient(155deg, #151f2c 0%, #080c14 65%, #020305 100%);
}

.story-scene::before {
  content: '';
  position: absolute;
  inset: -3%;
  z-index: 0;
  background-image: var(--story-background);
  background-position: center;
  background-size: cover;
  filter: saturate(0.72) brightness(0.62);
  transform: scale(1.04);
}

.story-scene--portrait::before {
  filter: blur(8px) saturate(0.48) brightness(0.34);
  transform: scale(1.075);
}

.story-scene--cg::before {
  filter: saturate(0.86) brightness(0.72);
}

.story-scene:not(.story-scene--has-background)::before {
  display: none;
}

.story-scene__shade {
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    linear-gradient(90deg, rgba(1, 4, 10, 0.72), transparent 31%, transparent 69%, rgba(1, 4, 10, 0.72)),
    linear-gradient(180deg, rgba(0, 0, 0, 0.28), transparent 42%, rgba(0, 0, 0, 0.82) 100%);
}

.story-scene--cg .story-scene__shade {
  background:
    radial-gradient(ellipse at center, transparent 35%, rgba(0, 0, 0, 0.45) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.12), transparent 45%, rgba(0, 0, 0, 0.84) 100%);
}

.story-scene__location,
.story-map-ui__location {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 24px 8px;
  border: 1px solid rgba(236, 204, 127, 0.7);
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(21, 39, 59, 0.94), rgba(5, 13, 25, 0.94));
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.58), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  color: #f4d98c;
  font-size: clamp(13px, 1.55vw, 21px);
  font-weight: 700;
  letter-spacing: 0.18em;
  white-space: nowrap;
  z-index: 4;
}

.story-scene__cast {
  position: absolute;
  inset: 8% 0 24%;
  pointer-events: none;
  z-index: 2;
}

.story-scene__actor {
  position: absolute;
  bottom: 0;
  width: min(38vw, 440px);
  height: min(69vh, 690px);
  opacity: 0.68;
  filter: saturate(0.7) brightness(0.62);
  transform: translateY(2%) scale(0.95);
  transform-origin: 50% 100%;
  transition: opacity 180ms ease, filter 180ms ease, transform 180ms ease;
}

.story-scene__actor--left { left: clamp(2%, 7vw, 10%); }
.story-scene__actor--right { right: clamp(2%, 7vw, 10%); }

.story-scene__actor img {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: auto;
  max-height: 100%;
  object-fit: contain;
  object-position: center bottom;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, rgba(0, 0, 0, 0.5) 8px, #000 16px);
  mask-image: linear-gradient(to bottom, transparent 0, rgba(0, 0, 0, 0.5) 8px, #000 16px);
  filter: drop-shadow(0 12px 13px rgba(0, 0, 0, 0.82));
}

.story-scene__actor--right img {
  transform: scaleX(-1);
}

.story-scene__actor.is-speaking {
  z-index: 2;
  opacity: 1;
  filter: saturate(1.03) brightness(1.05);
  transform: translateY(0) scale(1);
}

.story-scene__actor.is-muted {
  opacity: 0.48;
}

.story-scene__skip {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  min-width: 96px;
  min-height: 42px;
  padding: 7px 15px;
  border: 1px solid rgba(237, 211, 150, 0.68);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(34, 55, 78, 0.94), rgba(8, 18, 32, 0.96));
  color: #f6e4b4;
  font: 700 14px/1.2 'Noto Serif TC', 'Songti TC', 'PMingLiU', serif;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.45);
  z-index: 5;
}

.story-scene__skip:hover,
.story-scene__skip:focus-visible {
  color: #fff8d7;
  border-color: #ffe3a0;
  background: linear-gradient(180deg, rgba(54, 83, 112, 0.98), rgba(13, 30, 50, 0.98));
  outline: none;
}

.story-scene__dialogue {
  position: absolute;
  left: clamp(18px, 5vw, 86px);
  right: clamp(18px, 5vw, 86px);
  bottom: max(18px, env(safe-area-inset-bottom));
  min-height: clamp(112px, 21vh, 205px);
  box-sizing: border-box;
  padding: clamp(31px, 4.1vh, 47px) clamp(24px, 4vw, 60px) 25px;
  border: 2px solid #caa85c;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(25, 55, 88, 0.97), rgba(4, 14, 32, 0.98));
  box-shadow:
    inset 0 0 0 1px rgba(233, 244, 255, 0.18),
    inset 0 0 0 4px rgba(0, 3, 10, 0.48),
    0 9px 28px rgba(0, 0, 0, 0.62);
  z-index: 4;
}

.story-scene__speaker {
  position: absolute;
  top: -22px;
  left: clamp(18px, 3vw, 44px);
  min-width: 112px;
  padding: 7px 22px 8px;
  border: 1px solid #ffe3a0;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(180deg, #f0d68a, #a77b2e);
  color: #071426;
  font-size: clamp(15px, 1.55vw, 22px);
  font-weight: 900;
  letter-spacing: 0.12em;
  text-align: center;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.38);
  z-index: 2;
}

.story-scene__text {
  max-width: 1180px;
  font-size: clamp(17px, 2vw, 28px);
  line-height: 1.78;
  letter-spacing: 0.055em;
  text-shadow: 0 2px 4px #000;
}

.story-scene__next {
  position: absolute;
  right: 23px;
  bottom: 16px;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 10px solid #f2d477;
  filter: drop-shadow(0 0 5px rgba(255, 219, 121, 0.7));
  animation: dialogueNext 0.7s ease-in-out infinite alternate;
  transition: opacity 120ms ease;
}

.story-map-ui {
  z-index: 270;
  pointer-events: none !important;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.34), transparent 16%, transparent 75%, rgba(0, 0, 0, 0.35));
}

.story-map-ui .story-scene__skip {
  pointer-events: auto;
}

.story-scene-map-active #top-bar,
.story-scene-map-active #unit-panel,
.story-scene-map-active #action-menu,
.story-scene-map-active #combat-forecast,
.story-scene-map-active #terrain-info,
.story-scene-map-active #map-browse-hint,
.story-scene-map-active #end-turn-float-btn,
.story-scene-map-active #next-unit-float-btn,
.story-scene-map-active #ff-float-btn,
.story-scene-map-active #minimap-overlay {
  display: none !important;
}

.story-scene-map-active .map-unit__hp,
.story-scene-map-active .map-unit__boss,
.story-scene-map-active .map-unit__drop,
.story-scene-map-active #dom-cursor {
  display: none !important;
}

.story-scene-map-active #dialogue-box {
  z-index: 280;
}

.story-scene-active #mobile-toggle {
  display: none !important;
}

@media (max-width: 820px) {
  .story-scene__location,
  .story-map-ui__location {
    top: max(9px, env(safe-area-inset-top));
    padding: 5px 15px 6px;
    font-size: 12px;
  }

  .story-scene__skip {
    top: max(8px, env(safe-area-inset-top));
    right: max(9px, env(safe-area-inset-right));
    min-width: 88px;
    min-height: 38px;
    padding: 6px 11px;
    font-size: 12px;
  }

  .story-scene__cast {
    inset: 5% 0 29%;
  }

  .story-scene__actor {
    width: min(43vw, 310px);
    height: 62vh;
  }

  .story-scene__actor--left { left: -1%; }
  .story-scene__actor--right { right: -1%; }

  .story-scene__dialogue {
    left: 12px;
    right: 12px;
    bottom: max(8px, env(safe-area-inset-bottom));
    min-height: 100px;
    padding: 25px 18px 16px;
  }

  .story-scene__speaker {
    top: -17px;
    min-width: 88px;
    padding: 5px 14px;
    font-size: 13px;
  }

  .story-scene__text {
    font-size: clamp(14px, 3.5vw, 18px);
    line-height: 1.58;
  }
}

@media (max-height: 430px) and (orientation: landscape) {
  .story-scene__cast {
    inset: 2% 0 30%;
  }

  .story-scene__actor {
    width: min(29vw, 220px);
    height: 54vh;
  }

  .story-scene__dialogue {
    min-height: 92px;
    padding-top: 23px;
    padding-bottom: 12px;
  }

  .story-scene__text {
    font-size: clamp(13px, 2.2vw, 17px);
    line-height: 1.48;
  }
}

@media (prefers-reduced-motion: reduce) {
  .story-scene__actor,
  .story-scene__next {
    transition: none;
    animation: none;
  }
}

/* End turn button */
#btn-end-turn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  padding: 6px 16px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  z-index: 10;
}

#btn-end-turn.hidden { display: none; }
#btn-end-turn:hover { color: #fff; }

/* Battle scene transition: driven inline by UI._battleFxApply/Snap/Reset
   (CSS opacity/transform/filter transitions on #gameCanvas + #unit-layer). */

/* Damage popup */
.dmg-popup {
  position: absolute;
  font-size: 16px;
  font-weight: bold;
  color: #fff;
  text-shadow: 1px 1px 2px #000;
  pointer-events: none;
  z-index: 35;
  animation: dmgFloat 1s ease-out forwards;
}

@keyframes dmgFloat {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-30px); }
}

.dmg-crit { color: #ffd700; font-size: 20px; }
.dmg-miss { color: #888; font-style: italic; }
.dmg-heal { color: #4f4; }
.text-popup {
  z-index: 60;
  font-size: 18px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.65);
  white-space: nowrap;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 900px), (max-height: 600px), (hover: none) and (pointer: coarse) {
  body {
    width: 100vw;
    height: 100vh;
    min-height: 0;
    align-items: center;
    overflow: hidden;
    background: #000;
  }

  @supports (height: 100dvh) {
    body { height: 100dvh; }
  }

  #game-container {
    /* Keep the canvas and every DOM overlay inside one fitted 4:3 viewport.
       The previous full-screen container let the canvas letterbox by itself,
       so title/UI/unit layers stretched or overflowed independently. */
    width: min(100vw, 133.333vh);
    height: min(100vh, 75vw);
    max-width: 100vw;
    max-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  @supports (height: 100dvh) {
    #game-container {
      width: min(100vw, 133.333dvh);
      height: min(100dvh, 75vw);
      max-height: 100dvh;
    }
  }

  #gameCanvas {
    width: 100% !important;
    height: 100% !important;
    aspect-ratio: 4 / 3;
  }

  #ui-overlay,
  #unit-layer {
    width: 100%;
    height: 100%;
  }

  #title-logo {
    margin-bottom: clamp(16px, 4vh, 40px);
  }

  #title-menu {
    gap: 8px;
  }

  #title-menu button {
    padding: 10px 20px;
    font-size: clamp(14px, 2vh, 17px);
  }

  #top-bar {
    height: 44px;
    padding: 3px 6px;
    gap: 4px 7px;
    flex-wrap: wrap;
    align-content: center;
    font-size: 10px;
    line-height: 14px;
    overflow: hidden;
  }

  #chapter-name {
    flex: 1 1 145px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #turn-count,
  #phase-indicator {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  #phase-indicator {
    margin-left: 0;
  }

  #bgm-controls {
    flex: 0 0 auto;
    margin-left: auto !important;
    gap: 0 !important;
  }

  #bgm-controls > :not(#btn-mute-inner) {
    display: none !important;
  }

  #objective-display {
    order: 10;
    flex: 1 0 100%;
    width: 100%;
    min-width: 0;
    margin-left: 0 !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #unit-panel {
    top: 48px;
    right: 4px;
    max-height: calc(100% - 56px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .menu-open-hidden {
    display: none !important;
  }
}

@media (orientation: portrait) and (max-width: 600px) {
  #orientation-notice {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: max(24px, env(safe-area-inset-top))
             max(24px, env(safe-area-inset-right))
             max(24px, env(safe-area-inset-bottom))
             max(24px, env(safe-area-inset-left));
    background:
      radial-gradient(circle at 50% 42%, rgba(26, 104, 79, 0.38), transparent 42%),
      rgba(2, 6, 15, 0.97);
    color: #f5dda0;
    text-align: center;
  }

  .orientation-icon {
    color: #76e5ad;
    font-size: 58px;
    line-height: 1;
    text-shadow: 0 0 18px rgba(81, 230, 157, 0.55);
  }

  .orientation-title {
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 2px;
  }

  .orientation-text {
    color: #c5d8d2;
    font-size: 14px;
    line-height: 1.7;
  }
}

/* Larger touch targets for menus */
.menu-item {
  padding: 10px 20px;
  font-size: 16px;
  min-height: 40px;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#action-menu {
  min-width: 130px;
  border-radius: 6px;
  overflow: hidden;
}

/* Prevent text selection on touch */
#game-container {
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* Larger end turn button on mobile */
@media (max-width: 820px) {
  #btn-end-turn {
    padding: 10px 20px;
    font-size: 16px;
    bottom: 12px;
    right: 12px;
  }

  #unit-panel {
    width: 160px;
    font-size: 10px;
    top: 48px;
    right: 4px;
    padding: 6px;
  }

  #dialogue-box {
    height: 100px;
    padding: 8px 12px;
  }

  /* Smaller bust on phones so it does not swallow the 100px box */
  #portrait-canvas {
    width: 84px;
    height: 84px;
    margin-top: -26px;
  }

  #dialogue-name { top: -30px; left: 20px; font-size: 12px; }

  #dialogue-text { font-size: 13px; }

  #top-bar { font-size: 10px; height: 44px; }

  .forecast-header { font-size: 13px; }
  #combat-forecast { font-size: 11px; min-width: 280px; padding: 10px 14px; }

  #title-menu button { min-height: 42px; }
}

/* Phone landscape: the 4:3 game container is narrow (~520px wide), so the
   links leave the bottom-right corner and join the main column instead. */
@media (max-height: 500px) and (orientation: landscape) {
  #title-content {
    padding-top: 4vh;
    padding-left: calc(6vw + env(safe-area-inset-left));
  }

  #title-logo {
    width: min(220px, 42%);
    margin-bottom: 2.5vh;
  }

  #title-menu,
  #title-links {
    gap: 5px;
  }

  #title-menu button {
    width: 160px;
    min-height: 34px;
    padding: 4px 14px;
    font-size: 13px;
    letter-spacing: 2px;
  }

  #title-links a,
  #title-links button {
    width: 160px;
    min-height: 30px;
    font-size: 11px;
    letter-spacing: 1px;
    padding: 4px 14px;
  }

  #title-version {
    margin-top: 8px;
    font-size: 10px;
  }
}

/* Extremely short landscape (older phones): squeeze harder */
@media (max-height: 360px) and (orientation: landscape) {
  #title-content {
    padding-top: 3vh;
    padding-left: calc(5vw + env(safe-area-inset-left));
  }

  #title-logo {
    width: min(180px, 36%);
    margin-bottom: 1.5vh;
  }

  #title-menu {
    gap: 4px;
  }

  #title-menu button {
    width: 150px;
    min-height: 30px;
    padding: 3px 12px;
    font-size: 12px;
  }

  #title-links {
    gap: 4px;
  }

  #title-links a,
  #title-links button {
    width: 150px;
    font-size: 10px;
    min-height: 26px;
    padding: 3px 12px;
  }

  #title-version {
    margin-top: 6px;
  }
}

/* Desktop fullscreen is handled by JavaScript */
/* Mobile fullscreen styles below */

@media (max-width: 900px), (max-height: 600px), (hover: none) and (pointer: coarse) {
  body { margin: 0; padding: 0; overflow: hidden; }
  #gameCanvas { display: block; }
}


/* Mobile landscape: compact map menu */
@media (max-height: 500px) and (orientation: landscape) {
  #camp-header {
    padding: 4px 10px !important;
    gap: 8px !important;
  }

  #camp-body {
    padding: 6px 10px !important;
  }

  #camp-roster {
    flex-wrap: nowrap;
    justify-content: center;
    gap: 3px;
    overflow: visible;
    margin-bottom: 6px;
  }

  .camp-chip {
    flex: 0 0 42px;
    width: 42px;
    padding: 3px 1px;
  }

  .camp-chip img {
    width: 24px;
    height: 24px;
  }

  .camp-chip__name {
    font-size: 8px;
    white-space: nowrap;
  }

  .camp-chip__sub {
    display: none;
  }

  #camp-menu {
    gap: 4px !important;
    padding: 4px 6px !important;
    flex-wrap: nowrap !important;
  }

  #camp-menu .fe-button {
    padding: 5px 10px !important;
    font-size: 11px !important;
  }

  #map-menu-box {
    padding: 12px 20px !important;
    min-width: 200px !important;
  }
  #map-menu-box > div:first-child {
    font-size: 16px !important;
    margin-bottom: 10px !important;
  }
  #map-menu-items > div {
    padding: 6px 10px !important;
    margin: 3px 0 !important;
  }
  #map-menu-items > div > div {
    font-size: 10px !important;
  }
}

/* ===== DOM Unit Layer ===== */
#unit-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

#unit-world {
  position: absolute;
  top: 0; left: 0;
  will-change: transform;
}

/* Unit sprite element */
.map-unit {
  position: absolute;
  pointer-events: none;
}

.map-unit__sprite {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-repeat: no-repeat;
  image-rendering: auto;
  transform-origin: center center;
}

.map-unit__sprite--flip {
  transform: scaleX(-1);
}

/* Acted units become visibly inactive, but their ring and HUD stay legible. */
.map-unit--grayed .map-unit__sprite {
  filter: grayscale(92%) brightness(0.68);
  opacity: 0.88;
}

/* Faction ring — deliberately separate from the artwork so character colours
   remain authored rather than globally hue-shifted. */
.map-unit__faction-ring {
  position: absolute;
  z-index: 0;
  left: 50%;
  /* The authored sprite box is bottom-anchored at the unit's foot point.
     Keep the ellipse close to that baseline instead of around the ankles. */
  bottom: -5px;
  width: var(--faction-ring-width, 42px);
  height: var(--faction-ring-height, 12px);
  box-sizing: border-box;
  transform: translateX(-50%);
  border: 3px solid #76b8ff;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(40, 105, 255, 0.12) 0 35%, rgba(32, 110, 255, 0.82) 48% 67%, rgba(8, 40, 130, 0.22) 72% 100%);
  box-shadow: 0 0 7px #257fff, inset 0 0 4px rgba(225, 242, 255, 0.72);
}
.map-unit--enemy .map-unit__faction-ring {
  border-color: #ff8a75;
  background: radial-gradient(ellipse, rgba(255, 65, 45, 0.12) 0 35%, rgba(220, 45, 35, 0.84) 48% 67%, rgba(111, 8, 16, 0.22) 72% 100%);
  box-shadow: 0 0 7px #ed362d, inset 0 0 4px rgba(255, 225, 215, 0.72);
}
.map-unit--ally .map-unit__faction-ring {
  border-color: #8df0a7;
  background: radial-gradient(ellipse, rgba(55, 220, 100, 0.12) 0 35%, rgba(35, 175, 82, 0.82) 48% 67%, rgba(8, 89, 35, 0.22) 72% 100%);
  box-shadow: 0 0 7px #31cf69, inset 0 0 4px rgba(226, 255, 232, 0.72);
}
.map-unit--boss .map-unit__faction-ring {
  border-color: #ffe06b;
  box-shadow:
    0 0 0 3px rgba(136, 22, 20, 0.9),
    0 0 11px #ffc83d,
    inset 0 0 4px rgba(255, 239, 178, 0.7);
}
.map-unit--selected .map-unit__faction-ring {
  animation: faction-ring-selected 0.72s ease-in-out infinite alternate;
}
.map-unit--grayed .map-unit__faction-ring {
  opacity: 0.5;
  filter: saturate(0.68) brightness(0.8);
  box-shadow: none;
}
@keyframes faction-ring-selected {
  from { transform: translateX(-50%) scale(0.94); filter: brightness(0.92); }
  to { transform: translateX(-50%) scale(1.08); filter: brightness(1.38); }
}

/* HP bar — matches canvas: 26×3 @ (x+3,y+30) in 32px space → 52×6 in 64px tile */
.map-unit__hp {
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 52px;
  height: 6px;
  background: rgba(0, 0, 0, 0.82);
  border: 1px solid rgba(0, 0, 0, 0.65);
  border-radius: 3px;
  overflow: hidden;
  z-index: 2;
}
.map-unit__hp-fill {
  height: 2px;
  margin-top: 1px;
  margin-left: 1px;
  border-radius: 1px;
  background: linear-gradient(180deg, #6fe3a0, #35a862);
}
.map-unit__hp-fill--med { background: linear-gradient(180deg, #ecd95e, #b39b2a); }
.map-unit__hp-fill--low {
  background: linear-gradient(180deg, #ef7d6a, #b3402f);
  animation: hp-low-pulse 0.7s ease-in-out infinite alternate;
}
@keyframes hp-low-pulse {
  from { filter: brightness(0.82); }
  to   { filter: brightness(1.28); }
}

/* Boss indicator */
.map-unit__boss {
  position: absolute;
  z-index: 3;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 2px;
  background: #fc0;
}

/* Enemy loot marker. */
.map-unit__drop {
  position: absolute;
  top: -13px;
  right: 2px;
  width: 9px;
  height: 9px;
  box-sizing: border-box;
  background: #50e878;
  border: 1px solid #d8ffe0;
  transform: rotate(45deg);
  box-shadow: 0 0 5px #38ff6b, 0 1px 2px #000;
  z-index: 4;
  animation: drop-marker-pulse 0.9s ease-in-out infinite alternate;
}
.map-unit--enemy .map-unit__drop {
  filter: none;
}
@keyframes drop-marker-pulse {
  from { opacity: 0.72; }
  to { opacity: 1; box-shadow: 0 0 9px #38ff6b, 0 1px 2px #000; }
}

/* ===== DOM Cursor ===== */
#dom-cursor {
  position: absolute;
  width: 64px;
  height: 64px;
  pointer-events: none;
  box-sizing: border-box;
  border: 3px solid rgba(255,255,0,0.7);
  z-index: 100;
  display: none;
  animation: cursor-pulse 0.5s ease-in-out infinite alternate;
}

@keyframes cursor-pulse {
  0% { border-color: rgba(255,255,255,0.6); }
  100% { border-color: rgba(255,255,255,1.0); }
}

/* Corner accents */
.cursor-corner {
  position: absolute;
  width: 6px;
  height: 6px;
  pointer-events: none;
}
.cursor-tl {
  top: -1px; left: -1px;
  border-top: 3px solid rgba(255,255,0,0.9);
  border-left: 3px solid rgba(255,255,0,0.9);
  animation: cursor-nudge-tl 0.9s ease-in-out infinite alternate;
}
.cursor-tr {
  top: -1px; right: -1px;
  border-top: 3px solid rgba(255,255,0,0.9);
  border-right: 3px solid rgba(255,255,0,0.9);
  animation: cursor-nudge-tr 0.9s ease-in-out infinite alternate;
}
.cursor-bl {
  bottom: -1px; left: -1px;
  border-bottom: 3px solid rgba(255,255,0,0.9);
  border-left: 3px solid rgba(255,255,0,0.9);
  animation: cursor-nudge-bl 0.9s ease-in-out infinite alternate;
}
.cursor-br {
  bottom: -1px; right: -1px;
  border-bottom: 3px solid rgba(255,255,0,0.9);
  border-right: 3px solid rgba(255,255,0,0.9);
  animation: cursor-nudge-br 0.9s ease-in-out infinite alternate;
}

@keyframes cursor-nudge-tl { from { transform: translate(0, 0); } to { transform: translate(-2px, -2px); } }
@keyframes cursor-nudge-tr { from { transform: translate(0, 0); } to { transform: translate(2px, -2px); } }
@keyframes cursor-nudge-bl { from { transform: translate(0, 0); } to { transform: translate(-2px, 2px); } }
@keyframes cursor-nudge-br { from { transform: translate(0, 0); } to { transform: translate(2px, 2px); } }

/* Unit layer sizing is synced to canvas via JS in UnitLayer.update() */

/* ===== 視野解鎖: proportional UI-chrome scaling on large desktop viewports =====
   --ui-scale is set by main.js resizeGameCanvas() on #game-container
   (1 at 800×600 → 1.75 at 1920×1080). It stays 1 on mobile/touch, so every
   rule below is an identity there and all media queries above are untouched.

   Two techniques, chosen by how each piece is positioned:
   - zoom: only on chrome whose position is CSS-driven (absolute corner/edge
     anchors, or flex-centred overlay panels). Zoom scales the box around its
     anchor and never reflows the canvas (all of these are out-of-flow).
   - calc(... * var(--ui-scale)): for JS-anchored pieces (action menu, damage
     popups) whose left/top are set in container px from game code — zooming
     them would multiply their anchors away from the unit, so only their
     fonts and box metrics grow. */

/* Zoom group — CSS-anchored chrome */
#top-bar,
#dialogue-box,
#unit-panel,
#combat-forecast,
#phase-banner,
#level-up-screen,
#item-get-screen,
#chapter-title-card,
#terrain-info,
#map-browse-hint,
#exp-gain-overlay,
#map-menu-msg,
#end-turn-float-btn,
#next-unit-float-btn,
#ff-float-btn,
#map-menu-overlay,
#settings-overlay,
#confirm-overlay,
#unit-list-overlay,
#trade-overlay,
#status-screen,
#victory-overlay,
#gameover-overlay,
#ending-overlay,
#camp-overlay,
#promo-showcase {
  zoom: var(--ui-scale);
}
/* NOTE: #minimap-overlay is deliberately NOT zoomed — its click-to-jump
   handler divides client px by the tile scale, which zoom would desync. */

/* calc group — JS-anchored chrome (positions stay in container px) */
#action-menu {
  font-size: calc(14px * var(--ui-scale));
  min-width: calc(130px * var(--ui-scale));
}

.menu-item {
  padding: calc(10px * var(--ui-scale)) calc(20px * var(--ui-scale));
  font-size: calc(16px * var(--ui-scale));
  min-height: calc(40px * var(--ui-scale));
}

#action-menu .menu-icon {
  width: calc(22px * var(--ui-scale));
  font-size: calc(15px * var(--ui-scale));
}

#action-menu .menu-desc {
  font-size: calc(10px * var(--ui-scale));
}

#action-menu.rich-menu .menu-item {
  gap: calc(8px * var(--ui-scale));
  padding-top: calc(5px * var(--ui-scale));
  padding-bottom: calc(5px * var(--ui-scale));
}

.dmg-popup {
  font-size: calc(16px * var(--ui-scale));
}

.dmg-popup.dmg-crit {
  font-size: calc(20px * var(--ui-scale));
}

.dmg-popup.text-popup {
  font-size: calc(18px * var(--ui-scale));
  padding: calc(2px * var(--ui-scale)) calc(6px * var(--ui-scale));
}
