/* One viewport, three stable regions. Content and log scroll independently. */
html,body{width:100%;height:100%;overflow:hidden;overscroll-behavior:none}
body{margin:0}
#app{height:var(--game-height,100vh);height:min(var(--game-height,100dvh),100dvh);overflow:hidden}
#app>.loading{height:100%;overflow:auto;margin:0 auto;overscroll-behavior:contain}
.shell.viewport-shell{
  width:100%;max-width:1800px;height:100%;min-height:0;margin:0 auto;
  padding:12px max(16px,env(safe-area-inset-right)) max(6px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));
  display:grid;grid-template-rows:58px 34px minmax(0,1fr) 36px;gap:0;
}
.viewport-shell .masthead{min-width:0;min-height:0;padding:0 0 10px;gap:10px;overflow:hidden}
.viewport-shell .brand{gap:10px;min-width:0;white-space:nowrap}
.viewport-shell .brand strong{font-size:22px;letter-spacing:3px}
.viewport-shell .seal{width:32px;height:36px;flex-shrink:0}
.viewport-shell .mast-links{gap:16px;flex-shrink:0}
.viewport-shell .mast-links>a{display:inline-flex;align-items:center;min-height:44px;font-size:12px}
.resource-strip{display:flex;align-items:center;min-width:0;overflow:auto;white-space:nowrap;overscroll-behavior:contain;scrollbar-width:thin}
.strip-note{font-size:11px;letter-spacing:1px;color:var(--muted)}
.viewport-shell .resource-strip .resources{margin:0;padding:0;border:0;flex-wrap:nowrap;gap:20px;font-size:12px}
.shell.viewport-shell .viewport-layout{
  min-height:0;min-width:0;display:grid;grid-template-columns:110px minmax(0,1fr);
  grid-template-rows:minmax(0,1fr);gap:16px;margin:0;padding:0;align-items:stretch;
}
.viewport-shell .rail{grid-column:1;grid-row:1;position:static;min-height:0;min-width:0;overflow:auto;overscroll-behavior:contain;scrollbar-width:thin}
.viewport-shell .tabs{display:flex;flex-direction:column;gap:4px;margin:0;min-width:0}
.viewport-shell .tabs button{display:flex;min-height:44px;align-items:center;justify-content:flex-start;padding:8px 10px;gap:8px;font-size:13px;flex-shrink:0}
.viewport-shell.in-battle .tabs button:disabled{display:flex}
.prelude-navigation{margin:10px;font-size:12px;color:var(--muted);line-height:2.2}
.viewport-shell .main{
  grid-column:2;grid-row:1;height:100%;min-width:0;min-height:0;overflow:auto;
  padding:16px 20px 28px;border:1px solid var(--line);background:#f8f5eb80;
  overscroll-behavior:contain;scrollbar-gutter:stable;scrollbar-width:thin;overflow-wrap:anywhere;
}
.viewport-shell .main:focus-visible{outline:2px solid var(--green);outline-offset:-3px}
.viewport-shell .main .section-top h1{margin-bottom:14px;font-size:27px}
.viewport-shell .main .location{padding:20px;margin-bottom:16px}
.viewport-shell .main .prose{font-size:17px;line-height:2;margin-bottom:18px}
.viewport-shell .main .card{padding-block:16px}
.viewport-shell .main .story-door{min-height:74px;padding:12px 14px}
.viewport-shell .footer{min-width:0;min-height:0;overflow:hidden;display:flex;align-items:center;justify-content:space-between;margin:0;padding:0;border-top:0;font-size:11px;letter-spacing:0;gap:10px}
.viewport-shell .footer>span{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.viewport-shell .footer .text-action{min-height:32px;padding:2px 0;white-space:nowrap;font-size:11px}
.activity-panel{
  grid-column:3;grid-row:1;display:grid;grid-template-rows:48px minmax(0,1fr) 26px;min-height:0;min-width:0;
  overflow:hidden;border:1px solid var(--line);border-top:3px solid var(--green);background:var(--panel);
}
.activity-heading{display:flex;align-items:center;justify-content:space-between;gap:6px;padding:0 12px;border-bottom:1px solid var(--line);min-width:0;overflow:hidden}
.activity-heading h2{display:flex;align-items:center;gap:6px;white-space:nowrap;margin:0;font-size:14px}
.activity-heading .game-icon{width:16px;height:16px;flex-basis:16px}
.log-latest{display:flex;align-items:center;gap:4px;flex-shrink:0;min-height:44px;padding:0 4px;border:0;background:transparent;color:var(--green);font-size:11px}
.activity-list{min-height:0;min-width:0;overflow:auto;padding:0 12px;overscroll-behavior:contain;scrollbar-gutter:stable;scrollbar-width:thin;overflow-anchor:none}
.activity-list:focus-visible{outline:2px solid var(--green);outline-offset:-3px}
.activity-entry{padding:10px 0;border-bottom:1px dashed var(--line)}
.activity-meta{display:flex;align-items:center;justify-content:space-between;margin:0 0 4px;font-size:10px;color:var(--muted);font-variant-numeric:tabular-nums}
.activity-text{font-size:13px;line-height:1.8;white-space:pre-wrap;overflow-wrap:anywhere;margin:0}
.activity-empty{font-size:12px;line-height:2;color:var(--muted);margin:16px 0}
.activity-caption{display:flex;align-items:center;min-width:0;margin:0;padding:0 12px;border-top:1px solid var(--line);font-size:10px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.viewport-shell .opening{margin:12px auto;max-width:600px}
.viewport-shell .opening h1{font-size:28px}
.viewport-shell .opening-lines{font-size:18px}
.viewport-shell .opening-lines p{margin-block:5px}
.viewport-shell .opening-lines p:nth-child(3),.viewport-shell .opening-lines p:nth-child(5){margin-bottom:12px}
.viewport-shell .opening-lines p:last-child{font-size:23px}
.viewport-shell .opening .intro-line{margin:16px auto}
.viewport-shell .opening-actions{margin-top:18px}
.viewport-shell .battle-hint{min-height:0;margin-block:10px}
.viewport-shell .battle-grid{gap:12px}
.viewport-shell .battle-grid .battle-unit{padding:10px}
.viewport-shell .battle-transport{position:sticky;top:-16px;background:var(--panel);z-index:1}
html[data-short-viewport] .viewport-shell .battle-transport{position:static}
.skill-mode{display:flex;align-items:center;flex-wrap:wrap;gap:8px;margin:12px 0 6px}
.skill-mode>span{font-size:12px;color:var(--muted);margin-right:4px}
.skill-mode button{min-height:44px;min-width:88px;padding:6px 12px;font-size:12px}
.skill-mode button[aria-pressed=true]{color:#fff8e8;background:var(--green);border-color:var(--green)}
.skill-mode-hint{min-height:44px;margin:0;line-height:1.8}
dialog{max-height:calc(var(--game-height,100dvh) - 24px);overscroll-behavior:contain}
.recruit-result{max-height:calc(var(--game-height,100dvh) - 24px)}
@media(max-width:900px){
  .shell.viewport-shell{max-width:none;padding:6px max(10px,env(safe-area-inset-right)) max(4px,env(safe-area-inset-bottom)) max(10px,env(safe-area-inset-left));grid-template-rows:48px 28px minmax(0,1fr) 30px}
  .viewport-shell .masthead{padding-bottom:5px}
  .viewport-shell .brand{gap:8px}
  .viewport-shell .brand strong{font-size:20px;letter-spacing:2px}
  .viewport-shell .seal{width:28px;height:32px}
  .viewport-shell .edition{display:none}
  .viewport-shell .resource-strip .resources{font-size:11px;gap:14px}
  .shell.viewport-shell .viewport-layout{grid-template-columns:minmax(0,1fr);grid-template-rows:48px minmax(0,1fr);gap:8px}
  .viewport-shell .rail{grid-column:1;grid-row:1;overflow:hidden}
  .viewport-shell .tabs{height:100%;display:grid;grid-template-columns:repeat(7,minmax(0,1fr));gap:0;overflow:hidden}
  .viewport-shell .tabs button{display:flex;flex-direction:column;justify-content:center;min-width:0;min-height:44px;padding:3px 0;gap:3px;border-left:0;border-bottom:2px solid transparent;font-size:11px;line-height:1.2;white-space:nowrap}
  .viewport-shell .tabs button[aria-current=page]{border-bottom-color:var(--red)}
  .viewport-shell .tabs .game-icon{width:15px;height:15px;flex-basis:15px}
  .viewport-shell .main{grid-column:1;grid-row:2;padding:12px 12px 24px}
  .viewport-shell .main .section-top h1{font-size:24px;margin-bottom:12px;letter-spacing:2px}
  .viewport-shell .main .location{padding:16px 12px}
  .viewport-shell .main .prose{font-size:16px;line-height:1.9}
  .viewport-shell .main .story-door{min-height:68px;padding:10px;gap:8px}
  .viewport-shell .main .story-door strong{font-size:18px}
  .activity-panel{grid-column:1;grid-row:3;grid-template-rows:40px minmax(0,1fr) 20px}
  .activity-heading{padding-inline:10px}
  .activity-heading h2{font-size:13px}
  .log-latest{min-height:40px}
  .activity-list{padding-inline:10px}
  .activity-entry{padding-block:6px}
  .activity-text{font-size:12px;line-height:1.7}
  .activity-meta{font-size:10px;justify-content:flex-start;gap:10px;margin-bottom:2px}
  .activity-caption{padding-inline:10px;font-size:10px}
  .prelude-navigation{margin:0;line-height:44px;text-align:center;font-size:11px}
  .prelude-navigation br{display:none}
  .viewport-shell .footer{font-size:10px}
  .viewport-shell .footer .text-action{min-height:28px}
  .viewport-shell .battle-grid{gap:8px}
  .viewport-shell .battle-transport{top:-12px}
  .viewport-shell .main .savebox-current{padding:12px}
  .viewport-shell .main .savebox-files,.viewport-shell .main .savebox-cloud{padding:12px}
}
/* Landscape phones and short desktop windows keep the log beside the content. */
.growth-skill{border-top:1px solid var(--line);padding-block:14px;overflow-wrap:anywhere}
.growth-skill h3{display:flex;align-items:center;flex-wrap:wrap;gap:8px;margin-block:0 10px}
.growth-skill button{white-space:normal;min-height:44px;max-width:100%}
.growth-skill .note{margin-block:8px}
[data-fold^="hero-"] button,[data-fold^="stable-"] button{min-height:44px;max-width:100%;white-space:normal}
@media(min-width:600px) and (max-height:500px){
  .shell.viewport-shell{padding-top:4px;grid-template-rows:40px 24px minmax(0,1fr) 26px}
  .viewport-shell .brand strong{font-size:18px}
  .viewport-shell .seal{width:24px;height:28px}
  .shell.viewport-shell .viewport-layout{grid-template-columns:84px minmax(0,1fr);grid-template-rows:minmax(0,1fr);gap:8px}
  .viewport-shell .rail{grid-column:1;grid-row:1;overflow:auto}
  .viewport-shell .tabs{height:auto;display:flex;flex-direction:column;overflow:visible}
  .viewport-shell .tabs button{flex:0 0 auto;flex-direction:row;justify-content:flex-start;min-height:40px;font-size:11px;padding-inline:4px}
  .viewport-shell .main{grid-column:2;grid-row:1;padding:10px}
  .activity-panel{grid-column:3;grid-row:1;grid-template-rows:40px minmax(0,1fr) 20px}
  .activity-heading h2{font-size:12px}.activity-heading{padding-inline:8px}.activity-heading .game-icon{display:none}
  .log-latest{font-size:10px;min-height:40px}
}
/* An on-screen keyboard may reduce the usable height without changing CSS width. */
@media(max-width:599px){
  html[data-short-viewport] .shell.viewport-shell .viewport-layout{grid-template-rows:44px minmax(0,1fr);gap:4px}
  html[data-short-viewport] .activity-panel{grid-template-rows:32px minmax(0,1fr)}
  html[data-short-viewport] .activity-caption{display:none}
  html[data-short-viewport] .log-latest{min-height:32px}
}
