*{box-sizing:border-box}body{margin:0;color:#233e32;font-family:"Apple SD Gothic Neo","Malgun Gothic",system-ui,sans-serif;background-color:#f6f4e9;background-image:radial-gradient(#dedccd .75px,transparent .85px);background-size:6px 6px}header{background:#213c32;color:#f6f4de;border-bottom:4px solid #d3cdab}.bar,main{width:min(1080px,92vw);margin:auto}.bar{height:64px;display:flex;align-items:center;justify-content:space-between}.brand{display:flex;align-items:center;gap:11px;font-size:19px;font-weight:900;letter-spacing:-1px}.brandmark{width:32px;height:32px;display:grid;place-items:center;font-size:23px;color:#283d2d;background:#f7ce67;clip-path:polygon(20% 0,80% 0,80% 10%,100% 10%,100% 80%,90% 80%,90% 100%,20% 100%,20% 90%,0 90%,0 20%,20% 20%)}.region{font-size:13px;color:#e3e7cf;font-weight:700;display:flex;align-items:center;gap:8px}.small-compass{font-size:20px;color:#e0c771}.heading{display:flex;justify-content:space-between;align-items:flex-end;margin:32px 0 19px}.route{display:flex;align-items:center;gap:9px;font:700 11px/1.3 ui-monospace,monospace;color:#6a775e;letter-spacing:1px}.route span{width:18px;height:1px;background:#a1a68c}h1,h2,p{margin:0}h1{font-size:clamp(31px,5vw,46px);letter-spacing:-3px;line-height:1.18;margin-top:6px}.mode{font-size:12px;font-weight:800;background:#e5ebd6;color:#456641;border:1px solid #bac9a9;padding:6px 10px;border-radius:4px}.mode:before{content:"";display:inline-block;width:7px;height:7px;background:#638549;margin-right:6px}.console{overflow:hidden;border:4px solid #2f4235;border-radius:11px;box-shadow:0 5px 0 #c8c6ae;background:#263b2e}.viewport{position:relative;isolation:isolate}canvas{width:100%;height:auto;display:block;image-rendering:pixelated;background:#83ac64}.dialog{display:flex;gap:14px;align-items:center;min-height:72px;padding:11px 20px;background:#fdfbed;border-top:3px solid #364f39}.guide-icon{display:grid;place-items:center;background:#e4ead1;color:#536f46;width:38px;height:38px;flex:none;border:1px solid #b6c49b;border-radius:5px;font-size:26px}.dialog b{font-size:11px;color:#66805b;letter-spacing:.5px}.dialog p{font-size:15px;font-weight:650;margin-top:3px}.keystrip{display:flex;gap:14px;align-items:center;justify-content:flex-end;margin:14px 0 23px;font-size:11px;font-weight:700;color:#6a7361}.keystrip span{display:flex;align-items:center;gap:3px}.keystrip i{height:12px;width:1px;background:#c3c7b8}kbd{font:700 11px/1 monospace;padding:3px 5px;border:1px solid #b7beab;border-bottom-width:2px;border-radius:3px;background:#fbfaf1;color:#4f6051}.party-head{display:flex;align-items:center;gap:9px;margin-bottom:11px}h2{font-size:21px;font-weight:850;letter-spacing:-1px}.party-head>span{font-size:12px;color:#6e795f}.companions{margin:0 0 35px}#party{display:grid;grid-template-columns:repeat(3,1fr);gap:12px}.card{min-height:83px;border:1px solid #b9c2a9;border-radius:6px;display:flex;align-items:center;gap:10px;padding:9px 14px;background:#fbfaf1;box-shadow:0 2px #dadbc8}.card img{width:58px;height:58px;image-rendering:pixelated}.card strong{font-size:16px}.card small{display:block;color:#717c67;font-size:12px;margin-top:4px}.card.empty{background:#efefe3;border:1px dashed #c4c9b4;color:#79816c;box-shadow:none;font-size:13px;justify-content:center}.empty b{font:18px monospace;margin-right:6px}.type{display:inline-block;font-size:10px;vertical-align:middle;padding:2px 5px;border-radius:3px;margin-left:5px;background:#e7d6ad;color:#6c4e26}.type.electric{background:#f9e8a5;color:#775712}.type.water{background:#c8e3e6;color:#285f73}
#overlay:not([hidden]){position:absolute;inset:0;background:#193326bb;display:flex;align-items:center;justify-content:center;padding:8px}.panel{background:#fffced;border:3px solid #294833;border-radius:6px;box-shadow:3px 4px 0 #1d372a80;padding:14px 20px;text-align:center;max-width:96%;max-height:100%;overflow:auto}.panel h2{font-size:clamp(15px,2.1vw,23px);margin-bottom:8px}.choices,.duel{display:flex;gap:10px;justify-content:center}.pick,.fighter{min-width:100px;padding:4px 9px;display:grid;justify-items:center;font:inherit;color:inherit}.pick{border:2px solid #ccd0bc;border-radius:4px;background:#f0f0e2;cursor:pointer}.pick[aria-pressed=true]{border-color:#45613d;background:#e3ebcf;box-shadow:0 2px #45613d}.pick small,.fighter small,.resultmeta{font-size:12px;color:#56664e}.pick img,.fighter img,.joined{width:clamp(45px,8vw,100px);height:auto;image-rendering:pixelated}.fighter img{width:128px;max-width:13vw}.pick img{width:60px}.action{margin-top:10px;padding:6px 15px;color:#fffbee;background:#395a40;border:0;border-bottom:3px solid #233d2c;border-radius:4px;font:700 13px system-ui;cursor:pointer}.duel{align-items:center}.versus{color:#7b886d;font:800 14px monospace}.hp{width:90px;height:7px;background:#dddcc8;display:block;margin:4px 0}.hp i{display:block;height:100%;background:#719b4b}.joined{width:70px}.resultmeta{margin:4px 0}.panel button:focus-visible{outline:3px solid #c07d25}.hit img{animation:hit .23s}@keyframes hit{50%{opacity:.4;transform:translateX(4px)}}@media(max-width:680px){.bar,main{width:96%}.heading{margin:20px 0 12px}.viewport{min-height:210px}.viewport canvas{height:210px;object-fit:fill}.keystrip{justify-content:center;gap:6px}.card{padding:5px;gap:3px;flex-wrap:wrap;justify-content:center}.card img{width:38px;height:38px}.card small{font-size:10px}.card.empty{font-size:11px}.panel{padding:6px 10px}.dialog{padding:8px;gap:8px}.dialog p{font-size:13px}}
.type.fire{background:#f7d6bf;color:#8a4626}.type.ghost{background:#e1d5ed;color:#664784}.type.dragon{background:#cbdcc8;color:#3c603d}
.full-team{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:8px;list-style:none;margin:10px 0 0;padding:0}.full-team li{display:grid;justify-items:center;gap:3px;padding:6px 9px;background:#edf0de;border-radius:4px}.full-team img{width:58px;height:58px;image-rendering:pixelated}.full-team .type{margin:0}.full-team strong{font-size:14px}.panel.select .choices{display:grid;grid-auto-columns:minmax(0,1fr);grid-auto-flow:column}.panel.select .pick{min-width:0}.panel.select .pick strong,.panel.select .pick small{white-space:nowrap}
@media(max-width:680px){.full-team{grid-template-columns:repeat(3,1fr);gap:3px}.full-team li{padding:1px 6px;gap:1px}.full-team img{width:32px;height:32px}.panel.select .choices{gap:3px}.panel.select .pick{padding:3px}.panel.select .pick img{width:36px}.panel.select .pick strong{font-size:12px}.panel.select .pick small{font-size:10px}.panel.select h2{margin-bottom:5px}}
.field-tools{display:flex;align-items:center;gap:9px}:is(#center-open,#journal-open){cursor:pointer;font:800 13px system-ui;border:1px solid #aebd98;border-bottom-width:3px;border-radius:5px;padding:6px 9px;background:#f5f8e7;color:#3e5a41}:is(#center-open,#journal-open):disabled{opacity:.5;cursor:default}:is(#center-open,#journal-open) span{color:#a55746}:is(#center-open,#journal-open) kbd{margin-left:3px}.viewport{aspect-ratio:16/9;min-height:0}.viewport #field{width:100%;height:100%;object-fit:contain;outline-offset:-4px}#map-hud{position:absolute;right:10px;top:10px;background:#233f37e8;color:#eff1db;padding:5px 7px 7px;border:2px solid #c4d0ae;border-radius:4px;box-shadow:0 2px 0 #23433655;pointer-events:none}#map-hud span{display:block;font-size:10px;font-weight:800;margin:0 0 3px}#map-hud canvas{width:108px;height:72px;image-rendering:pixelated}#map-hud[hidden]{display:none}.viewport #overlay{z-index:1}.panel{max-height:95%}.panel h2{outline:none}.panel.center{width:min(480px,100%)}.center-team{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:5px}.center-option{font:inherit;color:inherit;padding:5px;border:1px solid #bec6a9;border-radius:3px;background:#f5f4e9;cursor:pointer}.center-option[aria-pressed=true]{border-color:#345d46;background:#dfeccf;box-shadow:inset 0 0 0 1px #345d46}.center-option:disabled,.pick:disabled{opacity:.6;cursor:default}.center-option img{width:40px;height:40px;image-rendering:pixelated;display:block;margin:auto}.center-option b,.center-option small{display:block}.center-option small,.card .vitals{font-size:11px;color:#516847}.center-status{font-size:12px;margin:8px 0 0}.controls{display:flex;gap:8px;justify-content:center}.action.secondary{background:#f1f0e1;color:#476047;border:1px solid #a6b69b}.action:disabled{opacity:.5;cursor:default}button:focus-visible,#field:focus-visible{outline:3px solid #b87b24}.pick .hp{width:100%;max-width:74px}.card .hp{width:65px;margin:3px 0 0;height:4px}.vitals{white-space:nowrap}.center-summary{font-size:13px;margin:0 0 9px}.dialog{min-height:64px}
@media(max-width:680px){.heading{align-items:center}.field-tools{gap:4px;flex-wrap:wrap;justify-content:flex-end}.field-tools .mode{font-size:10px}.center-team{grid-template-columns:repeat(3,1fr);gap:2px}.center-option{padding:2px;font-size:11px}.center-option img{width:22px;height:22px}.panel.center h2,.center-summary{margin:0 0 3px}.controls .action{margin-top:3px}.center-status{margin:2px 0}.viewport #field{height:100%}#map-hud{right:4px;top:4px;padding:3px}#map-hud canvas{width:72px;height:48px}#map-hud span{font-size:8px}.keystrip{flex-wrap:wrap}}
.map-tools{position:absolute;display:flex;align-items:flex-end;gap:6px;right:10px;bottom:10px}.map-tools[hidden]{display:none}.map-tools #map-hud{position:static}.map-tools :is(#center-open,#journal-open){color:#f4f3dd;background:#294337f0;border:2px solid #bac9a8;box-shadow:0 2px 0 #23433655}.map-tools :is(#center-open,#journal-open) span{color:#fed29e}
@media(max-width:680px){.map-tools{right:4px;bottom:4px;gap:3px}.map-tools :is(#center-open,#journal-open){font-size:11px;padding:3px 5px}.map-tools :is(#center-open,#journal-open) kbd{display:none}}
.center-option{position:relative}.center-option[aria-pressed=true]::after{content:"✓";position:absolute;top:3px;right:4px;font-size:12px;color:#375f3d;font-weight:900}

#trainer-picker { width:min(410px,92vw); padding:24px; text-align:center; color:#263f33; background:#fff9e8; border:3px solid #364e3c; border-radius:10px; box-shadow:0 6px 0 #776c51; }
#trainer-picker::backdrop { background:#192e26b8; }
#trainer-picker h2 { margin:0 0 18px; }
.trainer-options { display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-bottom:16px; }
.trainer-options button { display:grid; justify-items:center; padding:12px 4px; color:inherit; background:#edf1e3; border:2px solid #bbbea6; border-radius:6px; cursor:pointer; }
.trainer-options button[aria-pressed=true] { border-color:#385840; background:#f7e7b4; box-shadow:inset 0 0 0 2px #fff7d6; }
.trainer-options button:focus-visible { outline:2px dashed #30543b; outline-offset:2px; }
.trainer-options small { margin-top:3px; }
.portrait { height:96px; width:96px; image-rendering:pixelated; background:url('./assets/player-1.png') no-repeat 0 0 / 288px 384px; }
[data-player="2"] .portrait { background-image:url('./assets/player-2.png'); }
[aria-pressed=true] .portrait { animation:trainer-stride .55s step-end infinite; }
@keyframes trainer-stride { 0%,100% {background-position:-96px 0} 50% {background-position:-192px 0} }
@media (prefers-reduced-motion:reduce) { [aria-pressed=true] .portrait {animation:none;} }

.mode-options,.commanders,.foe {display:flex;gap:12px;justify-content:center;align-items:center}
.mode-options {margin-bottom:12px}
.mode-options button,.commanders button {border:1px solid #899882;border-radius:5px;background:#faf7e8;padding:7px 12px;cursor:pointer;color:#263e33}
.mode-options [aria-pressed=true] {background:#365b43;color:white}
#expedition {padding:10px 0;color:#395643;font-weight:650;font-size:.88rem}
.campaign-panel {min-width:min(440px,91%);overflow:auto}.campaign-panel>img,.foe img {width:68px;height:68px;image-rendering:pixelated}
.commanders {align-items:stretch}.commanders section {flex:1;padding:12px 6px;background:#ecefdf;border-radius:6px}
.campaign-panel .center-team {max-height:38vh;overflow:auto}.campaign-panel p {margin:8px 0}.campaign-panel h2{margin:8px}
#journal {border-block:1px solid #c8cbb6;padding:10px 0;color:#2d4b39}#journal{width:min(760px,90vw);max-height:80vh;box-sizing:border-box;overflow:auto;padding:16px;background:#faf8eb;border:2px solid #809471;border-radius:8px}#journal::backdrop{background:#19382bb3}#journal header{display:flex;align-items:center;justify-content:space-between}#journal header h2{margin:0}#journal button{cursor:pointer;padding:5px 12px}#journal-pages{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:12px}#journal ul{list-style:none;margin:0;padding:0}#journal li{display:flex;align-items:center;gap:8px;padding:4px}#journal li img,#journal .unknown{width:30px;height:30px;image-rendering:pixelated}#journal .unknown{text-align:center;background:#e5e5d7;border-radius:50%;line-height:30px}#journal small{display:block;color:#53614f}
.commanders img { display:block; width:50px;height:50px;image-rendering:pixelated;margin:0 auto 4px }
.commanders small {display:block;margin-top:3px;color:#506451}
.commanders .incoming {box-shadow:inset 0 0 0 2px #af6843}
.commanders .threat {color:#823817;font-weight:700}

#overlay.speech-layer {background:transparent;padding:0;display:block}
#overlay.speech-layer[hidden] {display:none}
.speech-box {position:absolute;box-sizing:border-box;width:min(348px,calc(100% - 8px));display:flex;flex-direction:column;align-items:flex-start;background:#fffae9;color:#263f33;border:2px solid #38513e;border-radius:10px;padding:9px 12px;box-shadow:0 3px 0 #243e3440;text-align:left}
.speech-box::after {content:"";position:absolute;left:var(--tail);width:12px;height:12px;background:#fffae9;transform:rotate(45deg);top:-8px;border-left:2px solid #38513e;border-top:2px solid #38513e}
.speech-box.above::after {top:auto;bottom:-8px;transform:rotate(225deg)}
.speech-name {background:transparent;color:#34563d;border:0;padding:0;font-size:14px;font-weight:800}
.speech-content {overflow:auto;min-height:0;width:100%;overscroll-behavior:contain}
.speech-content p,.reward-entry p {margin:4px 0}.speech-content h3{font-size:14px;margin:8px 0 3px}
.speech-box .action {align-self:flex-end;margin:4px 0 0;font-size:12px;padding:3px 9px}
.center-tabs {display:flex;justify-content:center;gap:6px;margin:6px 0 10px}
.center-tabs button {font:inherit;border:1px solid #abb6a0;background:#f9f7ea;color:#324c3b;border-radius:5px;padding:4px 12px;cursor:pointer}
.center-tabs [aria-pressed=true]{background:#34563d;color:white}
.reward-list {max-height:36vh;overflow:auto;overscroll-behavior:contain}
.reward-entry {text-align:left;border-left:3px solid #aebf8d;padding:5px 9px;margin:4px 0 10px;background:#f0f0df;font-size:13px}
.reward-entry small{display:block;color:#55664e}.reward-entry ul{padding-left:18px;margin:5px 0}.reward-unlock{font-weight:700;color:#365b3b}
.rival-title,.rival-match,.rival-choices,.rival-lineup,.rival-lineup li{display:flex;align-items:center;justify-content:center;gap:8px}
.rival-title>span{font-size:22px;color:#934d34}.rival-title h2{margin-left:0}.rival-lineup{list-style:none;padding:0;margin:10px 0;flex-wrap:wrap}.rival-lineup li{background:#eee9d6;border:1px solid #c8c4a9;border-radius:6px;padding:6px 12px;text-align:left;font-size:13px;font-weight:700}.rival-lineup img{width:40px;height:40px;image-rendering:pixelated}.rival-lineup small,.rival-match span{display:block;font-size:11px;color:#65735d;font-weight:600}.rival-choices .action{margin:0}.rival-choices .action[aria-pressed=false]{background:#f3eedf;color:#4a594b;border-color:#abae95}.rival-choices{margin-bottom:6px}.campaign-panel .rival-reward{font-size:12px;color:#76532e}.rival-match{justify-content:space-between;margin-bottom:6px;border-bottom:1px solid #d8d3b9;padding-bottom:5px;color:#784835;font-size:13px}

#journal-pages[hidden]{display:none}
.journal-entry{display:flex;align-items:center;gap:8px;width:100%;text-align:left;font:inherit;color:inherit;background:#f4f5e8;border:1px solid #bfcaac;border-radius:5px}
#journal-detail ol{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;list-style:none;margin:0;padding:0}
#journal-detail li{flex-direction:column;text-align:center;background:#edf1df;border-radius:6px}
#journal-detail li img{width:min(100%,96px);height:auto}

#current-objective{display:none}
.touch-game .keystrip,.touch-game .mode-options,.touch-game #center-open kbd{display:none}
#touch-controls[hidden]{display:none}
.touch-pad{display:grid;grid-template-columns:repeat(3,44px);grid-template-rows:repeat(3,44px);gap:2px;touch-action:none;user-select:none;-webkit-user-select:none}
.touch-pad [data-dir=ArrowUp]{grid-area:1 / 2}.touch-pad [data-dir=ArrowLeft]{grid-area:2 / 1}.touch-pad [data-dir=ArrowDown]{grid-area:3 / 2}.touch-pad [data-dir=ArrowRight]{grid-area:2 / 3}
#touch-controls button{border:2px solid #889c81;border-bottom-width:3px;border-radius:8px;background:#fcf9e9;color:#304b39;font:700 16px system-ui;min-height:44px;touch-action:none;user-select:none;-webkit-user-select:none}
#touch-controls button:active{background:#d3e3bf}#touch-action{min-width:84px}
.touch-game :is(.map-tools,#overlay,#journal,#trainer-picker) button{min-height:44px;min-width:44px}
#center-open,.center-screen button{-webkit-user-select:none;user-select:none;touch-action:manipulation}
.center-screen .center-option img{pointer-events:none}
.center-screen .center-option[aria-pressed=true]::after{content:"✓ 선택";background:#34563d;color:white;border-radius:4px;padding:2px 4px}



/* The camera, edge controls and HUD share one safe-area grid cell. */
html:has(body.touch-game){overflow:hidden;overscroll-behavior:none}
body.touch-game{
  --frame-gap:5px;--status-h:44px;--dialog-h:52px;
  margin:0;width:var(--game-vw,100vw);max-width:100vw;height:var(--game-vh,100dvh);max-height:100dvh;
  padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow:hidden;overscroll-behavior:none;background:#e9eddb;
}
.touch-game>header,.touch-game #expedition,.touch-game .companions{display:none}
.touch-game main{width:100%;height:100%;min-width:0;min-height:0;margin:0;display:grid;grid-template-rows:var(--status-h) minmax(0,1fr)}
.touch-game .heading{margin:0;padding:0 10px;min-width:0;display:flex;gap:10px;align-items:center;justify-content:flex-start;background:#253f34;color:#fffceb;border-bottom:2px solid #a8b18d}
.touch-game .heading>div:first-child{flex:none}
.touch-game .heading .route,.touch-game .heading .field-tools{display:none}
.touch-game h1{font-size:17px;letter-spacing:-.6px;line-height:1.2;margin:0;color:inherit}
.touch-game #current-objective{display:block;font-size:12px;color:#e5ebcf;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;min-width:0}
.touch-game .console{
  position:relative;display:grid;grid-template-columns:minmax(0,1fr);
  grid-template-rows:minmax(0,1fr) var(--dialog-h);
  align-items:stretch;min-width:0;min-height:0;max-width:none;margin:0;
  overflow:hidden;border:0;border-radius:0;box-shadow:none;background:#e7ecd9;
}
.touch-game .viewport{grid-column:1/-1;grid-row:1;align-self:stretch;position:relative;min-width:0;min-height:0;aspect-ratio:auto;overflow:hidden}
.touch-game .viewport #field{width:100%;height:100%;aspect-ratio:auto;display:block;object-fit:fill}
.touch-game #touch-controls:not([hidden]){display:contents}
.touch-game .touch-pad,.touch-game #touch-action,.touch-game .console>.map-tools:not([hidden]){
  grid-column:1;grid-row:1;position:relative;inset:auto;z-index:1;margin:8px;
}
.touch-game .touch-pad{align-self:end;justify-self:start;pointer-events:none}
.touch-game #touch-controls .touch-pad button{pointer-events:auto;background:rgba(248,248,227,.75);border-color:rgba(53,77,57,.75);color:#223b2b}
.touch-game #touch-controls .touch-pad button[data-move-pressed]{background:#d3e3bf}
.touch-game #touch-action{align-self:end;justify-self:end;min-width:88px;height:48px;color:#fffbe9;background:rgba(41,71,49,.84);border-color:rgba(222,232,204,.86)}
.touch-game #touch-action:disabled{background:rgba(224,228,204,.72);color:#4f6051;border-color:rgba(111,129,101,.65)}
.touch-game #touch-controls button:active{background:#d3e3bf;color:#253b2c}
.touch-game .console>.map-tools:not([hidden]){
  display:flex;align-self:start;justify-self:end;align-items:flex-start;gap:4px;pointer-events:none
}
.touch-game .console>.map-tools :is(#center-open,#journal-open){pointer-events:auto;padding:2px 5px;font-size:11px;line-height:1.2;background:rgba(36,63,47,.81);border-color:rgba(198,213,171,.85)}
.touch-game .map-tools #map-hud{position:static;padding:2px;border-radius:3px;box-shadow:none;opacity:.84}
.touch-game #map-hud span{display:none}
.touch-game #map-hud canvas{width:60px;height:40px}
.touch-game .dialog{grid-column:1/-1;grid-row:2;overflow:hidden;min-height:0;padding:3px 9px;gap:7px;border-top:2px solid #536a48;border-bottom:1px solid #b2b99e}
.touch-game .dialog .guide-icon{width:26px;height:26px;font-size:18px}
.touch-game .dialog>div{overflow:auto;max-height:100%;min-width:0;overscroll-behavior:contain;font-size:12px;line-height:1.4}
.touch-game .dialog #speaker{font-size:11px;margin-right:4px}.touch-game .dialog p{display:inline;font-size:12px;line-height:1.4;margin:0}
.touch-game .console:has(#overlay:not([hidden])){grid-template: minmax(0,1fr) var(--dialog-h) / minmax(0,1fr)}
.touch-game #overlay:not([hidden]){position:absolute;inset:0;height:auto;padding:4px;overflow:hidden}
.touch-game #overlay.speech-layer:not([hidden]){padding:0}
.touch-game #overlay .campaign-panel{width:min(540px,100%);max-width:100%;min-width:0;max-height:100%;overflow:auto;padding:7px;overscroll-behavior:contain}
.touch-game .campaign-panel h2{font-size:17px;margin:4px}
.touch-game .campaign-panel .action{margin-top:4px}
.touch-game #overlay .speech-box{position:absolute;max-width:calc(100% - 8px);margin:0}
.touch-game .center-screen .campaign-panel{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:auto auto minmax(0,1fr) auto;height:100%;overflow:hidden!important}
.touch-game .center-screen :is(h2,.center-tabs,.center-team,.reward-list){grid-column:1/-1}
.touch-game .center-screen .center-tabs{margin:2px 0 4px}
.touch-game .center-screen :is(.center-team,.reward-list){min-height:0;max-height:none;align-content:start;overflow:auto;overscroll-behavior:contain}
.touch-game .center-screen .center-option{min-width:0}.touch-game .center-screen .center-option img{width:32px;height:32px}
.touch-game .center-screen .action:only-of-type{grid-column:1/-1}
.touch-game #trainer-picker{max-height:calc(var(--game-vh,100dvh) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 12px);padding:12px;overflow:auto}

@media(orientation:landscape){
  body.touch-game{--status-h:36px;--dialog-h:44px}
  .touch-game #map-hud canvas{width:72px;height:48px}
  .touch-game #overlay .campaign-panel:has(.commanders){width:min(660px,100%);display:grid;grid-template-columns:minmax(150px,1fr) minmax(0,1.65fr);align-items:center;gap:2px 8px}
  .touch-game .campaign-panel:has(.commanders) :is(.rival-match,h2){grid-column:1/-1}
  .touch-game .campaign-panel:has(.commanders) h2{grid-row:1}
  .touch-game .campaign-panel:has(.commanders) .rival-match{grid-row:2}
  .touch-game .campaign-panel .commanders section{padding:5px}
  .touch-game .campaign-panel .commanders img{width:34px;height:34px}
  .touch-game #trainer-picker h2,.touch-game #trainer-picker .trainer-options{margin-bottom:5px}
  .touch-game #trainer-picker .trainer-options button{padding:4px}
}

/* Short landscape screens keep command controls on a full-height final row.
   Place the sprite beside the stats so the battle log never pushes that row down. */
@media (orientation:landscape) and (max-height:420px) {
  .touch-game .campaign-panel .commanders section {
    display:grid;
    grid-template-columns:48px minmax(56px,1fr) 48px;
    align-items:center;
    column-gap:4px;
    row-gap:2px;
  }
  .touch-game .commanders section > img {grid-area:1/1/4/2;margin:0 auto}
  .touch-game .commanders section > :is(b,small) {grid-column:2/-1;margin:0;line-height:1.25}
  .touch-game .commanders section > p {grid-column:1/-1;margin:2px 0;font-size:13px;line-height:1.25}
  .touch-game .commanders section > button {width:100%;height:44px;padding:2px 4px}
}

.console:has(.result-screen) > .dialog {display:none}
.touch-game .console:has(#overlay.result-screen) {grid-template: minmax(0,1fr) / minmax(0,1fr)}
.result-recruit {display:flex;justify-content:center;align-items:center;gap:12px;padding:10px;background:#e9f2dc;border-radius:8px}
.result-recruit img {width:64px;height:64px;image-rendering:pixelated}
.result-recruit div {text-align:left}
.result-recruit h3,.result-reward h3 {margin:2px 0}
.result-reward {padding:6px 0}
.result-reward h3 {font-size:1rem}
.result-reward p,.result-reward ul {margin:3px 0}
.result-reward ul {list-style:none;padding:0}
.result-last-turn summary {padding:7px;cursor:pointer}

.touch-game .commanders button{border-radius:0}
.touch-game #overlay.result-screen .campaign-panel {
  display:grid;
  grid-template-rows:auto minmax(0,1fr) auto;
  min-height:0;
  height:100%;
  overflow:hidden;
}
.result-screen .result-heading>img {width:64px;height:64px;image-rendering:pixelated}
.touch-game .result-screen .result-body {overflow-y:auto;min-height:0;overscroll-behavior:contain}
.touch-game .result-screen .action {justify-self:center;min-height:44px}
@media (orientation:landscape) and (max-height:480px) {
  .touch-game .result-screen .result-heading {display:flex;gap:10px;align-items:center;justify-content:center}
  .touch-game .result-recruit {padding:4px 8px}
  .touch-game .result-screen :is(.result-recruit,.result-heading)>img {width:48px;height:48px}
}

/* Consecutive combat confirmations are game input; preserve panning and pinch zoom. */
.touch-game .console,.touch-game .console button {touch-action:manipulation}
.touch-game .touch-pad,.touch-game #touch-controls button {touch-action:none}

.recruit-tip {display:block;font-size:13px;font-weight:700;color:#315a3d}
.commanders .lead-compare,
.touch-game .campaign-panel .commanders section.lead-compare {display:grid;grid-template-columns:minmax(0,1fr);gap:6px;align-content:start}
.lead-compare > b {grid-area:auto!important}
.lead-cards {display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:4px;max-height:32vh;overflow:auto}
.lead-cards button {padding:4px}
.lead-cards [aria-pressed="true"] {color:#fff;background:#34563f}
.lead-cards [aria-pressed="true"] small {color:inherit}
.lead-controls {display:flex;justify-content:center;gap:4px}

/* Fit the keyboard play area, instructions and battle controls in short windows. */
@media (orientation:landscape) and (max-height:480px) {
  body:not(.touch-game) > header,
  body:not(.touch-game) :is(.heading .route,#expedition,.companions) {
    display:none;
  }

  body:not(.touch-game) main {
    display:grid;
    grid-template-rows:auto minmax(0,1fr) auto;
    width:min(1080px,100%);
    height:100dvh;
    padding:0 8px;
  }

  body:not(.touch-game) .heading {
    align-items:center;
    gap:8px;
    margin:4px 0;
  }
  body:not(.touch-game) .heading h1 {
    margin:0;
    font-size:20px;
    letter-spacing:-.5px;
  }
  body:not(.touch-game) #current-objective {
    display:block;
    min-width:0;
    margin-right:auto;
    overflow:hidden;
    color:#456641;
    font-size:12px;
    text-overflow:ellipsis;
    white-space:nowrap;
  }
  body:not(.touch-game) .heading .mode {
    display:block;
    padding:3px 7px;
  }

  body:not(.touch-game) .console {
    display:grid;
    grid-template-rows:minmax(0,1fr) auto;
  }
  body:not(.touch-game) .viewport {
    min-height:0;
    aspect-ratio:auto;
  }
  body:not(.touch-game) .viewport #field { background:#283e38 }
  body:not(.touch-game) .dialog {
    min-height:36px;
    padding:3px 8px;
    gap:6px;
  }
  body:not(.touch-game) .dialog .guide-icon {
    width:25px;
    height:25px;
    font-size:16px;
  }
  body:not(.touch-game) .dialog > div {
    max-height:46px;
    overflow:auto;
    font-size:12px;
  }
  body:not(.touch-game) .dialog p {
    display:inline;
    margin:0;
    font-size:12px;
  }
  body:not(.touch-game) .keystrip {
    margin:0;
    min-height:23px;
    align-content:center;
  }

  body:not(.touch-game) #trainer-picker {
    padding:12px 16px;
  }
  body:not(.touch-game) #trainer-picker h2,
  body:not(.touch-game) #trainer-picker :is(.mode-options,.trainer-options) {
    margin-bottom:6px;
  }
  body:not(.touch-game) #trainer-picker .trainer-options button {
    padding:4px;
  }

  body:not(.touch-game) .campaign-panel:has(.commanders) {
    display:grid;
    grid-template-columns:minmax(0,1fr) minmax(0,3fr);
    width:min(720px,100%);
    max-height:100%;
    min-width:0;
    align-items:center;
    gap:4px 8px;
    padding:6px 8px;
  }
  body:not(.touch-game) .campaign-panel:has(.commanders) :is(h2,.rival-match) {
    grid-column:1/-1;
    margin:0;
  }
  body:not(.touch-game) .campaign-panel:has(.commanders) h2 { grid-row:1 }
  body:not(.touch-game) .campaign-panel:has(.commanders) .rival-match { grid-row:2 }
  body:not(.touch-game) .campaign-panel:has(.commanders) .recruit-tip {
    grid-column:1/-1;
    margin:0;
    font-size:12px;
  }
  body:not(.touch-game) .campaign-panel .foe {
    flex-direction:column;
    gap:3px;
    font-size:13px;
  }
  body:not(.touch-game) .campaign-panel .foe img {
    width:46px;
    height:46px;
  }
  body:not(.touch-game) .commanders { gap:6px }
  body:not(.touch-game) .commanders section {
    min-width:0;
    padding:5px;
  }
  body:not(.touch-game) .commanders section > img {
    width:34px;
    height:34px;
    margin-bottom:1px;
  }
  body:not(.touch-game) .commanders section > p {
    margin:4px 0;
    font-size:13px;
  }
  body:not(.touch-game) .commanders button {
    min-height:32px;
    padding:3px 7px;
  }

  body:not(.touch-game) .result-screen .campaign-panel {
    display:grid;
    grid-template-rows:auto minmax(0,1fr) auto;
    max-height:100%;
    overflow:hidden;
    padding:8px 12px;
  }
  body:not(.touch-game) .result-screen .result-heading {
    display:flex;
    align-items:center;
    justify-content:center;
    gap:10px;
  }
  body:not(.touch-game) .result-screen .result-recruit { padding:4px 8px }
  body:not(.touch-game) .result-screen :is(.result-heading,.result-recruit) > img {
    width:46px;
    height:46px;
  }
  body:not(.touch-game) .result-screen .result-body {
    overflow-y:auto;
    overscroll-behavior:contain;
  }
  body:not(.touch-game) .result-screen .action {
    justify-self:center;
    margin-top:4px;
  }
}

.combat-screen .campaign-panel {
  display:grid;
  grid-template-columns:minmax(104px,1fr) minmax(0,2.4fr);
  align-items:center;
  width:min(720px,100%);
  gap:6px 10px;
}
.combat-screen .campaign-panel h2 {
  grid-column:1/-1;
  order:-4;
  margin:0;
}
.combat-screen .rival-match {grid-column:1/-1;order:-3;margin:0}
.combat-screen .battle-tutorial {
  grid-column:1/-1;
  order:-2;
  margin:0;
  padding:5px 8px;
  background:#eef1de;
  border-radius:4px;
  font-size:12px;
  color:#36563f;
}
.combat-screen .foe {
  order:-1;
  flex-direction:column;
  gap:3px;
}
.combat-screen .foe small {display:block;color:#506451}
.combat-screen .commanders section:not(.lead-compare) {
  display:grid;
  grid-template-columns:auto minmax(0,1fr);
  align-items:center;
  gap:4px 6px;
  min-width:0;
}
.combat-screen .commanders section:not(.lead-compare) > img {
  grid-area:auto;
  width:44px;
  height:44px;
  margin:0;
}
.combat-screen .combat-stats {text-align:left}
.combat-screen .commanders section > :is(.threat,.attack-preview,.command-status,.command-buttons) {
  grid-column:1/-1;
  margin:0;
}
.combat-screen .commanders .attack-preview strong {color:#315a3d}
.combat-screen .command-status {font-size:13px}
.battle-hp {
  display:grid;
  gap:3px;
  justify-items:start;
  font-size:12px;
  font-variant-numeric:tabular-nums;
}
.foe .battle-hp {justify-items:center}
.battle-hp-meter {
  width:min(96px,100%);
  height:6px;
  background:#dcdcc8;
  border-radius:3px;
  overflow:hidden;
}
.battle-hp-meter i {
  display:block;
  height:100%;
  background:#537a3d;
  transform-origin:left;
  transform:scaleX(var(--hp-current));
}
.battle-hp-meter[data-change] i {animation:battle-hp-drain 240ms ease-out}
@keyframes battle-hp-drain {from {transform:scaleX(var(--hp-previous))}}
.command-buttons {display:flex;justify-content:center;flex-wrap:wrap;gap:4px}
.combat-screen .command-buttons button {
  border:1px solid #899882;
  border-radius:5px;
  background:#faf7e8;
  color:#263e33;
  padding:5px 10px;
  font:700 13px system-ui;
  cursor:pointer;
}
.combat-screen .command-buttons [aria-pressed=true] {background:#365b43;color:#fffced}
.touch-game .combat-screen .command-buttons button {flex:1;min-width:44px}
.battle-playback .replay-commanders {align-items:center}
.battle-playback .combat-member small {margin:0}
.battle-playback .campaign-panel .round-event {
  grid-column:1/-1;
  margin:0;
  padding:7px 8px;
  color:#fffced;
  background:#324f3d;
  border-radius:5px;
  font-size:14px;
  font-weight:700;
}
.battle-playback .round-event[data-event=enemyHit] {background:#783e29}
.battle-playback .fainted img {filter:grayscale(1);opacity:.35}
.battle-playback .strike-from img {animation:battle-strike 240ms ease-out}
.battle-playback .combat-arrive img {animation:battle-arrive 230ms ease-out}
.battle-recap {
  grid-column:1/-1;
  width:100%;
  border-top:1px solid #d8d3b9;
  color:#36563f;
  font-size:12px;
}
.battle-recap summary {
  padding:3px 0;
  cursor:pointer;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.battle-recap ol {margin:0;padding:0 0 4px 24px;text-align:left}
.touch-game #overlay.combat-screen .campaign-panel {grid-template-columns:minmax(0,1.65fr) minmax(95px,1fr)}
.touch-game .combat-screen .foe {order:0}
.touch-game .combat-screen .commanders {order:-1}
@keyframes battle-strike {50% {transform:translateX(5px);filter:brightness(1.2)}}
@keyframes battle-arrive {from {opacity:0;transform:translateY(7px)}}

@media (orientation:landscape) and (max-height:420px) {
  .combat-screen .campaign-panel {gap:3px 6px}
  .combat-screen .campaign-panel .battle-tutorial {padding:3px 5px}
  .combat-screen .commanders section:not(.lead-compare) > img {width:34px;height:34px}
  .combat-screen .battle-hp {gap:2px}
}
@media (prefers-reduced-motion:reduce) {
  .battle-playback :is(.hit,.strike-from,.combat-arrive) img,
  .battle-hp-meter[data-change] i {animation:none}
}

/* The signup form can open before the on-demand school theme arrives.
   Size the native controls in the initial stylesheet, including on iOS. */
#school-panel select {
  -webkit-appearance: none;
  appearance: none;
  min-width: 44px;
  min-height: 44px;
  height: 44px;
}

#overlay .campaign-panel:has(.quest-board-heading) {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}
.quest-board-heading {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#overlay .quest-board-heading :is(h2, button) { margin: 0; }
.quest-board-list { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.quest-board-list + button { flex: none; align-self: center; }

#trail-hud:not([hidden]){display:flex;align-items:stretch;gap:8px;background:#263e33;color:#fff9e2;padding:5px 8px}
.trail-signs{flex:1;min-width:0;display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:4px}
.trail-signs>div{display:flex;align-items:center;gap:4px;background:#fcf4d9;color:#293c2d;border:1px solid #a7a782;padding:3px 6px;border-radius:4px;line-height:1.2}
.trail-signs img{width:30px;height:30px;image-rendering:pixelated;flex:none}
.trail-signs strong,.trail-signs small{display:block;font-size:.82rem;overflow-wrap:anywhere}
.trail-vitals{display:flex;align-items:center;gap:8px;font-size:.82rem}
#trail-return,#trail-enter{min-height:44px;pointer-events:auto;font:700 .82rem system-ui;color:#f7f3df;background:#354f3a;border:1px solid #b3c09e;border-radius:4px;cursor:pointer}
.touch-game main:has(#trail-hud:not([hidden])){grid-template-rows:var(--status-h) auto minmax(0,1fr)}
.touch-game #trail-hud:not([hidden]){padding:3px 5px;gap:4px}
.touch-game #touch-action[hidden]{display:none}
.touch-game .trail-vitals{max-width:34%;line-height:1.1;gap:4px}
.touch-game .trail-vitals button{padding:1px 6px;flex:none}
@media (orientation:portrait) {
  .touch-game #trail-hud:not([hidden]){display:grid}
  .touch-game .trail-vitals{max-width:none;justify-content:space-between}
}
.trail-camp{display:grid;gap:6px;color:#2c4636}
.trail-camp h2,.trail-camp p,.trail-camp .action{margin:0}
.trail-camp select{max-width:100%;min-height:44px;font:inherit}
.trail-camp>div{display:grid;grid-template-columns:1fr 1fr;gap:6px}
.trail-camp .action{min-height:44px}
.trail-achievement{font-weight:800}
/* Leave the top edge of short playfields free for both the pad and the map. */
.touch-game.trail-field:has(#pilot-board) main{--status-h:max(46px,2.1rem)}
.touch-game.trail-field .heading #pilot-board{position:static;flex:none;margin-left:auto}

.growth-card {padding:4px 8px;line-height:1.3;background:#e7f3e0;color:#203e2d;border-inline-start:4px solid #527749;text-align:left}
.growth-card strong,.growth-card span {display:inline-block}
.growth-card .growth-gain,.growth-card .growth-hp {margin-inline-start:.35em}
.growth-hit,.growth-next,.growth-hp {font-size:.9em}

/* Battle panels include their own prompts and turn recap. Reserve the short
   landscape screen for the two combatants and their full-height touch buttons. */
@media (orientation: landscape) and (max-height: 420px) {
  .touch-game main:has(#overlay.combat-screen) { grid-template-rows:minmax(0,1fr); }
  .touch-game main:has(#overlay.combat-screen) > .heading,
  .touch-game .console:has(#overlay.combat-screen) > .dialog { display:none; }
  .touch-game .console:has(#overlay.combat-screen) {
    grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  }
}

/* The first water encounter usually offers two candidates. When there is only
   one row, let the cards grow with the child's text size without clipping it. */
.lead-cards:not(:has(> :nth-child(3))) {
  max-height:none;
  overflow:visible;
}
.lead-cards button { min-width:0; overflow-wrap:anywhere; }
