:root {
  color-scheme: dark;
  --bg: #1e2217;
  --shell: #2a2f22;
  --shell-line: #525941;
  --text: #efe9d2;
  --soft: #b8bca0;
  --accent: #e7be70;

  /* GBA 原版游戏内绿竹框 & 米绿底色 */
  --gba-bg: #e6f1cb;
  --gba-bg-soft: #d7e6b7;
  --gba-border: #689443;
  --gba-border-dark: #375724;
  --gba-border-gold: #c9c76c;
  --gba-ink: #273720;
  --gba-blue: #2d42c8;
  --gba-red: #cc2b2b;
  --gba-gray: #8b957d;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #2a3021 0%, var(--bg) 70%);
  color: var(--text);
  font: 15px/1.5 "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  user-select: none;
}

button, input { font: inherit; }
[hidden] { display: none !important; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px max(20px, calc((100% - 1020px) / 2));
  background: #24291d;
  border-bottom: 1px solid var(--shell-line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: .5px;
}

.brand .badge {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--accent);
  color: #222616;
  font-weight: 900;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.toolbar-playback {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toolbar button {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--shell-line);
  background: #363c2c;
  color: var(--text);
  cursor: pointer;
}

.toolbar button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #222616;
  font-weight: 700;
}

.volume-control, .speed-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border: 1px solid var(--shell-line);
  border-radius: 6px;
  background: #2c3123;
}

.volume-control input[type="range"] {
  width: 84px;
  accent-color: var(--accent);
  cursor: pointer;
}

.volume-control span, .speed-group span {
  font-size: 13px;
  color: var(--soft);
}

.shell {
  width: min(1020px, calc(100% - 24px));
  margin: 18px auto 32px;
}

.handheld-frame {
  background: var(--shell);
  border: 1px solid var(--shell-line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.45);
}

.stage-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  background: #141a0e;
  border: 3px solid #12160d;
  border-radius: 8px;
  overflow: hidden;
  container-type: inline-size;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.ui-layer, .modal-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ui-layer > *, .modal-layer > * {
  pointer-events: auto;
}

.modal-layer {
  background: rgba(16, 22, 12, 0.65);
  display: grid;
  place-items: center;
  z-index: 50;
}

/* ===== GBA 原版绿竹边框面板 ===== */
.gba-panel {
  background: var(--gba-bg);
  color: var(--gba-ink);
  border: 3px solid var(--gba-border);
  box-shadow:
    inset 0 0 0 2px var(--gba-border-gold),
    0 0 0 2px var(--gba-border-dark),
    3px 4px 0 rgba(0, 0, 0, 0.35);
  font-weight: 700;
  font-size: clamp(12px, 2.2cqw, 20px);
  line-height: 1.45;
}

