/* Phone layout for the Play Tester. Desktop keeps the original inline styles. */
.mobile-only { display: none !important; }
.pile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.pile-head:hover .name,
.pile-head:focus-visible .name { color: var(--accent); }

/* Card and tools action sheets are appended to body by the phone controller. */
body.mobile-sheet-open { overscroll-behavior: none; }
.mobile-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(5, 8, 10, .72);
  backdrop-filter: blur(3px);
}
.mobile-sheet {
  display: flex;
  flex-direction: column;
  width: min(100%, 520px);
  max-height: calc(100dvh - max(12px, env(safe-area-inset-top)));
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--edge-2);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -16px 48px rgba(0, 0, 0, .58);
}
.mobile-sheet-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 7px 12px 7px 16px;
  border-bottom: 1px solid var(--edge);
  font-size: 16px;
  font-weight: 700;
}
.mobile-sheet-head > :first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.mobile-sheet-head h2 { margin: 0; font-size: 17px; line-height: 1.2; }
.mobile-sheet-close {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--edge-2);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 22px;
}
.mobile-sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px 18px;
}
.mobile-sheet-preview,
.mobile-card-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 0;
  margin-bottom: 12px;
  padding: 8px;
  border: 1px solid var(--edge);
  border-radius: 10px;
  background: var(--surface-2);
}
.mobile-card-preview strong { text-align: center; font-size: 16px; }
.mobile-card-preview span { text-align: center; color: var(--muted); font-size: 13px; }
.mobile-sheet-preview img,
.mobile-card-preview img {
  display: block;
  flex: 0 0 auto;
  width: min(39vw, 150px);
  max-height: min(32dvh, 210px);
  object-fit: contain;
  border-radius: 8px;
}
.mobile-sheet-preview .face,
.mobile-card-preview .face { position: relative; width: min(39vw, 150px); height: min(54vw, 210px); flex: 0 0 auto; }
.mobile-sheet-actions { display: flex; flex-direction: column; gap: 7px; }
.mobile-sheet-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  border: 1px solid var(--edge-2);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font: 600 14px "Space Grotesk", system-ui, sans-serif;
  text-align: left;
}
.mobile-sheet-action:active { background: var(--surface-3); }
.mobile-sheet-action:disabled { opacity: .45; }
a.mobile-sheet-action { text-decoration: none; }
.mobile-sheet-action.danger { color: #f0b3a6; }
.mobile-sheet-group {
  margin: 10px 0 1px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.mobile-sheet-group:first-child { margin-top: 0; }
.mobile-sheet-empty { color: var(--muted); line-height: 1.5; padding: 8px 2px; }
.mobile-sheet-stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  border-bottom: 1px solid var(--edge);
}
.mobile-sheet-stat-row > :first-child { flex: 1 1 auto; min-width: 0; }
.mobile-sheet-stat-value { min-width: 34px; text-align: center; color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.mobile-sheet-stat-row button {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--edge-2);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 20px;
}
.mobile-sheet-stat-row button:active { background: var(--surface-3); }

@media (max-width: 640px) {
  html, body { height: 100%; }
  body { height: 100dvh; min-height: 0; overflow: hidden; }
  .app { height: 100%; min-height: 0; }
  .mobile-only { display: inline-flex !important; }
  .desktop-hint { display: none !important; }
  #preview { display: none !important; }

  /* Only the values used every turn stay in the header. */
  .appbar {
    flex: 0 0 auto;
    min-height: 52px;
    gap: 6px;
    padding: 4px 8px;
    overflow: visible;
  }
  .appbar .logo { gap: 0; }
  .appbar .logo img { height: 23px; }
  .appbar .logo .word { font-size: 17px; }
  .appbar .pill {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .appbar .spacer { flex: 1 1 0; min-width: 0; }
  .appbar > .stat { display: none; }
  .appbar > .life-stat,
  .appbar > .turn-stat { display: flex; }
  .appbar .stat .lbl {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  .appbar .counter { gap: 2px; padding: 2px 4px; }
  .appbar .life-stat .round { width: 44px; height: 44px; }
  .appbar .life-stat .val { min-width: 28px; font-size: 17px; }
  .appbar .turn-stat .counter { min-height: 40px; }
  .appbar .turn-stat .counter::before { content: "T"; color: var(--muted); font-size: 9px; }
  .appbar .turn-stat .val { min-width: 20px; font-size: 14px; }
  .appbar > .btn:not(#mobileToolsBtn) { display: none; }
  #mobileToolsBtn { align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 5px 7px; font-size: 12px; }

  .signin-strip { flex: 0 0 auto; margin: 0; padding: 5px 8px; font-size: 11px; line-height: 1.35; }
  .signin-strip .ss-text .mobile-only { display: inline !important; }
  .signin-strip .ss-close { flex: 0 0 44px; min-height: 44px; }

  .deckbar {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 3px 8px;
    min-height: 46px;
    padding: 5px 8px;
  }
  .deckbar .dn { grid-column: 1; max-width: none; min-width: 0; font-size: 14px; }
  .deckbar .tag { display: none; }
  .deckbar .deckswap,
  .deckbar .manabar { display: none; }
  #mobileManaBtn { grid-column: 2; grid-row: 1; align-items: center; justify-content: center; min-height: 44px; padding: 5px 9px; font-size: 11px; white-space: nowrap; }

  /* The compact zone strip remains in view; the battlefield gets the space. */
  .table { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
  .rail {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    align-items: stretch;
    gap: 4px;
    min-height: 52px;
    padding: 4px 8px;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--edge);
  }
  .rail .pile { min-width: 0; gap: 0; }
  .rail .pile .head { width: 100%; height: 100%; }
  .rail .pileface,
  .rail .mini { display: none !important; }
  .rail .pile-head {
    flex-direction: column;
    justify-content: center;
    gap: 1px;
    min-height: 44px;
    padding: 3px 1px;
    border: 1px solid var(--edge-2);
    border-radius: 8px;
    background: var(--surface);
    text-align: center;
  }
  .rail .pile-head .name { font-size: 9px; letter-spacing: .025em; white-space: nowrap; }
  .rail .pile-head .n { font-size: 12px; line-height: 1; }
  .rail #tokenBtn { min-width: 0; min-height: 44px; padding: 3px 1px; font-size: 11px; }

  .field { flex: 1 1 auto; min-height: 0; gap: 5px; padding: 6px 8px; overscroll-behavior: contain; touch-action: pan-y; }
  .zonerow { min-height: 80px; padding: 6px 8px; }
  .zonerow > h2 { margin-bottom: 4px; }
  .cards { gap: 20px 16px; padding: 5px 3px; }
  .field .tile { width: var(--phone-field-w, clamp(76px, 24vw, 98px)); height: auto; aspect-ratio: 5 / 7; }
  .tile .menu-btn { display: none; }

  .handbar {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 5px;
    min-width: 0;
    padding: 5px 8px max(5px, env(safe-area-inset-bottom));
  }
  .hand-actions { order: -1; gap: 2px; }
  .hand-actions .row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .hand-actions .row .btn { min-width: 0; min-height: 44px; padding: 6px 3px; }
  #mobileUndoBtn { align-items: center; justify-content: center; }
  .hand-actions .chk { display: none; }
  .hand-wrap { flex: 0 0 auto; min-width: 0; }
  .hand-title { display: flex; align-items: center; gap: 5px; margin-bottom: 4px; }
  .hand-title .mobile-hint { margin-left: auto; color: var(--muted); font-size: 10px; font-weight: 400; letter-spacing: 0; text-transform: none; }
  .hand-cards { min-height: 0; gap: 8px; padding: 1px 1px 3px; overflow-x: auto; overscroll-behavior-x: contain; touch-action: pan-x; -webkit-overflow-scrolling: touch; }
  .hand-cards .tile { width: var(--phone-hand-w, clamp(82px, 23vw, 96px)); height: auto; aspect-ratio: 5 / 7; }
  .mull { position: static; flex-wrap: wrap; gap: 5px; margin: 0 0 5px; padding: 5px 7px; box-shadow: none; }
  .mull .msg { flex: 1 1 auto; min-width: 0; font-size: 12px; }
  .mull .btn { flex: 0 0 auto; min-height: 44px; padding: 6px 10px; }
  .appfoot { display: none; }

  /* Existing dialogs must fit alongside the software keyboard. */
  .overlay-modal { align-items: flex-end; padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)); }
  .modal { width: 100%; max-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom))); }
  .modal header { gap: 8px; padding: 9px 12px; }
  .modal header h2 { font-size: 17px; }
  .modal .content { min-height: 0; padding: 11px 12px; }
  .modal footer { flex-wrap: wrap; padding: 9px 12px; }
  .modal button,
  .modal .mini2,
  .modal .chip { min-height: 44px; }
  .modal .field-row { flex-wrap: wrap; align-items: stretch; }
  .modal .field-row label { width: 100%; }
  .modal .field-row input,
  .modal .field-row textarea { min-width: 0; min-height: 44px; }
  .modal .field-row textarea { width: 100%; }
  .modal #tokCustomName { flex: 1 1 100% !important; }
  .modal #tokCustomPT { width: min(120px, 42%) !important; }
  .modal #tokCustomAdd { flex: 1 1 auto; }
  .modal .ctr-row .mini2 { min-width: 44px; }
  .modal .tok-item { min-height: 64px; }
  .modal .grid-cards { gap: 16px 10px; }
  .modal .grid-cards .tile { width: 88px; height: 123px; }
  #searchGrid .picker-card .over {
    inset: auto 0 0;
    min-height: 30px;
    background: rgba(5, 8, 10, .88);
    border-radius: 0 0 var(--radius) var(--radius);
    color: #fff;
    font-size: 11px;
    pointer-events: none;
  }

  /* Fallback for menus that still call the older floating-menu function. */
  .popmenu {
    left: 8px !important;
    right: 8px !important;
    top: auto !important;
    bottom: max(8px, env(safe-area-inset-bottom));
    width: auto;
    max-height: min(72dvh, 600px);
    overflow-y: auto;
  }
  .popmenu button { min-height: 44px; }
  .logpanel { width: min(100%, 390px); max-width: 100%; }
}

