/* Shared arcade framing and controls for Story and the Campaign Shop. */
.tactics-card {
  --card-surface: #17263a;
  --card-header: #245166;
  --card-accent: #91e8c7;
  --card-rim: #56a4a7;
  --card-edge: #0e192d;
  --card-ink: #fff0d2;
  --card-muted: #c0d0dc;
  border: 3px solid var(--card-edge);
  border-top-color: var(--card-rim);
  background: var(--card-surface);
  color: var(--card-ink);
  box-shadow: inset 0 0 0 1px #85babb38, 0 5px #091427;
}
.tactics-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 3px solid var(--card-edge);
  background: var(--card-header);
  color: var(--card-ink);
}
.tactics-card-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 7px 12px 10px;
  border: 2px solid #b8ffdf;
  background: #91e8c7;
  color: #132e3c;
  box-shadow: inset 0 -4px #50b9a8, 2px 3px #0a1d30;
  font: 700 1rem/1.12 Arcade, monospace;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 140ms, transform 120ms;
}
.tactics-card-action:hover:not(:disabled) { background: #b8f5da; }
.tactics-card-action:active:not(:disabled) { transform: translateY(2px); }
.tactics-card-action:disabled { color: #d1dbe4; background: #344359; border-color: #617488; box-shadow: inset 0 -3px #202c40; cursor: default; }
.tactics-card-action:focus-visible, .story-screen button:focus-visible, .story-viewport:focus-visible {
  outline: 3px solid #fff1bf;
  outline-offset: 3px;
}
.tactics-card-arrow {
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  background: #22515a;
  box-shadow: inset 0 -2px #183b48;
}
.tactics-card-arrow::before { content: ''; width: 8px; height: 10px; background: #d4ffed; clip-path: polygon(0 0, 100% 50%, 0 100%); }
.market-item.tactics-card { padding: 10px; }
.market-item.tactics-card p { color: var(--card-muted); }
.market-item.tactics-card .tactics-card-action { align-self: end; }

/* Main menu keeps the sunset scene and uses the same square, inset controls. */
.hub-menu { width: min(100%, 430px); }
.hub-hero .hub-menu h1 { line-height: .82; }
.hub-menu .hub-modes { gap: 9px; }
.hub-menu .hub-modes a {
  min-height: 52px;
  width: min(100%, 355px);
  border: 2px solid #547a91;
  border-left: 4px solid var(--mode);
  box-shadow: inset 0 -4px #101b2e, 3px 4px #080d20b0;
  background: #172941ed;
  transition: background-color 150ms, transform 170ms;
}
.hub-menu .hub-modes a.mode-story {
  grid-row: 1;
  min-height: 58px;
  border-color: #b8ffdf;
  background: #91e8c7;
  color: #15324a;
  box-shadow: inset 0 -4px #50b9a8, 3px 4px #080d20bc;
}
.hub-menu .hub-modes a.mode-story span { background: #226064; }
.hub-menu .hub-modes a.mode-story::after { color: #15324a; }
.hub-menu .hub-modes a:not(.mode-story):hover { background: #263d58; color: #fff0cb; }
.hub-menu .hub-modes a:hover { transform: translateX(4px); }
.hub-menu .hub-modes a:active { transform: translate(2px, 3px); }
.hub-menu .hub-modes a[href*="endless-leaderboard"] { min-height: 44px; font-size: clamp(.96rem, 1.8vw, 1.15rem); }
.hub-menu, .merchant-heading { animation: tactics-arrive 320ms ease-out both; }
@keyframes tactics-arrive { from { opacity: .45; transform: translateY(7px); } }

/* Campaign inventory uses the same frame, inset highlights and action as Story. */
body[data-page="shop"] { background: #101b2c; }
body[data-page="shop"] .tactics-hub { max-width: none; margin: 0; padding: 0; }
body[data-page="shop"] .hub-nav { padding: 0 clamp(12px, 3vw, 42px); min-height: 46px; align-items: center; background: #10192a; border-bottom: 2px solid #4b8097; }
.merchant { color: #fff0d2; }
.merchant-header {
  isolation: isolate;
  position: relative;
  display: grid;
  align-items: end;
  min-height: clamp(170px, 33vw, 285px);
  padding: clamp(20px, 4vw, 56px) max(clamp(14px, 4vw, 42px), calc((100vw - 1140px) / 2));
  border-bottom: 4px solid #508d98;
  background: #243c51 url('./campaign-merchant.png') center 52% / cover;
  image-rendering: pixelated;
}
.merchant-header::after { content: ''; position: absolute; inset: 0; z-index: -1; background: linear-gradient(90deg, #102136f5, #102136b0 35%, transparent 69%), linear-gradient(0deg, #151e319e, transparent 70%); }
.merchant-light { position: absolute; z-index: -1; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 81% 46%, #ffc98031, transparent 25%); animation: merchant-lantern 3.3s ease-in-out infinite alternate; }
@keyframes merchant-lantern { from { opacity: .28; } }
.merchant-heading h1 { margin: 0; font: 700 clamp(2.05rem, 6vw, 4.25rem)/.96 Arcade, monospace; text-shadow: 2px 4px #131b32; }
.merchant-heading p { margin: 10px 0; color: #dce9ec; font-size: clamp(.83rem, 2vw, 1rem); }
.merchant #wallet { position: relative; display: inline-block; color: #ffc77e; border: 2px solid #9d7b5a; background: #25283e; padding: 6px 9px; box-shadow: 2px 3px #151c2f; }
.merchant-receipt { position: absolute; left: calc(100% + 8px); color: #ffe3af; font: 700 1rem Arcade, monospace; animation: merchant-receipt 640ms ease-out both; pointer-events: none; }
@keyframes merchant-receipt { to { transform: translateY(-28px); opacity: 0; } }
.merchant-inventory { display: grid; grid-template-columns: minmax(0, 1fr) minmax(285px, .65fr); gap: clamp(12px, 2.2vw, 28px); max-width: 1200px; margin: 0 auto; padding: clamp(13px, 3vw, 27px) clamp(12px, 3vw, 35px) 32px; }
.merchant-categories { display: flex; flex-wrap: wrap; gap: 6px; }
.merchant-categories button {
  flex: 1;
  min-height: 44px;
  border: 2px solid #466780;
  box-shadow: inset 0 -3px #111b2e;
  background: #202e45;
  color: #fff0d2;
  font: 700 clamp(.87rem, 2.5vw, 1.12rem)/1 Arcade, monospace;
  cursor: pointer;
}
.merchant-categories button[aria-pressed="true"] { color: #cff7e6; border-color: #91e8c7; box-shadow: inset 0 -3px #57a79b; }
.merchant-categories button:active, .merchant-item:active { transform: translateY(2px); }
.merchant-categories button:focus-visible, .merchant-item:focus-visible { outline: 2px solid #fff0b6; outline-offset: 2px; }
.merchant .market-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 9px; margin-top: 10px; }
.merchant-item {
  display: grid;
  grid-template-rows: 64px auto 1fr;
  justify-items: center;
  gap: 5px;
  min-width: 0;
  min-height: 116px;
  padding: 7px 5px;
  text-align: center;
  cursor: pointer;
}
.merchant-item:hover, .merchant-item[aria-pressed="true"] { background: #213d52; border-color: #77c2b5; }
.merchant-item strong { font: 700 clamp(.87rem, 2.1vw, 1.14rem)/1.12 Arcade, monospace; }
.merchant-item-art { width: 64px; max-width: 100%; display: grid; place-items: center; background: linear-gradient(transparent 82%, #304c63 82% 91%, transparent 91%); }
.merchant-item-art :is(img, canvas) { width: 60px; height: 60px; object-fit: contain; image-rendering: pixelated; }
.merchant-price { color: #f9d796; font: 700 .73rem/1.15 system-ui, sans-serif; }
.merchant-preview { align-self: start; min-width: 0; }
.merchant-preview header { justify-content: space-between; }
.merchant-preview h2 { margin: 0; font: 700 1.5rem/1.15 Arcade, monospace; }
.merchant-preview header span { font-size: .79rem; color: #d6f4ed; }
.merchant-showcase {
  display: grid;
  place-items: center;
  min-height: 122px;
  background: linear-gradient(0deg,#132239 21%,transparent 21%), repeating-linear-gradient(90deg,#142940 0 19px,#1b3148 19px 20px);
}
.merchant-showcase :is(img, canvas) { width: 104px; height: 104px; object-fit: contain; image-rendering: pixelated; filter: drop-shadow(3px 5px #0a1526); }
.merchant-detail { display: grid; gap: 8px; padding: 13px; }
.merchant-detail p { margin: 0; line-height: 1.4; }
.merchant-detail .merchant-spec { color: var(--card-muted); font-size: .85rem; }
.merchant-detail .tactics-card-action { width: 100%; margin-top: 3px; }

/* Combat UI stays out of the tile grid. */
body[data-view="arena"] .action-bar, body[data-view="arena"] .preview-command {
  background: #172b41;
  border-color: #4f8ca0;
  box-shadow: inset 0 2px #8fc5c92e, 0 3px #142139aa;
}
body[data-view="arena"] .action-bar .primary {
  color: #18334a;
  font-family: Arcade, monospace;
  background: #91e8c7;
  border-color: #c2f6df;
  box-shadow: inset 0 -4px #4eaa9d, 2px 3px #0d2434;
}
body[data-view="arena"] .action-bar .primary:disabled { color: #e3e9e9; background: #3e546a; border-color: #728ba0; box-shadow: inset 0 -3px #2a3c52; }
body[data-view="arena"] .action-bar button:active:not(:disabled) { transform: translateY(2px); }
body[data-view="arena"] .board { box-shadow: 0 0 0 2px #284459, 0 0 0 4px #14263375; }
body[data-view="arena"] .board > canvas { position: relative; }
body[data-view="arena"] .result { width: min(88%, 310px); background: #17263a; border-color: #86d7bd; }
body[data-view="arena"] .result[data-outcome="loss"] { border-color: #eea18a; }
body[data-view="arena"] .result strong { font-family: Arcade, monospace; color: #f8d99c; }
body[data-view="arena"] .result:not([hidden]) { animation: arena-result 240ms ease-out both; }
@keyframes arena-result { from { opacity: .25; transform: translate(-50%, -45%) scale(.97); } }
/* Keep the board anchored when the shop leaves the layout. */
html:has(.polished-arena) { scrollbar-gutter: stable; }
.polished-arena .stadium:fullscreen { scrollbar-gutter: stable; }
.polished-arena .arena { align-self: start; }
.polished-arena:is([data-arena-phase="battle"], [data-arena-phase="march"]) #arena-shop { display: none; }
.polished-arena[data-arena-phase="battle"]:not(.training-arena) #action { display: none; }
.polished-arena[data-arena-phase="battle"]:not(.training-arena) .action-bar { animation: tactics-arrive 210ms ease-out both; }
.polished-arena[data-arena-phase="battle"] .board::after {
  content: '';
  position: absolute;
  pointer-events: none;
  inset: 0;
  box-shadow: inset 0 0 0 4px #ffeeb48a;
  animation: arena-start 480ms ease-out both;
}
@keyframes arena-start { to { opacity: 0; } }
.battle-tools { display: flex; gap: 7px; flex: none; }
.battle-tools button { min-height: 44px; padding: 5px 8px; font-weight: 800; }
.battle-tools button[aria-pressed="true"] { background: #405978; color: #fff0bf; }
@media (min-width: 761px) and (max-height: 680px) {
  .polished-arena:not(.training-arena) .action-bar { block-size: 86px; }
  .polished-arena:not(.training-arena) .action-bar > div:first-child { min-width: 0; }
  .polished-arena:not(.training-arena) .action-bar > div:first-child > p:not(.fight-key) {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}
@media (max-width: 680px) {
  .merchant-header { background-position: 61% 50%; min-height: 190px; }
  .merchant-header::after { background: linear-gradient(90deg,#102136ec, #1021367d 64%, transparent); }
  .merchant-inventory { grid-template-columns: minmax(0, 1fr); }
  .merchant .market-grid { gap: 8px; }
  .merchant-item { grid-template-rows: 52px auto 1fr; min-height: 104px; }
  .merchant-item-art :is(img, canvas) { width: 49px; height: 49px; }
  .hub-menu .hub-modes a { min-height: 46px; }
  .hub-menu .hub-modes a.mode-story { min-height: 50px; }
}
@media (prefers-reduced-motion: reduce) {
  .hub-menu, .merchant-heading, .merchant-light, .merchant-receipt,
  body[data-view="arena"] .result:not([hidden]),
  .polished-arena[data-arena-phase="battle"]:not(.training-arena) .action-bar,
  .polished-arena[data-arena-phase="battle"] .board::after { animation: none; }
  .polished-arena[data-arena-phase="battle"] .board::after { display: none; }
  .hub-menu .hub-modes a, .tactics-card-action { transition: none; }
}
.polished-arena:not(.training-arena) #arena-shop .shop { background: #282b3d; border-color: #7f6262; }
.polished-arena:not(.training-arena) #arena-shop .shop .section-head {
  background: repeating-linear-gradient(90deg,#664953 0 25px,#79535a 25px 50px);
  box-shadow: inset 0 2px #b78678, inset 0 -2px #493741;
}
.polished-arena:not(.training-arena) #arena-shop .offer:not(:hover) { background: #3f3749; }
@media (max-width: 680px) {
  .polished-arena[data-arena-phase="battle"] .action-bar .fight-key { gap: 3px 5px; }
  .polished-arena[data-arena-phase="battle"] .battle-tools { gap: 4px; }
}
/* Aim for stable readable controls. Camera size is set by the board, independently of the HUD. */
.polished-arena .layout {
  --camera-size: clamp(300px, calc(100dvh - 242px), 756px);
  grid-template-columns: minmax(0, 910px) clamp(265px, 24vw, 390px);
  justify-content: center;
}
.polished-arena.training-arena .layout { --camera-size: clamp(300px, calc(100dvh - 235px), 756px); }
.polished-arena .board {
  width: min(100%, var(--camera-size));
  width: round(down, min(100%, var(--camera-size)), 9px);
}
.polished-arena :is(.preview-command, .action-bar, .arena > .result-support) {
  width: min(100%, 690px);
}
.polished-arena .preview-command { min-height: 64px; }
.polished-arena .scoreboard .wave { min-width: 0; }
.polished-arena :is(#preview-shop, #reroll, .gear-buy) { min-height: 44px; }
.merchant-close { display: none; }
.merchant-sheet {
  inset: auto 0 0;
  margin: 0 auto;
  padding: 0 0 env(safe-area-inset-bottom, 0px);
  border: 0;
  width: min(100%, 525px);
  max-width: none;
  max-height: min(86dvh, 660px);
  background: #111d30;
  color: #fff0d2;
  overscroll-behavior: contain;
}
.merchant-sheet::backdrop { background: #06101db8; }
.merchant-sheet[open] { animation: merchant-sheet-in 240ms cubic-bezier(.2,.7,.25,1) both; }
@keyframes merchant-sheet-in { from { transform: translateY(18px); opacity: .3; } }
.merchant-sheet .merchant-close {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 2px solid #638498;
  background: #1c3048;
  color: #fff0d2;
  font-size: 1.35rem;
}
.merchant-sheet .merchant-item-type { margin-inline-start: auto; }
@media (max-width: 700px), (pointer: coarse) and (max-width: 820px) and (orientation: portrait) {
  .merchant-inventory { display: block; }
  .merchant .market-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .merchant-item { min-height: 112px; }
}
@media (max-width: 760px), (max-width: 900px) and (orientation: portrait) {
  .polished-arena .layout, .polished-arena.training-arena .layout {
    --camera-size: min(100%, 540px, max(290px, calc(100dvh - 218px)));
    grid-template-columns: minmax(0, 1fr);
    padding-inline: clamp(7px, 2vw, 18px);
  }
  .polished-arena :is(.preview-command, .action-bar, .arena > .result-support) { width: min(100%, 540px); }
  .polished-arena .side { width: min(100%, 540px); }
  .polished-arena .preview-command { min-height: 66px; }
  .polished-arena.chapter-draft .preview-command { min-height: 87px; }
  .polished-arena .action-bar { flex-wrap: wrap; }
  .polished-arena .action-bar > div:first-child { flex: 1; min-width: min(136px, 100%); }
  .polished-arena .action-bar .primary { white-space: normal; }
}
@media (max-width: 900px) and (orientation: portrait) and (pointer: coarse) {
  .hub-hero { align-items: start; padding: clamp(190px, 37svh, 375px) clamp(20px, 6vw, 48px) 74px; }
  .hub-hero h1 { font-size: clamp(3.3rem, 11vw, 6.5rem); }
  .vista-art { left: 50%; top: 0; width: max(137%, 88svh); transform: translateX(-63%); }
  .vista-character { left: 79%; height: 29%; }
  .hub-vista::after { background: linear-gradient(180deg, #140e2278, transparent 19%, transparent 31%, #160e23 68%); }
  .hub-menu .hub-modes a { width: 100%; }
}
/* Opening the inspector can grow the sidebar, never the battlefield page. */
@media (min-width: 901px), (min-width: 761px) and (orientation: landscape) {
  .polished-arena:not(.training-arena) #arena-shop {
    align-self: start;
    max-height: max(200px, calc(100dvh - 101px - var(--arena-tall-inset, 0px)));
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-gutter: stable;
  }
}
@media (orientation: landscape) and (max-height: 510px) and (max-width: 1100px) {
  .hub-hero { align-items: center; padding: 52px 22px 44px; }
  .hub-hero h1 { font-size: clamp(2.6rem, 8vw, 4rem); }
  .hub-menu { width: min(70%, 535px); }
  .hub-menu .hub-modes { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-top: 14px; }
  .hub-menu .hub-modes a { width: 100%; font-size: .95rem; min-height: 44px; gap: 5px; padding-inline: 6px; }
  .hub-menu .hub-modes a.mode-story { min-height: 46px; }
  .vista-art { left: 50%; top: 50%; width: max(100cqw, 177.68cqh); transform: translate(-50%, -50%); }
  .hub-vista::after { background: linear-gradient(90deg,#100e20d6, transparent 87%); }
  .story-screen .story-heading { inset-block-start: 39px; padding-block: 5px; }
  .story-screen .story-detail { bottom: 35px; max-height: calc(100% - 142px); }
  .merchant-header { min-height: 145px; padding-block: 15px; }
  .merchant-inventory { grid-template-columns: minmax(0, 1fr) minmax(235px, .72fr); }
  .polished-arena .scoreboard { min-height: 48px; padding-block: 2px; }
  .polished-arena:not(.training-arena) .layout {
    --camera-size: clamp(216px, calc(100dvh - 67px), 440px);
    grid-template-columns: minmax(0, 1fr) minmax(195px, 29%);
    gap: 9px;
    padding: 7px 10px 10px;
    min-height: 0;
  }
  .polished-arena:not(.training-arena) .arena {
    grid-template-columns: minmax(0, 1fr) minmax(115px, 30%);
    grid-template-rows: auto 1fr;
    align-items: start;
    gap: 7px;
  }
  .polished-arena:not(.training-arena) .board { grid-area: 1 / 1 / span 2; }
  .polished-arena:not(.training-arena) .preview-command {
    grid-area: 1 / 2;
    grid-template-columns: minmax(0,1fr);
    align-content: start;
    gap: 4px;
    min-height: 72px;
    padding: 5px 6px;
  }
  .polished-arena:not(.training-arena) :is(#preview-portrait, #preview-shop) { display: none; }
  .polished-arena:not(.training-arena) .action-bar {
    grid-area: 2 / 2;
    order: 0;
    flex-wrap: wrap;
    align-content: start;
    min-height: 68px;
    block-size: auto;
    gap: 5px;
  }
  .polished-arena:not(.training-arena) .action-bar > div:first-child > p:not(.fight-key) {
    white-space: normal;
  }
  .polished-arena:not(.training-arena) .action-bar #action { width: 100%; white-space: normal; }
  .polished-arena:not(.training-arena) #arena-shop { max-height: calc(100dvh - 67px); overflow: auto; overscroll-behavior: contain; width: 100%; }
}
@media (pointer: coarse) {
  .story-screen .story-pin { min-width: 62px; min-height: 66px; }
  .polished-arena .battle-tools button { min-width: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  .merchant-sheet[open] { animation: none; }
}
@media (min-width: 1101px) and (min-height: 1100px) {
  .polished-arena .layout {
    --arena-tall-inset: clamp(15px, calc((100dvh - 1020px) / 2), 540px);
    padding-block-start: var(--arena-tall-inset);
  }
}
@media (min-width: 1900px) {
  .story-screen .story-detail { right: max(var(--atlas-edge), calc((100vw - 1720px) / 2)); }
}
@media (orientation: landscape) and (max-height: 510px) and (max-width: 1100px) {
  .story-screen .story-detail { width: min(410px, 53vw); bottom: 34px; max-height: calc(100% - 134px); }
  .story-detail .story-stage-header { padding: 6px 55px 7px 10px; }
  .story-detail h2 { font-size: 1.22rem; }
  .story-detail .story-kicker { margin-bottom: 3px; }
  .story-detail .story-close { top: 2px; right: 3px; }
  .story-stage-tip { padding: 6px 10px; font-size: .8rem; }
  .story-lineup { margin-inline: 10px; }
  .story-lineup h3 { margin-bottom: 4px; }
  .story-foes li { padding-block: 3px; gap: 2px; }
  .story-foe-portrait, .story-foe-portrait img { height: 31px; }
  .story-stage-footer { grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; padding: 7px 10px 9px; gap: 5px; }
  .story-reward { padding-block: 4px; }
  .story-stage-footer .story-note { grid-column: 1 / -1; }
  .story-screen .story-stage-action { grid-column: 2; grid-row: 1; min-height: 44px; padding: 5px 8px; font-size: .83rem; }
}
@media (pointer: coarse) {
  body[data-page="home"] .hub-nav a,
  body[data-page="shop"] .hub-nav a { display: inline-flex; align-items: center; min-height: 44px; }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 510px) and (max-width: 1100px) {
  .merchant-header { min-height: 112px; padding-block: 11px; }
  .merchant-heading h1 { font-size: clamp(1.65rem, 5vw, 2.4rem); }
  .merchant-heading p { margin-block: 5px; }
  .merchant-inventory { display: block; }
  .merchant .market-grid { grid-template-columns: repeat(auto-fit, minmax(116px, 1fr)); }
  .merchant-sheet { inset: 8px 8px auto auto; margin: 0; width: min(51vw, 430px); max-height: calc(100dvh - 16px); }
  .merchant-sheet .merchant-showcase { min-height: 75px; }
  .merchant-sheet .merchant-showcase :is(img, canvas) { width: 68px; height: 68px; }
  .merchant-sheet .merchant-detail { gap: 5px; padding: 9px; }
}

/* Squad preparation uses the arena's mint, brass and dark steel finishes. */
.polished-arena:not(.training-arena) .preview-command {
  grid-template-columns: 46px minmax(0, 1fr) auto;
  block-size: 88px;
  padding: 6px 9px;
}
.polished-arena #preview-portrait {
  width: 46px;
  height: 48px;
  border: 1px solid #507487;
  box-shadow: inset 0 -3px #081b2d;
}
.polished-arena #preview-portrait img { width: 42px; height: 45px; }
.polished-arena .has-unit #preview-portrait { border-color: #c9a36b; background: #20465a; }
.polished-arena .preview-command #preview-stats { color: #a7ead3; font-weight: 700; font-variant-numeric: tabular-nums; }
.polished-arena #preview-details { min-height: 44px; padding-inline: 8px; }
.polished-arena .preview-command #preview-selection { font-family: Arcade, monospace; color: #ffe0a1; }
.polished-arena[data-arena-phase="setup"] .tiles { pointer-events: auto; touch-action: manipulation; }
.polished-arena:not(.training-arena) .tile.preview-destination {
  border: 1px solid #315b54;
  box-shadow: inset 0 0 0 2px #bbf4ce80;
  background: #78ddac45;
}
.polished-arena .tile.is-selected { box-shadow: inset 0 0 0 2px #573d2b, 0 0 0 2px #573d2b; z-index: 1; }

.prep-dock { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; border: 2px solid #4a7384; background: #14283b; }
.prep-dock button {
  min-height: 44px;
  padding: 3px;
  border: 1px solid #557886;
  background: #244657;
  color: #fff2d9;
  box-shadow: inset 0 -3px #132e3e;
  font-weight: 800;
}
.prep-dock button[aria-expanded="true"] { color: #132c3b; background: #a1e8cc; border-color: #c6f6e1; box-shadow: inset 0 -3px #589d92; }
.prep-dock button span { color: #f8d191; font-size: .78rem; white-space: nowrap; }
.prep-dock button[aria-expanded="true"] span { color: #264758; }
.prep-dock button:active, .polished-arena .offer:active:not(:disabled), .polished-arena .slot:active:not(:disabled) { transform: translateY(2px); }
.compact-prep #arena-shop { gap: 6px; padding-block-end: env(safe-area-inset-bottom, 0px); }
.compact-prep:not([data-prep-panel="shop"]) #prep-shop,
.compact-prep:not([data-prep-panel="bench"]) #prep-bench,
.compact-prep:not([data-prep-panel="roster"]) #prep-roster,
.compact-prep #tip,
.compact-prep:not([data-arena-phase="setup"]) #arena-shop { display: none; }
.compact-prep #prep-roster > summary { min-height: 44px; align-content: center; }
.polished-arena .inspect { padding: 8px 10px 10px; border-top: 1px solid #436b7b; background: #152c40; }
.polished-arena .inspect > strong { color: #ffdfa5; font-family: Arcade, monospace; font-size: .94rem; }
.polished-arena .inspect .inspect-stats { color: #b0ebd9; font-weight: 700; }
.polished-arena .inspect-actions button { min-height: 44px; }
.polished-arena .slot { min-height: 58px; border-top-color: #578d9d; }
.polished-arena .slot:not(.empty) { background: #225165; }
.polished-arena .slot.is-selected { background: #2d686e; }
.polished-arena .slot.empty { border: 1px dashed #4f7888; box-shadow: none; background: #112a3d; }
.polished-arena .slot img { width: min(38px, 100%); max-height: 38px; }

.polished-arena:not(.training-arena) #arena-shop .offer {
  min-height: 64px;
  border: 2px solid #83646a;
  border-top-color: #bd9387;
  background: #3d3648;
  box-shadow: inset 0 -3px #252635;
}
.polished-arena #arena-shop .offer-art {
  display: grid;
  place-items: center;
  flex: none;
  width: 52px;
  height: 51px;
  border: 1px solid #916d70;
  background: #282a3a;
  box-shadow: inset 0 -5px #202232;
}
.polished-arena #arena-shop .offer img { width: 48px; height: 48px; padding: 0; background: none; box-shadow: none; }
.polished-arena #arena-shop .offer strong { color: #fff0d8; line-height: 1.08; }
.polished-arena #arena-shop .offer small { color: #e3c7cc; }
.polished-arena #arena-shop .offer-upgrade { display: inline-block; margin-top: 4px; color: #ffe299; font-size: .77rem; font-weight: 800; }
.polished-arena:not(.training-arena) #arena-shop .offer[data-offer-state="upgrade"]:enabled { border-color: #ceaa64; background: #49404a; }
.polished-arena:not(.training-arena) #arena-shop .offer:disabled { opacity: 1; border-color: #655966; background: #2f2c3b; }
.polished-arena #arena-shop .offer:disabled :is(.offer-art, .price) { opacity: .65; }
.polished-arena:not(.training-arena) #arena-shop .offer[data-offer-state="sold"] { justify-content: center; border-style: dashed; }
.sold-mark { color: #a7dac6; font-size: 1.2rem; }
.polished-arena .gear-offer { border-color: #b58963; }
@media (hover: hover) {
  .polished-arena:not(.training-arena) #arena-shop .offer:not(:disabled):hover { border-color: #ffe1a0; background: #51465a; }
  .prep-dock button:not([aria-expanded="true"]):hover { background: #30596d; }
}
@media (max-width: 760px), (max-width: 900px) and (orientation: portrait) {
  .compact-prep .arena { gap: 8px; }
  .compact-prep .layout { row-gap: 8px; }
  .compact-prep .offers { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .compact-prep #arena-shop .offer { flex-direction: column; align-items: center; justify-content: start; text-align: center; min-height: 122px; padding: 5px 2px 7px; }
  .compact-prep #arena-shop .offer strong { font-size: .95rem; }
  .compact-prep #arena-shop .offer .price { margin: auto 0 0; }
  .compact-prep #arena-shop .offer[data-offer-state="sold"] { justify-content: center; }
}
@media (orientation: landscape) and (max-height: 510px) and (max-width: 1100px) {
  .compact-prep:not(.training-arena) .preview-command { grid-template-columns: minmax(0, 1fr); block-size: auto; min-height: 96px; }
  .compact-prep #preview-details { justify-self: start; }
  .compact-prep .prep-dock { position: sticky; top: 0; z-index: 2; }
  .compact-prep .prep-dock button span { display: block; }
  .compact-prep .offers { grid-template-columns: minmax(0, 1fr); }
  .compact-prep #arena-shop .offer { flex-direction: row; align-items: center; text-align: start; padding-inline: 5px; }
  .compact-prep #arena-shop .offer .price { margin: 0 0 0 auto; }
}
@media (orientation: landscape) and (max-height: 510px) and (max-width: 760px) {
  .compact-prep .preview-command #preview-selection { font-size: .85rem; }
}
.polished-arena:not([data-arena-phase="setup"]) #preview-portrait:empty::before {
  border: 0;
  background: #a3dfca;
  clip-path: polygon(0 60%, 25% 60%, 25% 30%, 49% 30%, 49% 60%, 70% 60%, 70% 0, 100% 0, 100% 100%, 0 100%);
}
.polished-arena #arena-shop .offer-restriction { display: block; margin-top: 4px; color: #f3b9ab; font-size: .73rem; line-height: 1.15; }
.polished-arena:not(.training-arena) .tile.preview-destination { border-color: #315b5480; background: #78ddac28; }
@media (orientation: landscape) and (max-height: 510px) and (max-width: 1100px) {
  .compact-prep #arena-shop { scroll-padding-top: 60px; }
}
.story-briefing {
  width: min(100%, 690px);
  background: #172b41;
  border: 2px solid #4f8ca0;
  color: #fff0cc;
  padding: 0 10px 8px;
}
.story-briefing summary { min-height: 44px; align-content: center; font-weight: 750; cursor: pointer; }
.story-briefing:not([open]) { padding-bottom: 0; }
.story-briefing p { margin-block: 0 7px; font-size: .88rem; }
.story-briefing a { color: #a9ecd7; display: inline-flex; min-height: 44px; align-items: center; }
.story-gear-select { margin: 6px 8px 0; min-height: 44px; max-width: calc(100% - 16px); background: #172b41; color: #fff0cc; }
body[data-play-mode="tactics-story"] .offer { min-width: 0; }
@media (orientation: landscape) and (max-height: 510px) and (max-width: 1100px) {
  .story-briefing { grid-column: 1 / -1; }
}
.boss-meter {
  position: absolute;
  z-index: 2;
  inset: 4px auto auto 50%;
  transform: translateX(-50%);
  width: min(70%, 222px);
  padding: 3px 7px;
  background: #221b36;
  border: 2px solid #deae70;
  color: #fff0bf;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.boss-meter strong { font: .9rem Arcade, monospace; }
.boss-meter progress { width: 100%; height: 10px; accent-color: #e8aa66; }

.story-gear-refund { margin: 0 8px 6px; min-height: 44px; }
.story-pin[data-boss="true"] .story-pin-number::after {
  content: "◆";
  position: absolute;
  top: 5px;
  right: 8px;
  font-size: 10px;
  color: #ffd480;
  text-shadow: 1px 1px #211b32;
  pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
  .boss-meter:not([hidden]) { animation: boss-intro 320ms ease-out both; }
}
@keyframes boss-intro {
  from { opacity: .2; transform: translate(-50%, -4px); }
}
@media (max-width: 480px) {
  .story-level-arena .scoreboard .label { font-size: .76rem; }
  .story-level-arena .scoreboard #score { white-space: nowrap; }
}

/* Keep Story recruitment reachable without making the board page scroll. */
.story-drawer[data-arena-phase="setup"] .layout { padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px)); }
.story-drawer #arena-shop {
  position: fixed;
  z-index: 6;
  inset: auto 0 0;
  width: min(100%, 540px);
  max-height: none;
  overflow: visible;
  margin-inline: auto;
  padding: 0 0 env(safe-area-inset-bottom, 0px);
  gap: 0;
  background: #14283b;
  border-top: 2px solid #7397a1;
  box-shadow: 0 -4px #13203274;
}
.story-drawer #prep-dock { order: 2; }
.story-drawer #prep-dock button { touch-action: manipulation; }
.story-drawer #arena-shop :is(#prep-shop, #prep-bench, #prep-roster) {
  max-block-size: min(34dvh, 320px);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-color: #668896 #182d40;
}
.story-drawer .prep-drawer-close {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding-inline: 12px;
  border: 0;
  border-bottom: 2px solid #44677a;
  background: #223c51;
  color: #ffe2a7;
  font: 1rem Arcade, monospace;
  text-align: start;
  touch-action: none;
}
.story-drawer .prep-drawer-close > :last-child { font: 700 .88rem system-ui, sans-serif; color: #dcf1e9; }
.story-drawer #prep-shop > .section-head { display: none; }
.story-level-arena #arena-shop .offer-drafted { display: block; margin-top: 3px; color: #b1eacf; font-size: .73rem; font-weight: 750; }
.story-level-arena:not(.training-arena) #arena-shop .offer.offer-selected { border-color: #9ae8cb; box-shadow: inset 0 0 0 2px #447872, inset 0 -4px #26343e; }
.story-level-arena #arena-shop .offer .price { white-space: nowrap; }
.story-level-arena #arena-shop .offer-art { width: 58px; height: 57px; }
.story-level-arena #arena-shop .offer img { width: 53px; height: 53px; }
.story-drawer #arena-shop .offer { min-height: 130px; gap: 4px; padding: 6px 3px 8px; }
.story-level-arena #inspect-portrait { float: right; display: grid; place-items: center; width: 52px; height: 52px; margin: 0 0 6px 8px; border: 1px solid #b99267; background: #203f53; }
#inspect-portrait:empty { display: none; }
#inspect-portrait img { width: 48px; height: 48px; object-fit: contain; image-rendering: pixelated; }
.story-level-arena .bench-name { margin-top: 3px; font-size: .73rem; line-height: 1.1; color: #e7f3e8; }
.story-level-arena .inspect-actions { clear: both; }
@media (prefers-reduced-motion: no-preference) {
  .story-drawer[data-prep-panel]:not([data-prep-panel=""]) #arena-shop { animation: prep-drawer-in 160ms ease-out; }
}
@keyframes prep-drawer-in { from { transform: translateY(9px); } }

.story-level-arena .restart-level {
  min-height: 44px;
  margin-top: 4px;
  padding: 5px 8px;
  white-space: nowrap;
}
.restart-dialog {
  width: min(408px, calc(100% - 24px));
  padding: 17px;
  background: #172b41;
  border: 2px solid #7397a1;
  color: #fff0cc;
  box-shadow: 4px 5px #0f1c2c;
}
.restart-dialog::backdrop { background: #090f1ac7; }
.restart-dialog h2 { margin: 0 0 8px; color: #ffdfa5; font: 1.25rem Arcade, monospace; }
.restart-dialog p { margin: 0; line-height: 1.45; }
.restart-dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 15px; }
.restart-dialog-actions button { min-height: 44px; }

.story-screen .story-endless-standings {
  justify-content: center;
  border-color: #688a97;
  background: #243b50;
  color: #fff0cf;
  box-shadow: inset 0 -3px #122638;
}
.endless-map-tabs { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 12px; }
.endless-map-tabs a { display: inline-flex; align-items: center; min-height: 44px; padding: 6px 12px; text-decoration: none; }
.endless-map-tabs a[aria-current="page"] { border-color: #ffdc99; color: #ffdc99; }
@media (min-width: 901px) and (min-height: 511px) {
  .endless-arena .layout { --camera-size: clamp(300px, calc(100dvh - 260px), 756px); }
}
