/* V3 viewport fit layer: keep the wasteland skin, remove page-level scrolling. */

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

body {
  min-height: 100dvh;
}

.app-shell {
  width: 100%;
  height: 100dvh;
  min-height: 0;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  gap: clamp(10px, 1.5vw, 22px);
  overflow: hidden;
  grid-template-columns: minmax(288px, 30vw) minmax(0, 1fr);
}

.control-panel,
.game-panel,
.stage-shell {
  min-height: 0;
}

.control-panel {
  height: 100%;
  overflow: hidden;
}

.game-panel {
  height: 100%;
  min-height: 0;
  padding: 0;
}

.stage-shell {
  width: 100%;
  height: 100%;
}

/* 进入现场后，行动台只保留身份条，避免菜单内容挤压地图或产生隐藏溢出。 */
body.in-run #panelBody {
  display: none;
}

@media (min-width: 981px) and (max-height: 960px) {
  .control-panel {
    padding: 16px 20px 12px;
  }

  .brand-block {
    padding: 24px 0 16px;
  }

  .brand-block h1 {
    margin: 10px 0 10px;
    font-size: clamp(3.2rem, 6vh, 4.6rem);
  }

  .brand-block p {
    line-height: 1.45;
  }

  .home-title {
    padding-top: 10px;
  }

  .home-title h2 {
    margin-bottom: 8px;
    font-size: 30px;
  }

  .home-title p {
    line-height: 1.45;
  }

  .panel-rule {
    margin: 12px 0;
  }

  .section-label {
    margin: 8px 0 6px;
  }

  .level-label {
    margin-top: 12px;
  }

  .level-grid {
    max-height: 180px;
  }

  .home-links {
    margin-top: 12px;
  }

  .version-stamp {
    margin-top: 12px;
  }
}

@media (min-width: 981px) and (max-height: 760px) {
  .control-panel {
    padding: 10px 18px 8px;
  }

  .brand-block {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: none;
    padding: 8px 0;
  }

  .brand-topline {
    display: none;
  }

  .brand-block h1 {
    flex: 0 0 auto;
    margin: 0;
    font-size: clamp(2.2rem, 6vh, 3rem);
    line-height: .85;
    white-space: nowrap;
  }

  .brand-block h1 br {
    display: none;
  }

  .brand-block p {
    max-width: 155px;
    font-size: 10px;
    line-height: 1.35;
  }

  .home-title {
    padding-top: 6px;
  }

  .home-title h2 {
    margin-bottom: 5px;
    font-size: 26px;
  }

  .home-title p {
    font-size: 10px;
    line-height: 1.35;
  }

  .panel-rule {
    margin: 7px 0;
  }

  .section-label {
    margin: 5px 0 4px;
  }

  .continue-card {
    padding: 7px 9px;
  }

  .level-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    max-height: none;
  }

  .level-card {
    min-height: 38px;
    padding: 5px 4px;
  }

  .level-card strong {
    margin: 3px 0;
    font-size: 8px;
  }

  .level-card span,
  .level-card small {
    font-size: 7px;
  }

  .home-links {
    gap: 12px;
    margin-top: 7px;
  }

  .version-stamp {
    margin-top: 7px;
  }

  .level-label,
  .home-links {
    margin-top: 10px;
  }

  .version-stamp {
    margin-top: 10px;
  }
}

@media (max-width: 980px) {
  .app-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .control-panel {
    width: 100%;
    height: clamp(112px, 22dvh, 188px);
    min-height: 0;
    padding: 10px 14px 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .console-head {
    height: 20px;
  }

  .brand-block {
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: none;
    padding: 8px 0 5px;
  }

  .brand-topline,
  .brand-block p,
  #panelBody .panel-kicker,
  #panelBody .section-label,
  #panelBody .home-links,
  #panelBody .version-stamp {
    display: none;
  }

  .brand-block h1 {
    flex: 0 0 auto;
    margin: 0;
    font-size: clamp(1.8rem, 7vw, 2.8rem);
    line-height: .9;
    white-space: nowrap;
  }

  .brand-block h1 br {
    display: none;
  }

  #panelBody {
    min-width: 0;
  }

  #panelBody .continue-card {
    min-height: 48px;
    padding: 8px 10px;
  }

  #panelBody .continue-card small {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .game-panel {
    min-height: 0;
    padding: 0;
  }

  .stage-shell {
    min-height: 0;
  }

  body.in-run .app-shell {
    grid-template-rows: auto minmax(0, 1fr);
  }

  body.in-run .control-panel {
    height: 42px;
    padding: 8px 14px;
  }

  body.in-run .brand-block,
  body.in-run #panelBody {
    display: none;
  }

  /* 方向盘属于运行态控件，简报/主菜单阶段不应提前占用舞台或接收误触。 */
  .dpad {
    display: none;
  }

  body.in-run .dpad {
    display: grid;
  }
}

