/* Shared styles across all instrument apps */

/* ========== RESET ========== */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: manipulation;
}

/* ========== BASE VARIABLES (can be overridden per-app) ========== */

:root {
    --toolbar-bg: rgba(0, 0, 0, 0.35);
    --toolbar-border: rgba(255,255,255,0.12);
    --text: #fff;
    --text-dim: rgba(255,255,255,0.5);
    --btn-bg: rgba(255,255,255,0.1);
    --btn-hover: rgba(255,255,255,0.18);
}

/* ========== TOOLBAR ========== */

#toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 16px;
    margin: 10px 12px 0;
    background: var(--toolbar-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--toolbar-border);
    border-radius: 14px;
    flex-shrink: 0;
    /* backdrop-filter already creates a stacking context here, but without an
       explicit z-index the toolbar paints in document order — meaning the
       later #song-row (and its absolutely-positioned #key-display, now
       anchored left) draws on top of the dropdown-menu that opens downward
       from the app-icon button. Lifting the toolbar above subsequent content
       keeps the open dropdown from being sliced by the transposer. */
    position: relative;
    z-index: 50;
}

.app-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.3px;
    white-space: nowrap;
}

#toolbar .spacer {
    flex: 1;
    min-width: 4px;
}

.toolbar-btn {
    background: var(--btn-bg);
    border: none;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
}

.toolbar-btn:hover {
    background: var(--btn-hover);
}

.toolbar-btn:active {
    transform: scale(0.95);
}

/* ========== DROPDOWN MENU ========== */

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 8px;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 12px;
    padding: 8px;
    display: none;
    flex-direction: column;
    gap: 4px;
    min-width: 200px;
    z-index: 100;
}

.dropdown-menu.open {
    display: flex;
}

.menu-item {
    padding: 10px 14px;
    border-radius: 8px;
    text-decoration: none;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 10px;
}

.menu-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.menu-item:hover {
    background: rgba(255,255,255,0.12);
}

/* ========== SONG ROW / TITLE ========== */

#song-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
    flex-shrink: 0;
    width: 100%;
    padding: 12px 20px;
}

.song-close-btn {
    background: rgba(255, 255, 255, 0.25);
    border: none;
    color: rgba(255, 255, 255, 0.85);
    font-size: 20px;
    font-weight: 600;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
    /* Float against the title pill's right edge without participating in
       the flex layout — otherwise the pill + X are centered as a group and
       the title drifts left whenever a song is active. Requires the
       containing `#song-bar` to be `position: relative`. */
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 6px;
}
.song-close-btn:hover { background: rgba(255, 255, 255, 0.35); }
.song-close-btn:active { transform: translateY(-50%) scale(0.9); }

#song-title-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0.35em 0.6em;
    background: var(--song-chip-bg, rgba(255, 255, 255, 0.18));
    border-radius: 12px;
}

#song-title-wrapper:hover {
    background: var(--song-chip-hover, rgba(255, 255, 255, 0.25));
}

#song-title {
    font-family: "SF Pro Rounded", ui-rounded, system-ui, sans-serif;
    font-size: 40px;
    font-weight: 700;
    letter-spacing: -0.5px;
    text-align: center;
    pointer-events: none;
}

#song-title-wrapper select {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    font-size: 16px;
    margin: 0;
    padding: 0;
    border: none;
}

/* ========== KEY DISPLAY ========== */

#key-display {
    position: absolute;
    /* Anchor to the left so the transposer visually lines up with the
       clef + key signature at the left edge of the staff below. */
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    background: var(--song-chip-bg, rgba(255, 255, 255, 0.18));
    border-radius: 12px;
    padding: 4px 6px;
}

#key-display.visible {
    opacity: 1;
    pointer-events: auto;
}

.key-step-btn {
    background: none;
    border: none;
    color: inherit;
    font-size: 20px;
    line-height: 1;
    padding: 6px 8px;
    cursor: pointer;
    transition: background 0.15s;
}

.key-step-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.key-step-btn:active {
    transform: scale(0.9);
}

#key-display-btn {
    font-family: "SF Pro Rounded", ui-rounded, system-ui, sans-serif;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: none;
    border: none;
    padding: 0 4px;
    line-height: 1.1;
    color: inherit;
    min-width: 48px;
    text-align: center;
}

/* ========== LYRICS AREA ========== */

#lyrics-area {
    display: none;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 0 16px 10px;
    flex-shrink: 0;
}

#lyrics-area.visible {
    display: flex;
}

.lyrics-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
}

.lyrics-word {
    display: flex;
    align-items: stretch;
}

