/* Compact game layout: keep the timeline, event and navigation within the viewport. */
body.compact-game{display:grid;grid-template-rows:64px minmax(0,1fr) calc(44px + env(safe-area-inset-bottom));height:100dvh;min-height:420px;overflow:hidden}
.compact-game>.game-header{grid-row:1}.compact-game>.game{grid-row:2}.compact-game>.game-footer{grid-row:3}
.compact-game .game-header{height:64px;display:grid;grid-template-columns:1fr auto 1fr;align-items:center;gap:12px}
.compact-game .brand{grid-column:1;grid-row:1;justify-self:start}
.compact-game .run-status{grid-column:2;grid-row:1;width:auto;min-height:0;margin:0;gap:10px}
.compact-game .landing-tools{position:static;grid-column:3;grid-row:1;justify-self:end}
.compact-game .game{height:100%;min-height:0;display:flex;flex-direction:column;gap:12px;padding:36px 0 12px;margin:0 auto}
.compact-game #heading,.compact-game #intro{display:none!important}
.compact-game .timeline-shell{flex:none;margin:0}
.compact-game .timeline-track{height:210px}
.compact-game .gap{height:210px}
.compact-game .timeline-token{min-height:154px;margin-bottom:46px;gap:7px}
html[data-timeline=thread] .compact-game .timeline-track::before{bottom:33px}
html[data-timeline=thread] .compact-game .gap::after{bottom:21px}
html[data-timeline=thread] .compact-game .gap.first::after{bottom:9px}
.compact-game .gap::before{bottom:12px;top:12px}
.compact-game .start-label{bottom:89px}
.compact-game .timeline-ends{top:199px}
.compact-game .scroll-hint{margin:6px 0 0;min-height:0;line-height:1.4}
.compact-game .scroll-hint:empty{display:none}
.compact-game .source-stack,.compact-game .result-panel,.compact-game .completion{flex:1;min-height:0;justify-content:center;align-items:center;padding:0;margin:0 auto;width:100%}
.compact-game .card-home{min-height:0;width:260px;max-width:100%}
.compact-game .event-card{width:260px;max-width:100%;min-height:148px;gap:10px;padding:4px 8px}
.compact-game .event-card .art-frame{width:80px;height:80px}
.compact-game .event-card img{width:74px;height:74px}
.compact-game .event-name{max-width:250px}
.compact-game .source-help{margin:8px 0 0;font-size:11px;line-height:1.5}
.compact-game .selection-note{min-height:0;margin:8px 0 0;line-height:1.5}
.compact-game .selection-note:empty{display:none}
.compact-game.selected .source-help{display:none}
.compact-game .result-panel{max-width:520px;overflow:hidden}
.compact-game .result-panel>.pixel-button{flex-shrink:0;margin:0 0 14px}
.compact-game .result-title{flex-shrink:0;font-size:21px;line-height:1.3;margin:0 0 6px}
.compact-game .placement-note{flex-shrink:0;font-size:19px;line-height:1.4;margin:0 0 10px}
.compact-game .fact{min-height:0;max-height:112px;overflow:auto;font-size:15px;line-height:1.5;margin:0 0 8px;padding:0 5px;scrollbar-width:thin}
.compact-game .history-source{flex-shrink:0;font-size:12px;line-height:1.4;margin:0}
.compact-game .completion{overflow:auto;max-width:520px;scrollbar-width:thin}
.compact-game .game-footer{display:grid;grid-template-columns:1fr auto 1fr;align-items:center;gap:12px;margin:0 auto;padding:6px 0 calc(6px + env(safe-area-inset-bottom));height:100%;font-size:11px}
.compact-game .game-footer>a{justify-self:start;padding:6px 0}
.compact-game .reset{grid-column:3;justify-self:end;padding:7px 0;font-size:11px}
@media(max-width:600px){
  body.compact-game{grid-template-rows:86px minmax(0,1fr) calc(44px + env(safe-area-inset-bottom))}
  .compact-game .game-header{height:86px;grid-template-columns:1fr auto;grid-template-rows:38px 22px;gap:6px 10px;padding:10px 0 9px;width:calc(100% - 32px)}
  .compact-game .landing-tools{grid-column:2;grid-row:1}
  .compact-game .run-status{grid-column:1/-1;grid-row:2;justify-self:center}
  .compact-game .points-total{font-size:18px}
  .compact-game .game{padding:24px 0 8px;gap:8px}
  .compact-game .game-footer{width:calc(100% - 32px);gap:8px}
  .compact-game .source-help{max-width:290px}
}
@media(max-height:580px){
  body.compact-game{grid-template-rows:56px minmax(0,1fr) calc(40px + env(safe-area-inset-bottom))}
  .compact-game .game-header{height:56px;padding:6px 0;grid-template-rows:1fr;grid-template-columns:1fr auto 1fr}
  .compact-game .landing-tools{grid-column:3;grid-row:1}
  .compact-game .run-status{grid-column:2;grid-row:1}
  .compact-game .game{padding:16px 0 8px;gap:8px}
  .compact-game .timeline-track,.compact-game .gap{height:170px}
  .compact-game .timeline-ends{top:159px}
  .compact-game .timeline-token{min-height:116px;gap:6px}
  .compact-game .token-art{width:56px;height:56px}
  .compact-game .token-art img{width:52px;height:52px}
  .compact-game .token-name{font-size:12px;min-height:31px}
  .compact-game .token-date{font-size:16px}
  .compact-game .event-card{min-height:118px;gap:8px;padding:0 8px}
  .compact-game .event-card .art-frame{width:64px;height:64px}
  .compact-game .event-card img{width:60px;height:60px}
  .compact-game .event-name{font-size:15px;line-height:1.3}
  .compact-game .result-panel>.pixel-button{min-height:38px;padding:7px 18px;margin-bottom:9px}
  .compact-game .result-title{font-size:18px;margin-bottom:4px}
  .compact-game .placement-note{font-size:17px;margin-bottom:6px}
  .compact-game .fact{font-size:14px;line-height:1.4;max-height:62px;margin-bottom:6px}
}

