/* ===================== Scene-first layout: tablets, phones and accessibility =====================
   Loaded after world.css. Everything is scoped to the scene-first layout (.w-sf / .w-stage.sf), so the classic layout
   is unchanged.
   - All widths: the view tools are one column at the right, and the time banner and HUD sit just to its left; the
     caption sits in the open space between the guide card and the map.
   - Tablets (721–1199px): crumbs collapse to the back button during a lesson, the steps to numbers when space is
     tight, a wider card and reading column; in portrait the reading column becomes a sheet along the bottom.
   - Phones (≤720px): the guide is a bottom sheet with three heights (peek, half, full) and a drag handle; the
     caption, map and HUD stay above it (world.js sets --sf-sheet-top, the sheet's top edge from the stage bottom).
   - Focus rings that show on dark glass, over bright scenes and on the light reading column; reduced motion. */
.w-stage.sf{--sf-railw:92px;--sf-cardw:min(410px,36%);--sf-colw:min(440px,40%);--sf-sheet-top:calc(var(--sf-dockh) + 28px)}
.w-stage.sf:has(> .w-player[hidden]){--sf-dockh:0px}

/* ---------- view tools: one column; banner and HUD beside it, never under it ---------- */
.w-stage.sf .w-viewctl{flex-direction:column;flex-wrap:nowrap;align-items:flex-end;left:auto;max-width:none;width:var(--sf-railw);gap:8px}
.w-stage.sf .w-viewctl #w-lbl,.w-stage.sf .w-viewctl #w-geo{width:var(--sf-railw);padding:0 8px;font-size:12px;height:36px}
.w-stage.sf .w-stack{right:calc(24px + var(--sf-railw));max-width:min(380px,calc(100% - var(--sf-cardw) - var(--sf-railw) - 62px));min-width:0}
.w-stage.sf.sf-dock .w-stack,.w-stage.sf:not(.w-guide-open) .w-stack{max-width:min(380px,calc(100% - var(--sf-railw) - 52px))}
.w-stage.sf .w-banner{overflow-wrap:anywhere}
/* the classic small-screen rules hide the HUD and stretch the stack; the scene-first layout has room for both */
.w-stage.sf .w-stack{bottom:auto}
.w-stage.sf .w-hud:not([hidden]){display:block}
.w-stage.sf .w-banner{font-size:12px}
/* a place or a tool: the title on the left, the KS3/GCSE switch on the right */
#world[data-step=explore] .w-stage.sf .w-ptop{justify-content:space-between}
.w-stage.sf .w-card{top:66px;right:calc(24px + var(--sf-railw));width:min(300px,calc(100% - var(--sf-railw) - 48px))}
/* the caption sits in the open space: right of the floating card, left of the map */
.w-stage.sf .w-caption{left:14px;right:110px;width:auto;transform:none;max-width:none;display:flex;justify-content:center;pointer-events:none}
.w-stage.sf .w-caption span{max-width:min(640px,100%)}
.w-stage.sf.w-guide-open:not(.sf-dock) .w-caption{left:calc(var(--sf-cardw) + 28px)}
.w-stage.sf:has(.w-locator:not(.collapsed)) .w-caption{right:calc(min(250px,40%) + 28px)}

/* ---------- tablets: 721–1199px ---------- */
@media (min-width:721px) and (max-width:1199px){
 .w-stage.sf{--sf-cardw:clamp(300px,38%,410px);--sf-colw:clamp(380px,42%,460px)}
 .w-stage.sf .w-panel{width:var(--sf-cardw)}
 /* top bar: in a lesson the crumbs collapse to the back button (its label names where it goes) */
 #world:not([data-step=explore]) .w-stage.sf .w-crumbnav{padding-right:3px}
 #world:not([data-step=explore]) .w-stage.sf #w-crumbs{display:none}
 .w-stage.sf .w-crumbnav{max-width:calc(100% - 120px)}
 .w-stage.sf .w-findbtn span,.w-stage.sf .w-findbtn kbd{display:none}
 .w-stage.sf .w-findbtn{width:40px;padding:0;justify-content:center}
 .w-stage.sf .w-steps li button{padding:7px 11px}
 .w-stage.sf .w-dockacts :is(.w-primary,[data-dock-action="w-next"]){max-width:220px;white-space:normal;line-height:1.2;text-align:left;padding:8px 14px}
}
/* landscape tablets: a wider reading column; the squeezed dock drops the clock and speed */
@media (min-width:901px) and (max-width:1199px){
 .w-stage.sf.sf-dock .w-viewport{right:var(--sf-colw)}
 .w-stage.sf.sf-dock .w-trail,.w-stage.sf.sf-dock .w-player{right:calc(var(--sf-colw) + 14px)}
 .w-stage.sf.sf-dock .w-panel{width:var(--sf-colw)}
 .w-stage.sf.sf-dock .w-time,.w-stage.sf.sf-dock .w-speed{display:none}
 .w-stage.sf.sf-dock #w-segs button span{display:none}
 .w-stage.sf.sf-dock .w-player{gap:10px}
 .w-stage.sf.sf-dock .w-steps li button{padding:6px 9px;font-size:0;gap:0}
 .w-stage.sf.sf-dock .w-steps li button[aria-current=step]{font-size:13px;gap:6px;padding:6px 12px}
}
/* portrait tablets: steps as numbers (the current one keeps its name); reading mode is a sheet along the bottom,
   not a narrow column */