.gba-panel-title {
  background: linear-gradient(180deg, #eff6da 0%, #dceab9 100%);
  padding: 0.45em 0.9em;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.gba-panel button {
  color: var(--gba-ink);
  font-weight: 800;
}

.txt-blue { color: var(--gba-blue); }
.txt-red { color: var(--gba-red); }
.txt-gray { color: var(--gba-gray); }

.gba-menu {
  display: flex;
  flex-direction: column;
  padding: 0.35em 0.45em;
  gap: 0.15em;
  min-width: 10em;
}

.gba-menu-item {
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.25em 0.6em;
  border: 0;
  background: transparent;
  color: var(--gba-ink);
  text-align: left;
  cursor: pointer;
  border-radius: 2px;
}

.gba-menu-item:hover:not(:disabled),
.gba-menu-item.active {
  background: rgba(104, 148, 67, 0.22);
}

.gba-menu-item.active::before {
  content: "▶";
  color: var(--gba-ink);
  font-size: 0.8em;
}

.gba-menu-item:not(.active)::before {
  content: "";
  width: 0.8em;
  display: inline-block;
}

.gba-menu-item:disabled {
  color: var(--gba-gray);
  cursor: not-allowed;
}

.title-screen {
  position:absolute;
  inset:0;
  width:100%;
  border:0;
  padding:0;
  color:#fff1d0;
  overflow:hidden;
  background:
    linear-gradient(105deg,#121c2c 0%,#162539 38%,#16253940 70%),
    radial-gradient(ellipse at 75% 40%,#b96236 0%,#583d3d 45%,#161d2a 80%);
}
.title-cover { cursor:pointer; text-align:left; }
.title-logo {
  position:absolute;
  z-index:2;
  left:6%;
  top:12%;
  width:48%;
  max-height:42%;
  object-fit:contain;
  object-position:left center;
  image-rendering:pixelated;
  filter:drop-shadow(0 3px 12px #080d18b0);
}
.title-character-gallery {
  position:absolute;
  inset:3% 2.5% 0 41%;
  pointer-events:none;
}
.title-character {
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  object-fit:contain;
  object-position:right bottom;
  image-rendering:pixelated;
  filter:drop-shadow(-6px 7px 8px #111827a8);
  opacity:0;
  transform:translateX(2%);
  transition:opacity .54s ease,transform .58s ease;
}
.title-character[data-current="true"] { opacity:1; transform:translateX(0); }
.title-footer {
  position:absolute;
  z-index:2;
  left:7%;
  bottom:4%;
  width:clamp(105px,27cqw,230px);
  height:auto;
}
.title-prompt {
  position:absolute;
  z-index:2;
  left:7%;
  top:61%;
  display:grid;
  gap:.25em;
  color:#f9eedb;
  font-size:clamp(9px,1.7cqw,15px);
}
.title-prompt strong { color:#ffd183; font-size:clamp(16px,4.2cqw,34px); }
.title-screen--menu .title-logo { top:4%; width:40%; height:29%; }
.title-menu {
  position:absolute;
  z-index:2;
  top:34%;
  left:7%;
  max-height:55%;
  min-width:min(38%,13em);
  overflow:auto;
  font-size:clamp(10px,2.2cqw,19px);
}
.title-demo {
  position:absolute;
  inset:0;
  width:100%;
  border:0;
  padding:0;
  background:none;
  cursor:pointer;
}
.title-demo span { position:absolute; right:3%; bottom:1%; color:#fff2d9; font-size:clamp(8px,1.25cqw,12px); }
@media (prefers-reduced-motion:reduce) { .title-character { transition:none; } }

.character-profile {
  min-height:0;
  min-width:0;
  display:flex;
  align-items:center;
  gap:clamp(8px,2cqw,20px);
  padding:clamp(8px,1.7cqw,16px);
  overflow:auto;
}
.party-profile { flex:1; }
.party-profile-data {
  flex:1;
  min-width:0;
  display:flex;
  align-items:center;
  gap:clamp(8px,2cqw,18px);
}
.party-profile-stats { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:.35em .7em; }
.profile-portrait {
  display:block;
  flex:none;
  width:clamp(42px,12cqw,96px);
  height:clamp(42px,12cqw,96px);
  object-fit:contain;
}
.profile-portrait--sprite {
  width:clamp(21px,6cqw,48px);
  background-size:900% 100%;
  background-repeat:no-repeat;
  image-rendering:pixelated;
}
.profile-art {
  flex:none;
  width:33%;
  height:100%;
  min-height:0;
  object-fit:contain;
  object-position:right bottom;
  filter:drop-shadow(1px 3px 2px #37472242);
}
.dex-profile { align-items:flex-start; }
.dex-profile-data { flex:1; min-width:0; display:grid; gap:.5em; }
.dex-profile-heading { display:flex; align-items:center; gap:clamp(6px,1.4cqw,12px); }
.dex-profile .profile-portrait { width:clamp(36px,10cqw,80px); height:clamp(36px,10cqw,80px); }
.dex-profile .profile-portrait--sprite { width:clamp(18px,5cqw,40px); }
.dex-profile .profile-art { width:43%; object-position:right center; }
.dex-profile .profile-art--cutin {
  width:46%;
  height:auto;
  max-height:76%;
  align-self:flex-end;
  object-position:right bottom;
  image-rendering:pixelated;
}
.dex-profile .profile-art--unit {
  width:clamp(56px,15cqw,112px);
  height:auto;
  max-height:74%;
  align-self:flex-end;
  margin-inline-start:auto;
  object-position:center bottom;
  image-rendering:pixelated;
}
.dex-profile .profile-art--sprite {
  width:clamp(44px,11cqw,88px);
  height:auto;
  aspect-ratio:1/2;
  align-self:flex-end;
  margin-inline-start:auto;
  background-repeat:no-repeat;
  background-size:900% 100%;
  background-position:0 0;
  image-rendering:pixelated;
}
@container (max-width:460px) {
  .party-profile-data { align-items:flex-start; flex-direction:column; }
  .title-menu .gba-menu-item { padding-block:.15em; }
  .dex-profile { position:relative; display:block; }
  .dex-profile:has(.profile-art) .dex-profile-heading { padding-inline-end:28%; }
  .dex-profile .profile-art { position:absolute; right:3%; top:5px; width:25%; height:auto; }
  .dex-profile .profile-art--cutin { top:auto; bottom:6px; width:44%; }
  .dex-profile .profile-art--sprite { width:34px; }
}

/* ===== 卷轴对话框 ===== */
.scroll-dialog {
  position: absolute;
  left: 2.5%;
  right: 2.5%;
  bottom: 3%;
  min-height: 28%;
  padding: 0.7em 1.1em;
  background: linear-gradient(180deg, #f3f7df 0%, #e1ecc2 100%);
  border-top: 4px solid var(--gba-border);
  border-bottom: 4px solid var(--gba-border);
  border-left: 8px solid #d4b84d;
  border-right: 8px solid #d4b84d;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  color: var(--gba-ink);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
}

.scroll-speaker {
  color: var(--gba-blue);
  font-size: clamp(13px, 2.3cqw, 21px);
  font-weight: 800;
  margin-bottom: 0.2em;
}

.story-copy { display:flex; flex:1; min-width:0; flex-direction:column; }
.scroll-dialog.has-portrait {
  display:grid;
  grid-template-columns:clamp(43px,15cqw,130px) minmax(0,1fr);
  gap:clamp(7px,1.5cqw,15px);
}
.story-portrait {
  width:100%;
  height:clamp(43px,15cqw,130px);
  align-self:center;
  object-fit:contain;
}
.exam-panorama {
  display:block;
  width:100%;
  height:clamp(52px,14cqw,138px);
  object-fit:cover;
  object-position:center;
  image-rendering:pixelated;
}

.scroll-text {
  font-size: clamp(13px, 2.2cqw, 20px);
  font-weight: 700;
  line-height: 1.5;
  flex: 1;
}

.story-controls {
  position: absolute;
  top: 2.5%;
  right: 2.5%;
  display: flex;
  gap: 6px;
}

.story-controls button {
  padding: 0.3em 0.75em;
  font-size: clamp(11px, 1.6cqw, 14px);
  font-weight: 700;
  color: var(--gba-ink);
  background: var(--gba-bg);
  border: 2px solid var(--gba-border);
  border-radius: 4px;
  cursor: pointer;
}

.story-controls button.on {
  background: var(--accent);
  border-color: #8c6a1f;
}

/* ===== 技能标签圆标（忍 / 体 / 攻 / 移 / 连 / 技 / 具） ===== */
.tag-pill {
  display: inline-grid;
  place-items: center;
  width: 1.45em;
  height: 1.45em;
  border-radius: 50%;
  font-size: 0.85em;
  font-weight: 900;
  border: 1.5px solid #2b3422;
  margin-left: 2px;
}
.tag-white { background: #eef1e6; color: #222; }
.tag-yellow { background: #f2cf3d; color: #222; }
.tag-red { background: #e84e2b; color: #1a0b06; }

/* ===== 底部操作提示 ===== */
.controls-hint {
  margin-top: 10px;
  font-size: 13px;
  color: var(--soft);
  text-align: center;
}

.touch-controls { display: none; }

.battle-command-bar {
  position: absolute;
  top: 2%;
  right: 2.5%;
  display: flex;
  gap: 6px;
  pointer-events: auto;
}

.battle-command-hint {
  padding: 2px 10px;
  font-size: clamp(11px, 1.6cqw, 14px);
}

.stage-viewport .gba-panel, .stage-viewport .scroll-dialog { color-scheme: light; }
.stage-viewport .txt-gray { color: #526146; }
.stage-viewport :focus-visible { outline: 3px solid #a54d18; outline-offset: -3px; }
.facing-controls { display:flex; flex-wrap:wrap; gap:.35em; justify-content:center; }
.facing-arrow[aria-pressed=true], .hub-regions button[aria-pressed=true] {
  background:#ffda73; border-color:#945615; color:#262016;
}
.hub-node[aria-current=true] { outline:2px solid #ffda73; outline-offset:1px; }
.hub-regions { position:absolute; bottom:3%; left:2.5%; display:flex; gap:.25em; padding:.25em; }
.illusion-note { font-size:.85em; padding:.2em .6em; }
.tactics-panel { width:min(80%,32rem); max-height:85%; overflow:auto; padding:1em; }
.tactics-panel h3 { margin:0 0 .5em; }
.tactics-panel button { width:100%; }
.round-story { position:absolute; inset:0; pointer-events:auto; }
.round-story canvas { width:100%; height:100%; image-rendering:pixelated; }
.modal-layer:not([hidden]) { pointer-events:auto; }


.story-choice-menu { max-height:35cqh; overflow:auto; margin-top:.4em; }
.story-choice-menu button { width:100%; }
.terrain-hud { position:absolute; bottom:19%; left:2.5%; padding:.18em .55em; font-size:clamp(10px,1.62cqw,14px); }
.catalog-screen {
  position:absolute; inset:0; background:#1d3018; padding:clamp(6px,2cqw,15px);
  display:flex; flex-direction:column; gap:.5em;
}
.catalog-tabs { display:flex; gap:.35em; flex-wrap:wrap; }
.catalog-active { font-weight:bold; background:#f5d879; }
.catalog-totals { display:flex; justify-content:space-between; align-items:center; padding:.3em .7em; }
.catalog-scroll { flex:1; min-height:0; overflow:auto; }
.collection-grid {
  display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,10em),1fr));
  grid-auto-rows:minmax(3.5em,max-content); align-content:start; gap:.5em; padding:3px;
}
.collection-card { padding:.5em .65em; display:flex; flex-direction:column; justify-content:space-between; gap:.3em; }
.collection-card small { align-self:flex-end; }
.collection-empty { grid-column:1 / -1; margin:0; padding:.5em .65em; }

.skill-stage { position:absolute; inset:0; background:#080d0e; }
.skill-stage canvas { display:block; width:100%; height:100%; image-rendering:pixelated; }
.skill-stage-cue { position:absolute; right:2%; bottom:1%; color:#e0ecc9; font-size:clamp(8px,1.5cqw,13px); }
.skill-stage-only { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap; }
.battle-open,.battle-turn { position:absolute; top:47%; left:50%; transform:translate(-50%,-50%); pointer-events:none; }
.battle-open {
  font: bold clamp(56px,20cqw,140px)/1.15 "KaiTi","STKaiti",serif;
  color:#10100f; -webkit-text-stroke:3px white; paint-order:stroke fill;
}
.battle-open canvas:not([hidden]) {
  display:block;
  width:clamp(128px,52cqw,384px);
  height:auto;
  image-rendering:pixelated;
}
.battle-turn {
  padding:.55em 1.6em; min-width:46%; text-align:center; 
  display:grid; gap:.2em; font-size:clamp(12px,3.25cqw,26px);
}
.facing-banner {
  position:absolute; bottom:2.3%; left:2%; right:2%;
  display:flex; justify-content:center; align-items:center; flex-wrap:wrap;
  gap:.45em .75em; padding:.5em;
}
.facing-defense {
  flex-basis:100%; display:flex; flex-wrap:wrap; justify-content:center;
  gap:.25em 1em; border:1px solid var(--gba-border); padding:.25em .45em;
}
.facing-defense label { cursor:pointer; white-space:nowrap; }
.clone-swap {
  position:absolute; z-index:1; top:18%; left:50%; transform:translateX(-50%);
  text-align:center; padding:.65em .8em; width:max-content; max-width:90%;
}
.clone-swap-controls { display:flex; gap:.4em; justify-content:center; margin-top:.5em; }
.clone-swap-controls button { min-width:3em; text-align:center; }
.briefing-map {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: .4em;
  padding: .55em;
  background: #192412;
  font-size: clamp(10px, 2.3cqw, 17px);
}
.briefing-map-board {
  container-type: size;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
  background: #18231a;
}
#briefing-map-canvas {
  display: block;
  width: min(100cqw, calc(100cqh * var(--map-ratio)));
  height: auto;
  image-rendering: pixelated;
  cursor: crosshair;
}
#briefing-map-canvas:focus-visible { outline: 2px solid #e9e1ac; outline-offset: -2px; }
.briefing-map-info { display: grid; gap: .2em; min-height: 2.6em; padding: .3em .55em; }
.briefing-map-info span { max-height: 2.5em; overflow: auto; }

.briefing-heading {
  padding: 8px 14px;
  text-align: center;
}

.briefing-heading span {
  font-size: clamp(18px, 3.4cqw, 30px);
  letter-spacing: 1px;
}

.briefing-copy {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: clamp(15px, 2.7cqw, 24px);
  line-height: 1.55;
}

@container (max-width: 460px) {
  .title-menu {
    top: 30%;
    max-height: 66%;
    min-width: 42%;
    font-size: clamp(12px, 3.3cqw, 15px);
  }

  .title-menu .gba-menu-item { min-height: 26px; }
  .scroll-dialog { max-height: 78%; overflow-y: auto; }
  .briefing-heading { padding: 4px 8px; }
  .briefing-heading span { font-size: clamp(16px, 4cqw, 19px); }
  .briefing-copy { padding: 6px 9px; font-size: clamp(13px, 3.35cqw, 15px); }

  .battle-command-bar { left: 2.5%; justify-content: flex-end; align-items: stretch; gap: 4px; }
  .battle-command-bar button { white-space: nowrap; }
  .battle-command-hint { min-width: 0; padding-inline: 5px; }
}

@media (max-width: 600px), (any-pointer: coarse) and (orientation: landscape) and (max-height: 560px) {
  body {
    min-height: 100dvh;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  .topbar {
    gap: 5px 8px;
    padding: calc(6px + env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left));
  }

  .brand { gap: 6px; font-size: 13px; }
  .brand .badge { flex: none; width: 23px; height: 23px; }
  .toolbar, .toolbar-playback { gap: 4px; }
  .toolbar button { min-height: 34px; padding: 2px 6px; font-size: 13px; }
  .volume-control, .speed-group { gap: 3px; padding: 0 3px; }
  .volume-control input[type="range"] { width: clamp(40px, 12vw, 72px); }
  .volume-control span { min-width: 3ch; font-size: 11px; }
  .speed-group > span { display: none; }

  .shell {
    width: auto;
    margin: 6px max(6px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom))
      max(6px, env(safe-area-inset-left));
  }

  .handheld-frame { padding: 3px; border-radius: 9px; }
  .stage-viewport { border-width: 2px; }
}

@media (any-pointer: coarse) {
  .controls-hint { display: none; }
  #game-canvas { touch-action: none; }
  .title-prompt > span { display: none; }

  .touch-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    padding: 7px 4px 4px;
  }

  .touch-directions {
    display: grid;
    grid: repeat(2, 44px) / repeat(3, 44px);
    gap: 4px;
  }

  .touch-directions button:first-child { grid-column: 2; }
  .touch-directions button:nth-child(2) { grid-row: 2; grid-column: 1; }
  .touch-directions button:nth-child(3) { grid-row: 2; grid-column: 2; }
  .touch-directions button:nth-child(4) { grid-row: 2; grid-column: 3; }
  .touch-actions { display: flex; gap: 6px; }

  .touch-controls button {
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 1px solid #77805f;
    border-radius: 8px;
    background: #3b4330;
    color: var(--text);
    font-size: 18px;
    font-weight: 700;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .touch-actions button { min-width: 58px; font-size: 14px; }
  .touch-actions button:last-child { background: var(--accent); color: #222616; }
  .touch-controls button:active { filter: brightness(.8); }
  .touch-controls button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
}

@media (any-pointer: coarse) and (orientation: landscape) and (max-height: 560px) {
  .topbar { flex-wrap: nowrap; }
  .brand { min-width: 0; white-space: nowrap; }
  .brand > span:last-child { overflow: hidden; text-overflow: ellipsis; }
  .toolbar { flex: none; }
  .handheld-frame {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 5px;
  }

  .stage-viewport {
    grid-column: 2;
    grid-row: 1;
    justify-self: center;
    width: min(100%, calc((100dvh - 68px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 1.5));
  }

  .touch-controls { display: contents; }
  .touch-directions { grid-area: 1 / 1; }
  .touch-actions { grid-area: 1 / 3; flex-direction: column; }
}
