/* Keep import and transport controls inside the iPhone portrait viewport. */
@media (max-width: 650px) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    width: 100%;
    min-width: 0;
  }
  .topbar > .brand { grid-column: 1; min-width: 0; }
  .topbar > #help { grid-column: 2; grid-row: 1; order: 0; }
  .topbar > .importstrip {
    grid-column: 1 / -1;
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: visible;
    order: 0;
  }
  .importstrip > * { min-width: 0; max-width: 100%; }
  .importstrip #chooseAudio,
  .importstrip #filename,
  .importstrip #analyze,
  .importstrip #enableAudio { grid-column: 1 / -1; width: 100%; flex: none; order: 0; }
  .importstrip #filename { white-space: normal; overflow-wrap: anywhere; padding: 2px 4px; }
  .importstrip .tempo { border-left: 0; padding-left: 0; order: 0; }
  .importstrip .tempo input,
  .importstrip .tempo select { min-width: 0; max-width: 100%; }
  .importstrip #playOriginal,
  .importstrip #stopOriginal { width: 100%; flex: none; order: 0; white-space: normal; padding: 8px 4px; }
}

/* The source/MIDI transport stays directly between the trim controls and note lanes. */
.near-grid-transport {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-top: 1px solid #5c655f;
  border-bottom: 1px solid #5c655f;
  background: linear-gradient(110deg, #202925, #101917);
}
.near-grid-heading { display: flex; flex-direction: column; gap: 2px; min-width: 130px; }
.near-grid-heading strong { color: #f1d39e; font: 700 12px 'Space Grotesk', sans-serif; letter-spacing: .12em; }
.near-grid-heading span { color: #b7c4bd; font-size: 11px; line-height: 1.35; }
.near-grid-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.near-grid-actions .compare { padding: 0; border: 0; }
.near-grid-actions button { min-height: 40px; padding: 8px 12px; white-space: nowrap; }
.near-grid-actions #playOriginal { color: #f6e4c4; border-color: #c09259; background: linear-gradient(#5b452c, #32261d); }
.near-grid-actions #play { color: #fff; border-color: #dc6d74; background: linear-gradient(#ac4650, #6e242f); }
.near-grid-actions #stop { border-color: #8b6c6b; }
.near-grid-actions #enableAudio { font-size: 11px; min-height: 32px; }
#stopOriginal[hidden] { display: none !important; }

@media (max-width: 850px) {
  .near-grid-transport { align-items: stretch; flex-direction: column; }
  .near-grid-heading { flex-direction: row; flex-wrap: wrap; gap: 5px 10px; }
  .near-grid-actions { justify-content: stretch; }
}
@media (max-width: 650px) {
  .near-grid-transport { padding: 10px; }
  .near-grid-heading { display: block; }
  .near-grid-heading strong { display: block; }
  .near-grid-heading span { display: block; margin-top: 3px; }
  .near-grid-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .near-grid-actions #playOriginal { grid-column: 1; grid-row: 1; width: 100%; }
  .near-grid-actions #play { grid-column: 2; grid-row: 1; width: 100%; }
  .near-grid-actions .compare { grid-column: 1 / -1; grid-row: 2; min-width: 0; }
  .near-grid-actions .compare > label { display: block; }
  .near-grid-actions .compare select { width: 100%; }
  .near-grid-actions .check { grid-column: 1; grid-row: 3; }
  .near-grid-actions #stop { grid-column: 2; grid-row: 3; }
  .near-grid-actions #enableAudio { grid-column: 1 / -1; grid-row: 4; }
  .near-grid-actions button { min-width: 0; white-space: normal; }
}