@media (min-width:721px) and (max-width:900px){
 .w-stage.sf{--sf-psheet:44%}
 .w-stage.sf .w-steps li button{padding:6px 9px;font-size:0;gap:0}
 .w-stage.sf .w-steps li button[aria-current=step]{font-size:13px;gap:6px;padding:6px 12px}
 .w-stage.sf .w-time{display:none}
 .w-stage.sf.sf-dock .w-viewport{right:0;bottom:var(--sf-psheet)}
 .w-stage.sf.sf-dock .w-trail{right:14px}
 .w-stage.sf.sf-dock .w-player{right:14px;bottom:calc(var(--sf-psheet) + 14px)}
 .w-stage.sf.sf-dock .w-panel{left:0;right:0;top:auto;bottom:0;width:auto;height:var(--sf-psheet);border-left:0;border-top:1px solid #d9d3c4;border-radius:18px 18px 0 0;box-shadow:0 -10px 30px rgba(0,0,0,.25)}
 .w-stage.sf.sf-dock .w-panel.w-minimised{height:auto;width:auto;bottom:0}
 .w-stage.sf.sf-dock:has(.w-panel.w-minimised){--sf-psheet:50px}
 .w-stage.sf.sf-dock .w-stack{max-width:min(380px,calc(100% - var(--sf-railw) - 52px))}
}

/* ---------- phones: ≤720px. The guide is a bottom sheet: peek, half or full ---------- */
.w-sheet-handle{display:none}
@media (max-width:720px){
 .w-stage.sf{width:100vw;margin-inline:calc(50% - 50vw);--sf-railw:84px}
 /* crumbs: on a place they fit beside the back button; in a lesson the steps need the room */
 .w-stage.sf .w-crumbnav{max-width:calc(100% - 104px)}
 .w-stage.sf #w-crumbs{display:flex}
 #world:not([data-step=explore]) .w-stage.sf #w-crumbs{display:none}
 #world:not([data-step=explore]) .w-stage.sf .w-crumbnav{padding-right:3px}
 /* view tools: a column at the right; zoom stays (not everyone can pinch); the keys card is for keyboards */
 .w-stage.sf .w-viewctl{top:58px;right:8px;gap:6px}
 .w-stage.sf .w-viewctl button{width:38px;height:38px}
 .w-stage.sf .w-viewctl #w-lbl,.w-stage.sf .w-viewctl #w-geo{width:var(--sf-railw);height:34px;font-size:11.5px}
 .w-stage.sf .w-viewctl #w-keys{display:none}
 .w-stage.sf .w-dockacts .w-primary{white-space:normal;line-height:1.2;text-align:left;max-width:168px}
 /* "Next" is the secondary button until the stage has been watched: it wraps like the primary one and stops at two
    lines, so a long stage title cannot push the play button and timeline under the guide sheet */
 .w-stage.sf .w-dockacts [data-dock-action="w-next"].w-secondary{min-height:42px;max-width:168px;font-size:13.5px;padding:8px 12px;white-space:normal;line-height:1.2;text-align:left}
 .w-stage.sf .w-dockacts [data-dock-action="w-next"]{display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;line-clamp:2;overflow:hidden}
 .w-stage.sf .w-stack{left:8px;right:auto;top:58px;align-items:flex-start;max-width:calc(100% - var(--sf-railw) - 28px);max-height:calc(100% - 58px - var(--sf-sheet-top) - 12px);overflow:hidden}
 .w-stage.sf.sf-dock .w-stack,.w-stage.sf:not(.w-guide-open) .w-stack{max-width:calc(100% - var(--sf-railw) - 28px)}
 /* the sheet's top edge is the floor for everything that floats over the scene */
 .w-stage.sf .w-caption{left:8px;right:96px;bottom:calc(var(--sf-sheet-top) + 10px);justify-content:flex-start;max-width:none}
 .w-stage.sf.w-guide-open:not(.sf-dock) .w-caption{left:8px}
 .w-stage.sf:has(.w-locator:not(.collapsed)) .w-caption{right:calc(36% + 20px)}
 .w-stage.sf .w-caption span{font-size:12.5px;text-align:left}
 .w-stage.sf .w-locator{right:8px;bottom:calc(var(--sf-sheet-top) + 10px)}
 .w-stage.sf .w-locator:not(.collapsed){width:36%}
 .w-stage.sf .w-trail:has(#w-guidechip:not([hidden])){gap:4px}
 .w-stage.sf .w-trail:has(#w-guidechip:not([hidden])) .w-trailtools{gap:4px}
 .w-stage.sf .w-guidechip{gap:5px}
 .w-stage.sf .w-guidechip>span{display:none}
 .w-stage.sf .w-guidechip>button{font-size:11px;padding:7px 9px;white-space:nowrap}
 .w-stage.sf .w-trail:has(#w-guidechip:not([hidden])) #w-crumbs{display:none}
 #world:not([data-step=explore]) .w-trail:has(#w-guidechip:not([hidden])) .w-steps li button{font-size:0;gap:0;padding:6px 4px}
 #world:not([data-step=explore]) .w-guidechip>button{font-size:0;padding:4px;width:34px;height:34px}
 #world:not([data-step=explore]) .w-guidechip>button::before{content:"↶";font-size:22px}
 .w-stage.sf .w-toast{bottom:calc(var(--sf-sheet-top) + 56px)}
 .w-stage.sf .w-card{top:auto;right:8px;left:8px;width:auto;bottom:calc(var(--sf-sheet-top) + 10px);max-height:calc(100% - var(--sf-sheet-top) - 70px);overflow:auto;z-index:36}
 /* the chart dock sits above the caption and the map (which share the row on the sheet's top edge) and left of the
    view tools, not over them */
 .w-stage.sf .w-chart{bottom:calc(var(--sf-sheet-top) + 10px + var(--sf-rowh, 58px));left:8px;width:min(300px,calc(100% - var(--sf-railw) - 28px))}
 .w-stage.sf:has(.w-locator:not(.collapsed)) .w-chart{--sf-rowh:max(58px,calc((100vw - 16px) * .36 * .4 + 12px))}
 .w-stage.sf.w-guide-open .w-caption{display:flex}
 .w-stage.sf.w-guide-open .w-locator{display:block}
 .w-stage.sf.w-guide-open .w-stack{display:flex}
 .w-stage.sf.w-guide-open .w-chart{display:block}
 /* full sheet: nothing is left showing beneath it, so take the scene controls out of the way (and out of the tab order) */
 .w-stage.sf.sf-sheet-full .w-caption,.w-stage.sf.sf-sheet-full .w-locator,.w-stage.sf.sf-sheet-full .w-stack,.w-stage.sf.sf-sheet-full .w-viewctl,.w-stage.sf.sf-sheet-full .w-chart{visibility:hidden}
 /* the sheet */
 .w-stage.sf .w-panel,.w-stage.sf .w-panel:not(.w-float-left),.w-stage.sf.sf-dock .w-panel{max-height:calc(100% - var(--sf-dockh) - 56px);transition:height .28s cubic-bezier(.2,.8,.2,1);box-shadow:0 -10px 34px rgba(0,0,0,.35)}
 .w-stage.sf.sf-sheet-half .w-panel{height:48%}
 .w-stage.sf.sf-sheet-full .w-panel{height:calc(100% - var(--sf-dockh) - 56px)}
 .w-stage.sf.sf-sheet-peek .w-panel{height:auto;max-height:42%}
 .w-stage.sf.sf-sheet-drag .w-panel{transition:none}
 .w-stage.sf #w-float-toggle{display:none}
 .w-stage.sf .w-sheet-handle{display:flex;flex:none;align-items:center;justify-content:center;width:100%;height:24px;margin:0;padding:0;border:0;background:none;cursor:grab;touch-action:none;color:inherit}
 .w-stage.sf .w-sheet-handle span{display:block;width:44px;height:5px;border-radius:3px;background:currentColor;opacity:.55}
 .w-stage.sf .w-sheet-handle:hover span{opacity:.85}
 .w-stage.sf .w-floatbar{padding-top:2px;touch-action:none;cursor:grab}
 .w-stage.sf.sf-sheet-drag,.w-stage.sf.sf-sheet-drag *{cursor:grabbing}
 .w-stage.sf .w-panel-content{touch-action:pan-y}
 /* peek: the step, the scene title and the key idea */
 .w-stage.sf.sf-sheet-peek:not(.sf-sheet-drag) .w-panel-content{overflow:hidden;padding-top:10px;padding-bottom:12px;gap:6px}
 .w-stage.sf.sf-sheet-peek:not(.sf-sheet-drag) .w-panel-content>:not(#w-body):not(.w-ptop),
 .w-stage.sf.sf-sheet-peek:not(.sf-sheet-drag) .w-ptop .w-level,
 .w-stage.sf.sf-sheet-peek:not(.sf-sheet-drag) #w-body>:not(.w-stepk):not(.w-stitle):not(.w-key):not(.w-question):not(p.w-body),
 .w-stage.sf.sf-sheet-peek:not(.sf-sheet-drag) #w-body:has(> .w-key) > p.w-body,
 .w-stage.sf.sf-sheet-peek:not(.sf-sheet-drag) #w-body:has(> .w-question) > p.w-body,
 .w-stage.sf.sf-sheet-peek:not(.sf-sheet-drag) #w-body .w-key ~ .w-key,
 .w-stage.sf.sf-sheet-peek:not(.sf-sheet-drag) .w-float-actions{display:none}
 .w-stage.sf.sf-sheet-peek:not(.sf-sheet-drag) #w-body p.w-body,.w-stage.sf.sf-sheet-peek:not(.sf-sheet-drag) #w-body .w-question{display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}
 .w-stage.sf.sf-sheet-peek:not(.sf-sheet-drag) #w-body .w-stitle{font-size:20px;margin:2px 0 8px}
 .w-stage.sf.sf-sheet-peek:not(.sf-sheet-drag) #w-body .w-key p{display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}
 #world[data-step=explore] .w-stage.sf.sf-sheet-peek:not(.sf-sheet-drag) .w-ptop h2{font-size:22px}
}

/* ---------- focus: visible on dark glass, over bright scenes and on the light reading column ---------- */
.w-stage.sf :is(button,a,input,select,textarea,summary,label,[tabindex]):focus-visible{outline:3px solid var(--sf-amber2);outline-offset:2px;box-shadow:0 0 0 2px #0d151b}
.w-stage.sf.sf-dock .w-panel :is(button,a,input,select,textarea,summary,label,[tabindex]):focus-visible{outline-color:#174c45;box-shadow:0 0 0 2px #fff}
.w-stage.sf.sf-dock .w-panel textarea:focus-visible{outline-offset:0}
.w-stage.sf .w-viewport canvas:focus-visible{outline:none;box-shadow:inset 0 0 0 3px var(--sf-amber2),inset 0 0 0 6px #0d151b}
.w-stage.sf #w-crumbs button:focus-visible{outline-offset:-3px;box-shadow:none}
.w-stage.sf .w-q label:has(input:focus-visible){outline:3px solid var(--sf-amber2);outline-offset:2px}
.w-stage.sf.sf-dock .w-q label:has(input:focus-visible){outline-color:#174c45}
.w-stage.sf #w-body:focus-visible,.w-stage.sf .w-stitle:focus-visible{outline:none;box-shadow:none}
.w-stage.sf .w-panel-content{scroll-padding-block:12px}

/* ---------- contrast: glass stays dark enough for AA text even over a bright, sunlit scene ---------- */
.w-sf{--sf-glass:rgba(13,21,27,.86)}
.w-stage.sf #w-segs button{color:#c3cfd2}
.w-stage.sf .w-caption span{background:rgba(10,16,22,.88)}
.w-stage.sf .w-locator .w-loctog{font-weight:700}

/* ---------- reduced motion (the system setting and the in-page switch) ---------- */
.world.reduced .w-stage.sf .w-dockacts .w-primary.pulse{animation:none;outline:3px solid var(--sf-amber);outline-offset:2px}
.world.reduced .w-stage.sf .w-panel,.world.reduced .w-stage.sf .w-caption span{transition:none}
@media (prefers-reduced-motion:reduce){
 .w-stage.sf .w-panel{transition:none}
 .w-stage.sf .w-dockacts .w-primary.pulse{outline:3px solid var(--sf-amber);outline-offset:2px}
}

@media(max-width:360px){
 .w-stage.sf .w-guidechip>button{font-size:10px;padding:6px 7px}
}
