/* 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) {
  :root {
    --strip: 46px; /* treasury */
    --send: 54px; /* the radio box */
    --tabs: 64px; /* the bar of sheets, with the talk button */
    --tick: 30px; /* the last line of the radio log */
    --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, #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; }
  #radio > h2 { 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;
  }
  #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 line always, the whole of it as a sheet ---- */
  #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 li:not(:last-child) { display: 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"] #log {
    z-index: 5; overflow-y: auto; border-block-start: 2px solid var(--brass-dim); gap: .35rem;
    block-size: min(52dvh, calc(100dvh - var(--strip) - var(--send) - var(--tabs) - var(--safe-t) - var(--safe-b)));
  }
  #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 { min-block-size: 88px; font-size: .8rem; }
  #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; }
  #nerve { inline-size: 22px; block-size: 22px; }
  #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 .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; }
  #lobby-share { flex-wrap: wrap; }
  #lobby-seats li { min-block-size: 44px; 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 #log { inset-block-end: calc(var(--kb) + var(--send)); }
  html.typing #voice-status { display: none; }
}

/* Fingers pinch; the two zoom buttons would only cover the map. */
@media (pointer: coarse) and (max-width: 700px), (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: 26px; --tabs: 0px; --rail: 76px; }

  #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));
  }
  #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"] #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"] #log { padding-inline: .6rem; }
}