/* Keep the long rail inside the viewport rather than sizing the page's grid. */
body.compact-game{--header-height:64px;--footer-height:44px;--safe-top:env(safe-area-inset-top,0px);grid-template-columns:minmax(0,1fr);grid-template-rows:calc(var(--header-height) + var(--safe-top)) minmax(0,1fr) calc(var(--footer-height) + env(safe-area-inset-bottom,0px));min-height:0;width:100%;max-width:100%}
.compact-game .game-header{height:100%;min-width:0;padding:var(--safe-top) 0 0}
.compact-game .game,.compact-game .timeline-shell,.compact-game .source-stack,.compact-game .result-panel,.compact-game .completion{min-width:0}
.compact-game .game-header,.compact-game .game-footer{width:min(1120px,calc(100% - max(32px,env(safe-area-inset-left,0px)) - max(32px,env(safe-area-inset-right,0px))))}
.compact-game .game{width:min(1120px,calc(100% - max(24px,env(safe-area-inset-left,0px)) - max(24px,env(safe-area-inset-right,0px))))}
.compact-game .history-source{overflow-wrap:anywhere}
@media(max-width:600px){
  body.compact-game{--header-height:86px}
  .compact-game .game-header{padding:calc(10px + var(--safe-top)) 0 9px}
  .compact-game .game-header,.compact-game .game,.compact-game .game-footer{width:calc(100% - max(16px,env(safe-area-inset-left,0px)) - max(16px,env(safe-area-inset-right,0px)))}
}
@media(max-height:580px){
  body.compact-game{--header-height:56px;--footer-height:40px}
  .compact-game .game-header{padding:calc(6px + var(--safe-top)) 0 6px}
}
/* A narrow portrait header needs two rows even on a shorter phone. */
@media(max-width:600px) and (orientation:portrait){
  body.compact-game{--header-height:86px}
  .compact-game .game-header{grid-template-columns:1fr auto;grid-template-rows:38px 22px;gap:6px 10px;padding:calc(10px + var(--safe-top)) 0 9px}
  .compact-game .landing-tools{grid-column:2;grid-row:1}
  .compact-game .run-status{grid-column:1/-1;grid-row:2;justify-self:center}
}
/* On a landscape phone, put the card beside the rail to retain usable height. */
@media(max-height:480px) and (orientation:landscape){
  .compact-game .game{display:grid;grid-template-columns:minmax(0,1.4fr) minmax(190px,.9fr);grid-template-rows:minmax(0,1fr);gap:16px;padding:8px 0}
  .compact-game .timeline-shell{grid-column:1;grid-row:1;align-self:center}
  .compact-game .source-stack,.compact-game .result-panel,.compact-game .completion{grid-column:2;grid-row:1;height:100%;max-height:100%}
  .compact-game .source-stack{display:flex}
  .compact-game .source-help{font-size:10px;margin-top:5px}
  .compact-game .result-panel>.pixel-button{margin-bottom:8px}
  .compact-game .completion h2{font-size:20px}
}
@media(max-height:540px) and (orientation:portrait){
  .compact-game .timeline-track,.compact-game .gap{height:154px}
  .compact-game .timeline-ends{top:143px}
  .compact-game .game{padding:8px 0;gap:6px}
  .compact-game .source-help{font-size:10px;margin-top:4px}
}
@media(max-height:580px){
  .compact-game .token-name{display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;min-height:32px;max-height:32px;overflow:hidden}
}
@media(max-height:540px) and (orientation:portrait){
  .compact-game .timeline-token{min-height:108px}
  .compact-game .token-art{width:48px;height:48px}
  .compact-game .token-art img{width:44px;height:44px}
  .compact-game .event-card{min-height:108px}
  .compact-game .event-card .art-frame{width:56px;height:56px}
  .compact-game .event-card img{width:52px;height:52px}
  .compact-game .event-name{font-size:14px}
  .compact-game .result-panel{justify-content:flex-start;overflow:auto}
  .compact-game .fact{flex-shrink:0;max-height:62px}
}

