/* ---- 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, body.phone.keys .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; }
/* On a phone "What & where" opens as a sheet over the app: the rest is dimmed and blurred,
   so it is clear you are on another layer. Tap outside or Done to close. */
.drawer-backdrop, .sheet-head { display: none; }
body.phone.drawer-open { overflow: hidden; }
/* "Play across zones" only matters once two or more zones are picked on an upright phone */
body.phone-portrait.no-zones #run-mode { display: none; }
/* the layout sits under the header (z 10 vs 20): lift it while the sheet is open so the blur covers the header too */
body.phone.drawer-open .app-layout { z-index: 40; }
body.phone.drawer-open .drawer-backdrop {
    display: block; position: fixed; inset: 0; z-index: 290;
    background: rgba(8, 14, 21, .28);
    -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
    animation: sheet-fade .2s ease;
}
body.phone.drawer-open .controls-sidebar {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 300;
    max-height: 80vh; max-height: 80dvh; overflow-y: auto; overscroll-behavior: contain;
    background: var(--surface-ground); border-radius: 16px 16px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, .35);
    padding: 0 12px calc(16px + env(safe-area-inset-bottom, 0px));
    animation: sheet-up .25s ease;
}
body.phone.drawer-open .sheet-head {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 1; background: var(--surface-ground);
    padding: 14px 4px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line);
}
.sheet-head span { font-family: 'Oswald', sans-serif; font-size: 18px; letter-spacing: 1px; text-transform: uppercase; color: var(--ink); }
.sheet-head button { padding: 8px 18px; font-weight: 800; background: var(--action); color: var(--on-action); border-color: var(--action); }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes sheet-fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { body.phone.drawer-open .controls-sidebar, body.phone.drawer-open .drawer-backdrop { animation: none; } }
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; }
/* phone: Options opens as a sheet from the bottom, over the blurred app */
body.phone .rhythm-pop {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; z-index: 60;
    border-radius: 16px 16px 0 0; background: var(--surface-ground); border: 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, .35);
    padding: 0 16px calc(18px + env(safe-area-inset-bottom, 0px));
    animation: sheet-up .25s ease;
}
body.phone .rhythm-pop .pop-head { position: static; padding: 14px 0 10px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
body.phone .rhythm-pop .pop-head h4 { font-size: 18px; margin: 0; }
body.phone .rhythm-pop .seg button, body.phone .rhythm-pop .pop-row button { padding: 10px 6px; font-size: 12px; }
@media (prefers-reduced-motion: reduce) { body.phone .rhythm-pop { animation: none; } }
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; }
}
