/* Phones. The same page and the same elements as the desk layout in debug.css, rearranged:
   the map takes the screen, the treasury becomes a slim strip on top, and the radio log,
   squads, build buttons and settings open as sheets from a bar at the bottom whose middle
   is the push-to-talk button. Held sideways, the bar stands on the edge under the thumb.
   The breakpoint is repeated in mobile.js (PHONE). Tablets and desks keep the sidebar. */

#dock { display: none; }

/* The server went away: said once, plainly, on every layout. */
#no-server { display: none; }
body.no-server #no-server {
  display: block; position: fixed; z-index: 12; inset-block-start: calc(env(safe-area-inset-top, 0px) + 3.6rem); left: 50%; transform: translateX(-50%);
  margin: 0; padding: .45rem .9rem; max-inline-size: 92vw; text-align: center;
  color: #1a1405; background: var(--warn); border: 1px solid #ffd9a8; font-weight: 600;
}

/* The microphone is not available on this address (see voice.insecure). */
#ptt.no-voice { filter: grayscale(1); opacity: .6; }

@media (max-width: 700px), (max-height: 500px), (pointer: coarse) and (max-width: 1100px) {
  :root {
    --strip: 46px; /* treasury */
    --send: 54px; /* the radio box */
    --tabs: 64px; /* the bar of sheets, with the talk button */
    --tick: 96px; /* the last four lines of the radio log */
    --nets: 40px; /* the two tabs over the open radio sheet */
    --sheet: min(52dvh, calc(100dvh - var(--strip) - var(--send) - var(--tabs) - var(--safe-t) - var(--safe-b)));
    --rail: 0px; /* the bar's width when it stands on the edge (landscape) */
    --kb: 0px; /* height of the on-screen keyboard, set by mobile.js */
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-s: env(safe-area-inset-left, 0px); /* inline start and end; swapped below for Hebrew */
    --safe-e: env(safe-area-inset-right, 0px);
    font-size: 15px;
  }
  [dir="rtl"] { --safe-s: env(safe-area-inset-right, 0px); --safe-e: env(safe-area-inset-left, 0px); }

  html, body { height: 100dvh; }
  body {
    overflow: hidden; overscroll-behavior: none; touch-action: manipulation;
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  }
  input, :is(#log, #squad-log, #team-log) .text { -webkit-user-select: text; user-select: text; }

  /* The desk's boxes dissolve; each part below is placed on the screen by itself. */
  main, #stage, #radio { display: contents; }
  /* The two nets' tabs belong to the open radio sheet; the strip is always the command net. */
  #net-tabs { display: none; }
  html[data-sheet="radio"] #net-tabs {
    display: flex; position: fixed; z-index: 5; inset-inline: 0; margin: 0; gap: 0;
    inset-block-end: calc(var(--send) + var(--tabs) + var(--safe-b) + var(--sheet) - var(--nets));
    block-size: var(--nets); padding-inline: max(.4rem, var(--safe-s)) max(.4rem, var(--safe-e));
    background: var(--panel); border-block-start: 2px solid var(--brass-dim);
  }
  html[data-sheet="radio"] #net-tabs button { flex: 1; font-size: .8rem; }
  html:not([data-sheet="radio"]) :is(#squad-log, #team-log, #team-hint) { display: none; }
  html:not([data-sheet="radio"]) #radio[data-net="squad"] #log { display: flex; }
  /* No room for two nets at once: the panes dissolve like the desk's other boxes, and
     the split, the side panel and their buttons are not offered. */
  .net-pane, .net-pane[hidden] { display: contents; }
  .net-pane > header, #net-tools, #net-side { display: none; }

  #map-wrap {
    position: fixed; inset-inline: 0;
    inset-block: calc(var(--strip) + var(--safe-t)) calc(var(--send) + var(--tabs) + var(--tick) + var(--safe-b));
  }
  #zoom { inset-block-start: .5rem; left: .5rem; }
  #zoom button { inline-size: 44px; block-size: 44px; font-size: 1.2rem; }
  #orders { padding: .6rem; gap: .5rem; }
  #orders button { min-block-size: 48px; min-inline-size: 4.6rem; font-size: 1rem; }

  /* ---- top strip: gold, clock, points, the two headquarters ---- */
  #treasury {
    visibility: visible; position: fixed; z-index: 6; inset: 0 0 auto;
    block-size: calc(var(--strip) + var(--safe-t));
    padding-block: var(--safe-t) 0; padding-inline: max(.6rem, var(--safe-s)) max(.6rem, var(--safe-e));
    display: flex; align-items: center; gap: .85rem; border-inline: 0; border-block-start: 0;
  }
  /* A watcher's side picker: in the strip, as wide as a thumb needs and no wider. */
  #follow-box { flex: 0 1 9.5rem; }
  #follow-box span { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); }
  #follow { min-block-size: 2.2rem; font-size: .8rem; }
  #gold-box { flex-direction: row; align-items: baseline; gap: .3rem; }
  #gold-box > span, #gold-box small span { display: none; } /* the brass number needs no label */
  #gold-box strong { font-size: 1.4rem; }
  #gold-box small { font-size: .72rem; white-space: nowrap; }
  #treasury dl { flex-direction: row; gap: .85rem; }
  #treasury dl div { display: flex; flex-direction: column; line-height: 1.15; }
  dt { font-size: .56rem; white-space: nowrap; }
  dd { font-size: .95rem; }
  .bars { flex: 1; min-inline-size: 3rem; grid-template-columns: 1fr; gap: 5px; }
  .bars span { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); }
  .bar { block-size: .45rem; }

  /* ---- bottom bar ---- */
  #dock {
    display: grid; position: fixed; z-index: 6; inset: auto 0 0;
    block-size: calc(var(--tabs) + var(--safe-b));
    padding-block-end: var(--safe-b); padding-inline: var(--safe-s) var(--safe-e);
    grid-template-columns: 1fr 1fr 76px 1fr 1fr; /* the gap in the middle is the talk button's */
    background: #0e1316; border-block-start: 2px solid var(--brass-dim);
  }
  #dock button {
    clip-path: none; border: 0; border-block-start: 3px solid transparent; background: none; padding: 0 .2rem;
    font-size: .8rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
  }
  #dock button:nth-child(3) { grid-column: 4; }
  #dock button[aria-pressed="true"] { color: var(--brass); border-block-start-color: var(--brass); background: #1a2227; }

  #send {
    position: fixed; z-index: 7; inset-inline: 0; inset-block-end: calc(var(--tabs) + var(--safe-b));
    block-size: var(--send); gap: 6px; align-items: stretch;
    padding-block: 4px; padding-inline: max(6px, var(--safe-s)) max(6px, var(--safe-e));
    background: var(--panel); border-block-start: 1px solid var(--edge-hi);
  }
  #send button { min-inline-size: 46px; }
  #text { font-size: 16px; } /* anything smaller and iOS zooms the page when the box is focused */

  /* The talk button: big, round, under the thumb, clear of every sheet. */
  #ptt {
    position: fixed; z-index: 9; inset-block-end: calc(var(--safe-b) + 1px); left: 50%; transform: translateX(-50%);
    inline-size: 62px; block-size: 62px; padding: 0; border-radius: 50%; clip-path: none; font-size: 1.7rem; line-height: 1;
    background: var(--brass); border: 2px solid #f6d27a; box-shadow: 0 2px 10px #000b;
  }
  #ptt:hover:not(:disabled) { background: var(--brass); }
  #ptt.live { background: var(--warn); transform: translateX(-50%) scale(1.14); box-shadow: 0 0 0 6px #f0a04a55, 0 2px 10px #000b; }

  /* ---- radio log: its last four lines always, the whole of it as a sheet ---- */
  :is(#log, #squad-log, #team-log) {
    position: fixed; z-index: 4; inset-inline: 0; inset-block-end: calc(var(--send) + var(--tabs) + var(--safe-b));
    block-size: var(--tick); flex: none; overflow: hidden; border-inline: 0; font-size: .86rem;
    padding-block: 4px; padding-inline: max(.6rem, var(--safe-s)) max(.6rem, var(--safe-e));
  }
  html:not([data-sheet="radio"]) #log { justify-content: flex-end; gap: 0; }
  /* The page marks which four: radio to the player comes before system lines (cues.js). */
  html:not([data-sheet="radio"]) #log li:not(.strip) { display: none; }
  html:not([data-sheet="radio"]) #log li { block-size: 22px; line-height: 22px; flex: none; }
  html:not([data-sheet="radio"]) #log .text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-inline-size: 0; }
  html:not([data-sheet="radio"]) #log .who { min-inline-size: 0; }
  html[data-sheet="radio"] :is(#log, #squad-log, #team-log) {
    z-index: 5; overflow-y: auto; gap: .35rem;
    block-size: calc(var(--sheet) - var(--nets));
  }
  #voice-status {
    position: fixed; z-index: 8; inset-inline: .5rem; inset-block-end: calc(var(--send) + var(--tabs) + var(--tick) + var(--safe-b) + 6px);
    margin: 0; padding: .45rem .7rem; text-align: center; background: #10161af2; border: 1px solid var(--edge-hi);
  }

  /* ---- sheets: squads, build, more ---- */
  #sidebar {
    position: fixed; z-index: 5; inset-inline: 0; inset-block-end: calc(var(--send) + var(--tabs) + var(--safe-b));
    inline-size: auto; overflow-y: auto; visibility: hidden; overscroll-behavior: contain;
    max-block-size: min(60dvh, calc(100dvh - var(--strip) - var(--send) - var(--tabs) - var(--safe-t) - var(--safe-b)));
    border-inline-start: 0; border-block-start: 2px solid var(--brass-dim);
    padding-inline: max(3px, var(--safe-s)) max(3px, var(--safe-e));
  }
  html[data-sheet="squads"] #sidebar, html[data-sheet="build"] #sidebar, html[data-sheet="more"] #sidebar { visibility: visible; }
  html:not([data-sheet="squads"]) #sidebar > [data-sheet="squads"],
  html:not([data-sheet="build"]) #sidebar > [data-sheet="build"],
  html:not([data-sheet="more"]) #sidebar > [data-sheet="more"] { display: none; }

  #sidebar header { flex-wrap: wrap; }
  #controls button, #roster .tier button { min-block-size: 44px; min-inline-size: 44px; padding-inline: .8rem; font-size: .85rem; }
  #roster li { min-block-size: 52px; padding: .45rem .6rem; }
  #build { grid-template-columns: repeat(auto-fill, minmax(5.6rem, 1fr)); gap: 6px; }
  #build button[data-unit] { min-block-size: 88px; font-size: .8rem; }
  #structures { grid-template-columns: repeat(auto-fill, minmax(5.6rem, 1fr)); gap: 6px; }
  #structures button { min-block-size: 96px; font-size: .78rem; }
  #structure-list li { min-block-size: 32px; }
  #radar-map { max-inline-size: 24rem; margin-inline: auto; }
  #mute { inline-size: 44px; block-size: 44px; }
  #volume { flex: 1; block-size: 44px; }
  footer.panel { font-size: .9rem; }
  footer.panel label { display: flex; align-items: center; gap: .5rem; min-block-size: 44px; margin: 0; }
  footer.panel select { min-block-size: 40px; font-size: 16px; margin: 0; }
  #hint { display: none; } /* it speaks of clicking; Help says the same for fingers */

  /* ---- start, result and help fill the screen ---- */
  #overlay .card { padding: 1.5rem 1.2rem; max-block-size: 94dvh; overflow: auto; }
  #overlay h1 { font-size: 1.7rem; }
  #overlay .row { flex-wrap: wrap; }
  #overlay .row button { min-block-size: 48px; }
  #help { place-items: stretch; }
  #help .card {
    inline-size: auto; max-block-size: none; block-size: 100dvh;
    padding-block: calc(1rem + var(--safe-t)) calc(1rem + var(--safe-b)); padding-inline: max(1rem, var(--safe-s)) max(1rem, var(--safe-e));
  }
  #help .tabs button, #help-close { min-block-size: 44px; }
  #help .dock-row { display: none; } /* no room beside the map on a phone */
  #help .examples { gap: .7rem; }
  #help .examples li { grid-template-columns: 1fr; gap: .15rem; }
  #help .examples code { padding-block: .35rem; }

  /* ---- the lobby: every choice a thumb can hit, the buttons within reach ---- */
  #overlay { align-items: end; padding-block: var(--safe-t) var(--safe-b); padding-inline: var(--safe-s) var(--safe-e); }
  #overlay .card { inline-size: 100%; max-block-size: calc(100dvh - var(--safe-t) - var(--safe-b)); padding-block-end: 1.2rem; }
  #overlay form label, #lobby-watch { display: flex; align-items: center; gap: .55rem; min-block-size: 44px; }
  #overlay form input[type="radio"], #overlay form input[type="checkbox"] { inline-size: 22px; block-size: 22px; flex: none; }
  #overlay form select, #overlay input[type="text"] { min-block-size: 44px; font-size: 16px; min-inline-size: 0; flex: 1; }
  #lobby-level-row, #overlay form > label { flex-wrap: wrap; }
  #lobby-join { flex-wrap: wrap; }
  #lobby-join label { display: block; min-block-size: 0; }
  #lobby-join button, #lobby-copy { min-block-size: 44px; }
  #commander button, #commander .pair input { min-block-size: 44px; }
  #lobby-share { flex-wrap: wrap; }
  #lobby-seats li { min-block-size: 44px; align-items: center; }
  #lobby-watch { flex-wrap: wrap; }
  #lobby-watch > span { flex: 1; min-inline-size: 0; }
  #scores-box { max-block-size: none; }
  #scores-table th, #scores-table td { padding: .45rem .3rem; }
  #live-list { max-block-size: none; }
  #live-list li { align-items: center; }
  #live-list .go { min-block-size: 44px; display: inline-flex; align-items: center; }
  /* The buttons that move the lobby on stay in view while the choices scroll. */
  #overlay .row { position: sticky; inset-block-end: -1.2rem; margin-inline: -1.2rem; padding: .7rem 1.2rem; background: linear-gradient(#151b1f00, #151b1f 30%); }
  #overlay .row button { flex: 1 1 auto; }

  /* ---- who thinks for the squads: a full sheet, with the close button in reach ---- */
  #brains {
    inline-size: 100vw; max-inline-size: none; block-size: 100dvh; max-block-size: none; margin: 0; border: 0;
    padding-block: calc(1rem + var(--safe-t)) calc(1rem + var(--safe-b)); padding-inline: max(1rem, var(--safe-s)) max(1rem, var(--safe-e));
    overflow: auto;
  }
  #brains select, #brains input[type="password"] { min-block-size: 44px; font-size: 16px; inline-size: 100%; }
  #brains label.check { display: flex; align-items: center; gap: .55rem; min-block-size: 44px; }
  #brains input[type="checkbox"] { inline-size: 22px; block-size: 22px; flex: none; }
  #brains .row { flex-wrap: wrap; }
  #brains .row button { min-block-size: 48px; flex: 1 1 auto; }

  /* The on-screen keyboard is up: the radio box rides on top of it. */
  html.typing #send { inset-block-end: var(--kb); }
  html.typing :is(#log, #squad-log, #team-log) { inset-block-end: calc(var(--kb) + var(--send)); }
  html.typing #net-tabs { display: none; }
  html.typing #voice-status { display: none; }
}