.lyric-btn {
    background: var(--btn-bg, rgba(255,255,255,0.2));
    border: none;
    color: var(--text, #fff);
    font-family: "SF Pro Rounded", ui-rounded, system-ui, sans-serif;
    font-size: 18px;
    font-weight: 600;
    padding: 4px 10px;
    cursor: pointer;
    transition: background 0.06s, transform 0.06s;
    line-height: 1.2;
    touch-action: manipulation;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lyric-btn:hover {
    background: var(--btn-hover, rgba(255,255,255,0.3));
}

.lyric-btn.active {
    background: rgba(255, 255, 255, 0.9);
    color: var(--instrument-color);
    transform: scale(0.95);
}

.lyrics-word .lyric-btn + .lyric-btn { margin-left: -1px; }

.lyrics-word .lyric-btn:first-child {
    border-radius: 24px 0 0 24px;
    padding-left: 14px;
}

.lyrics-word .lyric-btn:last-child {
    border-radius: 0 24px 24px 0;
    padding-right: 14px;
}

.lyrics-word .lyric-btn:only-child {
    border-radius: 24px;
    padding: 4px 14px;
}

.lyrics-word .lyric-gap {
    width: 6px;
    background: var(--btn-bg, rgba(255,255,255,0.2));
    pointer-events: none;
}

.lyrics-word .lyric-dash {
    color: var(--text-dim, rgba(255,255,255,0.5));
    font-family: "SF Pro Rounded", ui-rounded, system-ui, sans-serif;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.2;
    background: var(--btn-bg, rgba(255,255,255,0.2));
    padding: 4px 0;
    pointer-events: none;
    display: flex;
    align-items: center;
}

.lyric-sub {
    font-size: 14px;
    font-weight: 600;
    opacity: 0.62;
    margin-top: 2px;
}

.lyric-midi {
    font-size: 9px;
    font-weight: 500;
    opacity: 0.5;
    margin-bottom: 2px;
}

/* ========== HAMBURGER MENU ========== */

#menu-toggle {
    display: none;
    font-size: 18px;
    padding: 4px 10px;
}

@media (max-width: 800px) {
    #menu-toggle {
        display: block;
    }
}

/* ========== RESPONSIVE ========== */

@media (max-width: 800px) {
    #key-display-btn { font-size: 20px; }
}

@media (max-width: 600px) {
    #song-row {
        flex-direction: column;
        gap: 4px;
        padding-bottom: 8px;
    }
    #key-display {
        position: static;
        transform: none;
        align-self: center;
    }
    #key-display-btn { font-size: 18px; }
    .key-step-btn { font-size: 16px; }
}

/* ========== TAP TO START OVERLAY ========== */

#tap-to-start {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
    transition: opacity 0.3s;
}

#tap-to-start.hidden {
    opacity: 0;
    pointer-events: none;
}

#tap-to-start span {
    font-family: "SF Pro Rounded", ui-rounded, system-ui, sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    background: rgba(255, 255, 255, 0.18);
    padding: 16px 36px;
    border-radius: 999px;
    letter-spacing: 0.5px;
    user-select: none;
    -webkit-user-select: none;
}

/* ========== RECORDING CONTROLS ========== */

#rec-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rec-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    transition: transform 0.15s;
    flex-shrink: 0;
}
.rec-toggle:active { transform: scale(0.95); }
.rec-toggle:disabled { opacity: 0.3; pointer-events: none; }

