/* ==========================================================================
   layout.css - Certamen Quest layout layer (WS5 sections A, B, D, E, H). Owner: LAYOUT only.
   Loaded as #cq-layout, the LAST stylesheet (after the boot script). No !important outside
   reduced-motion / print. Sections: TOKENS · SHELL · SCREENS · QUESTION · OVERLAYS · INPUT · A11Y · PRINT
   ========================================================================== */

/* ===== TOKENS ===== */
:root{
  --tap:44px; --tap-lg:48px;
  --gutter:max(16px, env(safe-area-inset-left,0px));
  --col-std:760px; --col-quiz:960px; --col-wide:1120px; --col-xl:1240px; --col-doc:864px;
  --nav-offset:0px;
  --topbar-h:46px;
  --fs-floor:.75rem;
  --fs-label:.8125rem; --fs-q:1.15rem;
  --line-ui:var(--line);
  --focus:var(--gold-hi); --focus-on-light:#3a2c18;
  --z-topbar:60; --z-nav:61; --z-modal:85; --z-toast:95;
  --vh-full:100vh;
}
@supports (height:100dvh){ :root{ --vh-full:100dvh; } }
@media (min-width:1800px){
  :root{ --col-std:47.5rem; --col-quiz:60rem; --col-wide:75rem; --col-xl:75rem; }
}
@media (prefers-contrast:more){ :root{ --line-ui:#8a7898; } }

/* iOS address-bar safe heights (U24) */
body{ min-height:var(--vh-full); }
#scr-load{ min-height:var(--vh-full); }
@media (pointer:coarse){ body{ background-attachment:scroll; } }

/* ===== SHELL (topbar, nav, columns) ===== */
/* type scale (A.5): root follows viewport, text-size token, short pinned, xxl scales */
html{ --ts:1; font-size:calc(clamp(1rem, .875rem + .5vw, 1.125rem) * var(--ts)); }
html[data-text="l"]{ --ts:1.125; }
html[data-text="xl"]{ --ts:1.25; }
@media (max-height:560px) and (orientation:landscape){ html{ font-size:calc(1rem * var(--ts)); } }
@media (min-width:1800px){ html{ font-size:calc(clamp(1.125rem, .375rem + .75vw, 1.375rem) * var(--ts)); } }
body{ font-size:1.03125rem; }
@media (max-width:599px){ body{ font-size:1rem; } }
.art{ width:1.75rem; height:1.75rem; } .art.s{ width:1.3125rem; height:1.3125rem; }
.art.m{ width:2.125rem; height:2.125rem; } .art.l{ width:3.25rem; height:3.25rem; } .art.xl{ width:5.125rem; height:5.125rem; }
.foe-stage .art.xl{ width:8rem; height:8rem; }
@media (max-width:599px){ .art.xl{ width:4.25rem; height:4.25rem; } .foe-stage .art.xl{ width:6.5rem; height:6.5rem; } }

/* columns: .scr follows body[data-layout]; the topbar follows the wide column at >= 1024 */
body{ --col:var(--col-std); }
body[data-layout="quiz"]{ --col:var(--col-quiz); }
body[data-layout="wide"]{ --col:var(--col-wide); }
body[data-layout="doc"]{ --col:var(--col-doc); }
#topbar{ --topbar-h:46px; min-height:var(--topbar-h); }
#topbar .tb-rank{ display:inline; }
@media (max-width:599px){ #topbar .tb-rank{ display:none; } }
@media (min-width:600px){
  #topbar{ --topbar-h:50px; }
  body[data-layout="doc"] .scr{ max-width:var(--col-doc); }
}
@media (min-width:1024px){
  body{ --topbar-h:50px; }
  body[data-layout="quiz"] .scr{ max-width:var(--col-quiz); }
  body[data-layout="wide"] .scr{ max-width:var(--col-wide); }
  #topbar{ max-width:var(--col-wide); }
}
@media (min-width:1360px){
  body[data-layout="wide"] .scr, #topbar{ max-width:var(--col-xl); }
}
@media (min-width:1800px){
  body[data-layout="wide"] .scr, #topbar{ max-width:var(--col-wide); }
  body[data-layout="wide"]{ --col:var(--col-wide); }
}
@media (min-width:1360px) and (max-width:1799px){ body[data-layout="wide"]{ --col:var(--col-xl); } }
/* std screens that must not centre vertically: anchored top on wide */
@media (min-width:1024px){
  body[data-layout="std"] .scr{ padding-top:min(8vh,64px); }
}
/* short landscape: compact chrome */
@media (max-height:560px) and (orientation:landscape){
  #topbar{ --topbar-h:40px; padding-top:3px; padding-bottom:3px; margin-bottom:6px; }
  #topbar .tb-xp, #topbar .tb-rank{ display:none; }
  .scr{ padding-top:6px; }
  .scene-head{ padding:12px; }
  .scene-head .title-display, .scene-head h1, .scene-head h2{ font-size:1.3rem; }
}

/* navigation: one "<- Forum" button (option B), shown after scrolling */
#navbar{ position:fixed; z-index:var(--z-nav); left:max(16px, env(safe-area-inset-left), calc((100vw - var(--col)) / 2));
  bottom:calc(16px + env(safe-area-inset-bottom)); margin:0; padding:0; }
#navbar[hidden]{ display:none; }
#navbar button, #navbar .btn{ min-height:var(--tap-lg); border-radius:24px; padding:0 20px; font-weight:700;
  background:var(--panel); color:var(--gold-hi); border:2px solid var(--gold); box-shadow:0 3px 0 rgba(8,4,12,.5); cursor:pointer; }
body.has-nav{ --nav-offset:calc(48px + 32px + env(safe-area-inset-bottom)); padding-bottom:var(--nav-offset); }
body.has-nav #toasts{ bottom:calc(var(--nav-offset) + 8px); }
body[data-scr="home"] #navbar, body[data-scr="domus"] #navbar, body.cq-asking #navbar{ display:none; }


/* ===== SCREENS (one block per screen) ===== */
/* Grounds hub: rail + grid, Gate on top of the grid (B.3) */
@media (min-width:1024px) and (orientation:landscape){
  body[data-scr="home"] #scr-home{ display:grid; grid-template-columns:minmax(320px,380px) minmax(0,1fr);
    column-gap:16px; align-items:start; }
  body[data-scr="home"] #scr-home > *{ grid-column:1; }
  body[data-scr="home"] #scr-home > .gate-wrap{ grid-column:2; grid-row:1; }
  body[data-scr="home"] #scr-home > .grounds-grid{ grid-column:2; grid-row:2 / span 8; margin-top:0;
    grid-template-columns:repeat(2,minmax(0,1fr)); }
  body[data-scr="home"] .grounds-grid > :last-child:nth-child(odd){ grid-column:1 / -1; }
  body[data-scr="home"] #scr-home > .grounds-mini{ grid-template-columns:1fr; }
  body[data-scr="home"] .gate-wrap .btn-gate .gate-nm{ white-space:nowrap; }
}
@media (min-width:600px) and (max-width:1023px){
  body[data-scr="home"] #scr-home .grounds-grid{ grid-template-columns:repeat(2,minmax(0,1fr)); }
}
/* Hodie inherited card layout */
.hodie .dq-card{ flex-direction:row; }
@media (min-width:600px){
  .hodie .hd-quests{ display:grid; grid-template-columns:repeat(auto-fill,minmax(260px,1fr)); gap:10px; }
}