/* Fingers pinch; the two zoom buttons would only cover the map. */
@media (pointer: coarse) and (max-width: 1100px), (pointer: coarse) and (max-height: 500px) {
  #zoom-in, #zoom-out { display: none; }
}

/* ---- held sideways: the bar stands on the edge, sheets open beside it ---- */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --strip: 38px; --send: 46px; --tick: 52px; --tabs: 0px; --rail: 76px; }
  /* Sideways there is little height: two lines of the log, not four. */
  html:not([data-sheet="radio"]) #log li:not(.strip2) { display: none; }

  #map-wrap {
    inset-inline: 0 calc(var(--rail) + var(--safe-e));
    inset-block: calc(var(--strip) + var(--safe-t)) calc(var(--send) + var(--tick) + var(--safe-b));
  }
  #treasury { gap: 1.4rem; }
  .bars { max-inline-size: 14rem; margin-inline-start: auto; }

  #dock {
    inset-block: calc(var(--strip) + var(--safe-t)) 0; inset-inline: auto 0;
    inline-size: calc(var(--rail) + var(--safe-e)); block-size: auto;
    padding-block-end: calc(var(--safe-b) + 72px); padding-inline: 0 var(--safe-e);
    grid-template-columns: none; grid-auto-rows: 1fr;
    border-block-start: 0; border-inline-start: 2px solid var(--brass-dim);
  }
  #dock button { border-block-start: 0; border-inline-start: 3px solid transparent; }
  #dock button:nth-child(3) { grid-column: auto; }
  #dock button[aria-pressed="true"] { border-inline-start-color: var(--brass); }

  #ptt { left: auto; inset-inline-end: calc(var(--safe-e) + (var(--rail) - 62px) / 2); inset-block-end: calc(var(--safe-b) + 6px); transform: none; }
  #ptt.live { transform: scale(1.14); }

  #send {
    inset-inline: 0 calc(var(--rail) + var(--safe-e)); inset-block-end: 0;
    block-size: calc(var(--send) + var(--safe-b)); padding-block-end: calc(4px + var(--safe-b));
  }
  :is(#log, #squad-log, #team-log) { inset-inline: 0 calc(var(--rail) + var(--safe-e)); inset-block-end: calc(var(--send) + var(--safe-b)); }
  #voice-status { inset-inline: .5rem calc(var(--rail) + var(--safe-e) + .5rem); inset-block-end: calc(var(--send) + var(--tick) + var(--safe-b) + 6px); }

  html[data-sheet="radio"] :is(#log, #squad-log, #team-log), #sidebar {
    inset-block: calc(var(--strip) + var(--safe-t)) calc(var(--send) + var(--safe-b));
    inset-inline: auto calc(var(--rail) + var(--safe-e));
    inline-size: min(25rem, 58vw); block-size: auto; max-block-size: none;
    border-block-start: 0; border-inline-start: 2px solid var(--brass-dim); padding-inline: 3px;
  }
  html[data-sheet="radio"] :is(#log, #squad-log, #team-log) { padding-inline: .6rem; inset-block-start: calc(var(--strip) + var(--safe-t) + var(--nets)); }
  html[data-sheet="radio"] #net-tabs {
    inset-block: calc(var(--strip) + var(--safe-t)) auto; inset-inline: auto calc(var(--rail) + var(--safe-e));
    inline-size: min(25rem, 58vw); border-block-start: 0; border-inline-start: 2px solid var(--brass-dim);
  }
}

