/* VK Mini Apps WebView: overrides for the existing v0.3.5 game UI. */
:root{
  --vk-safe-top: env(safe-area-inset-top, 0px);
  --vk-safe-right: env(safe-area-inset-right, 0px);
  --vk-safe-bottom: env(safe-area-inset-bottom, 0px);
  --vk-safe-left: env(safe-area-inset-left, 0px);
}
html,body,#app{width:100%;min-width:0;max-width:100%}
body{overflow-x:clip}
button,select,input{touch-action:manipulation}
.game-header{
  padding-top:max(11px,var(--vk-safe-top));
  padding-left:max(14px,var(--vk-safe-left));
  padding-right:max(14px,var(--vk-safe-right));
}
.game-layout,.map-side,.sidebar,.panel{min-width:0}
.game-root{min-height:100vh;min-height:100dvh}
.sidebar{max-height:calc(100vh - 66px);max-height:calc(100dvh - 66px)}
.event-overlay,.guide-overlay{
  padding-top:max(12px,var(--vk-safe-top));
  padding-right:max(12px,var(--vk-safe-right));
  padding-bottom:max(12px,var(--vk-safe-bottom));
  padding-left:max(12px,var(--vk-safe-left));
}
.event-modal,.guide-modal{max-height:calc(100vh - 24px);max-height:calc(100dvh - 24px)}
.event-modal,.guide-body,.sidebar{overscroll-behavior:contain}
@media(max-width:1023px) and (min-width:768px){
  .game-layout{grid-template-columns:minmax(0,1fr) minmax(290px,38%)}
  .game-header{flex-wrap:wrap;gap:8px}
  .sidebar{max-height:calc(100dvh - 100px)}
}
@media(max-width:767px){
  .game-header{flex-wrap:wrap;gap:8px;padding-block:10px}
  .game-title{font-size:16px}
  .game-title small{font-size:9px}
  .header-status{width:100%;gap:6px;font-size:12px}
  .header-status button{min-height:44px;padding:8px 10px}
  .head-pill{padding:7px 9px}
  .game-layout{display:flex;flex-direction:column;flex:1;min-height:0}
  .map-side{flex:0 0 auto;width:100%}
  .map-viewport{flex:0 0 auto;height:clamp(235px,39dvh,420px);min-height:235px}
  .map-topbar{top:7px;left:7px;right:7px;gap:6px}
  .map-topbar .map-instr{max-width:calc(100% - 88px);padding:7px 9px;font-size:11px;line-height:1.32}
  .map-toolset button{min-width:44px;min-height:44px}
  .sidebar{width:100%;max-height:none;overflow:visible;border-left:0;border-top:1px solid #bcc9cf}
  .panel{padding:12px}
  .player-strip{padding:9px;scrollbar-width:thin}
  .start-shell{padding:12px 12px max(20px,var(--vk-safe-bottom))}
  .start-shell .hero-banner{padding:16px}
  .start-shell .setup{padding:14px}
  .hero-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
  .hero-pick{min-height:0}
  .route-end-list{max-height:240px}
  .route-variants{max-height:180px}
  .route-end-list button,.route-variants button,.choice-list button{min-height:44px}
  .event-modal{width:100%;max-height:calc(100dvh - 24px);padding:14px}
  .guide-modal{width:100%;max-height:calc(100dvh - 24px)}
  .guide-body{padding:12px}
  .guide-head{padding:12px}
  .guide-exit{min-width:44px;min-height:44px}
  .guide-grid{grid-template-columns:minmax(0,1fr)}
  .result-shell{padding:14px 12px max(32px,var(--vk-safe-bottom))}
  .result-shell h1{font-size:25px}
}
@media(max-width:420px){
  .map-viewport{height:clamp(225px,36dvh,340px);min-height:225px}
  .event-modal .event-body{flex-direction:column}
  .event-modal img{width:min(38vw,132px);max-height:190px}
  .route-end-list{grid-template-columns:repeat(2,minmax(0,1fr))}
  .welcome-copy{padding:18px}
  .welcome-copy h1{font-size:28px}
  .welcome-art-caption{font-size:14px}
}
@media(max-height:570px) and (min-width:768px){
  .sidebar{max-height:calc(100dvh - 88px)}
  .map-viewport{min-height:300px}
}


/* VK controls iframe height and may suppress scrolling of the outer document.
   Keep the game scrollable *inside* its own viewport, also in preview iframes. */
html.app-embedded,
html.app-embedded body {
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}
html.app-embedded #app {
  height: 100vh;
  height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scroll-padding-bottom: 32px;
}
html.app-embedded .start-shell {
  padding-bottom: max(40px, var(--vk-safe-bottom));
}
@media (min-width: 768px) {
  html.app-embedded #app {
    scrollbar-gutter: stable;
  }
}


/* Mobile map: maximize visible playfield and keep controls reachable. */
@media (max-width: 767px) {
  /* The descriptive panel overlaps the playfield in portrait orientation.
     Rules and reward counts remain available in the game UI. */
  .map-topbar .map-instr {
    display: none;
  }
  .map-topbar {
    justify-content: flex-end;
  }
  /* Leave enough viewport below the map to reveal the game controls. */
  .map-viewport {
    height: clamp(300px, 52dvh, 520px);
    min-height: 300px;
  }
  /* A single row of map actions exposes more of the map than a tall stack. */
  .map-toolset {
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    gap: 5px;
  }
  .map-toolset button {
    min-width: 44px;
    min-height: 44px;
  }
  .map-toolset .tool-long {
    width: auto;
    min-width: 70px;
    padding-inline: 6px;
    font-size: 12px;
  }
}