@media (max-width: 640px) and (max-height: 700px) {
  /* Distinct compact sizes leave room for the battlefield on a short screen. */
  .hand-cards .tile { width: var(--phone-short-hand-w, 70px); }
  .field .tile { width: var(--phone-short-field-w, 72px); }
  .hand-title .mobile-hint { font-size: 9px; }
}

@media (max-width: 640px) and (max-height: 600px) {
  /* On the shortest phones the optional invitation would take most of the field. */
  .signin-strip { display: none !important; }
}

@media (max-width: 640px) and (orientation: landscape) {
  .app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 38%);
    grid-template-rows: auto auto minmax(0, 1fr);
  }
  .appbar { grid-column: 1 / -1; grid-row: 1; }
  .deckbar { grid-column: 1 / -1; grid-row: 2; }
  .signin-strip { display: none !important; }
  .table { grid-column: 1; grid-row: 3; min-height: 0; height: 100%; }
  .rail { display: none; }
  .field { min-height: 0; }
  .handbar {
    grid-column: 2;
    grid-row: 3;
    min-height: 0;
    height: 100%;
    gap: 3px;
    padding: 4px 6px max(4px, env(safe-area-inset-bottom));
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-top: 0;
    border-left: 1px solid var(--edge);
  }
  .hand-actions { flex: 0 0 auto; }
  .hand-actions .row { gap: 3px; }
  .hand-actions .row .btn { padding: 4px 1px; font-size: 11px; }
  .hand-title .mobile-hint { display: none !important; }
  .hand-title::after { content: "Tap card"; margin-left: auto; color: var(--muted); font-size: 10px; font-weight: 400; letter-spacing: 0; text-transform: none; }
  .hand-cards .tile { width: var(--phone-land-hand-w, 55px); }
  .mull { gap: 3px; margin-bottom: 3px; padding: 3px 5px; }
  .mull .msg { flex: 1 1 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
  .mull .btn { flex: 1 1 0; padding: 4px 2px; font-size: 11px; }
}
