:root {
  --ink: #173b3a;
  --muted: #5f7c78;
  --mint: #e8f4ef;
  --paper: #fffdf7;
  --green: #2e7d63;
  --green-dark: #205b4d;
  --gold: #e2a83b;
  --line: #cfe2d8;
  --shadow: 0 18px 48px rgba(27, 71, 61, .12);
  font-family: ui-rounded, "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--mint);
}

* { box-sizing: border-box; }
html { overflow-y: auto; overscroll-behavior-y: contain; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 10% 0%, #f9fff9 0, var(--mint) 48%, #dceee7 100%); }
body[data-screen="stage"], body[data-screen="battle"] { overflow: hidden; overscroll-behavior: none; }
button, select { font: inherit; }
button { color: inherit; }
.screen { min-height: 100vh; width: 100%; max-width: 1120px; margin: 0 auto; padding: 18px 20px 64px; }
[hidden] { display: none !important; }

.loading-panel { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.loading-card { width: min(420px, 100%); padding: 32px; border: 1px solid var(--line); border-radius: 28px; background: rgba(255,253,247,.92); box-shadow: var(--shadow); text-align: center; }
.loading-mark { display: block; color: var(--gold); font-size: 48px; animation: breathe 1.3s ease-in-out infinite; }
.loading-track { height: 8px; margin-top: 20px; overflow: hidden; border-radius: 99px; background: #e4eee8; }
.loading-track i { display: block; width: 46%; height: 100%; border-radius: inherit; background: var(--green); animation: load 1.1s ease-in-out infinite; }
@keyframes load { from { transform: translateX(-130%); } to { transform: translateX(250%); } }
@keyframes breathe { 50% { transform: translateY(-4px) rotate(-6deg); } }

.topbar, .panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 58px; }
.return-link { display: inline-flex; align-items: center; gap: 10px; color: var(--green-dark); font-weight: 800; text-decoration: none; }
.return-link > span:first-child { font-size: 26px; line-height: 1; }
.brand-mark { display: grid; place-items: center; width: 58px; height: 48px; border-radius: 14px 20px 14px 20px; background: var(--green-dark); color: #f7f6df; letter-spacing: .08em; font-size: 14px; }
.utilities { position: relative; }
.icon-btn, .back-btn, .secondary-btn, .text-btn, .primary-btn, .flap-btn, .stage-card, .setting-row { border: 0; cursor: pointer; }
.icon-btn { width: 48px; height: 48px; border-radius: 50%; background: #f7fffa; border: 1px solid var(--line); font-size: 23px; }
.icon-btn:focus-visible, button:focus-visible, select:focus-visible { outline: 3px solid #f0b844; outline-offset: 3px; }
.settings-panel { position: absolute; z-index: 5; top: 56px; inset-inline-end: 0; right: auto; width: min(280px, calc(100vw - 40px)); padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); box-shadow: var(--shadow); }
.settings-panel > strong { display: block; margin-bottom: 10px; }
.setting-row { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 6px; border-top: 1px solid #e4eee8; background: transparent; text-align: start; }
.setting-row select { min-width: 132px; border: 1px solid var(--line); border-radius: 10px; padding: 7px; color: var(--ink); background: #fff; }

.hero-grid { display: grid; grid-template-columns: minmax(300px, .9fr) minmax(0, 1.1fr); gap: clamp(28px, 6vw, 84px); align-items: center; max-width: 980px; margin: 34px auto 46px; }
.field-poster { position: relative; aspect-ratio: 1; max-width: 470px; overflow: hidden; border-radius: 34px; background: #173b3a; box-shadow: 0 24px 60px rgba(21, 70, 56, .24); }
.field-poster-image { display: block; width: 100%; height: 100%; object-fit: cover; }
.kicker, .eyebrow { margin: 0 0 8px; color: var(--green); font-size: 13px; letter-spacing: .11em; text-transform: uppercase; font-weight: 900; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 16px; font-size: clamp(44px, 7vw, 80px); line-height: .98; letter-spacing: -.05em; }
.intro { max-width: 560px; margin-bottom: 12px; font-size: clamp(20px, 2.5vw, 29px); line-height: 1.22; font-weight: 800; }
.summary { max-width: 530px; color: var(--muted); font-size: 16px; line-height: 1.55; }
.progress, .best-line { color: var(--muted); font-size: 14px; }
.hero-actions, .battle-actions, .result-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.primary-btn, .secondary-btn, .text-btn, .back-btn { min-height: 52px; border-radius: 16px; padding: 13px 20px; font-weight: 850; }
.primary-btn { background: var(--green-dark); color: #fffdf7; box-shadow: 0 9px 20px rgba(32,91,77,.2); }
.primary-btn:hover { background: #17473e; }
.secondary-btn { border: 1px solid #a9cec0; background: rgba(255,253,247,.7); color: var(--green-dark); }
.text-btn, .back-btn { background: transparent; color: var(--green-dark); padding-inline: 8px; }
.best-line strong { color: var(--ink); }
.guide-card, .stage-canvas, .battle-canvas, .result-card { border: 1px solid var(--line); background: rgba(255,253,247,.82); box-shadow: var(--shadow); }
.battle-canvas { background-color: rgba(255,253,247,.82); background-image: linear-gradient(rgba(255,253,247,.58), rgba(255,253,247,.76)), url("assets/animal-folded-field-background.png"); background-position: center; background-size: cover; }
.guide-card { max-width: 980px; margin: 0 auto; padding: 26px; border-radius: 26px; }
.guide-card h2 { margin-bottom: 20px; font-size: 24px; }
.guide-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.guide-grid article { padding: 18px; border-radius: 18px; background: #eef7f1; }
.guide-grid p { margin: 8px 0 0; color: var(--muted); font-size: 14px; line-height: 1.45; }

.panel-screen { display: grid; place-items: start center; gap: 0; padding-top: 24px; }
.stage-canvas, .battle-canvas { width: min(920px, 100%); min-height: 610px; border-radius: 28px; padding: 20px; }
.panel-head h2 { margin: 0; font-size: clamp(24px, 4vw, 38px); letter-spacing: -.04em; }
.panel-head > div:nth-child(2) { flex: 1; }
.back-btn { white-space: nowrap; }
.panel-utility { flex: 0 0 auto; width: 44px; height: 44px; font-size: 18px; }
.panel-intro { max-width: 620px; margin: 18px auto 22px; color: var(--muted); text-align: center; }
.stage-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; max-width: 820px; margin: 34px auto; }
.stage-card { min-height: 220px; padding: 20px; border: 1px solid var(--line); border-radius: 22px; background: #f4faf4; text-align: start; transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease; }
.stage-card:hover, .stage-card:focus-visible { transform: translateY(-4px); border-color: #75aa91; box-shadow: 0 12px 22px rgba(36,95,77,.11); }
.stage-number { display: inline-block; margin-bottom: 20px; color: var(--green); font-size: 13px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.stage-card h3 { margin-bottom: 8px; font-size: 24px; }
.stage-card p { min-height: 62px; margin-bottom: 14px; color: var(--muted); line-height: 1.45; }
.stage-chip { display: inline-block; padding: 7px 10px; border-radius: 999px; color: var(--green-dark); background: #dfeee4; font-size: 13px; font-weight: 800; }
.stage-tabs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; max-width: 460px; margin: 0 auto; color: var(--muted); }
.stage-tabs span { height: 1px; background: var(--line); }
.stage-tabs button { border: 0; background: transparent; color: var(--green-dark); font-weight: 850; }

.panel-head-actions { display: flex; align-items: center; gap: 10px; }
.check-pill { display: inline-flex; gap: 6px; align-items: center; padding: 10px 12px; border-radius: 999px; background: #e9f3eb; color: var(--green-dark); font-size: 13px; white-space: nowrap; }
.battle-content { max-width: 780px; margin: 28px auto 0; }
.goal-card { display: flex; justify-content: space-between; gap: 20px; align-items: end; margin-bottom: 20px; padding: 20px; border-radius: 20px; background: #eef7f1; }
.goal-card h3 { margin: 0; font-size: clamp(24px, 4vw, 35px); }
.goal-card p { max-width: 360px; margin: 0; color: var(--muted); line-height: 1.45; text-align: end; }
.pattern-summary { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin: 12px 0; color: var(--muted); font-size: 13px; font-weight: 800; }
.pattern-row { display: flex; gap: 8px; }
.pattern-cell { display: grid; place-items: center; min-width: 80px; min-height: 44px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); font-size: 12px; font-weight: 800; }
.pattern-cell::before { content: ""; width: 16px; height: 16px; margin-right: 5px; display: inline-block; border: 2px solid currentColor; border-radius: 50% 50% 45% 45%; vertical-align: -4px; }
.pattern-cell.is-lifted { color: var(--green-dark); background: #e1f1e3; }
.pattern-cell.is-lifted::before { border-radius: 50% 50% 8px 8px; background: #9dceb0; }
.current-summary { padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.aligned-count { min-width: 82px; color: var(--green); text-align: end; }
/* Four stable slots cover the largest authored page without a second row.
   Three-flap pages leave the last slot empty; controls do not grow on removal. */
.flap-board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 24px 0 16px; }
.flap-btn { min-width: 0; overflow-wrap: anywhere; }
.flap-btn { position: relative; min-height: 176px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px; padding: 16px 10px; border: 2px solid #b6d2c3; border-radius: 24px 24px 36px 36px; background: #f7fcf6; transition: transform .15s ease, background .15s ease, border-color .15s ease; }
.flap-btn:hover { transform: translateY(-3px); }
.flap-btn.is-lifted { border-color: #609d7b; background: #e1f1e3; }
.flap-btn.is-tucked { background: #f5f2df; border-color: #d0c57e; }
.flap-btn .flap-icon { display: grid; place-items: center; width: 66px; height: 76px; border: 2px solid currentColor; border-radius: 50% 50% 16px 16px; color: var(--green-dark); font-size: 35px; font-weight: 900; }
.flap-btn.is-tucked .flap-icon { transform: rotate(180deg); color: #8e7425; }
.flap-btn strong { font-size: 16px; }
.flap-btn small { color: var(--muted); font-size: 13px; font-weight: 800; }
.flap-btn .link-dot { position: absolute; top: 12px; right: 14px; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.battle-status { height: 30px; min-height: 30px; margin: 10px 0; overflow: hidden; color: var(--green-dark); font-weight: 850; line-height: 30px; text-align: center; white-space: nowrap; }
.move-hint { margin: 18px 0 0; color: var(--muted); font-size: 13px; text-align: center; }

.result-card { width: min(680px, 100%); min-height: 500px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 44px 26px; border-radius: 30px; text-align: center; }
.result-emblem { display: grid; place-items: center; width: 84px; height: 84px; margin-bottom: 18px; border-radius: 50%; background: #e4f2df; color: var(--gold); font-size: 48px; }
.result-card h2 { max-width: 540px; margin-bottom: 12px; font-size: clamp(30px, 5vw, 52px); letter-spacing: -.05em; }
.result-card > p:not(.kicker) { max-width: 520px; color: var(--muted); line-height: 1.55; }
.result-badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 18px 0 26px; }
.result-badge { padding: 9px 12px; border-radius: 999px; background: #eef7f1; color: var(--green-dark); font-size: 13px; font-weight: 850; }

@media (max-width: 760px) {
  .screen { padding-inline: 14px; }
  .hero-grid { grid-template-columns: 1fr; margin-top: 24px; gap: 28px; }
  .field-poster { width: min(440px, 100%); margin: 0 auto; }
  .hero-copy { text-align: center; }
  .hero-actions, .battle-actions, .result-actions { justify-content: center; }
  .summary { margin-inline: auto; }
  .guide-grid, .stage-list { grid-template-columns: 1fr; }
  .stage-card { min-height: auto; }
  .stage-card p { min-height: auto; }
  .stage-canvas, .battle-canvas { padding: 14px; border-radius: 22px; }
  .battle-canvas { background-position: 74% center; background-image: linear-gradient(rgba(255,253,247,.52), rgba(255,253,247,.72)), url("assets/animal-folded-field-background.png"); }
  .goal-card { align-items: start; flex-direction: column; }
  .goal-card p { text-align: start; }
  .pattern-summary { align-items: start; flex-direction: column; gap: 8px; }
  .pattern-row { width: 100%; }
  .pattern-cell { flex: 1; min-width: 0; }
  .aligned-count { text-align: start; }
  .flap-board { gap: 8px; }
  .flap-btn { min-height: 148px; padding-inline: 4px; border-radius: 20px 20px 28px 28px; }
  .flap-btn .flap-icon { width: 50px; height: 60px; font-size: 27px; }
  .flap-btn strong { font-size: 14px; }
  .flap-btn small { font-size: 11px; }
  .panel-head { gap: 8px; }
  .panel-head h2 { font-size: 24px; }
  .panel-head-actions { gap: 5px; }
  .check-pill { padding-inline: 8px; }
}

@media (max-width: 420px) {
  .return-link > span:first-child { font-size: 22px; }
  .brand-mark { width: 50px; height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .pattern-cell { font-size: 10px; padding-inline: 5px; }
}

/* Interface 6 shell contract: keep Main, Stage, and Battle readable at every
   validator viewport while preserving the authored field-book visual language. */
html { min-width: 320px; }
body { min-width: 0; overflow-x: hidden; }

#mainScreen {
  width: min(100%, 920px);
  margin: 0 auto;
  padding: 14px 16px 28px;
}
#mainScreen .topbar {
  position: relative;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 48px;
  align-items: center;
  gap: 10px;
  height: 48px;
  min-height: 48px;
}
#mainScreen .wp-shell-return {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 58px;
  height: 48px;
  padding: 0;
  overflow: hidden;
  border: 1px solid #d8c8a9;
  border-radius: 14px;
  background: #fffdf8;
  color: #29485a;
  font-size: 1.15rem;
  font-weight: 900;
  text-decoration: none;
}
#mainScreen .wp-shell-return img { width: 28px; height: 28px; object-fit: contain; flex: 0 0 auto; }
#mainScreen .wp-shell-main-title {
  position: absolute;
  left: 50%;
  max-width: calc(100% - 150px);
  overflow: hidden;
  color: #29485a;
  font-size: 1.05rem;
  text-align: center;
  text-overflow: ellipsis;
  transform: translateX(-50%);
  white-space: nowrap;
}
#mainScreen .utilities { position: relative; justify-self: end; }
#mainScreen .wp-shell-settings-button {
  width: 48px !important;
  height: 48px !important;
  padding: 0;
  border: 1px solid #d8c8a9;
  border-radius: 14px;
  background: #fffdf8;
  color: #29485a;
  font-weight: 900;
}
#mainScreen .wp-shell-settings-popover {
  position: absolute;
  z-index: 10;
  top: 54px;
  right: -4px;
  width: min(280px, calc(100vw - 24px));
  padding: 14px;
  border: 1px solid #d8c8a9;
  border-radius: 16px;
  background: #fffdf8;
  box-shadow: 0 18px 42px rgba(23, 59, 58, .18);
}
#mainScreen[dir="rtl"] .wp-shell-settings-popover,
html[dir="rtl"] #mainScreen .wp-shell-settings-popover {
  right: auto;
  left: 0;
}
#mainScreen .wp-shell-settings-popover .setting-row { min-height: 44px; padding: 9px 4px; }
#mainScreen .wp-shell-settings-popover select { min-height: 36px; }

#mainScreen .hero-grid {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  align-items: center;
  gap: 28px;
  max-width: none;
  margin: 16px auto 24px;
}
#mainScreen .field-poster { width: 420px; max-width: 420px; border-radius: 24px; }
#mainScreen .field-poster-image { display: block; width: 100%; height: 100%; object-fit: cover; }
#mainScreen .hero-copy { min-width: 0; }
#mainScreen .hero-title { margin-bottom: 12px; font-size: clamp(40px, 6vw, 72px); }
#mainScreen .wp-standard-main-summary { max-width: 530px; }
#mainScreen .wp-standard-main-progress {
  display: flex;
  align-items: center;
  min-height: 42px;
  height: 42px;
  margin: 12px 0 0;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f4faf4;
}
#mainScreen .hero-actions { margin-top: 16px; }
#mainScreen #startBtn { min-height: 52px; height: 52px; }

#gameGuide { display: none; }
body[data-screen="main"] #gameGuide { display: block; }
#gameGuide.game-page-info {
  width: min(calc(100% - 36px), 860px);
  margin: 0 auto 28px;
  padding: 16px 18px;
  border: 1px solid #cfe2d8;
  border-radius: 18px;
  background: #e8f1ea;
  box-shadow: 0 12px 30px rgba(27, 71, 61, .1);
}

#stageScreen, #battleScreen {
  position: fixed;
  z-index: 10;
  inset: 0;
  width: min(100vw, 920px);
  height: calc(100dvh - 56px);
  min-height: 0;
  margin: 0 auto;
  padding: 14px 18px;
  overflow: hidden;
  touch-action: none;
  background: #e8f4ef;
}
#stageScreen {
  background-color: #e8f4ef;
  background-image: linear-gradient(rgba(232, 244, 239, .5), rgba(232, 244, 239, .78)), var(--wp-stage-art, none);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}
#stageScreen .stage-canvas, #battleScreen .battle-canvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0 auto;
  padding: 14px 16px 24px;
  overflow: hidden;
  background-color: rgba(255, 253, 247, .78);
  background-image: linear-gradient(rgba(232, 244, 239, .42), rgba(255, 253, 247, .72)), var(--wp-stage-art, none), var(--wp-battle-art, none);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}
#stageScreen .panel-head, #battleScreen .panel-head {
  display: grid;
  grid-template-columns: minmax(58px, auto) 1fr minmax(48px, auto);
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
#stageScreen .panel-head .back-btn, #battleScreen .panel-head .back-btn { width: 58px; min-width: 58px; flex: 0 0 58px; min-height: 48px; padding: 0; }
#stageScreen .panel-intro { margin: 18px 0 0; }
#stageScreen .stage-list {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 200px;
  min-height: 198px;
  max-height: 200px;
  margin-top: 18px;
  padding-inline: 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  touch-action: pan-x !important;
  user-select: none;
  -webkit-user-select: none;
}
#stageScreen .stage-list::-webkit-scrollbar { display: none; }
#stageScreen .stage-card {
  box-sizing: border-box;
  flex: 0 0 264px;
  width: 264px;
  min-width: 264px;
  max-width: 264px;
  height: 190px;
  min-height: 190px;
  max-height: 190px;
  scroll-snap-align: center;
}
#stageScreen .stage-tabs { margin-top: 18px; }
#stageScreen .stage-tabs button { min-height: 44px; padding: 10px 16px; }
#battleScreen .battle-canvas { display: flex; flex-direction: column; touch-action: none; }
#battleScreen .battle-content { width: min(100%, 780px); min-height: 0; flex: 1; margin: 28px auto 0; overflow-y: auto; overscroll-behavior-y: contain; touch-action: pan-y; }
#battleScreen .battle-actions { justify-content: flex-end; }
.stage-ad-reserve, .battle-ad-reserve {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 9;
  width: min(100vw, 920px);
  height: 56px;
  transform: translateX(-50%);
  border-top: 1px solid rgba(255, 255, 255, .2);
  background: #173b3a;
  pointer-events: none;
}
.stage-ad-reserve[hidden], .battle-ad-reserve[hidden] { display: none !important; }

@media (max-width: 699px) {
  #mainScreen .hero-grid { grid-template-columns: 1fr; gap: 18px; margin-top: 16px; text-align: center; }
  #mainScreen .field-poster { width: 100%; max-width: none; }
  #mainScreen .hero-copy .summary { margin-inline: auto; }
  #mainScreen .hero-actions { justify-content: center; }
  #gameGuide.game-page-info { width: calc(100% - 28px); }
  #gameGuide .game-info-facts, #gameGuide .game-info-sections { grid-template-columns: 1fr; }
  #stageScreen, #battleScreen { padding-inline: 14px; }
  #battleScreen .pattern-summary { align-items: flex-start; flex-direction: column; gap: 8px; }
  #battleScreen .pattern-row { width: 100%; }
  #battleScreen .pattern-cell { flex: 1; min-width: 0; }
  #battleScreen .battle-content { margin-top: 16px; }
  #battleScreen .goal-card { margin-bottom: 14px; padding: 16px; }
  #battleScreen .flap-board { margin: 16px 0 10px; }
  #battleScreen .flap-btn { min-height: 140px; }
}
@media (min-width: 700px) { #mainScreen .field-poster { width: 420px; } }
@media (orientation: landscape) and (max-height: 560px) {
  #mainScreen .field-poster { width: 420px; max-width: 420px; }
  #stageScreen .stage-list { height: 138px; min-height: 138px; max-height: 138px; margin-top: 8px; }
  #stageScreen .stage-card { height: 138px; min-height: 138px; max-height: 138px; }
}

@media (min-width: 700px) and (max-height: 760px) {
  #battleScreen .battle-content { margin-top: 10px; }
  #battleScreen .goal-card { margin-bottom: 8px; padding: 12px 16px; }
  #battleScreen .pattern-summary { margin: 6px 0; }
  #battleScreen .flap-board { margin: 10px 0 8px; }
  #battleScreen .flap-btn { min-height: 148px; padding-block: 10px; gap: 6px; }
  #battleScreen .flap-btn .flap-icon { width: 58px; height: 62px; font-size: 30px; }
  #battleScreen .battle-status { min-height: 24px; margin: 4px 0; }
  #battleScreen .move-hint { margin-top: 8px; }
}

@media (min-width: 700px) and (orientation: landscape) and (max-height: 560px) {
  #battleScreen .battle-canvas {
    display: grid;
    grid-template-rows: 48px minmax(0, 1fr);
    align-content: start;
    padding: 8px 12px 10px;
  }
  #battleScreen .panel-head { min-height: 48px; height: 48px; flex: 0 0 48px; }
  #battleScreen .panel-head h2 { font-size: 20px; line-height: 24px; }
  #battleScreen .round-label { margin: 0; font-size: 12px; line-height: 16px; }
  #battleScreen .battle-content { min-height: 0; overflow: hidden; }
  #battleScreen .battle-content { display: grid; grid-template-columns: minmax(300px, .9fr) minmax(0, 1.8fr); grid-template-rows: auto auto auto minmax(0, 1fr) auto; column-gap: 10px; row-gap: 4px; margin-top: 4px; }
  #battleScreen .goal-card { grid-column: 1 / -1; align-items: center; flex-direction: row; gap: 12px; margin-bottom: 0; padding: 6px 10px; }
  #battleScreen .goal-card h3 { font-size: 20px; }
  #battleScreen .goal-card p { max-width: 320px; font-size: 11px; line-height: 1.2; }
  #battleScreen .pattern-summary { grid-column: 1; gap: 8px; margin: 0; }
  #battleScreen .pattern-summary:not(.current-summary) { grid-row: 2; }
  #battleScreen .current-summary { grid-row: 3; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 8px; }
  #battleScreen .current-summary .pattern-row { grid-column: 2; }
  #battleScreen .current-summary .aligned-count { grid-column: 1 / -1; min-width: 0; text-align: start; }
  #battleScreen .pattern-row { min-width: 0; flex: 1; }
  #battleScreen .pattern-cell { min-width: 0; flex: 1; min-height: 28px; padding: 3px 5px; font-size: 10px; }
  #battleScreen .pattern-cell::before { width: 11px; height: 11px; margin-right: 3px; border-width: 1px; }
  #battleScreen .flap-board { grid-column: 2; grid-row: 2 / 5; align-self: center; gap: 8px; margin: 0; }
  #battleScreen .flap-btn { min-height: 78px; padding-block: 4px; gap: 2px; border-radius: 16px 16px 24px 24px; }
  #battleScreen .flap-btn .flap-icon { width: 38px; height: 42px; font-size: 22px; }
  #battleScreen .flap-btn strong { font-size: 11px; }
  #battleScreen .flap-btn small { font-size: 9px; }
  #battleScreen .battle-status { grid-column: 1; grid-row: 4; width: 100%; height: 16px; min-height: 16px; margin: 0; overflow: hidden; font-size: 11px; line-height: 16px; white-space: nowrap; }
  #battleScreen .battle-actions { grid-column: 1; grid-row: 5; flex-wrap: nowrap; gap: 6px; }
  #battleScreen .battle-actions button { min-height: 40px; height: 40px; padding: 8px 12px; font-size: 13px; }
  #battleScreen .move-hint { display: none; }
}

/* Stable footer: content may scroll, but primary controls never do. */
#battleScreen .battle-canvas {
  display:grid;
  grid-template-rows:48px minmax(0,1fr) 52px;
  row-gap:8px;
}
#battleScreen .battle-canvas > .battle-actions {
  grid-column:1;
  grid-row:3;
  margin:0;
  align-items:stretch;
  flex-wrap:nowrap;
}
#battleScreen .battle-canvas > .battle-actions button {
  height:52px;
  min-height:52px;
}

/* Result is a Battle substate: keep it in the same logical Canvas and replace
   the live HUD/board/footer without exposing a Main destination. */
#battleScreen[data-battle-state="result"] .battle-canvas {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  row-gap: 0;
}
#battleScreen[data-battle-state="result"] #resultScreen {
  display: grid;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
#battleScreen[data-battle-state="result"] #resultScreen .result-card {
  width: min(680px, 100%);
  min-height: 0;
  max-height: 100%;
  margin: auto;
  overflow-y: auto;
}
#battleScreen[data-battle-state="result"] .result-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: min(100%, 600px);
  gap: 10px;
}
#battleScreen[data-battle-state="result"] .result-actions > button {
  min-width: 0;
  min-height: 52px;
}
#battleScreen[data-battle-state="result"] #resultPrimaryBtn:disabled {
  cursor: not-allowed;
  opacity: .48;
}