/* ---- a large touch screen (an unfolded phone, a small tablet): the phone layout, with the
   talk button bigger and on the right, where the thumb of the holding hand is ---- */
@media (pointer: coarse) and (min-width: 701px) and (max-width: 1100px) and (min-height: 501px) {
  /* The button is on the physical right in both languages, so the room made for it is too. */
  #dock { grid-template-columns: repeat(4, 1fr); padding-right: calc(env(safe-area-inset-right, 0px) + 124px); }
  #dock button:nth-child(3) { grid-column: auto; }
  #send { padding-right: calc(env(safe-area-inset-right, 0px) + 124px); }
  #ptt {
    left: auto; right: calc(env(safe-area-inset-right, 0px) + 14px); inset-block-end: calc(var(--safe-b) + 10px); transform: none;
    inline-size: 96px; block-size: 96px; font-size: 2.6rem;
  }
  #ptt.live { transform: scale(1.1); }
}

/* The build sheet's tabs are thumb-sized on a phone. */
@media (max-width: 700px), (max-height: 500px), (pointer: coarse) and (max-width: 1100px) {
  #build-tabs button { min-block-size: 44px; font-size: .85rem; }
  #structure-list { max-block-size: none; }
  #lobby-map-cards { grid-template-columns: repeat(2, 1fr); gap: .35rem; } /* four maps: two rows of two on a narrow screen */
  /* A card stacks its drawing, name and size, whatever the form does with other labels. */
  #overlay form #lobby-map-cards label { display: grid; grid-template-columns: minmax(0, 1fr); gap: .2rem; min-block-size: 44px; padding: .25rem; }
  #overlay form #lobby-map-cards input[type="radio"] { inline-size: 1px; block-size: 1px; }
  #lobby-map-cards strong, #lobby-map-cards small { overflow-wrap: anywhere; }
  #lobby-gold-other { min-block-size: 44px; font-size: 16px; }
  #lobby-match canvas { inline-size: 6rem; }
}

