/* Phones and tablets. Up to 1000px wide the battle screen is the board with one panel and a tab bar
   under it; a phone held sideways gets the board on the left and the panel on the right. Touch
   screens get bigger buttons. The behaviour that goes with it is in js/mobile.js. */

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, .btn, .cmd, input, select, label { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.board-wrap { touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; overscroll-behavior: contain; }

/* only on narrow screens or touch */
.ptabs, #btn-more, .modal-x { display: none; }
.cmd-tabs, .cmd-head { display: contents; }
#btn-more svg { display: block; }
.cmd[aria-disabled="true"] { color: #6c6656; }
.net-chip { border-color: var(--bad); color: var(--bad); animation: glow 1s ease-in-out infinite; white-space: nowrap; }
.more-menu .btn { font-size: 10px; }

/* the notch and the home bar */
.home-wrap, .page { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.home-wrap { padding-top: max(40px, env(safe-area-inset-top)); padding-bottom: max(40px, env(safe-area-inset-bottom)); }
.drawer { padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: max(12px, env(safe-area-inset-bottom)); padding-right: max(14px, env(safe-area-inset-right)); }

/* ---------- touch screens: fingers need room ---------- */
@media (hover: none) and (pointer: coarse) {
  .btn { min-height: 40px; padding: 11px 14px; }
  .btn.small { font-size: 9px; min-height: 36px; padding: 10px 10px; }
  .cmd { min-height: 40px; padding: 8px 8px 8px 22px; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  .cmd:not([aria-disabled="true"]):active { background: #c9b27a33; }
  .cmd.on::before { top: calc(50% - 9px); }
  .order-win li { min-height: 38px; }
  .opt-row input[type=checkbox] { width: 22px; height: 22px; flex: none; margin-top: 0; }
  .opt-row { align-items: center; min-height: 36px; }
  input[type=checkbox] { accent-color: var(--gold); }
  textarea { font-size: 16px; } /* iOS zooms into text fields with smaller text */
  #board { cursor: default; }
  .modal-x { display: block; float: right; position: sticky; top: 0; z-index: 2; margin: -4px -6px 4px 8px; width: 36px; min-height: 36px; padding: 0; font-size: 10px; }
  .vol input[type=range] { height: 32px; }
  .track { min-height: 40px; }
  .track-play { width: 36px; height: 36px; }
}

/* ---------- narrow screens ---------- */
@media (max-width: 1000px) {
  body:has(#view-battle.active) { overflow: hidden; overscroll-behavior: none; }
  #view-battle.active, #view-battle.active * { -webkit-user-select: none; user-select: none; }
  #view-battle.active input, #view-battle.active textarea { -webkit-user-select: text; user-select: text; }

  /* topbar: back, name, round, music, and ⋯ for the rest */
  .topbar { flex-wrap: nowrap; gap: 6px; padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left)); }
  .tb-left { flex: 1 1 auto; min-width: 0; flex-wrap: nowrap; gap: 6px; }
  .tb-right { flex: none; flex-wrap: nowrap; gap: 6px; }
  .tb-left > * { flex: none; }
  .tb-left > .b-name { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
  #b-code, #b-who, #btn-mychars, #btn-dice, #btn-gm { display: none !important; }
  /* the saved/practice chip moves into the ⋯ menu, and the reconnecting chip takes the round's place */
  .tb-left > .mode-chip { display: none; }
  .tb-left:has(.net-chip:not(.hidden)) #b-round { display: none; }
  #btn-more { display: inline-block; }
  .music-chip { max-width: 40vw; }
  .music-chip #music-label { display: none; }
  .music-chip.blocked #music-label { display: inline; }
  /* a note while nothing plays, so it is not mistaken for the ⋯ menu */
  .music-chip:not(.playing) .eq { width: 14px; height: 14px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M6 2h8v3h-6v7H7v2H3v-1H2v-2h1v-1h3z' fill='%23f0dca0'/%3E%3C/svg%3E") center / contain no-repeat; }
  .music-chip:not(.playing) .eq i { display: none; }
  .gm-bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .gm-bar > * { flex: none; }
  #gm-hint { display: none; }

  /* the board, one panel, and the tabs */
  .battle {
    --panel-h: clamp(176px, 38dvh, 380px);
    display: grid; gap: 6px; min-height: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) var(--panel-h) auto;
    grid-template-areas: "board" "panel" "tabs";
    padding: 6px max(6px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left));
  }
  .board-col, .side-col { display: contents; }
  .board-wrap { grid-area: board; min-height: 0; max-height: none; }
  /* two by two in the corner, so they hide little of a short board */
  .board-tools { grid-area: board; align-self: end; justify-self: end; z-index: 2; margin: 0 9px 9px 0; display: grid; grid-template-columns: repeat(2, 40px); gap: 6px; pointer-events: none; }
  .board-tools .btn { pointer-events: auto; width: 40px; min-height: 0; height: 40px; padding: 0; font-size: 14px; display: flex; align-items: center; justify-content: center; background: #000c; box-shadow: 0 0 0 2px #000; }
  #zoom-in { order: 1; } #zoom-out { order: 2; } #zoom-fit { order: 3; } #zoom-me { order: 4; }
  #hover-info, .zoom-level { display: none; }

  #command, .order-win, .card-win, .log-win { grid-area: panel; min-height: 0; max-height: none; overflow: auto; padding: 8px 10px; }
  body[data-ptab]:not([data-ptab="act"]) #command,
  body:not([data-ptab="order"]) .order-win,
  body:not([data-ptab="card"]) .card-win,
  body:not([data-ptab="log"]) .log-win { display: none; }
  .order-win ol { max-height: none; }
  .log-win { overflow: hidden; }
  #log { min-height: 0; }

  .ptabs { grid-area: tabs; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .ptabs button {
    position: relative; min-height: 44px; padding: 4px 2px; font-family: var(--pixel); font-size: 9px; color: var(--muted);
    background: #000a; border: 2px solid #5a5236; border-radius: 4px; cursor: pointer; transition: color .15s, border-color .15s;
  }
  .ptabs button.on { color: var(--gold-hi); border-color: var(--gold); background: linear-gradient(#36492e, #1c2818); box-shadow: 0 0 0 2px #000, 0 0 10px #c9b27a33; }
  .ptabs button.new::after { content: ''; position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--sel); box-shadow: 0 0 6px var(--sel); animation: glow 1s ease-in-out infinite; }
  .ptabs button[data-tab="act"].new { color: var(--sel); border-color: var(--sel); }

  /* command menu: header with the categories in a sideways row, commands below */
  .command { flex-direction: column; gap: 6px; min-height: 0; }
  .command .cmd-cats {
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0;
    position: sticky; top: -8px; z-index: 1; margin: -8px -10px 0; padding: 8px 10px 6px; background: #1f2d1b; border-bottom: 1px dashed #5a5236;
  }
  .command .cmd-cats.planning { border-left: 0; padding-left: 10px; }
  .command .cmd-head { display: flex; flex: 1 1 0; min-width: 0; align-items: center; gap: 8px; }
  .command .cmd-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .command .cmd-cats .turn-pips { margin: 0; flex: none; }
  .command .cmd-cats .end-turn { margin: 0 0 0 auto; }
  .command .cmd-tabs { display: flex; order: 9; flex: 1 0 100%; gap: 2px; overflow-x: auto; scrollbar-width: none; }
  .command .cmd-tabs::-webkit-scrollbar { display: none; }
  .command .cmd-tabs .cmd { flex: none; white-space: nowrap; }
  .command .plan-head { margin: 0; flex-basis: 100%; }
  .command .cmd-list { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); max-height: none; overflow: visible; }
  .command .cmd-desc { width: auto; max-height: none; overflow: visible; border-left: 0; border-top: 1px dashed #5a5236; padding: 6px 0 0; font-size: 16px; }
  .command .cmd-desc:has(> .muted:only-child) { border-top: 0; padding-top: 0; }
  .targeting { gap: 8px; }

  .card-win .attrs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .card-win .tag { display: inline-block; margin: 2px 0; }
  #toasts { width: max-content; max-width: calc(100vw - 24px); align-items: center; }
  body:has(#view-battle.active) #toasts { bottom: calc(60px + env(safe-area-inset-bottom)); }
  .drawer { width: 100%; }
}

/* ---------- phone held sideways: board left, panel right ---------- */
@media (max-width: 1000px) and (orientation: landscape) and (max-height: 600px) {
  .topbar { padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: 4px; }
  .battle {
    --side-w: clamp(280px, 47vw, 440px);
    grid-template-columns: minmax(0, 1fr) var(--side-w);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "board tabs" "board panel";
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }
  .ptabs { padding-bottom: 0; }
  .ptabs button { min-height: 36px; font-size: 8px; }
  .command .cmd-list { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .gm-bar { padding-top: 3px; padding-bottom: 3px; }
  body:has(#view-battle.active) #toasts { bottom: calc(12px + env(safe-area-inset-bottom)); left: 35%; }
}

/* ---------- small phones: pages and windows ---------- */
@media (max-width: 600px) {
  .home-wrap { padding-top: max(24px, env(safe-area-inset-top)); padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .logo-row { margin-bottom: 22px; }
  h2, h3 { line-height: 1.4; }
  .home-grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .page { padding-top: max(14px, env(safe-area-inset-top)); padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); gap: 12px; }
  .page-head { gap: 10px; }
  .window { padding: 10px 12px; }
  .upload-row, .row { flex-wrap: wrap; }
  #rules-tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
  #rules-tabs .btn { flex: none; }
  .rules-list { max-height: none; }
  .char-list, .sheet-preview { grid-template-columns: minmax(0, 1fr); }
  .gm-battle { flex-wrap: wrap; }
  /* windows come up from the bottom, where the thumb is */
  .modal { align-items: flex-end; padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  .modal-box { max-height: calc(100dvh - 16px - env(safe-area-inset-top)); padding: 12px; }
  .prompt-box .opts .btn { font-size: 10px; }
  .dice-pop { font-size: 14px; }
}