@media (max-width: 560px) {
  .app-shell {
    gap: 8px;
  }

  .control-panel {
    height: clamp(104px, 21dvh, 162px);
    padding: 8px 11px 6px;
  }

  .console-head {
    gap: 6px;
    height: 18px;
    font-size: 8px;
  }

  .brand-block {
    gap: 10px;
    padding: 6px 0 3px;
  }

  .brand-block h1 {
    font-size: clamp(1.85rem, 9vw, 2.7rem);
  }

  #panelBody .continue-card {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 6px;
    min-height: 42px;
    padding: 6px 8px;
  }

  #panelBody .continue-card strong {
    font-size: 11px;
  }

  #panelBody .continue-card small,
  #panelBody .continue-card b {
    font-size: 8px;
  }

  body.in-run .control-panel {
    height: 38px;
    padding: 7px 11px;
  }

  .stage-caption {
    top: 9px;
  }

  .overlay {
    padding: 10px;
  }

  .overlay-card {
    max-height: calc(100% - 20px);
    overflow: hidden;
    padding: 24px 17px 16px;
  }

  .overlay-card h2 {
    margin-bottom: 12px;
    font-size: clamp(28px, 8vw, 34px);
  }

  .brief-story {
    margin-bottom: 10px;
    line-height: 1.5;
  }

  .brief-pace {
    padding: 8px;
    gap: 5px;
  }
}

@media (max-width: 980px) and (max-height: 720px) {
  .app-shell {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-right: max(8px, env(safe-area-inset-right));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    padding-left: max(8px, env(safe-area-inset-left));
  }

  .control-panel {
    height: clamp(96px, 20dvh, 132px);
    padding: 7px 10px 5px;
  }

  .brand-block {
    padding: 4px 0 2px;
  }

  .brand-block h1 {
    font-size: clamp(1.7rem, 8vw, 2.35rem);
  }

  #panelBody .continue-card {
    min-height: 36px;
    padding: 5px 7px;
  }

  #panelBody .continue-card small {
    display: none;
  }

  body.in-run .control-panel {
    height: 34px;
    padding: 6px 10px;
  }
}

/* Canvas 内部始终按正方形视口绘制；窗口较宽或较高时只留安全留白，不拉伸格子。 */
.stage-shell canvas {
  object-fit: contain;
  object-position: center;
}

/* 废土图集进入 HUD：保留文字信息，同时让工具槽使用规划中的实物图标。 */
.hud-pause {
  background: rgba(23, 18, 14, 0.82) url("./assets/wasteland/generated/slices/ui/ui_btn_pause_default_v02.png") center / 88% 88% no-repeat;
}

.hud-pause span {
  display: none;
}

.hud-tool {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.tool-icon {
  width: 29px;
  height: 29px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  image-rendering: auto;
}

.tool-hotkey {
  position: absolute;
  top: 4px;
  right: 5px;
  min-width: 19px;
  padding: 2px 3px;
  color: var(--ink);
  background: var(--amber);
  font: 700 7px var(--mono);
  line-height: 1;
  letter-spacing: 0;
}

.tool-icon-radar { background-image: url("./assets/wasteland/generated/slices/props/prop_radar_v02.png"); }
.tool-icon-dash { background-image: url("./assets/wasteland/generated/slices/props/prop_dash_module_v02.png"); }
.tool-icon-decoy { background-image: url("./assets/wasteland/generated/slices/props/prop_decoy_paperfish_v02.png"); }
.tool-icon-anchor { background-image: url("./assets/wasteland/generated/slices/props/prop_memory_anchor_v02.png"); }
.tool-icon-sonar { background-image: url("./assets/wasteland/generated/slices/props/prop_sonar_beacon_v02.png"); }
.tool-icon-empty { background-image: url("./assets/wasteland/generated/slices/ui/ui_icon_cancel_v02.png"); opacity: 0.5; }

.tool-label {
  color: inherit;
  font: inherit;
  line-height: 1;
}

.tool-status {
  min-height: 8px;
  color: var(--muted);
  font: 7px var(--mono);
  line-height: 1;
  letter-spacing: .02em;
}

.tool-status.is-cooling {
  color: var(--rust);
}

.hud-tool.is-cooling {
  border-color: rgba(199, 94, 63, .55);
}

/* 运行态的持续字幕改为 toast 瞬时提示，地图底部不再被一块半透明条遮住。 */
body.in-run #subtitleHud {
  display: none;
}
