/* Phone layout. Loaded last, so it only changes things under 720px wide.
   Tap targets are at least 44px tall, rows stack, and the room tabs scroll sideways. */
@media (max-width: 720px) {
  html, body { overflow-x: hidden; }
  .wrap { padding: 8px 8px 60px; }
  .topunit { margin-bottom: 10px; border-radius: 12px; }

  .bar { flex-direction: column; align-items: stretch; gap: 10px; padding: 10px 12px; }
  .brand { gap: 10px; }
  .brand h1 { font-size: 24px; }
  .brand .orb { width: 34px; height: 34px; }

  /* Room tabs: one scrolling line, nothing wraps into a mess */
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 6px; padding: 2px 0 6px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs > * { flex: 0 0 auto; white-space: nowrap; min-height: 44px; padding: 0 14px; }

  /* Tools: a tidy two-column grid */
  .tools { display: flex; gap: 8px; width: 100%; margin: 0; }
  .tools > .btn { flex: 1 1 0; min-width: 0; min-height: 44px; justify-content: center; }
  .menu { left: 0; right: 0; width: auto; max-height: 75vh; overflow-y: auto; }
  .menu .btn, .menu .sel { min-height: 44px; }
  .ear-actions .btn.go { flex: 2; }
  .menu .vol { min-height: 44px; }

  details.note > summary { min-height: 44px; display: flex; align-items: center; font-size: 15px; }
  details.note > p { font-size: 13px; padding: 0 14px 12px; }

  /* Room header and windows */
  .room-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .room-head h2 { font-size: 22px; }
  .room-grid { gap: 12px; }
  details.win > summary { min-height: 48px; font-size: 16px; padding: 10px 14px; }
  details.win > .body { padding: 12px; }

  /* Tap targets */
  .btn { min-height: 44px; padding: 10px 14px; font-size: 15px; }
  .btn.sm { min-height: 40px; padding: 8px 12px; font-size: 14px; }
  .chip { min-height: 38px; padding: 6px 12px; font-size: 14px; }
  .seg { flex-wrap: wrap; }
  .seg button { min-height: 40px; padding: 8px 12px; }
  .row { flex-wrap: wrap; gap: 8px; }
  .row.tight { gap: 6px; }
  input, select, textarea { font-size: 16px; min-height: 42px; max-width: 100%; }
  input[type=range] { height: 34px; }
  input[type=range]::-webkit-slider-thumb { width: 26px; height: 26px; }
  input[type=range]::-moz-range-thumb { width: 26px; height: 26px; }

  /* Single-column layouts */
  .sx-split, .sx-grid2, .tuner-layout, .circle-layout, .ear-body, .midi-top { grid-template-columns: 1fr !important; }
  .sx-bar { flex-wrap: wrap; gap: 8px; }
  .sx-readout { font-size: 22px; }
  .circle-fig svg.cof { width: 100%; max-width: 340px; height: auto; margin: 0 auto; display: block; }
  .picker { padding: 12px; }
  .room-cards { grid-template-columns: 1fr; gap: 12px; }
  .room-card { padding: 14px; }

  /* Ear training */
  .ear-top { flex-direction: column; align-items: stretch; }
  .ear-top .btn { width: 100%; }
  .ear-top .chips, .ear-top .seg { width: 100%; }
  .ear-top .seg button { flex: 1; }
  .ear-lengthrow { flex-wrap: wrap; }
  .ear-settings { grid-template-columns: 1fr; }
  .ear-options { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; margin-top: 8px; }
  .ear-options .opt { min-height: 56px; padding: 6px 8px; font-size: 16px; }
  .ear-options.compact .opt { min-height: 36px; padding: 4px 8px; font-size: 14px; }
  .ear-pool .chip { min-height: 28px; font-size: 12px; }
  .ear-options .opt-row { grid-column: 1 / -1; gap: 4px; }
  .ear-actions { gap: 8px; }
  .ear-actions .btn { flex: 1; }
  .ear-stats { grid-template-columns: 1fr 1fr; }
  .ear-prompt { font-size: 18px; }
  .aero-score b { font-size: 44px; }
  .aero-rows div { font-size: 13px; }

  /* Scale and equal-division boxes */
  .sx-wrap .step, .sx-formula .step { min-width: 48px; }
  .step.h, .step.w, .step.a { min-height: 44px; }
  .sx-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  canvas.disp, canvas.roll { max-width: 100%; }
}

@media (max-width: 380px) {
  .tools { grid-template-columns: 1fr; }
  .ear-options { grid-template-columns: 1fr; }
  .brand h1 { font-size: 21px; }
}

/* Fixes found on a phone: the bar and tabs must never push past the screen edge. */
@media (max-width: 720px) {
  .topunit, .bar, .brand, .tools { min-width: 0; max-width: 100%; }
  .bar { overflow: visible; }
  .tabs { max-width: 100%; min-width: 0; }
  .wrap { overflow-x: hidden; }

  /* Ear training: Start and Halt sit at the very top, side by side, before the categories. */
  .ear-top { display: flex; flex-direction: row; flex-wrap: wrap; gap: 8px; align-items: stretch; }
  .ear-top .btn { order: -2; flex: 1 1 0; min-width: 0; width: auto; }
  .ear-top .btn.go { order: -3; }
  .ear-top .chips, .ear-top .seg { flex: 1 1 100%; }
  .ear-top .seg button { flex: 1; }
}
@media (max-width: 720px) { .aero-items { grid-template-columns: 1fr; } }