/* Folded Field keeps the shared Interface 7 skin's rounded Guide and the
   canonical 420px compact-landscape Main poster. These scoped declarations
   outrank the token skin without altering other games. */
@layer wp-frame-contract {
  html[data-wp-shared-interface="7"] body[data-wp-game-id="animal-folded-field"] .game-page-info {
    border-radius:24px !important;
  }
  html[data-wp-shared-interface="7"] body[data-wp-game-id="animal-folded-field"] .game-info-sections {
    display:grid !important;
    grid-template-columns:minmax(0, 1.3fr) minmax(280px, 0.7fr) !important;
  }
  html[data-wp-shared-interface="7"] body[data-wp-game-id="animal-folded-field"] .game-page-info .game-info-section,
  html[data-wp-shared-interface="7"] body[data-wp-game-id="animal-folded-field"] .game-page-info .game-info-fact {
    border-radius:16px !important;
  }
  @media (min-width:700px) and (orientation:landscape) and (max-height:560px) {
    html[data-wp-shared-interface="7"] body[data-wp-game-id="animal-folded-field"] .wp-standard-main-composition {
      --wp-main-landscape-poster-size:420px !important;
    }
    html[data-wp-shared-interface="7"] body[data-wp-game-id="animal-folded-field"] .wp-standard-main-poster,
    html[data-wp-shared-interface="7"] body[data-wp-game-id="animal-folded-field"] .wp-standard-main-poster-media,
    html[data-wp-shared-interface="7"] body[data-wp-game-id="animal-folded-field"] .wp-standard-main-poster-media > img,
    html[data-wp-shared-interface="7"] body[data-wp-game-id="animal-folded-field"] .wp-standard-main-poster > img {
      width:420px !important;
      min-width:420px !important;
      max-width:420px !important;
      height:420px !important;
      min-height:420px !important;
      max-height:420px !important;
    }
  }
}
