.sr-only {
  position:absolute; width:1px; height:1px; padding:0; margin:-1px;
  overflow:hidden; clip-path:inset(50%); white-space:nowrap; border:0;
}
.rail-toggle {
  display:flex; align-items:center; gap:13px; min-height:44px;
  padding:6px 18px; margin:8px 10px 0; color:#c6cec1; text-align:left;
}
.rail-toggle:hover { background:#344843; color:white; }
.rail-nav { padding-top:8px; }
.rail-nav button { flex-shrink:0; }
.scene-open { height:100vh; height:100dvh; min-height:0; overflow:hidden; }
.scene-open .play-area { min-height:0; display:flex; flex-direction:column; }
.scene-open .hud { flex:none; min-height:62px; padding-block:6px; }
.scene-open .play-area main {
  display:flex; flex:1; flex-direction:column; min-height:0; min-width:0;
  width:100%; max-width:none; margin:0; padding:0;
}
.scene-open #screen { flex:1; min-height:0; min-width:0; position:relative; }
.scene-heading {
  min-height:49px; flex:none; display:flex; align-items:center; gap:18px;
  padding:0 clamp(12px,1.6vw,24px); background:#f7f5ef;
  border-bottom:1px solid #c9cec0;
}
.scene-tabs { display:flex; align-self:stretch; gap:10px; }
.scene-tabs button {
  border-radius:0; border:0; border-bottom:3px solid transparent; background:none;
  display:inline-flex; align-items:center; gap:7px; min-height:44px;
  padding:4px 8px 1px; color:#53655b; white-space:nowrap;
}
.scene-tabs button[aria-current="page"] { border-bottom-color:#9c783b; font-weight:750; color:#253d31; }
.scene-heading .page-status { margin-left:auto; flex-direction:row; align-items:center; gap:12px; }
.scene-open .alert-text { margin:0; flex:none; }
.dialog-inner { max-height:calc(100dvh - 38px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow-y:auto; overscroll-behavior:contain; }
.dialog-buttons { position:sticky; bottom:-1px; background:var(--panel); padding-block:5px; }
.dialog-inner {max-height:min(calc(100dvh - 38px - env(safe-area-inset-top) - env(safe-area-inset-bottom)),calc(var(--visible-height,100dvh) - 32px));}
@media(max-width:760px) {
  .scene-open {
    display:grid; grid-template-columns:minmax(0,1fr); grid-template-rows:minmax(0,1fr) auto;
    padding-top:env(safe-area-inset-top); background:var(--deep);
  }
  .scene-open .play-area { height:100%; background:var(--paper); }
  .scene-open .bottom-nav { position:static; }
  .scene-open .hud { min-height:50px; padding:2px max(8px,env(safe-area-inset-right)) 2px max(8px,env(safe-area-inset-left)); }
  .scene-open .resources { padding:0; border:0; }
  .scene-open .stock { min-height:44px; }
  .scene-heading { min-height:44px; gap:6px; padding-inline:8px; }
  .scene-heading .scene-tabs { gap:3px; }
  .scene-heading .scene-tabs button { min-height:44px; padding-inline:5px; font-size:.86rem; }
    .scene-heading .page-status { gap:7px; }
  .scene-heading .connection { font-size:.72rem; }
}
@media(max-height:520px) and (orientation:landscape) {
  .scene-open .hud { min-height:44px; padding-block:0; }
  .scene-open .scene-heading { min-height:40px; }
  .scene-open .scene-heading button { min-height:40px; }
  .scene-open .bottom-nav button { min-height:44px; }
}
.command-strip{display:flex;align-items:stretch;flex:none;gap:clamp(4px,1.3vw,22px);padding:0 clamp(12px,2vw,36px);background:#e7eadf;border-bottom:1px solid #bfc8b7;color:#243c31}
.command-strip button,.army-tabs button{min-height:44px;display:inline-flex;align-items:center;justify-content:center;gap:7px;padding:3px 8px;font-size:.88rem;line-height:1.25}
.command-strip button:hover,.command-strip button:focus-visible{background:#d8dfcf}
.command-strip span{overflow-wrap:anywhere}
.threat-strip{display:flex;flex:none;align-items:center;gap:8px;text-align:left;padding:4px 14px;min-height:44px;background:#703624;color:white}.threat-strip strong{margin-left:auto}
.army-tabs{display:flex;flex-wrap:wrap;gap:4px;border-bottom:1px solid var(--line);margin:0 0 16px}.army-tabs button{min-width:64px}
.army-tabs [aria-current="page"]{color:#254032;box-shadow:inset 0 -3px #866828;font-weight:700;background:#e5eadf}
.care-summary{display:flex;gap:8px 18px;flex-wrap:wrap;padding:12px 0;color:#283f34}
.kingdom-fold{margin:12px 0}.kingdom-fold summary,.fold summary{min-height:44px;padding-block:10px}
.kingdom-fold[open]{padding-bottom:16px}.kingdom-fold p,.kingdom-fold h3,.kingdom-fold ul,.kingdom-fold ol{margin:12px 0}
.kingdom-goal{gap:12px}.goal-funds{display:grid;grid-template-columns:repeat(auto-fit,minmax(130px,1fr));gap:6px 18px}.goal-funds progress{display:block;width:100%}
.work-row{display:flex;align-items:center;gap:10px;min-height:48px;text-align:left;padding:8px;border-bottom:1px solid var(--line)}.work-row small{display:block}.work-row time{margin-left:auto}
.order-quote{margin:10px 0;background:#edf0e6;border-left:3px solid #6b7c57;padding:9px}.order-quote p{margin:3px 0}.order-quote:empty{display:none}
#order-form button,#action-dialog .soft{min-height:44px}.dialog-buttons button,.action-btn{overflow-wrap:anywhere}
.command-strip .icon,.threat-strip .icon{flex:none}
@media(max-width:760px){.bottom-nav{grid-template-columns:repeat(5,minmax(0,1fr))}.command-strip{gap:0;padding:0 4px;flex-wrap:wrap}.command-strip button{font-size:.84rem;gap:4px}.command-strip .goal-link{flex:1;justify-content:flex-end}.hud .stock{min-height:44px}.care-summary{font-size:.95rem}.order{gap:6px}.army-tabs button{flex:1;min-width:54px}.threat-strip{flex-wrap:wrap;line-height:1.25}}
@media(max-width:430px){.goal-link .icon{display:none}.dialog-inner{padding-inline:16px}.command-strip button{padding-inline:5px}.threat-strip{font-size:.85rem}}
@media(max-height:530px){.scene-open .command-strip button{min-height:32px}}

/* Scene furniture stays at screen scale while the valley and atlas cameras move. */
.hud .compact-stock,.hud-brand{display:none}
.hud .shield-status{display:inline-flex;align-items:center;justify-content:center;gap:6px;border:1px solid #c7a86b;border-radius:99px;min-height:40px;padding:5px 15px;white-space:nowrap;color:#f8e7bb;background:#293e2c;font-weight:650}
.hud .shield-status.exposed{border-color:#a9aea0;background:#29382f;color:#ecede2}
.command-strip{align-items:center;justify-content:flex-start;gap:10px;min-width:0}
.command-strip .goal-link{margin:0;display:inline-flex;align-items:center;gap:9px;min-width:0;text-align:left}
.goal-link small{display:flex;align-items:center;gap:4px;white-space:nowrap}
.goal-link small .icon{font-size:.9em}
.operation-cards{display:flex;align-items:center;gap:8px;min-width:0}
.work-card>span{display:flex;flex-direction:column;min-width:50px;text-align:left;gap:3px}
.work-card progress{width:100%;height:6px;accent-color:#c1a05a}
.work-card progress::-webkit-progress-bar{background:#60715c;border-radius:8px}
.work-card progress::-webkit-progress-value{background:#d7b66b;border-radius:8px}
.work-card progress::-moz-progress-bar{background:#d7b66b;border-radius:8px}
.command-strip .work-card .timer{font:normal .76rem/1.2 var(--sans);color:inherit}
@media(min-width:761px) {
  .game-shell{
    --frame-height:clamp(58px,4.2vw,72px);--rail-width:154px;
    grid-template-columns:var(--rail-width) minmax(0,1fr);
  }
  .game-shell[data-rail=closed]{--rail-width:clamp(70px,5.3vw,92px);grid-template-columns:var(--rail-width) minmax(0,1fr)}
  .game-shell .play-area{padding-top:var(--frame-height)}
  .game-shell .rail{height:calc(100dvh - var(--frame-height));max-height:none;top:var(--frame-height);margin-top:var(--frame-height);background:linear-gradient(100deg,#142a21,#0d211c);border-right:1px solid #5d6147}
  .game-shell .rail-nav{flex:0;gap:5px;padding:clamp(14px,3.5vh,38px) 8px 10px}
  .game-shell .rail-nav button{display:flex;flex-direction:row;justify-content:flex-start;gap:13px;min-height:55px;color:#f2edda;border:1px solid transparent;line-height:1.2;font:600 .98rem/1.2 var(--serif)}
  .rail-nav button .icon{color:#c7cdb6;width:26px;height:26px;stroke-width:1.45}
  .game-shell[data-rail=closed] .rail-nav button{flex-direction:column;justify-content:center;gap:6px;min-height:clamp(60px,8.3vh,86px);padding:4px}
  .game-shell[data-rail=closed] .rail-nav button span{display:inline}
  .game-shell .rail-nav button[aria-current=page]{color:#ffeeaf;border-color:#c2a66e;background:linear-gradient(120deg,#435638,#2c432e);box-shadow:inset 0 0 0 2px #213825}
  .rail-nav button[aria-current=page]:before{display:none}
  .game-shell .rail-toggle{margin:auto 8px 9px;padding:5px 12px;min-height:44px;align-self:stretch;color:#d9dcc9}
  .game-shell[data-rail=closed] .rail-toggle{margin:auto 8px 9px;align-self:center;justify-content:center;min-width:44px}
  .game-shell[data-rail=closed] .rail-toggle span{display:none}
  .rail-toggle[aria-expanded=true] .icon{transform:rotate(180deg)}
  .game-shell .hud{position:fixed;z-index:12;inset:0 0 auto;min-height:var(--frame-height);height:var(--frame-height);display:flex;flex-wrap:nowrap;align-items:center;gap:clamp(12px,2vw,35px);padding:3px clamp(12px,1.6vw,30px);background:linear-gradient(110deg,#152c22,#11251d 67%,#172b20);border-bottom:1px solid #8c8059;color:#f4eedb;box-shadow:0 2px 8px #10201433}
  .hud-brand{display:flex;align-items:center;flex:none;padding-right:clamp(12px,3.6vw,66px);border-right:1px solid #8d8359}
  .hud-brand .brand{gap:10px}.hud-brand .brand .crest{width:37px;height:37px}.hud-brand .brand strong{font-size:clamp(1.1rem,1.8vw,2rem);line-height:1;color:#fff5d9}.hud-brand .brand span{color:#e6ce8c;font-size:clamp(.55rem,.66vw,.76rem);letter-spacing:.24em}
  .hud .resources{display:flex;max-width:none;gap:clamp(3px,1.1vw,20px);justify-content:space-around;padding:0}
  .hud .stock{min-height:44px;justify-content:center;gap:clamp(5px,.8vw,14px);padding:0 4px;width:auto;background:transparent}
  .hud .stock:hover{background:#ffffff0d}
  .hud .stock>span{display:flex;gap:clamp(4px,.6vw,12px);align-items:baseline;white-space:nowrap}
  .hud .stock small{color:#f0ecd9;font:600 clamp(.85rem,1.03vw,1.18rem)/1.3 var(--serif)}
  .hud .stock b{color:#fff7e3;font:650 clamp(1.05rem,1.32vw,1.55rem)/1.2 Georgia,var(--serif)}
  .hud .stock .icon{width:clamp(20px,1.6vw,30px);height:clamp(20px,1.6vw,30px);stroke-width:1.55}
  .hud .stock.food,.hud .stock.iron{color:#dcb469}.hud .stock.wood{color:#b8cd98}.hud .stock.stone{color:#d6d6c5}.hud .stock.diamonds{color:#c1d6b9}
  .hud .shield-status{min-height:40px;position:relative}
  .hud .shield-status:before{content:"";position:absolute;left:calc(-1 * clamp(6px,1vw,18px));height:26px;width:1px;background:#8d8359}
  .scene-open .play-area main{position:relative;isolation:isolate}
  .scene-open .scene-heading{position:absolute;z-index:5;top:16px;left:clamp(12px,1.7vw,30px);min-height:44px;max-width:66%;padding:0;gap:16px;background:none;border:none;pointer-events:none}
  .scene-open .scene-heading .scene-tabs{pointer-events:auto;align-self:center;gap:0;min-height:44px;overflow:hidden;border:1px solid #b9a273;border-radius:5px;background:linear-gradient(130deg,#273b2bee,#10251ded);box-shadow:0 2px 8px #10211666}
  .scene-open .scene-tabs button{height:44px;min-width:clamp(74px,6.4vw,112px);padding:4px 13px;color:#f6eed4;border:0;justify-content:center;font:650 clamp(.85rem,1.03vw,1.2rem)/1.15 var(--serif)}
  .scene-open .scene-tabs button[aria-current=page]{background:linear-gradient(120deg,#f2d18e,#d0a554);color:#202b19;box-shadow:inset 0 0 0 1px #ebcb85}
  .scene-identity{display:flex;align-items:center;gap:10px;padding:5px 9px;background-color:#20382cde;border-radius:3px;color:#fff9e3;text-shadow:0 1px 3px #101e15}
  .scene-identity h1{font:700 clamp(1.24rem,1.65vw,1.85rem)/1.2 var(--serif);letter-spacing:-.035em}
  .scene-identity span{border-left:1px solid #eedebdaa;padding-left:10px;font:600 .88rem/1.3 var(--serif)}
  .scene-heading .page-status{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
  .scene-open #disconnect:not([hidden]){z-index:7;background:#fff0d4;position:relative;flex:none}
  .scene-open .threat-strip{position:absolute;left:clamp(12px,1.7vw,30px);top:68px;z-index:6;box-shadow:0 2px 8px #10211655;border:1px solid #c49164;border-radius:5px}
  .scene-open .command-strip{position:absolute;z-index:5;bottom:clamp(10px,1.8vh,23px);left:clamp(12px,1.3vw,25px);max-width:calc(100% - 260px);display:flex;align-items:flex-end;gap:clamp(9px,2.5vw,52px);padding:0;background:transparent;border:0;pointer-events:none}
  .scene-open .command-strip button{pointer-events:auto;min-height:46px;padding:5px clamp(9px,.85vw,18px);box-shadow:0 2px 8px #16201470;line-height:1.2}
  .scene-open .goal-link{position:relative;min-width:0;max-width:min(36vw,460px);background:linear-gradient(115deg,#fcf3d9,#ead8b4);color:#2a3323;border:1px solid #967c47;border-radius:5px;box-shadow:inset 0 0 0 2px #f9edd4,0 2px 8px #16201470;font-family:var(--serif)}
  .goal-link>span{min-width:0;overflow-wrap:anywhere}.goal-link small{font:600 .76rem/1.1 var(--sans);color:#42503b}
  .operation-cards{gap:8px}
  .scene-open .work-card,.scene-open .work-total{border:1px solid #b5a16a;border-radius:5px;background:linear-gradient(115deg,#30452eee,#172c20f5);color:#f9ebc7;font:600 .88rem/1.2 var(--serif)}
  .scene-open .work-card>span{min-width:clamp(54px,6vw,105px)}.scene-open .work-card>.icon,.scene-open .work-total .icon{color:#dbc38d}
  .game-shell .more-sheet:not([hidden]){display:block;position:fixed;z-index:15;left:calc(var(--rail-width) + 8px);top:calc(var(--frame-height) + 12px);width:min(360px,75vw);max-height:calc(100dvh - var(--frame-height) - 24px);overflow:auto;padding:18px;background:#fcf5e2;color:#273d2f;border:1px solid #ab915f;border-radius:7px;box-shadow:0 0 0 100vmax #10201969,0 5px 24px #172a1d66}
  .more-sheet header,.more-sheet footer{display:flex;align-items:center;justify-content:space-between;gap:8px}.more-sheet header{margin-bottom:12px}.more-sheet header button,.more-sheet footer button{min-height:44px;padding:6px 8px}
  .more-sheet>div{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:7px}.more-sheet>div button{border:1px solid #c4bd9d;color:#294735;background:#f3edd8;padding:6px 12px;min-height:46px}
  .more-sheet>footer{border-top:1px solid #d9cda8;margin-top:14px;font-size:.86rem}
  .more-sheet>footer>span{margin-right:auto}
}
@media(min-width:761px) and (max-width:1120px){.scene-identity span{display:none}.hud-brand{padding-right:11px}.game-shell .hud{gap:12px}.hud .stock>span{flex-direction:column;gap:0}.hud .stock small{font-size:.75rem}.hud .shield-status{padding-inline:9px}}
@media(min-width:761px) and (max-width:940px){.scene-identity{display:none}.scene-open .command-strip{max-width:calc(100% - 175px)}.scene-open .goal-link small{display:none}.scene-open .operation-cards{gap:4px}.hud-brand .brand .crest{width:29px;height:29px}.hud-brand .brand{gap:4px}}
@media(max-width:760px){
  .hud .exact-stock{display:none}.hud .compact-stock{display:inline}
  .hud .shield-status{min-height:44px;flex-direction:column;gap:1px;background:transparent;border:none;color:#f2d99e;font-size:.7rem;line-height:1.15;padding:1px 2px}
  .hud .shield-status.exposed{background:transparent;color:#d1d3c0}
  .game-shell .hud{display:flex;flex-wrap:nowrap;align-items:center;gap:4px}
  .game-shell .hud .resources{flex:1;min-width:0;flex-basis:auto;padding:0;border:0}
  .scene-heading .scene-identity{display:none}
  .scene-open .command-strip{order:-1;display:flex;gap:4px;flex-wrap:nowrap;min-height:44px}
  .command-strip .goal-link{margin:0;justify-content:flex-start;flex:1}
  .command-strip .goal-link small{display:none}
  .command-strip .operation-cards{gap:0}
  .command-strip .work-card>span{min-width:0}
  .command-strip .work-card .timer,.command-strip .work-card progress{display:none}
}
@media(min-width:761px) and (max-height:520px){.game-shell .rail-nav{padding-top:4px;gap:0}.game-shell[data-rail=closed] .rail-nav button{min-height:44px;flex-direction:row;gap:3px;font-size:.74rem}.game-shell[data-rail=closed] .rail-nav .icon{width:17px;height:17px}.scene-open .scene-heading{top:5px}.scene-open .command-strip button{min-height:38px}}
@media(min-width:761px){.game-shell .rail-nav button span{white-space:nowrap}}
@media(min-width:761px) and (max-width:1000px) and (max-height:550px) and (pointer:coarse){
  .game-shell,.game-shell[data-rail=closed]{display:block;--rail-width:0px;--frame-height:44px}
  .game-shell.scene-open,.game-shell.guided{display:grid;grid-template: minmax(0,1fr) auto / minmax(0,1fr);height:100dvh}
  .game-shell .rail{display:none}
  .game-shell .bottom-nav{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));position:fixed;inset:auto 0 0;z-index:7;padding:0 4px env(safe-area-inset-bottom);background:#192e25;border-top:1px solid #8c8059}
  .scene-open .bottom-nav,.guided .bottom-nav{position:static}
  .bottom-nav button{min-height:44px;display:flex;align-items:center;justify-content:center;gap:7px;color:#f1ebd5}
  .bottom-nav button[aria-current=page]{color:#ffe3a1;box-shadow:inset 0 2px #d7b66b}
  .game-shell .more-sheet:not([hidden]){left:auto;right:10px;top:auto;bottom:calc(48px + env(safe-area-inset-bottom));max-height:calc(100dvh - 65px)}
  .hud-brand .brand .crest{height:30px;width:30px}
  .hud .stock>span{flex-direction:row;align-items:center;gap:3px}
  .hud .stock b{font-size:.98rem}
}
@media(min-width:761px){.scene-identity span{max-width:12ch;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}}
@media(min-width:1160px) and (min-height:640px){
  .scene-open.guided{--guide-width:clamp(400px,36vw,600px)}
  .scene-open.guided .play-area{position:relative}
  .scene-open .tutorial-dock:has(#tutorial-guide){
    position:absolute;z-index:6;left:clamp(12px,1.3vw,25px);bottom:clamp(10px,1.8vh,23px);width:var(--guide-width);
    max-height:26dvh;background:linear-gradient(118deg,#fff6df,#f1e3c5);border:1px solid #a08653;border-radius:5px;
    box-shadow:inset 0 0 0 2px #f8ebcb,0 2px 9px #15231875
  }
  .scene-open.guided .tutorial-dock .guide-strip{gap:8px;padding:7px 9px}
  .scene-open.guided .tutorial-dock .guide-count{padding-right:8px}
  .scene-open.guided .tutorial-dock .guide-tools{display:flex;gap:2px;align-items:center;flex-direction:column}
  .scene-open.guided .tutorial-dock .guide-cta,.scene-open.guided .tutorial-dock .guide-help{min-height:44px;min-width:44px}
  .scene-open.guided .tutorial-dock .guide-fold{min-height:32px}
  .scene-open.guided .tutorial-dock .guide-full-label{display:none}
  .scene-open.guided .tutorial-dock .guide-cta{padding:5px;flex-direction:column;gap:2px}
  .scene-open.guided .tutorial-dock .guide-cta .guide-short{display:inline;font-size:.73rem}
  .scene-open .play-area:has(#tutorial-guide) .command-strip{left:calc(clamp(12px,1.3vw,25px) + var(--guide-width) + 12px);max-width:calc(100% - var(--guide-width) - 260px)}
}
/* Keep a usable map and command sheet when the user's font setting leaves
   fewer than sixteen rem across a phone. The scene can scroll with the page. */
@media(max-width:760px){
  #app:has(.scene-open){container:game-width / inline-size}
  @container game-width (max-width:16rem){
    #app .game-shell.scene-open{height:auto;min-height:100dvh;overflow:visible;grid-template-rows:auto auto}
    .scene-open .play-area{height:auto}
    .scene-open .play-area main{flex:none;overflow:visible}
    .scene-open #screen{flex:none;height:max(68dvh,18rem)}
    .scene-open .hud{flex-wrap:wrap}
    .scene-open .hud .resources{flex-basis:100%;display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:2px 6px}
    .scene-open .hud .stock{display:flex;justify-content:flex-start;gap:4px}
    .scene-open .scene-heading{flex-wrap:wrap}
    .scene-open .scene-heading .page-status{margin-left:0;flex-wrap:wrap}
    .scene-open .bottom-nav{position:static}
  }
}
