/* Responsive lobby and a multi-touch combat deck. Desktop bindings stay available. */
#combatControls { display: contents; }
#touchControls { display: none; }
#app { height: var(--app-height, 100dvh); }
button { -webkit-tap-highlight-color: transparent; }

@media (max-width: 900px), (pointer: coarse) {
  html, body { width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
  #app { width: 100%; }
  #lobby {
    padding: calc(62px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
    touch-action: pan-y; -webkit-overflow-scrolling: touch;
  }
  #lobby header { flex: none; margin-bottom: 14px; min-width: 0; }
  #lobby h1 { font-size: clamp(25px, 7.6vw, 44px); overflow-wrap: anywhere; text-shadow: 2px 2px 0 var(--brown); }
  #lobby header p { font-size: 12px; }
  #lobby main { display: flex; flex: none; flex-direction: column; gap: 14px; width: 100%; min-width: 0; }
  #lobby .panel { flex: none; width: 100%; min-width: 0; overflow: visible; padding: 12px; }
  #lobby .panel.you { min-height: 0; padding: 0; cursor: default; }
  #lobby .panel.chars { display: block; }
  #lobby .panel.side-info { display: flex; min-height: 360px; }
  #app[data-screen="lobby"] #stage { display: none; }
  .preview-hint { display: none; }
  .namebox { gap: 6px; padding: 6px 8px; }
  .namebox button { min-width: 40px; min-height: 40px; }
  .namebox input, #chatForm input, input[type="text"] { font-size: 16px; }
  .name-hint { font-size: 11px; }
  #charList { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; height: auto; min-height: auto; overflow: visible; padding: 0; }
  .char { min-width: 0; padding: 10px 8px; touch-action: pan-y; }
  .char h3 { font-size: 19px; letter-spacing: 0; }
  .char .desc { min-height: 0; font-size: 11px; line-height: 1.35; overflow-wrap: anywhere; }
  .char .stat { grid-template-columns: 1fr; gap: 2px; margin: 5px 0; font-size: 10px; }
  .char .stat div { height: 5px; }
  .char .meta { font-size: 10px; overflow-wrap: anywhere; }
  .actions { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 12px; }
  .actions button { min-height: 46px; }
  #lobbyStatus { min-height: 0; font-size: 12px; }
  #playerList li { flex-wrap: wrap; }
  #playerList small { white-space: normal; }
  #lobbyChat { min-height: 250px; }
  #chatMessages { flex: none; height: 180px; }
  #chatForm button { min-height: 44px; }
  #settings, #app[data-screen="fight"] #settings {
    top: calc(8px + env(safe-area-inset-top, 0px)); right: calc(60px + env(safe-area-inset-right, 0px)); bottom: auto; gap: 4px;
  }
  #settings button { min-width: 40px; min-height: 40px; }
  #settings input { width: 64px; height: 30px; }
  #gamepadStatus { max-width: 18px; white-space: nowrap; overflow: hidden; }
  #helpBtn { top: calc(8px + env(safe-area-inset-top, 0px)); right: calc(10px + env(safe-area-inset-right, 0px)); width: 40px; height: 40px; }
  #controlsDialog { max-height: calc(var(--app-height, 100dvh) - 24px); padding: 16px; }
  .dialog-header { position: sticky; top: -16px; z-index: 2; padding: 10px 0; background: #211a29; }
  #closeHelpBtn { min-width: 44px; min-height: 44px; }
  #controlsDialog .controls { font-size: 12px; gap: 6px; }
  #controlsDialog .controls dt { white-space: normal; }
  .touch-help { font-size: 14px; line-height: 1.5; }

  /* Map, floor, fighters and floating labels share one viewport above the controls. */
  #app[data-screen="fight"] #stage,
  #app[data-screen="fight"] #map,
  #app[data-screen="fight"] #floats { height: calc(100% - var(--combat-height, 216px)); }
  #app[data-screen="fight"] #settings { top: auto; bottom: calc(5px + env(safe-area-inset-bottom, 0px)); right: calc(8px + env(safe-area-inset-right, 0px)); }
  #app[data-screen="fight"] #settings input { display: none; }
  #app[data-screen="fight"] #settings button { min-width: 36px; min-height: 36px; }
  #app[data-screen="fight"] #helpBtn { top: auto; bottom: calc(7px + env(safe-area-inset-bottom, 0px)); right: calc(111px + env(safe-area-inset-right, 0px)); width: 36px; height: 36px; }
  .hud-top { top: max(8px, env(safe-area-inset-top, 0px)); left: max(8px, env(safe-area-inset-left, 0px)); right: max(8px, env(safe-area-inset-right, 0px)); grid-template-columns: minmax(0, 1fr) 48px minmax(0, 1fr); gap: 6px; }
  .side { min-width: 0; }
  .nameplate { gap: 4px; min-width: 0; }
  .nameplate .name { min-width: 0; font: 14px var(--display); letter-spacing: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .pips { gap: 3px; flex: none; }
  .pips i { width: 8px; height: 8px; border-width: 1px; }
  .bar { height: 16px; }
  .bar.stomach { height: 12px; width: 100%; }
  .bar.stomach span { font-size: 8px; line-height: 10px; }
  .clock { min-width: 0; }
  #timer { font-size: 30px; }
  .clock small { font-size: 9px; letter-spacing: 0; }
  #announcer { top: 19%; }
  #announcer .big { font-size: clamp(36px, 10vw, 72px); -webkit-text-stroke-width: 1px; }
  #announcer .sub { font-size: 18px; padding: 0 12px; }
  #gamepadFightHint { display: none; }
  #combatControls {
    position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; gap: 7px;
    padding: 9px max(8px, env(safe-area-inset-right, 0px)) calc(49px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
    background: #19131ff5; border-top: 1px solid var(--line); pointer-events: auto;
  }
  #touchControls { display: flex; gap: 8px; justify-content: space-between; touch-action: none; }
  #touchControls button { flex: 1; min-width: 44px; min-height: 48px; padding: 2px 5px; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
  #touchControls span { display: block; font-size: 22px; line-height: 24px; }
  #touchControls small { display: block; font-size: 10px; line-height: 14px; text-transform: capitalize; }
  #touchControls .pressed { color: #17210a; background: var(--toxic); border-color: var(--toxic); }
  #skillbar { position: static; transform: none; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; touch-action: none; }
  #skillbar .group, #skillbar .group.extra { display: contents; }
  .skill { width: 100%; min-width: 44px; height: 48px; min-height: 44px; aspect-ratio: auto; border-radius: 8px; }
  .extra .skill { border-color: var(--mustard); }
  .skill .icon { font-size: 25px; padding-bottom: 10px; }
  .skill .key { display: none; }
  .skill .label { position: absolute; display: block; bottom: 1px; left: 2px; right: 2px; font: 9px/11px var(--body); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .skill .cost, .gamepad .skill .cost { top: 0; bottom: auto; right: 2px; font-size: 9px; }
  #leaveBtn, #leaveBtn.armed { left: max(8px, env(safe-area-inset-left, 0px)); bottom: calc(5px + env(safe-area-inset-bottom, 0px)); max-width: calc(100% - 170px); min-height: 38px; font-size: 11px; opacity: 1; }
  #tooltip { max-width: calc(100vw - 20px); pointer-events: none; }
  .overhead .bubble { width: 30px; height: 30px; font-size: 20px; border-width: 2px; }
  .overhead .status { font-size: 15px; }
  .float { font-size: 21px; }
}

@media (max-width: 900px) and (orientation: landscape), (pointer: coarse) and (orientation: landscape) {
  #lobby h1 { font-size: 34px; }
  #charList { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #combatControls { flex-direction: row; align-items: center; gap: 10px; }
  #touchControls { flex: 0 0 144px; display: grid; grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(2, 44px); gap: 3px; }
  #touchControls button { width: 44px; min-height: 44px; padding: 0; }
  #touchControls [data-direction="up"] { grid-column: 2; grid-row: 1; }
  #touchControls [data-direction="left"] { grid-column: 1; grid-row: 2; }
  #touchControls [data-direction="down"] { grid-column: 2; grid-row: 2; }
  #touchControls [data-direction="right"] { grid-column: 3; grid-row: 2; }
  #touchControls small { font-size: 8px; }
  #touchControls span { font-size: 19px; line-height: 21px; }
  #skillbar { flex: 1; grid-template-columns: repeat(auto-fit, minmax(44px, 1fr)); }
  .skill { height: 44px; }
}