/* ---- power and our own structures, on a phone ---- */
@media (max-width: 820px), (pointer: coarse) and (max-height: 520px) {
  /* In the strip there is room for the bolt and the two numbers; low power turns them to the warning colour. */
  #power { display: flex; align-items: center; gap: .25rem; font-size: .72rem; white-space: nowrap; }
  #power[hidden] { display: none; }
  #power .label, #power .bar, #power .state { display: none; }
}

/* ---- super powers bar, touch aiming banner and picker modal on phones ---- */
@media (max-width: 700px), (max-height: 500px), (pointer: coarse) and (max-width: 1100px) {
  #super-bar-list button.sp-slot, #super-bar-list button.sp-choose { min-inline-size: 0; min-block-size: 44px; }
  #super-aim {
    inset-block-start: .45rem; gap: .4rem .55rem; padding: .45rem .6rem;
    max-inline-size: calc(100% - .9rem); font-size: .78rem;
  }
  #super-aim button { min-block-size: 44px; min-inline-size: 4.8rem; padding-inline: .75rem; font-size: .85rem; }
  #super-picker { padding: .4rem; align-items: stretch; }
  #super-picker .card {
    inline-size: 100%; max-block-size: calc(100dvh - var(--safe-t) - var(--safe-b) - .8rem);
    padding: .85rem .9rem;
  }
  #super-pick-grid { grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); }
  #super-pick-grid button.sp-card { min-block-size: 56px; padding: .6rem .7rem; }
  #super-picker .row { flex-wrap: wrap; }
  #super-picker .row button { min-block-size: 46px; flex: 1 1 auto; }
}