span.rec-swatch {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 4px solid #fff;
    background: var(--btn-bg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.rec-swatch svg {
    width: 60%;
    height: 60%;
}

.rec-swatch svg .rec-square,
.rec-swatch svg .rec-play,
.rec-swatch svg .rec-pause { display: none; }

.rec-toggle.recording .rec-swatch { border-color: transparent; }
.rec-toggle.recording svg .rec-circle { display: none; }
.rec-toggle.recording svg .rec-square { display: block; animation: pulse 0.8s ease-in-out infinite; }

.rec-toggle.stopped .rec-swatch { border-color: transparent; }
.rec-toggle.stopped svg .rec-circle { display: none; }
.rec-toggle.stopped svg .rec-play { display: block; }

.rec-toggle.playing .rec-swatch { border-color: transparent; }
.rec-toggle.playing svg .rec-circle { display: none; }
.rec-toggle.playing svg .rec-pause { display: block; }

.rec-restart-btn {
    background: var(--btn-bg);
    border: none;
    color: rgba(255,255,255,0.85);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.15s;
    flex-shrink: 0;
}
.rec-restart-btn:hover { background: var(--btn-hover); }
.rec-restart-btn:active { transform: scale(0.9); }
.rec-restart-btn:disabled { opacity: 0.5; pointer-events: none; }
.rec-restart-btn svg {
    width: 65%;
    height: 65%;
    fill: rgba(255,255,255,0.85);
}

.rec-close-btn {
    background: var(--btn-bg);
    border: none;
    color: rgba(255,255,255,0.85);
    font-size: 18px;
    font-weight: 600;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.15s;
    flex-shrink: 0;
}
.rec-close-btn:hover { background: var(--btn-hover); }
.rec-close-btn:active { transform: scale(0.9); }
.rec-close-btn:disabled { opacity: 0.5; pointer-events: none; }

/* ========== NOTATION NAV ========== */

.notation-nav {
    display: none;
    max-width: 540px;
    width: 100%;
    margin: 0 auto;
    padding: 4px 0 8px;
    gap: 10pt;
}

.notation-nav.visible {
    display: flex;
}

.notation-nav-btn {
    /* Match the translucent tone of the muted-fingering placeholder pills so
       the two controls read as the same visual weight. */
    background: rgba(255, 255, 255, 0.3);
    border: none;
    color: #fff;
    height: 48px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
    flex: 1 1 0;
    min-width: 0;
}

/* Prev, replay, and next stay square; the iconless "space" button stretches to fill. */
#notation-prev,
#notation-replay,
#notation-next {
    flex: 0 0 48px;
    width: 48px;
}

.notation-nav-btn svg {
    width: 28px;
    height: 28px;
    fill: none;
    stroke: currentColor;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.notation-nav-btn:active,
.notation-nav-btn.key-active {
    transform: scale(0.95);
}

.notation-nav-btn:disabled {
    opacity: 0.25;
    pointer-events: none;
}

/* ========== NOTATION STRIP ========== */

.notation-scroll {
    display: none;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    flex-shrink: 0;
    /* Horizontal gutter lives on the scroller (not flex-centered margins on
       the inner), so scrollLeft=0 always aligns the viewport with the real
       leading edge of the staff on all browsers. */
    padding: 4px 13px 9px;
}

/* Notation scrollbar styling. Shared between the single-SVG layout (ilophone,
   piano-without-sticky-clef) and sticky-header mode (bandonion, piano-with-
   sticky-clef) so long pieces always get the same translucent 8px indicator
   at the bottom regardless of which layout the instrument picks. */
.notation-scroll::-webkit-scrollbar,
.notation-notes-scroll::-webkit-scrollbar {
    height: 8px;
}

.notation-scroll::-webkit-scrollbar-track,
.notation-notes-scroll::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.notation-scroll::-webkit-scrollbar-thumb,
.notation-notes-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.notation-scroll::-webkit-scrollbar-thumb:hover,
.notation-notes-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

.notation-scroll,
.notation-notes-scroll {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) rgba(255, 255, 255, 0.1);
}

/* Avoid `display:flex; justify-content: safe center` here: `safe` is poorly
   supported (Safari often behaves like plain `center`), which centers
   overflowing notation and makes the true start unreachable at scrollLeft=0.
   Block layout + `width:fit-content; margin-inline:auto` on `.notation-inner`
   centers short strips and left-aligns the scroll origin when content is wide. */
.notation-scroll.visible {
    display: block;
}

.notation-inner {
    display: block;
    width: fit-content;
    margin: 0 auto;
    background: var(--notation-bg, rgba(255,255,255,0.95));
    border-radius: 12px;
    color: var(--notation-text, #222);
    padding: 8px 0;
    box-shadow: 0 1px 4px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.08);
}

/* Mobile / short-window size: the clarinet and notation compete for vertical
   space, so shrink the notation to 80% whenever the viewport is tight. `zoom`
   (unlike `transform: scale`) shrinks the actual laid-out size, so the strip
   takes proportionally less vertical room instead of leaving blank space. */
@media (max-width: 600px), (max-height: 800px) {
    .notation-inner {
        zoom: 0.8;
    }
}

.notation-inner svg {
    display: block;
}

/* Sticky-header mode: the notation card becomes a two-item HStack — a static
   clef/key-signature panel on the left and a horizontally-scrolling notes
   view on the right. The card is a single rounded container sized to content
   (up to the available width); both left and right edges are rounded. When
   notes overflow the available width they scroll inside `.notation-notes-scroll`
   while the clef panel stays put. */
.notation-inner.sticky-header-mode {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
    /* Unified card styling stays on the parent so both edges share one radius. */
    overflow: hidden;
}

.notation-header-panel {
    flex-shrink: 0;
    position: relative;
    z-index: 2;
    padding: 8px 0;
    /* Shadow fades in while notes are scrolled past the start, reinforcing
       that the clef floats above the scrolling content. */
    transition: box-shadow 0.18s ease-out;
}

.notation-header-panel.scrolled {
    box-shadow: 6px 0 14px -4px rgba(0, 0, 0, 0.28);
}

.notation-notes-scroll {
    /* Shrink to fit the notes SVG; cap at the parent's available width so long
       songs trigger horizontal scrolling inside this element. The translucent
       8px scrollbar styling is shared with `.notation-scroll` above so the
       sticky-header layout gets the same scroll indicator as ilophone. */
    flex: 0 1 auto;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    padding: 8px 0;
}

.notation-note-col {
    cursor: pointer;
    touch-action: pan-x pan-y;
}

.notation-note-col:hover ellipse {
    opacity: 0.7;
}

/* Dark mode notation */
.color-invert .notation-inner,
.dark-bg .notation-inner {
    background: var(--notation-bg-dark, rgba(40,40,44,0.95));
    color: var(--notation-text-dark, #e8e8e8);
    --notation-label-color: #333;
}

/* ========== UTILITY ========== */

.flex-spacer {
    flex: 1;
}
