/* The flight surface consumes gestures; readers and inventories retain native scrolling. */
.touch-mode #view{touch-action:none;}
#touchControls{position:fixed;inset:0;z-index:4;pointer-events:none;user-select:none;-webkit-user-select:none;color:#f3e3bf;font:12px/1.3 system-ui,sans-serif;--safe-bottom:env(safe-area-inset-bottom,0px);--safe-top:env(safe-area-inset-top,0px);--safe-left:max(14px,env(safe-area-inset-left,0px));--safe-right:max(14px,env(safe-area-inset-right,0px));}
#touchControls[hidden]{display:none;}
#touchControls button,#touchControls input,#touchStick{pointer-events:auto;touch-action:none;-webkit-tap-highlight-color:transparent;}
#touchControls button{font:inherit;min-height:44px;color:inherit;border:1px solid #d0b47896;background:#172032d9;border-radius:8px;box-shadow:inset 0 0 12px #d7b86c0d;padding:4px 6px;}
#touchControls button:active,#touchControls button.held{background:#66534acb;border-color:#fff1bd;}
#touchControls button:focus-visible{outline:2px solid #b5ffe7;outline-offset:2px;}
.touch-menu{position:absolute;left:50%;top:calc(var(--safe-top) + 8px);transform:translateX(-50%);display:flex;gap:5px;}
.touch-menu button{min-width:44px;}
#touchStick{position:absolute;left:var(--safe-left);bottom:calc(var(--safe-bottom) + 61px);width:132px;height:132px;border:1px solid #dfc18c9c;border-radius:50%;background:radial-gradient(circle,#26314920 30%,#1820338f 70%);box-shadow:inset 0 0 0 6px #bda47518;}
.touch-compass{position:absolute;inset:19px;border:1px solid #d5b97860;transform:rotate(45deg);pointer-events:none;}
.touch-compass:after{content:'';position:absolute;inset:0;border:1px solid #d5b97844;transform:rotate(45deg);border-radius:50%;}
#touchKnob{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);display:grid;place-items:center;width:46px;height:46px;border:1px solid #f7dba5bd;border-radius:50%;background:#33364cd9;color:#ffe6b6;font:26px Georgia;font-style:normal;pointer-events:none;}
.touch-stick-caption{position:absolute;left:0;right:0;bottom:9px;text-align:center;color:#e6d7b9;font-size:10px;letter-spacing:.1em;pointer-events:none;text-shadow:0 1px 4px #000;}
.touch-throttle{position:absolute;left:var(--safe-left);bottom:calc(var(--safe-bottom) + 205px);width:132px;background:#172032cf;border-radius:6px;padding:5px 8px 0;box-sizing:border-box;}
.touch-throttle>span{display:flex;justify-content:space-between;font-size:11px;}
#touchThrottle{display:block;width:100%;height:32px;margin:0;accent-color:#e8ca93;cursor:pointer;}
.touch-combat{position:absolute;right:var(--safe-right);bottom:calc(var(--safe-bottom) + 61px);display:grid;grid-template-columns:65px 82px;grid-template-rows:48px 48px;gap:10px;align-items:center;}
#touchControls #touchFire{grid-column:2;grid-row:1/3;width:82px;height:82px;border-radius:50%;outline:1px solid #d5ad6d70;outline-offset:5px;font-size:17px;background:radial-gradient(circle,#40304ed9,#192337ed);}
#touchControls #touchFire.held{background:radial-gradient(circle,#89709c,#423249ed);box-shadow:0 0 16px #cda6ff70;}
#touchWard,#touchBrake{height:48px;}
#touchBrake small{display:block;font-size:9px;color:#c8bba3;margin-top:3px;}
#touchWard.cooldown{color:#a6a2b5;}
#touchContext{position:absolute;right:var(--safe-right);bottom:calc(var(--safe-bottom) + 185px);min-width:90px;}
#touchContext.resonance{background:#665036f0;color:#fff2bb;outline:2px solid #ffe7a9;box-shadow:0 0 22px #ffe19c66;}
.touch-slots{position:absolute;left:50%;bottom:calc(var(--safe-bottom) + 7px);transform:translateX(-50%);display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:5px;width:min(350px,calc(100vw - 28px));}
.touch-slots button{display:flex;gap:4px;align-items:center;justify-content:center;}
.touch-slots b{font:17px Georgia;color:#dfc18c;}.touch-slots span{font-size:10px;}
#touchControls .touch-slots .selected{border-color:#f0d799;background:#514331e8;box-shadow:inset 0 2px #ffe3a6;}
#touchControls .touch-slots .unavailable{color:#93919f;}.touch-slots .unavailable b{color:#8d8996;}
.touch-mode #openStory,.touch-mode #keys{display:none!important;}
.touch-help{white-space:pre-line;font:13px/1.9 system-ui;max-width:340px;margin:22px auto 0;color:#e0d7cb;}
.touch-mode .hud-tl,.touch-mode .hud-tr,.touch-mode .hud-bl .throttle-track,.touch-mode #throttleLabel,.touch-mode #wardStatus,.touch-mode .duel-readout small,.touch-mode #trick{display:none!important;}
.touch-mode .route-hud,.touch-mode #hud.skirmish .route-hud{left:14px;right:14px;top:calc(env(safe-area-inset-top,0px) + 63px);transform:none;max-width:none;grid-template-columns:1fr;padding:6px 10px;}
.touch-mode .route-hud strong{font-size:13px;}.touch-mode .route-hud span{font-size:11px;}.touch-mode .route-hud small,.touch-mode .chapter-seal{display:none;}
.touch-mode .hud-bl,.touch-mode #hud.skirmish .hud-bl{left:14px;top:calc(env(safe-area-inset-top,0px) + 126px);bottom:auto;width:180px;padding:0;background:none;border:0;}
.touch-mode .mana-track{margin-top:0;height:4px;}.touch-mode #manaLabel{font-size:11px;margin-top:3px;}
.touch-mode .duel-readout{font-size:11px;margin-top:3px;}.touch-mode .duel-readout span{font-size:10px;}
.touch-mode .hud-br{right:14px;top:calc(env(safe-area-inset-top,0px) + 126px);bottom:auto;font-size:28px;}
.touch-mode #duelEnergy{display:none;}.touch-mode .flight-readout{font-size:10px;max-width:145px;}
.touch-mode #battleHint,.touch-mode #prompt{display:none!important;}
.touch-mode #threat{top:28%;font-size:11px;white-space:nowrap;}
.touch-mode #storyRadio{bottom:calc(env(safe-area-inset-bottom,0px) + 265px);font-size:11px;width:calc(100vw - 60px);box-sizing:border-box;}
.touch-mode #ritualPrompt{top:47%;padding:7px 12px;max-width:65vw;font-size:11px;}.touch-mode #ritualPrompt kbd{display:none;}
.touch-mode .toast,.touch-mode #hud.skirmish .toast{top:24%;max-width:88vw;white-space:normal;text-align:center;font-size:14px;}
.touch-mode #spellBook button,.touch-mode #chartPanel button{min-height:44px;}
.touch-mode #spellBook{max-height:94dvh;padding:12px;}.touch-mode #spellCards{grid-template-columns:repeat(2,minmax(0,1fr));}
.touch-mode #storyDialog button{min-height:44px;}.touch-mode #storyTabs{overflow-x:auto;flex-shrink:0;gap:5px;}.touch-mode #storyTabs button{white-space:nowrap;}
.touch-mode #storyDialog{gap:8px;padding:12px;}.touch-mode .story-header{padding-bottom:7px;}.touch-mode .story-header h2{font-size:19px;}
.touch-mode .story-header button{flex-shrink:0;}.touch-mode .story-footer{gap:6px;padding-top:7px;}
@media(max-width:800px){
  .touch-mode .story-layout{grid-template-rows:120px minmax(0,1fr);gap:10px;}
  .touch-mode #storyDialog.archive .story-layout{grid-template-rows:64px 100px minmax(0,1fr);gap:8px;}
  .touch-mode .story-illustration{display:flex;}
  .touch-mode #storyDialog.archive #storyShelf{max-height:none;}
  .touch-mode .story-illustration figcaption{padding:12px 10px 6px;font-size:11px;pointer-events:none;}
  .touch-mode #storyEnlarge{top:4px;right:4px;}
  .touch-mode #storyScroll{font-size:14px;padding-right:5px;}
  .touch-mode #storyScroll h3{font-size:18px;margin-bottom:8px;}
  .touch-mode #storyNext{max-width:45%;}
}
@media(orientation:landscape) and (max-height:600px){
  #touchStick{width:112px;height:112px;bottom:calc(var(--safe-bottom) + 46px);}
  #touchKnob{width:40px;height:40px;}
  .touch-menu{left:auto;right:var(--safe-right);transform:none;gap:4px;}
  .touch-menu button{min-width:44px;}
  .touch-combat{bottom:calc(var(--safe-bottom) + 46px);grid-template-columns:60px 72px;gap:8px;}
  #touchControls #touchFire{width:72px;height:72px;}
  #touchContext{bottom:calc(var(--safe-bottom) + 163px);}
  .touch-throttle{left:50%;transform:translateX(-50%);width:180px;bottom:calc(var(--safe-bottom) + 57px);}
  .touch-slots{width:320px;}
  .touch-mode .route-hud,.touch-mode #hud.skirmish .route-hud{left:var(--safe-left,14px);right:auto;top:calc(env(safe-area-inset-top,0px) + 8px);width:min(43vw,340px);box-sizing:border-box;}
  .touch-mode .hud-bl,.touch-mode #hud.skirmish .hud-bl{top:calc(env(safe-area-inset-top,0px) + 70px);width:175px;}
  .touch-mode .hud-br{top:calc(env(safe-area-inset-top,0px) + 62px);right:max(14px,env(safe-area-inset-right,0px));}
  .touch-mode #threat{top:20%;}.touch-mode .toast,.touch-mode #hud.skirmish .toast{top:28%;}
  .touch-mode #storyRadio{bottom:112px;width:42vw;padding:5px 10px;}
  .touch-mode #storyRadio p{margin:1px 0;}
  .touch-mode #spellCards{grid-template-columns:repeat(4,minmax(0,1fr));}
  .touch-mode #storyDialog{height:96dvh;max-height:96dvh;gap:5px;}
  .touch-mode .story-layout{grid-template-columns:minmax(110px,.55fr) minmax(0,1fr);grid-template-rows:minmax(0,1fr);gap:12px;}
  .touch-mode #storyDialog.archive .story-layout{grid-template-columns:110px minmax(100px,.5fr) minmax(0,1fr);grid-template-rows:minmax(0,1fr);gap:10px;}
  .touch-mode #storyDialog.archive #storyShelf{display:block;max-height:none;}
  .touch-mode #storyShelf button{min-width:0;}
  .touch-mode .story-illustration{display:flex;}
  .touch-mode .story-header small,.touch-mode #storySkip{display:none;}
  .touch-mode .story-header{padding-bottom:3px;}.touch-mode .story-footer{padding-top:3px;}
  .touch-mode #storyTabs button{padding:3px 10px;}.touch-mode #storyScroll{font-size:13px;}
}

#touchControls{
  --touch-scale:1;--touch-opacity:1;--touch-lift:0px;
  --touch-rise:min(var(--touch-lift),17dvh);--touch-base:61px;
  --stick-size:clamp(90px,calc(132px * var(--touch-scale)),min(39vw,162px));
  --fire-size:clamp(60px,calc(82px * var(--touch-scale)),min(26vw,100px));
  --side-size:clamp(50px,calc(65px * var(--touch-scale)),min(21vw,80px));
  --combat-row:clamp(44px,calc(48px * var(--touch-scale)),58px);
  --combat-gap:10px;
  --control-bottom:calc(var(--safe-bottom) + var(--touch-base) + var(--touch-rise));
  --context-bottom:calc(var(--control-bottom) + 2 * var(--combat-row) + var(--combat-gap) + 16px);
  opacity:var(--touch-opacity);
}
#touchControls #touchStick{width:var(--stick-size);height:var(--stick-size);bottom:var(--control-bottom);}
#touchControls #touchKnob{width:calc(var(--stick-size) * .35);height:calc(var(--stick-size) * .35);}
#touchControls .touch-combat{bottom:var(--control-bottom);grid-template-columns:var(--side-size) var(--fire-size);grid-template-rows:repeat(2,var(--combat-row));gap:var(--combat-gap);}
#touchControls #touchFire{width:var(--fire-size);height:var(--fire-size);}
#touchControls :is(#touchBrake,#touchWard){height:var(--combat-row);}
#touchControls #touchContext{bottom:var(--context-bottom);}
#touchControls #touchRepair{position:absolute;right:var(--safe-right);bottom:calc(var(--context-bottom) + 50px);min-width:90px;border-color:#d18e72;background:#512c38e8;}
#touchControls #touchRepair.held{background:#2d5550;border-color:#a1e4d2;}
#touchControls .touch-throttle{width:var(--stick-size);bottom:calc(var(--control-bottom) + var(--stick-size) + 12px);}
#touchControls.mirrored #touchStick,#touchControls.mirrored .touch-throttle{left:auto;right:var(--safe-right);}
#touchControls.mirrored .touch-combat,#touchControls.mirrored #touchContext,#touchControls.mirrored #touchRepair{right:auto;left:var(--safe-left);}
#touchControls.mirrored .touch-combat{grid-template-columns:var(--fire-size) var(--side-size);}
#touchControls.mirrored #touchFire{grid-column:1;}
#touchControls.mirrored :is(#touchWard,#touchBrake){grid-column:2;}
@media(orientation:landscape) and (max-height:600px){
  #touchControls{--touch-base:46px;--stick-size:clamp(86px,calc(112px * var(--touch-scale)),135px);
    --fire-size:clamp(58px,calc(72px * var(--touch-scale)),94px);--side-size:clamp(50px,calc(60px * var(--touch-scale)),74px);--combat-gap:8px;}
  #touchControls .touch-throttle,#touchControls.mirrored .touch-throttle{left:50%;right:auto;width:180px;bottom:calc(var(--safe-bottom) + 57px);}
  #touchControls #touchRepair,#touchControls.mirrored #touchRepair{left:50%;right:auto;bottom:calc(var(--safe-bottom) + 113px);transform:translateX(-50%);}
}
