/* TD2 v3.6 portrait hotfix: no overlap between gameplay, menu and controls. */
#startScreen #menuHeroBtn{
  display:flex;align-items:center;gap:15px;width:100%;margin:0;padding:12px 18px;
  min-height:58px;background:#151b21e8;border:1px solid #7e8f9670;
  color:#e7e4db;text-align:left;
}
#startScreen #menuHeroBtn>span:first-child{font-size:25px;color:#d0ac76}
#startScreen #menuHeroBtn>span:last-child{margin-left:auto;font-size:24px;color:#c6b384}
#startScreen #menuHeroBtn small{display:block;color:#a8b5b8;letter-spacing:0}
#startScreen #menuHeroBtn:focus-visible{outline:3px solid #92d9ec;outline-offset:3px}
.hero-combat-overview{line-height:1.7;color:#d6dfd9;background:#152226;border:1px solid #617c7566;padding:15px;border-radius:6px}

/* Keep the changes scoped to real portrait play, not desktop or landscape. */
@media (orientation:portrait) and (max-width:700px){
  .left-hud{
    top:var(--hud-safe-top);left:var(--hud-safe-left);
    width:calc(100vw - var(--hud-safe-left) - var(--hud-safe-right) - 96px);
    min-width:0;max-width:none;padding:6px 9px;
    display:grid;grid-template-columns:1fr 1fr;gap:2px 8px;
    border-radius:6px;background:#0b1418e3;
  }
  .left-hud .hud-label,.left-hud .hud-label b{font-size:12px;line-height:1.25}
  .left-hud .meter{height:5px;margin-top:2px}
  .header-actions{top:var(--hud-safe-top);right:var(--hud-safe-right);z-index:20}
  .hud-menu summary{min-height:42px}
  .hud-menu-panel{position:fixed;top:calc(var(--hud-safe-top) + 136px);right:var(--hud-safe-right);z-index:8;min-width:0;width:min(320px,calc(100vw - var(--hud-safe-left) - var(--hud-safe-right)));max-height:min(42dvh,280px);grid-template-columns:repeat(2,minmax(0,1fr));gap:5px;padding:8px;overflow-y:auto}
  .hud-menu-panel button{width:100%;min-width:0;min-height:42px;padding:5px 6px;font-size:clamp(10px,2.8vw,13px);line-height:1.15;white-space:normal}
  .objective{
    top:calc(var(--hud-safe-top) + 52px);left:var(--hud-safe-left);right:auto;
    bottom:auto;transform:none;
    width:calc(100vw - var(--hud-safe-left) - var(--hud-safe-right) - 160px);
    min-width:0;max-width:none;padding:6px 8px;text-align:left;
    background:#0b1418e3;border:1px solid #a58e6229;pointer-events:none;
  }
  .objective>span{font-size:14px;letter-spacing:.03em}
  .objective small{font-size:12px;line-height:1.15;margin-top:3px}
  .objective #wavePreview{font-size:11px;line-height:1.25}
  .objective #storyText{display:none}
  .objective #nextWaveBtn{pointer-events:auto;min-height:38px;border-color:var(--gold2);color:var(--gold2)}
  .right-hud{
    top:calc(var(--hud-safe-top) + 52px);
    right:var(--hud-safe-right);left:auto;bottom:auto;
    width:145px;display:grid;grid-template-columns:1fr 1fr;gap:4px;align-items:stretch;
  }
  .right-hud .resource{display:block;min-width:0;padding:5px 6px;background:#0b1418e3}
  .right-hud .resource div{display:block}
  .right-hud .resource small{font-size:11px}
  .right-hud .resource b{font-size:15px;white-space:nowrap}
  .boss-hud{top:calc(var(--hud-safe-top) + 123px);left:50%;right:auto;bottom:auto;transform:translateX(-50%);width:min(230px,65vw);padding:6px}
  .boss-hud>div:first-child{font-size:10px}

  .joystick{
    display:flex;left:calc(var(--hud-safe-left) + 3px);
    bottom:calc(var(--hud-safe-bottom) + 16px);
    width:100px;height:100px;z-index:7;touch-action:none;
  }
  .joystick>span{width:40px;height:40px}
  .controls,.controls:has(#buildBtn:not(.hidden)),
  .controls:has(#upgradeBtn:not(.hidden)),
  .controls:has(#sellBtn:not(.hidden)),
  .controls:has(#targetBtn:not(.hidden)){
    position:fixed;left:auto;right:var(--hud-safe-right);
    bottom:calc(var(--hud-safe-bottom) + 3px);transform:none;
    width:min(204px,54vw);max-width:none;display:grid;
    grid-template-columns:repeat(2,minmax(0,1fr));gap:5px;
    justify-content:stretch;align-items:stretch;white-space:normal;z-index:7;
  }
  .controls .action-btn{
    width:100%;min-width:0;min-height:44px;padding:5px 4px;
    display:flex;align-items:center;justify-content:center;
    border-radius:5px;background:#070d12f4;border-color:#b49b6566;
  }
  .controls .action-btn span{font-size:13px;letter-spacing:0;line-height:1.12;overflow-wrap:anywhere}
  .controls .action-btn.hidden{display:none!important}
  .controls #targetBtn:not(.hidden){display:flex}
  .arsenal,#app:has(#upgradeBtn:not(.hidden)) .arsenal{
    position:fixed;left:auto;right:var(--hud-safe-right);transform:none;
    bottom:calc(var(--hud-safe-bottom) + 162px);
    width:min(204px,54vw);max-width:none;display:grid;
    grid-template-columns:repeat(2,minmax(0,1fr));gap:4px;
    overflow:visible;padding:0;z-index:7;
  }
  .arsenal.hidden{display:none!important}
  .arsenal button{min-width:0;min-height:41px;padding:4px 3px;gap:4px;width:100%;justify-content:center}
  .arsenal button span,.arsenal button b{font-size:12px;line-height:1.1}
  .hero-subtitle{
    left:var(--hud-safe-left);top:calc(var(--hud-safe-top) + 182px);right:auto;bottom:auto;
    transform:none;width:min(300px,calc(100vw - 2 * var(--hud-safe-left)));
    max-width:none;padding:7px 10px;border-radius:4px;
    max-height:86px;overflow:hidden;text-align:left;
    background:#071318ee;
  }
  .hero-subtitle b{font-size:10px;margin-bottom:1px}
  .hero-subtitle span{font-size:12px;line-height:1.3}
  .toast{top:34%;max-width:86vw;font-size:12px;padding:7px}
  .wave-banner{top:29%;font-size:14px}
  .fps-overlay{bottom:calc(var(--hud-safe-bottom) + 125px);left:var(--hud-safe-left);font-size:10px;z-index:6}
  .storage-warning{bottom:calc(var(--hud-safe-bottom) + 255px);max-width:90vw;font-size:11px}
  .character-screen .character-preview{height:120px;min-height:0}
  .character-screen .character-showcase>p{font-size:12px;margin:5px 0}
  .character-screen .character-header h2{font-size:26px}
  .character-screen .character-tabs button{font-size:12px}
}
/* Smaller handsets: conserve remaining canvas area. */
@media (orientation:portrait) and (max-width:360px){
  .left-hud{width:calc(100vw - var(--hud-safe-left) - var(--hud-safe-right) - 90px)}
  .objective{width:calc(100vw - var(--hud-safe-left) - var(--hud-safe-right) - 145px)}
  .right-hud{width:130px}
  .joystick{width:90px;height:90px}
  .controls,.controls:has(#buildBtn:not(.hidden)),.controls:has(#upgradeBtn:not(.hidden)),
  .controls:has(#sellBtn:not(.hidden)),.controls:has(#targetBtn:not(.hidden)),
  .arsenal,#app:has(#upgradeBtn:not(.hidden)) .arsenal{width:min(190px,53vw)}
  .controls .action-btn span{font-size:12px}
}
@media (orientation:portrait) and (max-height:600px){
  .hero-subtitle{top:calc(var(--hud-safe-top) + 145px);max-height:65px}
  .controls .action-btn{min-height:40px}
  .arsenal,#app:has(#upgradeBtn:not(.hidden)) .arsenal{bottom:calc(var(--hud-safe-bottom) + 150px)}
  .arsenal button{min-height:38px}
  .joystick{width:90px;height:90px}
}
@media (orientation:portrait) and (max-width:700px){
  .hud-menu-panel{width:min(270px,calc(100vw - var(--hud-safe-left) - var(--hud-safe-right)));min-width:0;max-height:min(56dvh,360px);grid-template-columns:repeat(2,minmax(0,1fr));gap:5px;padding:7px}
  .hud-menu-panel button{min-width:0;min-height:36px;padding:6px 7px;font-size:11px;line-height:1.15;white-space:normal}
  .hud-menu-panel #inventoryBtn{display:flex;align-items:center;justify-content:space-between;gap:3px}
  .hud-menu-panel #inventoryBtn span{margin-left:0;font-size:10px}
  .hud-menu-panel #inventoryBtn kbd{display:none}
  .hud-menu-panel #telemetryBtn{grid-column:1/-1}
}

/* v4.0.0-alpha.4 — touch polish for the in-game menu (alpha 4). */
@media (orientation:portrait){
  .hud-menu summary{touch-action:manipulation;-webkit-tap-highlight-color:transparent}
  .hud-menu-panel{touch-action:manipulation;-webkit-tap-highlight-color:transparent;overscroll-behavior:contain;box-shadow:0 12px 32px #0009}
  .hud-menu-panel button{min-height:48px}
}

/* Phase 6: thumb-sized menu and tower choices with safe-area bounds. */
.hud-menu-panel{max-height:calc(100dvh - 96px - env(safe-area-inset-bottom,0px));overflow-y:auto;overscroll-behavior:contain}
.hud-menu summary:focus-visible,.arsenal button:focus-visible,.controls button:focus-visible{outline:2px solid #f0d69a;outline-offset:3px}
@media(pointer:coarse){
 .hud-menu summary,.header-actions>.icon-btn{min-height:48px;min-width:48px;display:flex;align-items:center;justify-content:center}
 .hud-menu-panel button,.arsenal button,.controls .action-btn{min-height:48px;touch-action:manipulation}
 .joystick{border:2px solid #d5b679aa;box-shadow:0 3px 18px #0007,inset 0 0 18px #d5b67918}
}
@media(pointer:coarse) and (orientation:landscape) and (max-height:500px){
 .hud-menu-panel{width:min(340px,70vw);grid-template-columns:repeat(2,minmax(0,1fr));max-height:calc(100dvh - 78px - env(safe-area-inset-bottom,0px))}
 .joystick{bottom:max(14px,env(safe-area-inset-bottom,0px));left:max(14px,env(safe-area-inset-left,0px))}
}

/* Wide screens: keep wave composition readable without covering the map. */
@media (min-width:900px) and (orientation:landscape){
 .objective{width:min(420px,calc(100vw - 620px));padding:8px 14px}
 .objective #wavePreview{font-size:11px;line-height:1.4;letter-spacing:.03em}
 .objective #nextWaveBtn{min-height:44px}
 .boss-hud{top:155px;width:min(340px,calc(100vw - 660px))}
}

/* V4.1 touch patch: build controls stay in place and dim instead of hiding. */
.arsenal button:disabled{opacity:.5;filter:saturate(.5)}
.controls .action-btn:disabled{opacity:.55;background:#0c1920a0}

/* V5 graphics pass: compact portrait HUD with readable label sizes. */
@media (orientation:portrait) and (max-width:700px){
  .topbar{height:46px;padding:6px 10px}
  .brand strong{font-size:13px;letter-spacing:.04em}
  .header-actions .icon-btn,.hud-menu summary{min-height:38px;font-size:11px;padding:5px 8px}
  .left-hud{padding:5px 8px;gap:1px 8px}
  .left-hud .hud-label,.left-hud .hud-label b{font-size:13px}
  .left-hud .meter{height:4px;margin-top:1px}
  .objective{padding:5px 8px}
  .objective>span{font-size:14px}
  .objective small{font-size:12px}
  .objective #wavePreview{font-size:11px}
  .right-hud .resource{padding:4px 6px}
  .right-hud .resource small{font-size:12px}
  .right-hud .resource b{font-size:15px}
  .boss-hud{padding:5px}
  .boss-hud>div:first-child{font-size:12px}
  .arsenal button span,.arsenal button b{font-size:13px}
  .controls .action-btn span{font-size:14px}
  .hud-menu-panel button{font-size:12px}
}
@media (orientation:portrait) and (max-width:700px) and (pointer:coarse){
  .controls .move-hint{display:none}
}
