/* ---- Phone / narrow windows: neck first, then the controls ---- */
@media (max-width: 1249px) {
    /* main-content children join the layout: neck on top, legend at the bottom */
    .main-content { display: contents; }
    .fretboard-wrapper { order: -3; }
    .now-playing { order: -2; }
    .board-hint { order: -3; }
    .view-bar { order: -1; width: 100%; }
    .quiz-panel { order: -1; width: 100%; }
    .legend-box { order: 1; width: 100%; max-width: 520px; }
    .controls-sidebar { width: 100%; max-width: 520px; }
}

/* ================= Phone ================= */
.phone-nav, .drawer-btn, .fab-play { display: none; }
.phone-actions { display: none; }
body.phone .phone-actions { display: flex; gap: 10px; justify-content: center; width: 100%; }
body.phone .phone-actions button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 46px; padding: 0 20px; font-size: 14px; font-weight: 800; border: none; border-radius: 23px;
}
body.phone .fab-play { background: var(--action); color: var(--on-action); min-width: 120px; }
body.phone .fab-play.playing { background: var(--deg-root); color: var(--on-deg-root); }
body.phone .drawer-btn { background: var(--surface-drawer-btn); color: var(--ink); border: 1px solid var(--control-border-feature) !important; }
body.phone.drawer-open .drawer-btn { background: var(--selected); color: var(--on-selected); }
body.phone .bar-play { display: none; }
body.phone.study .phone-actions, body.phone.build .phone-actions, body.phone.quiz .phone-actions, body.phone.findit .phone-actions { display: none; }
body.phone .fretboard-wrapper { order: -10; }
body.phone .phone-nav { order: -9; }
body.phone .phone-actions { order: -8; }
body.phone .controls-sidebar { order: -7; }
body.phone .board-hint { order: -6; }
body.phone .now-playing { order: -5; }
body.phone .quiz-panel { order: -4; }
body.phone .view-bar { order: -3; }
body.phone { padding: 10px; }
body.phone .app-layout { gap: 10px; }
body.phone .now-playing { margin-top: 0; }
body.phone .fretboard { min-width: 0; padding: 8px 8px 8px 8px; }
body.phone .fretboard-wrapper { overflow-x: hidden; padding-bottom: 6px; }
body.phone .num-row { margin-top: 4px; }
body.phone .fret-num-cell { font-size: 12px; }
body.phone .vb-group { border-left: none; padding-left: 0; }
body.phone .view-buttons { gap: 10px; }
body.phone .toggles { gap: 4px; }
body.phone .toggle-group { padding: 5px 6px; }
body.phone .toggle-group span { font-size: 0.6em; margin-bottom: 3px; }
body.phone .toggle-group button { padding: 4px 7px; }
body.phone .legend-box ul { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-flow: row; }
body.phone-portrait h1.brand { gap: 8px; margin-top: 2px; justify-content: flex-start; }
body.phone-portrait .brand-logo { width: 70px; height: 38px; }
body.phone-portrait .brand-word { font-size: 28px; }
body.phone-portrait p.subtitle { font-size: 9px; letter-spacing: 2.5px; margin-bottom: 12px; text-align: left; }
body.phone-land p.subtitle { display: none; }
body.phone-portrait .note { width: 32px; height: 32px; font-size: 12px; }

body.phone-portrait .phone-nav { display: flex; align-items: center; justify-content: center; gap: 14px; }
.phone-nav button { width: 52px; height: 44px; font-size: 16px; }
.phone-nav span { font-family: 'Oswald', sans-serif; font-size: 16px; letter-spacing: 1px; color: var(--action); min-width: 110px; text-align: center; }

/* inline controls, opened by the Controls button */
body.phone .controls-sidebar { display: none; width: 100%; max-width: none; }
body.phone.drawer-open .controls-sidebar { display: block; }
body.phone.lefty .fretboard { padding: 8px; }

/* header on phones: brand + buttons on one row, the modes below, scrollable */
body.phone .app-header { grid-template-columns: 1fr auto; gap: 8px 10px; margin-bottom: 10px; }
body.phone .modes { grid-column: 1 / -1; grid-row: 2; width: 100%; overflow-x: auto; }
body.phone .modes button { flex: 1 0 auto; padding: 8px 10px; font-size: 11px; }
body.phone #settings-btn span, body.phone #share-btn span { display: none; }
body.phone .settings-pop, body.phone .help-pop { right: 10px; left: 10px; width: auto; top: 96px; }
body.phone .rhythm-pop { left: auto; right: -40px; width: min(330px, calc(100vw - 30px)); }
body.phone .view-buttons { white-space: normal; }
body.phone-land .app-header p.subtitle { display: none; }
body.phone .play-group { flex-wrap: wrap; justify-content: center; row-gap: 6px; }

/* ================= Tablet (stacked, not a phone) ================= */
body.tablet .fretboard { min-width: 0; }
body.tablet .fretboard-wrapper { overflow-x: hidden; }
@media (max-width: 1100px) {
    body:not(.phone) .app-header { grid-template-columns: 1fr auto; gap: 10px 14px; }
    body:not(.phone) .modes { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
    body:not(.phone) .modes button { white-space: nowrap; }
}