/* Lūdus */
@media (min-width:1024px){
  #scr-ludus .scene-head{ background-position:center 40%; max-height:220px; }
}
@media (min-width:600px){
  #scr-ludus .ludus-modes{ grid-template-columns:repeat(2,minmax(0,1fr)); }
}
#scr-ludus .flip.ludus-flip{ max-width:560px; margin-left:auto; margin-right:auto; }
@media (max-height:560px) and (orientation:landscape){
  #scr-ludus .flip.ludus-flip{ min-height:0; height:260px; }
}

/* Cards: 4-up tablet, 5-up wide, 6-up xl */
@media (min-width:600px){ .ct-grid{ grid-template-columns:repeat(4,minmax(0,1fr)); } }
@media (min-width:1024px){ .ct-grid{ grid-template-columns:repeat(5,minmax(0,1fr)); } }
@media (min-width:1360px){ .ct-grid{ grid-template-columns:repeat(6,minmax(0,1fr)); } }
@media (max-height:560px) and (orientation:landscape){ .ct-grid{ grid-template-columns:repeat(4,minmax(0,1fr)); } }

/* Profile and Templum: two columns of panels on wide */
@media (min-width:1024px){
  #scr-profile, #scr-quests{ column-count:2; column-gap:16px; }
  #scr-profile > *, #scr-quests > *{ break-inside:avoid; }
  #scr-profile > p:has(> [data-go="home"]), #scr-quests > p:has(> [data-go="home"]){ column-span:all; }
}
@media (max-height:560px) and (orientation:landscape){ #scr-profile, #scr-quests{ column-count:1; } }
summary{ min-height:var(--tap-lg); display:flex; align-items:center; gap:8px; cursor:pointer; }

/* Comites: 2-up phone, 3-up tablet, 4-up wide */
@media (min-width:600px){ .comes-grid{ grid-template-columns:repeat(3,minmax(0,1fr)); } }
@media (min-width:1024px){ .comes-grid{ grid-template-columns:repeat(4,minmax(0,1fr)); } }
@media (max-height:560px) and (orientation:landscape){ .comes-grid{ grid-template-columns:repeat(3,minmax(0,1fr)); } }

/* Shop and run end */
.shop-list{ display:grid; grid-template-columns:1fr; gap:10px; }
@media (min-width:600px){ .shop-list{ grid-template-columns:repeat(2,minmax(0,1fr)); } }
@media (max-height:560px) and (orientation:landscape){ .shop-list{ grid-template-columns:1fr; } }
@media (min-width:1024px){
  #scr-runend{ display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1.2fr); gap:14px 16px; align-items:start; }
  #scr-runend > *{ grid-column:1 / -1; }
  #scr-runend > .panel:nth-of-type(1){ grid-column:1; }
  #scr-runend > .panel:nth-of-type(2){ grid-column:2; }
  #scr-runend > #runend-share{ grid-column:1 / -1; }
}
@media (max-height:560px) and (orientation:landscape){ #scr-runend{ display:block; } }

/* Fama: anchored top */
body[data-scr="fama"] .scr, body[data-scr="raid"] .scr{ padding-top:14px; }

/* Map (B.6) */
#scr-map .table-wrap{ container-type:inline-size; }
@media (max-width:599px){
  #scr-map .map-board{ gap:clamp(6px, calc((100cqw - 242px)/4), 30px); padding:16px 0; min-width:0; }
}
@media (min-width:600px){
  #scr-map .map-board{ justify-content:space-between; }
  #scr-map .map-flex{ display:grid; grid-template-columns:minmax(0,1fr) minmax(220px,300px); gap:14px; align-items:start; }
}
#btn-abandon{ background:transparent; border:2px solid var(--terra); color:var(--terra); margin-top:10px; }
.map-legend{ font-size:var(--fs-label); color:var(--dim); margin-top:8px; }

/* Battle (B.4): hooks bt-foe / bt-kind / bt-flavor, plus structural fallbacks until RUN lands */
#scr-battle .foe-head{ align-items:center; }
#scr-battle .bt-flavor{ color:var(--dim); font-size:.88rem; font-style:italic; margin-top:8px; }
@media (max-width:599px){
  #scr-battle .foe-stage{ min-height:128px; margin-bottom:8px; }
  #scr-battle .foe-stage .art.xl{ width:5rem; height:5rem; }
  #scr-battle .bt-flavor{ display:none; }
  #scr-battle #battle-q{ padding:10px 12px; }
  #scr-battle .q-text{ font-size:1.02rem; }
  #scr-battle .q-opt{ min-height:46px; }
}
@media (min-width:1024px){
  #scr-battle .foe-stage{ min-height:330px; }
}
@media (min-width:1024px) and (orientation:landscape){
  #scr-battle{ display:grid; grid-template-columns:minmax(0,1.05fr) minmax(0,1fr); gap:0 16px; align-items:start; }
  #scr-battle > :first-child{ grid-column:1; grid-row:1; }
  #scr-battle > #player-strip{ grid-column:1; grid-row:2; }
  #scr-battle > #battle-q{ grid-column:2; grid-row:1 / span 2; position:sticky; top:calc(var(--topbar-h) + 14px); }
  #scr-battle .foe-stage .art.xl{ width:10rem; height:10rem; }
}
@media (max-height:560px) and (orientation:landscape){
  #scr-battle{ display:grid; grid-template-columns:minmax(0,.85fr) minmax(0,1.15fr); gap:0 10px; align-items:start; }
  #scr-battle > :first-child{ grid-column:1; grid-row:1; padding:6px 8px; margin-bottom:6px !important; }
  #scr-battle > #player-strip{ grid-column:1; grid-row:2; padding:6px 8px; margin-bottom:0 !important; }
  #scr-battle > #battle-q{ grid-column:2; grid-row:1 / span 2; position:sticky; top:calc(var(--topbar-h) + 6px); padding:8px 10px; margin-bottom:0 !important; }
  #scr-battle .foe-stage{ min-height:0; height:150px; margin-bottom:4px; }
  #scr-battle .foe-stage .art.xl{ width:4.5rem; height:4.5rem; }
  #scr-battle .bt-flavor, #scr-battle .intent{ display:none; }
}

/* Map side panel and short */
@media (max-height:560px) and (orientation:landscape){
  #scr-map .map-flex{ grid-template-columns:minmax(0,1fr) 220px; }
}

/* Domus / Fama / quiz heads on short */
@media (max-height:560px) and (orientation:landscape){
  #scr-arena .panel, #scr-oracle .panel, #scr-cert .panel, #scr-aeternus .panel{ padding:10px 12px; }
}

/* Big moments (B.11) */
.omen-banner{ padding:max(24px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
  max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); }
@media (max-height:560px) and (orientation:landscape){
  .ceremony .cer-ring{ width:110px; }
  .ceremony .cer-rank{ font-size:2.4rem; }
  .boss-intro, .ceremony, .omen-banner{ overflow-y:auto; justify-content:safe center; }
}

/* ===== QUESTION (fold rule) ===== */
.ask{ container-type:inline-size; }
.ask-top{ position:relative; }
.ask-head{ display:flex; align-items:center; justify-content:space-between; gap:4px 10px; flex-wrap:wrap; }
.q-opts{ display:grid; grid-template-columns:1fr; gap:8px; }
@media (min-width:600px){ .q-opts{ grid-template-columns:1fr 1fr; } }
@media (max-width:599px){ .q-opts.q-2x2{ grid-template-columns:1fr 1fr; } }
.q-opts .q-opt{ margin:0; }
@container (min-width:600px){
  .q-opts{ display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; }
  .q-opts .q-opt{ margin:0; min-height:56px; }
}
.q-note.on{ opacity:1; }
.nw{ white-space:nowrap; }
.power-tray{ gap:6px; }
@media (max-width:599px){
  .power{ min-width:var(--tap); padding-left:8px; padding-right:8px; }
}
@media (min-width:1024px){
  body[data-layout="quiz"] .q-text{ font-size:1.3rem; }
}
/* certamen buzz stays put on phones */
#cert-stage .w{ visibility:hidden; }
#cert-stage .w.on{ visibility:visible; }
@media (max-width:599px){
  #cert-stage #cert-buzz{ position:sticky; bottom:calc(var(--nav-offset) + 8px + env(safe-area-inset-bottom)); }
}
/* short landscape: forced 2x2, tight stem (C7b on 844x390 and 844x340) */
@media (max-height:560px) and (orientation:landscape){
  .q-opts{ grid-template-columns:repeat(2,minmax(0,1fr)); gap:6px; }
  .q-opts .q-opt{ margin:0; min-height:0; padding:7px 10px; font-size:.95rem; line-height:1.25; }
  .q-text{ font-size:1rem; line-height:1.35; margin:4px 0 8px; }
  .ask-top{ min-height:0; }
  .ask-head{ margin-bottom:2px; }
  .ask .eyebrow{ margin:0; }
  .power-tray{ margin:6px 0 0; }
  .power{ min-height:36px; padding-top:2px; padding-bottom:2px; }
  .pw-info{ min-height:36px; }
  .ask .bar.timer{ margin:4px 0; }
}

/* ===== OVERLAYS (modal, sheet, popover, toast, big moments) ===== */
.modal-back{ z-index:var(--z-modal); }
.modal{ max-height:min(var(--vh-full) - 40px, 640px); overscroll-behavior:contain; }
.modal-x{ min-width:var(--tap); min-height:var(--tap); display:inline-flex; align-items:center; justify-content:center; }
.modal-btns{ display:flex; flex-wrap:wrap; gap:8px; justify-content:flex-end; }
#toasts{ z-index:var(--z-toast); }
.toast{ overflow-wrap:anywhere; }
body.cq-asking #toasts{ display:none; }
.modal-back[data-size="sheet"]{ align-items:flex-end; }
@media (min-width:600px){
  .modal-back[data-size="sheet"]{ align-items:center; }
  .modal{ width:min(460px, calc(100vw - 32px)); }
  .modal[data-size="l"], .modal-l, .modal-full{ width:min(720px, calc(100vw - 32px)); }
  .modal[data-size="m"], .modal-m{ width:min(520px, calc(100vw - 32px)); }
}
@media (max-height:560px) and (orientation:landscape){
  .modal-back{ align-items:center; }
  .modal{ max-height:calc(var(--vh-full) - 16px); }
}
/* popover / tips */
[data-tip]{ cursor:help; }
[data-tip]:focus-visible{ outline:2px solid var(--focus); outline-offset:2px; }
.cq-pop{ position:fixed; z-index:var(--z-toast); max-width:min(280px, calc(100vw - 16px)); padding:8px 10px;
  background:var(--panel2); color:var(--ink); border:1px solid var(--gold); border-radius:8px; font-size:.85rem;
  line-height:1.35; box-shadow:0 4px 12px rgba(0,0,0,.5); }

/* bar numbers: centred pill, readable on every fill (WS5 H.1) */
.bar{ height:16px; }
.bar-txt{
  inset:50% auto auto 50%; transform:translate(-50%,-50%);
  padding:2px 6px; border-radius:8px; white-space:nowrap;
  background:rgba(20,13,28,.72); text-shadow:none;
}

/* ===== INPUT (targets, hover gating, key hints, focus) ===== */
button, [role=button], .q-opt, .map-node{ touch-action:manipulation; -webkit-tap-highlight-color:transparent; }
#tb-id, #tb-den{ position:relative; min-height:36px; display:inline-flex; align-items:center; }
#tb-den{ min-width:var(--tap); justify-content:center; }
#tb-id::after, #tb-den::after{ content:""; position:absolute; left:0; right:0; top:50%; height:var(--tap); transform:translateY(-50%); }
.hz-del{ min-width:var(--tap); min-height:var(--tap); }
button.chip{ min-height:var(--tap); min-width:var(--tap); cursor:pointer; }
.chip{ cursor:default; }
.besti-tile{ cursor:default; }
.besti-tile:hover{ transform:none; }
.hodie .hd-row .btn{ min-height:var(--tap); }
#hodie-strip{ min-height:var(--tap); }
.power{ min-height:var(--tap); }
@media (pointer:coarse){
  .btn{ min-height:var(--tap-lg); }
  .hz-code{ font-size:max(16px, 1em); }
}
::placeholder{ color:rgba(185,169,196,.8); }
.table-wrap, .tray, .villa-tray{ overscroll-behavior-x:contain; }

/* key hints: only for mouse devices or keyboard mode */
.q-opt[data-key]::before{ content:attr(data-key); display:none; }
@media (hover:hover) and (pointer:fine){
  .q-opt[data-key]::before{ display:inline-block; }
}
body.kb .q-opt[data-key]::before{ display:inline-block; }
.q-opt[data-key]::before{ min-width:1.4em; margin-right:.6em; padding:0 .35em; text-align:center; border:1px solid var(--line);
  border-radius:4px; color:var(--dim); font-size:.75rem; line-height:1.5; vertical-align:middle; }
body.kb :focus-visible{ outline:3px solid var(--focus); outline-offset:2px; }

/* hover neutralisers for JS-injected :hover rules (WS5 E.2) */
@media (hover:none){
  .hero-card:hover, .hero-plaque:hover, .hodie-strip:hover, .bld-card:hover, .bld-card.bld-locked:hover,
  .besti-tile:hover, .comes-card.own:hover, .hz-del:hover{ transform:none; }
}

/* focus */
.rep-sheet :focus-visible, .parch :focus-visible{ outline-color:var(--focus-on-light); }
@media (forced-colors:active){ :focus-visible{ outline-color:Highlight; } }

/* ===== A11Y (type floor, art scale, contrast, reduced motion, forced colors) ===== */
.eyebrow, .table-wrap th, .bar-txt, .hero-plaque small, .slot.empty, .dq-prog, .aurea-badge,
.r-aurea::after, .bld-card .bld-badge, .bld-card .badge,
.hodie-strip .hs-ready, .bld-card .bld-note, .bld-card.bld-mini .bld-sub, .badge,
.besti-tile .b-nm, .besti-tile .b-kill, .hodie .dq-card .dq-nm span,
.ct-rar, .ct-pw, .ct-count, .ct-new, .ct-refund, .pb-t, .pb-s, .eq-slot.full small, .eq-x, .aurea-tag,
.tb-rank, .hz-cmp b, .hz-code{ font-size:max(var(--fs-floor), .75rem); }
.bld-card .bld-note{ color:#5c4210; }
.bld-card .bld-sub, .hero-plaque small, .hero-plaque .hp-txt small{ color:#5e4b2e; }
.toast.bad{ color:#d98a6a; }

/* ===== PRINT (base) ===== */
@page{ margin:12mm; }
@media print{
  :root{ --night:#fff; --panel:#fff; --panel2:#f5f0e6; --line:#9a8fa3; --line-dk:#9a8fa3;
         --ink:#1f1a24; --marble:#1f1a24; --dim:#4a4050; --gold:#7a5a14; --gold-hi:#5c4210; color-scheme:light; }
  body{ background:#fff !important; color:var(--ink); padding:0 !important; }
  #topbar, #navbar, #toasts, #modal-root, .power-tray, .bar.timer, .btn, button.chip[data-nav], .omen-banner,
  .scene-head::before, .vignette::after, .modal-back{ display:none !important; }
  .scene-head, .stage-scene, .hub-banner-art{ background-image:none !important; }
  .scr{ max-width:none !important; }
  *, *::before, *::after{ box-shadow:none !important; text-shadow:none !important;
                          animation:none !important; transition:none !important; }
  :where(.panel, .bld-card, .card-tile, .dq-card, table, svg, img){ break-inside:avoid; }
  :where(h1, h2, h3, .eyebrow){ break-after:avoid; }
}

/* ===== FIX round (S2 gate F1-F5) ===== */
/* F1 (C3): 44px hit-slop without growing the box (keeps the question fold). Tips are inline-level flex items. */
.ask-head > [data-tip], .ask-top [data-tip], .omen-chip{ position:relative; }
.ask-head > [data-tip]::after, .ask-top [data-tip]::after, .omen-chip::after{
  content:""; position:absolute; left:0; right:0; top:50%; height:var(--tap); min-width:var(--tap); transform:translateY(-50%); }
/* battle strip: the two tip spans wrap onto separate rows on phones, so slop would overlap; grow them instead */
.bt-who, #combo-meter{ min-height:var(--tap); }
.modal-x{ position:relative; z-index:2; }
#cr-name, #hz-in, .hz-in, #fama-refresh, .fama-tabs .chip, button.tray-chip{ min-height:var(--tap) !important; }
#cr-name, #hz-in, .hz-in{ box-sizing:border-box; }
@media (max-height:560px) and (orientation:landscape){
  button.pw-info{ min-width:var(--tap); min-height:var(--tap); }
}
/* F3 (C4): a bar inside a flex .statline (shop HP) has no intrinsic width; give it room for its label */
.statline > .bar{ flex:1 1 120px; min-width:120px; }
/* F4 (C14): body.rm mirrors the OS reduced-motion rules */
body.rm *, body.rm *::before, body.rm *::after{ animation:none !important; }
body.rm .badge[style*="hm-pulse"]{ animation:none !important; }
/* F5 (C28): .scr keeps a transform through its entry animation (fill-mode both), which turns it into the containing
   block of fixed overlays such as the omen splash. Release the transform once the animation has ended. */
.scr{ animation-fill-mode:backwards; }

/* ===== S3 FIX (orchestrator): toasts clear the villa's bottom dock (confirm bar + tray) ===== */
body[data-scr="domus"] #toasts{ bottom:auto; top:calc(env(safe-area-inset-top, 0px) + 58px); }

/* ===== S4 FIX: villa two-column grid (container >= 980px) let its 1fr plot column keep its min-content width, pushing the
   340px side panel 48px past the viewport at 1024 wide (ipad1024L, ipadPro13P). Let the plot column shrink. ===== */
.villa-body > .villa-plot, .villa-body > .villa-side{ min-width:0; }

/* ===== S5 PHASE 3 (LAYOUT): display settings, contrast, forced colours, Hodie variants, <details> ===== */
/* Text size: the --ts token (html[data-text]) is defined in SHELL. Keep fixed-px chrome from clipping at l / xl. */
html[data-text="l"] #topbar, html[data-text="xl"] #topbar{ min-height:var(--topbar-h); height:auto; }
html[data-text="l"] .btn, html[data-text="xl"] .btn{ min-height:var(--tap); height:auto; }
html[data-text="xl"] .q-opt{ overflow-wrap:anywhere; }
html[data-text="xl"] .bar-txt{ white-space:nowrap; }

/* Reduce motion (Auto leaves @media in charge; On = body.rm / html.rm): no running animation or smooth scroll */
html.rm, html.rm body{ scroll-behavior:auto !important; }
html.rm *, html.rm *::before, html.rm *::after{ animation:none !important; transition-duration:.001ms !important; }

/* More contrast follows the OS (no row) */
@media (prefers-contrast:more){
  :root{ --dim:#d6c9df; }
  .panel, .btn, .chip, .q-opt, input, select, textarea{ border-color:var(--line-ui); }
  ::placeholder{ opacity:1; color:#cdbfd8; }
  .hodie-strip, .bld-card, .besti-tile{ border-color:var(--line-ui); }
}
html[data-contrast="more"]{ --line-ui:#8a7898; --dim:#d6c9df; }

/* Forced colours: system colours for borders, fills, focus; nothing may rely on a background image or shadow */
@media (forced-colors:active){
  .panel, .btn, .chip, .q-opt, .hodie-strip, .bld-card, .besti-tile, .dq-card, details > summary, input, select, textarea{
    border:2px solid CanvasText; forced-color-adjust:auto; }
  .btn:disabled, .btn[disabled]{ border-color:GrayText; color:GrayText; }
  .bar{ border:1px solid CanvasText; background:Canvas; }
  .bar > i, .bar > b, .bar > span.fill, .bar .f{ background:Highlight; forced-color-adjust:none; }
  .bar-txt{ background:Canvas; color:CanvasText; border:1px solid CanvasText; }
  :focus-visible{ outline:3px solid Highlight; outline-offset:2px; }
  .q-opt.right, .q-opt.wrong{ border-style:double; border-width:4px; }
  .q-opt.right::after, .q-opt.wrong::after{ forced-color-adjust:none; }
  a{ color:LinkText; }
}

/* Hodie, both variants (B.3): HOME renders the strip and the full panel; CSS picks one per device so rotation swaps them */
#scr-home .hodie-panel, #scr-home #hodie-host{ display:none; }
/* spec says min-height:1000px; the C22 lint admits only the A.1 table, so portrait >= 600 wide stands in (iPad portrait) */
@media (min-width:600px) and (orientation:portrait){
  #scr-home .hodie-panel, #scr-home #hodie-host{ display:block; }
  #scr-home .hodie-strip, #scr-home #hodie-strip{ display:none; }
}

/* <details> collapsing (U12): Profile Bestiarium / Res Gestae and Templum "Perfecta" */
#scr-profile details, #scr-quests details{ break-inside:avoid; }
#scr-profile details > summary, #scr-quests details > summary{
  box-sizing:border-box; width:100%; min-height:var(--tap-lg); padding:6px 12px; list-style:none;
  display:flex; align-items:center; gap:8px; cursor:pointer; font-family:var(--disp); font-weight:700; }
#scr-profile details > summary::-webkit-details-marker, #scr-quests details > summary::-webkit-details-marker{ display:none; }
#scr-profile details > summary::after, #scr-quests details > summary::after{
  content:"\25B8"; margin-left:auto; font-size:1.1em; transition:transform .15s; }
#scr-profile details[open] > summary::after, #scr-quests details[open] > summary::after{ transform:rotate(90deg); }
