/* FormyDog v50 · small-screen professional layout
   Keeps the board touch-safe and brings boosters back into the game flow. */

@media (max-width:520px){
  html,body{
    width:100%!important;
    min-height:100%!important;
    overflow-x:hidden!important;
    background:#062b57!important;
  }

  body{overflow-y:auto!important}

  html body .app{
    width:100%!important;
    min-height:auto!important;
    height:auto!important;
    padding:4px 4px max(8px,env(safe-area-inset-bottom))!important;
    gap:4px!important;
    overflow:visible!important;
    background:
      radial-gradient(circle at 50% 22%,rgba(55,166,226,.26),transparent 34%),
      linear-gradient(180deg,#0b5794 0%,#073a70 46%,#062b57 100%)!important;
  }

  /* Header: clearer hierarchy and all three resources always visible. */
  html body .app>.topbar{
    width:100%!important;
    height:84px!important;
    min-height:84px!important;
    padding:4px 6px!important;
    grid-template-columns:minmax(0,1fr) 62px!important;
    grid-template-rows:27px 25px 22px!important;
    gap:3px 5px!important;
    border-radius:14px!important;
    overflow:hidden!important;
    box-shadow:0 3px 0 rgba(4,69,131,.9),0 9px 22px rgba(2,25,55,.18)!important;
  }

  html body .app>.topbar .brand{height:27px!important;gap:6px!important}
  html body .app>.topbar .brand-avatar{
    width:27px!important;height:27px!important;min-width:27px!important;flex-basis:27px!important;border-radius:8px!important
  }
  html body .app>.topbar .brand-avatar img{width:25px!important;height:25px!important}
  html body .app>.topbar .brand h1{max-width:132px!important;font-size:10px!important;letter-spacing:.09em!important}
  html body .app>.topbar .brand p{display:none!important}

  html body .app>.topbar #fdLevelChip,
  html body .app>.topbar .fd-level-chip{
    width:62px!important;min-width:62px!important;height:27px!important;min-height:27px!important;
    padding:2px 4px!important;border-radius:9px!important;
    grid-template-rows:14px 8px!important;
    background:rgba(255,255,255,.91)!important;
    border-color:rgba(84,187,236,.42)!important;
  }
  html body .app>.topbar .fd-level-chip span{font-size:4.7px!important}
  html body .app>.topbar .fd-level-chip b{font-size:12px!important}
  html body .app>.topbar .fd-level-chip small{font-size:4.5px!important}

  html body .app>.topbar .resources{
    display:grid!important;
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
    width:100%!important;height:25px!important;gap:4px!important;
  }
  html body .app>.topbar .resources>.resource{
    display:grid!important;
    visibility:visible!important;
    opacity:1!important;
    width:100%!important;min-width:0!important;height:25px!important;min-height:25px!important;
    grid-template-columns:18px minmax(0,1fr)!important;
    padding:2px 5px!important;gap:3px!important;border-radius:8px!important;
    background:rgba(255,255,255,.94)!important;
    border:1px solid rgba(91,190,234,.28)!important;
    box-shadow:0 2px 6px rgba(12,66,104,.07)!important;
  }
  html body .app>.topbar .resources>.resource:nth-child(1){background:linear-gradient(180deg,#fffaf0,#fff4d7)!important}
  html body .app>.topbar .resources>.resource:nth-child(2){background:linear-gradient(180deg,#f5fbff,#eaf7ff)!important}
  html body .app>.topbar .resources>.resource:nth-child(3){background:linear-gradient(180deg,#fff7f8,#ffebef)!important}
  html body .app>.topbar .resource img{width:17px!important;height:17px!important;max-width:17px!important;max-height:17px!important}
  html body .app>.topbar .resource b{
    display:block!important;visibility:visible!important;opacity:1!important;
    font-size:9px!important;font-weight:1000!important;color:#0758ad!important;line-height:1!important;
  }
  html body .app>.topbar .resource span{display:none!important}

  html body .app>.topbar .fd-header-tools{
    height:22px!important;grid-template-columns:repeat(4,30px)!important;gap:6px!important
  }
  html body .app>.topbar .fd-header-tools button{
    width:30px!important;min-width:30px!important;height:22px!important;min-height:22px!important;border-radius:8px!important
  }

  /* Main content stays packed; no artificial empty lower half. */
  html body .app>.game-layout{
    width:100%!important;
    height:auto!important;min-height:0!important;
    display:grid!important;
    grid-template-columns:1fr!important;
    grid-template-rows:auto auto auto auto!important;
    gap:4px!important;
    align-content:start!important;
    overflow:visible!important;
  }

  html body .app>.game-layout>.goals{
    grid-row:1!important;
    width:100%!important;height:48px!important;min-height:48px!important;
    padding:4px 5px!important;
    grid-template-columns:minmax(0,1fr) 70px!important;
    gap:4px!important;border-radius:12px!important;
    box-shadow:0 3px 0 rgba(4,69,131,.75),0 8px 18px rgba(2,30,59,.13)!important;
  }
  html body .app>.game-layout>.goals .goal-box{
    height:40px!important;min-height:40px!important;
    grid-template-columns:28px minmax(0,1fr)!important;
    gap:5px!important;padding:3px 7px!important;border-radius:9px!important;
  }
  html body .app>.game-layout>.goals .goal-box img{width:25px!important;height:25px!important}
  html body .app>.game-layout>.goals .goal-box strong{font-size:14px!important}
  html body .app>.game-layout>.goals .goal-box span{font-size:6px!important;color:#6a8296!important}
  html body .app>.game-layout>.goals .moves-box{
    width:70px!important;height:40px!important;min-height:40px!important;padding:3px!important;border-radius:9px!important
  }
  html body .app>.game-layout>.goals .moves-box span{font-size:5px!important}
  html body .app>.game-layout>.goals .moves-box strong{font-size:15px!important}

  html body .app>.game-layout>.center{
    grid-row:2!important;
    width:100%!important;gap:3px!important;margin:0!important;padding:0!important;
  }

  html body .app>.game-layout>.center .board-shell{
    width:min(calc(100vw - 8px),430px)!important;
    max-width:100%!important;
    height:auto!important;max-height:none!important;
    aspect-ratio:1/1!important;
    margin:0 auto!important;
    padding:5px!important;
    border-radius:18px!important;
    box-shadow:0 5px 0 #06407d,0 14px 30px rgba(0,18,48,.27),0 0 26px rgba(79,208,255,.14)!important;
  }
  html body .app>.game-layout>.center .board-mount{inset:6px!important;border-radius:14px!important}

  html body .app>.game-layout>.center .status{
    display:flex!important;
    width:min(calc(100vw - 14px),420px)!important;
    height:22px!important;min-height:22px!important;max-height:22px!important;
    margin:0 auto!important;padding:3px 7px!important;
    border-radius:9px!important;
    font-size:7px!important;line-height:1!important;
    background:rgba(5,45,95,.92)!important;
    border:1px solid rgba(104,211,255,.32)!important;
    color:#eaf9ff!important;
    overflow:hidden!important;
  }
  html body .app>.game-layout>.center .status-dot{width:6px!important;height:6px!important;flex:0 0 6px!important}

  html body .app>.game-layout>.fd-board-ad{
    grid-row:3!important;
    min-height:18px!important;height:18px!important;
    margin:0 auto!important;padding:3px 10px!important;
    font-size:6px!important;
    background:rgba(245,251,255,.82)!important;
    border-color:rgba(121,204,239,.30)!important;
    color:#5f7890!important;
    box-shadow:0 3px 9px rgba(3,39,75,.08)!important;
  }

  /* Boosters stay in document flow and become sticky only when scrolling. */
  html body .app>.game-layout>.boosters{
    grid-column:1!important;grid-row:4!important;
    position:sticky!important;
    left:auto!important;right:auto!important;
    bottom:max(4px,env(safe-area-inset-bottom))!important;
    z-index:1800!important;
    width:100%!important;
    height:62px!important;min-height:62px!important;max-height:62px!important;
    margin:2px 0 0!important;
    padding:5px 4px!important;
    display:grid!important;
    grid-template-columns:repeat(5,minmax(0,1fr))!important;
    grid-template-rows:52px!important;
    gap:3px!important;
    align-items:stretch!important;
    overflow:visible!important;
    border-radius:14px!important;
    background:rgba(247,252,255,.97)!important;
    border:1px solid rgba(100,199,238,.42)!important;
    box-shadow:0 4px 0 rgba(5,70,132,.75),0 12px 24px rgba(1,25,53,.22)!important;
    backdrop-filter:blur(12px)!important;
    -webkit-backdrop-filter:blur(12px)!important;
  }

  html body .app>.game-layout>.boosters::before{
    content:attr(data-fd50-label);
    position:absolute;
    right:8px;top:-16px;
    min-height:14px;
    padding:3px 7px;
    display:flex;align-items:center;
    border-radius:999px;
    background:rgba(5,50,99,.90);
    color:#eaf9ff;
    font:900 5.7px/1 system-ui,sans-serif;
    letter-spacing:.04em;
    box-shadow:0 3px 9px rgba(1,27,54,.18);
    pointer-events:none;
    white-space:nowrap;
  }
  html body .app>.game-layout>.boosters[data-fd50-state="ready"]::before{background:rgba(15,126,89,.92)!important}
  html body .app>.game-layout>.boosters[data-fd50-state="selected"]::before{background:rgba(7,105,199,.96)!important}
  html body .app>.game-layout>.boosters[data-fd50-state="busy"]::before{background:rgba(184,119,15,.94)!important}
  html body .app>.game-layout>.boosters[data-fd50-state="offline"]::before{background:rgba(174,57,69,.94)!important}

  html body .app>.game-layout>.boosters>.side-title,
  html body .app>.game-layout>.boosters>.fd47-booster-health,
  html body .app>.game-layout>.boosters>.fd47-power-preview{display:none!important}

  html body .app>.game-layout>.boosters .booster,
  html body .app>.game-layout>.boosters .mini-btn{
    width:100%!important;min-width:0!important;
    height:52px!important;min-height:52px!important;max-height:52px!important;
    margin:0!important;padding:3px!important;
    border-radius:10px!important;
    overflow:hidden!important;
    border:1px solid rgba(83,180,224,.30)!important;
    box-shadow:0 2px 0 rgba(93,160,194,.34),inset 0 1px rgba(255,255,255,.96)!important;
  }

  html body .app>.game-layout>.boosters .booster{
    position:relative!important;
    display:grid!important;
    grid-template-columns:1fr!important;
    grid-template-rows:32px 11px!important;
    place-items:center!important;
    background:linear-gradient(180deg,#fff,#eaf8ff)!important;
    transition:transform .14s ease,box-shadow .14s ease,filter .14s ease!important;
  }
  html body .app>.game-layout>.boosters .booster:not(:disabled):active{transform:scale(.96)!important}
  html body .app>.game-layout>.boosters .booster img{
    grid-row:1!important;
    width:29px!important;height:29px!important;max-width:29px!important;max-height:29px!important;
    margin:0!important;
    filter:drop-shadow(0 3px 5px rgba(16,75,113,.18)) saturate(1.08)!important;
  }
  html body .app>.game-layout>.boosters .booster>span{
    grid-row:2!important;display:block!important;min-width:0!important;max-width:100%!important;line-height:1!important
  }
  html body .app>.game-layout>.boosters .booster>span b{
    display:block!important;
    max-width:100%!important;
    font-size:6px!important;line-height:1!important;
    color:#0759ad!important;
    white-space:nowrap!important;overflow:hidden!important;text-overflow:ellipsis!important;
  }
  html body .app>.game-layout>.boosters .booster>span small{display:none!important}
  html body .app>.game-layout>.boosters .booster em{
    position:absolute!important;right:3px!important;top:3px!important;
    min-width:15px!important;height:15px!important;padding:0 3px!important;
    display:grid!important;place-items:center!important;
    border-radius:999px!important;
    background:#fff!important;color:#0759ad!important;
    font-size:6.5px!important;line-height:1!important;
    box-shadow:0 2px 6px rgba(5,71,122,.16)!important;
  }

  html body .app>.game-layout>.boosters .booster[data-fd50-connected="1"]::after{
    content:"";
    position:absolute;left:5px;top:5px;
    width:6px;height:6px;border-radius:50%;
    background:#24c77a;
    box-shadow:0 0 0 2px rgba(36,199,122,.12),0 0 7px rgba(36,199,122,.48);
    pointer-events:none;
  }
  html body .app>.game-layout>.boosters .booster.active{
    transform:translateY(-2px)!important;
    background:linear-gradient(180deg,#f4fdff,#cdefff)!important;
    border-color:rgba(16,137,212,.62)!important;
    box-shadow:0 0 0 2px rgba(46,184,241,.16),0 6px 15px rgba(5,92,156,.20),inset 0 1px #fff!important;
  }
  html body .app>.game-layout>.boosters .booster.active img{transform:scale(1.08)!important}
  html body .app>.game-layout>.boosters .booster:disabled{opacity:.48!important;filter:saturate(.55)!important}

  html body .app>.game-layout>.boosters .mini-btn{
    display:grid!important;place-items:center!important;
    font-size:6px!important;line-height:1.05!important;font-weight:1000!important;
    white-space:normal!important;
    background:linear-gradient(180deg,#f9fdff,#eaf6ff)!important;
  }
  html body .app>.game-layout>.boosters .store{
    background:linear-gradient(180deg,#2c94ed,#0758b6)!important;
    color:#fff!important;border-color:#0a62bd!important;
  }

  /* Input ownership remains Phaser-only. */
  html body .board-shell::before,
  html body .board-shell::after,
  html body .board-mount::before,
  html body .board-mount::after,
  html body .fd47-ambient,
  html body .fd47-light,
  html body .fd47-scene-decor,
  html body .fd47-flash{pointer-events:none!important}

  html body #gameMount,
  html body #gameMount canvas{
    pointer-events:auto!important;
    touch-action:none!important;
    -webkit-user-select:none!important;
    user-select:none!important;
  }
}

@media (max-width:390px) and (max-height:780px){
  html body .app>.topbar{height:80px!important;min-height:80px!important;grid-template-rows:26px 24px 20px!important}
  html body .app>.topbar .resources{height:24px!important}
  html body .app>.topbar .resources>.resource{height:24px!important;min-height:24px!important}
  html body .app>.topbar .fd-header-tools{height:20px!important}
  html body .app>.game-layout>.goals{height:46px!important;min-height:46px!important}
  html body .app>.game-layout>.goals .goal-box,
  html body .app>.game-layout>.goals .moves-box{height:38px!important;min-height:38px!important}
  html body .app>.game-layout>.center .status{height:20px!important;min-height:20px!important;max-height:20px!important}
  html body .app>.game-layout>.boosters{height:58px!important;min-height:58px!important;max-height:58px!important;grid-template-rows:48px!important}
  html body .app>.game-layout>.boosters .booster,
  html body .app>.game-layout>.boosters .mini-btn{height:48px!important;min-height:48px!important;max-height:48px!important}
  html body .app>.game-layout>.boosters .booster img{width:26px!important;height:26px!important;max-width:26px!important;max-height:26px!important}
  html body .app>.game-layout>.boosters .booster>span b{font-size:5.4px!important}
  html body .app>.game-layout>.boosters .mini-btn{font-size:5.4px!important}
}

@media (max-width:340px){
  html body .app>.topbar .brand h1{max-width:94px!important;font-size:9px!important}
  html body .app>.topbar .fd-header-tools{grid-template-columns:repeat(4,28px)!important;gap:5px!important}
  html body .app>.topbar .fd-header-tools button{width:28px!important;min-width:28px!important}
  html body .app>.game-layout>.boosters{gap:2px!important;padding-inline:3px!important}
  html body .app>.game-layout>.boosters .booster>span b,
  html body .app>.game-layout>.boosters .mini-btn{font-size:5px!important}
}