/* The page stays fixed while the rail alone owns any extra horizontal width. */
html[data-timeline=thread]{overflow:clip}
.compact-game .timeline-viewport{contain:inline-size;overflow-anchor:none}

/* Keep the ending action in view on short phones, even after a long run. */
@media(max-height:580px){
  .compact-game .completion{padding:0 4px 0}
  .compact-game .completion h2{font-size:18px;line-height:1.25;margin:0 0 4px}
  .compact-game .completion .score{font-size:22px;line-height:1.25;margin:0 0 2px}
  .compact-game .completion .timeline-summary{margin:0 auto 4px;font-size:11px}
  .compact-game .completion .timeline-summary summary{padding:3px}
  .compact-game .completion>.pixel-button{min-height:34px;font-size:14px;padding:7px 16px}
}

@media(max-height:540px) and (orientation:portrait){
  .compact-game.complete .game{padding-top:4px;gap:4px}
}

/* Larger, unfilled navigation stays quiet over the foreground. */
.compact-game .game-footer{padding-top:3px;padding-bottom:calc(3px + env(safe-area-inset-bottom,0px))}
html[data-theme] .scene-page.compact-game .game-footer>:is(a,.reset){
  display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:36px;
  padding:6px 12px;border:1px solid transparent;
  background:transparent;color:#efe1ba;box-shadow:none;
  font:13px/1.2 Historicle,monospace;text-decoration:none;text-shadow:none;white-space:nowrap;
}
html[data-theme=light] .scene-page.compact-game .game-footer>:is(a,.reset){
  color:#24474a;
}
html[data-theme] .scene-page.compact-game .game-footer>:is(a,.reset):hover{color:#fff1cc;text-decoration:underline;text-underline-offset:4px}
html[data-theme=light] .scene-page.compact-game .game-footer>:is(a,.reset):hover{color:#183c40}
.compact-game .game-footer>:is(a,.reset):active{transform:translateY(1px);box-shadow:none}
@media(max-height:580px){
  .compact-game .game-footer{padding-top:2px;padding-bottom:calc(2px + env(safe-area-inset-bottom,0px))}
  html[data-theme] .scene-page.compact-game .game-footer>:is(a,.reset){min-height:34px;padding:5px 10px}
}
