/* ============================================
   MidiMath — Clean Calculator Theme
   ============================================ */

/* ---------- Custom Properties ---------- */
:root {
    /* Dark monospace palette */
    --bg-primary: #0a0a0a;
    --bg-secondary: #141414;
    --bg-tertiary: #1a1a1a;
    --text-primary: #e0e0e0;
    --text-secondary: #888888;
    --text-tertiary: #505050;
    --border: #404040;
    --border-light: #303030;

    /* Accent */
    --accent: #c0c0c0;
    --accent-hover: #e0e0e0;
    --accent-glow: rgba(255, 255, 255, 0.2);

    /* Functional colors */
    --success: #35e335;
    --warning: #c0c0c0;
    --danger: #e82828;

    /* Layout */
    --touch-min: 40px;
    --button-radius: 4px;
    --card-radius: 6px;
    --container-padding: 20px;
    --section-gap: 16px;

    /* Animation */
    --bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
    --smooth: cubic-bezier(0.4, 0, 0.2, 1);

    /* Safe areas */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    /* Card shadow */
    --card-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    --card-shadow-hover: 0 5px 20px rgba(0, 0, 0, 0.9);
}

/* ---------- Reset & Base ---------- */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'IBM Plex Mono', 'Courier New', monospace;
    font-weight: 400;
    margin: 0;
    padding: 0;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Container ---------- */
.container {
    max-width: 540px;
    margin: 0 auto;
    padding: var(--container-padding);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* ---------- H1 Logo ---------- */
h1 {
    margin: 0;
    padding-top: 6px;
    padding-left: 4px;
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0;
}

/* ---------- Title Row ---------- */
.title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: var(--section-gap);
}

input.title-input {
    flex: 1;
    min-width: 150px;
    max-width: 400px;
    margin: 0;
    background: #141414;
    color: #f0f0f0;
    border: 1px solid #404040;
    border-radius: 6px;
    padding: 10px 12px;
    height: 40px !important;
    font-family: inherit;
    font-size: 14px;
    transition: all 0.3s;
    box-sizing: border-box;
    text-align: left;
}

input.title-input::placeholder {
    color: #606060;
}

input.title-input:focus {
    outline: none;
    border-color: #00ff00;
    background-color: #1a1a1a;
}

/* ---------- Player Controls ---------- */
.player-controls {
    display: none;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.player-controls.active {
    display: flex;
}

.small-player-btn {
    width: var(--touch-min);
    height: var(--touch-min);
    min-width: var(--touch-min);
    border-radius: 4px;
    font-size: 18px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #0a0a0a;
    background: linear-gradient(to bottom, #141414 0%, #1c1c1c 50%, #141414 100%);
    color: var(--text-primary);
    cursor: pointer;
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.small-player-btn:hover {
    transform: translateY(-1px);
    box-shadow: 
        0 2px 5px rgba(0, 0, 0, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.small-player-btn:active {
    transform: translateY(0px);
    box-shadow: 
        0 1px 2px rgba(0, 0, 0, 0.7),
        inset 0 1px 2px rgba(0, 0, 0, 0.3);
}

.small-player-btn svg {
    width: 18px;
    height: 18px;
}

/* Active states for toolbar buttons */
.small-player-btn.eraser-active,
.small-player-btn.loop-active,
.small-player-btn.volume-active,
.small-player-btn.play-active {
    background: #101010;
    color: #e0e0e0;
    border-color: #707070;
    border-width: 2px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.85), inset 0 -1px 0 rgba(255, 255, 255, 0.06);
}

.small-player-btn.eraser-active:active,
.small-player-btn.loop-active:active,
.small-player-btn.volume-active:active,
.small-player-btn.play-active:active {
    background: #141414;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.85), inset 0 -1px 0 rgba(255, 255, 255, 0.08);
}

/* ---------- Play Button - Primary Action ---------- */
#playBtn {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

#playBtn:active {
    background: var(--bg-tertiary);
}

#playBtn.play-active {
    background: #101010;
    border-color: #707070;
    border-width: 2px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.85);
}

/* ---------- Header Row ---------- */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
}

/* ---------- Help Button ---------- */
.about-details {
    margin: 0;
    border: none;
    background: transparent;
    position: relative;
    z-index: 100;
}

.about-details summary {
    padding: 6px 12px;
    cursor: pointer;
    color: var(--accent);
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    list-style: none;
    background: var(--bg-secondary);
    border-radius: var(--button-radius);
    box-shadow: var(--card-shadow);
    transition: transform 0.3s var(--bounce), box-shadow 0.2s var(--smooth);
}

.about-details summary:active {
    transform: scale(0.92);
}

.about-details summary::-webkit-details-marker {
    display: none;
}

.about-content {
    position: absolute;
    right: 0;
    top: 36px;
    width: 300px;
    max-width: calc(100vw - 32px);
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow-hover);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
    animation: popIn 0.3s var(--bounce);
}

.about-content p {
    margin: 0 0 12px 0;
}

.about-content p:last-child {
    margin-bottom: 0;
}

.hotkey {
    display: inline-block;
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 3px 8px;
    font-size: 12px;
    font-family: 'Nunito', monospace;
    font-weight: 700;
    color: var(--text-primary);
}

/* ---------- Visualizer ---------- */
.visualizer {
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: var(--card-radius);
    padding: 0;
    margin-bottom: var(--section-gap);
    overflow: hidden;
    position: relative;
    cursor: pointer;
    box-shadow: var(--card-shadow);
}

.visualizer-display-wrapper {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-radius: calc(var(--card-radius) - 2px);
}

.visualizer canvas {
    width: 100%;
    height: 180px;
    background: #000000;
    display: block;
    border-radius: calc(var(--card-radius) - 2px);
}

#playbackLine {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 1px;
    background: #808080;
    pointer-events: none;
    z-index: 10;
    box-shadow: none;
}

.visualizer.eraser-mode {
    cursor: crosshair;
}

.eraser-preview {
    position: absolute;
    border: 2px solid rgba(255, 100, 100, 0.8);
    background: transparent;
    pointer-events: none;
    border-radius: 50%;
    z-index: 15;
    display: none;
}

.visualizer.eraser-mode .eraser-preview {
    display: block;
}

/* ---------- Algorithm Selector ---------- */
.algorithm-selector {
    margin-bottom: -5px;
}

.algorithm-selector select {
    width: 100%;
    height: 44px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--border);
    border-bottom: none;
    border-radius: var(--card-radius) var(--card-radius) 0 0;
    padding: 0 44px 0 20px;
    font-family: inherit;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23808080' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 18px center;
    background-size: 16px;
    transition: box-shadow 0.2s var(--smooth);
}

.algorithm-selector select:focus {
    outline: none;
    box-shadow: 0 0 0 4px var(--accent-glow);
}

/* ---------- Controls Panel ---------- */
.controls {
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-top: none; /* shared edge with algorithm selector above */
    padding: 20px;
    border-radius: 0 0 var(--card-radius) var(--card-radius);
    margin-bottom: var(--section-gap);
    box-shadow: var(--card-shadow);
}

/* ---------- Control Rows ---------- */
.control-row {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 14px;
}

.control-row:last-child {
    margin-bottom: 0;
}

/* ---------- Slider Control Groups ---------- */
.control-group {
    flex: 1 1 calc(50% - 7px);
    min-width: 140px;
    display: flex;
    flex-direction: column;
}

.control-group label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

/* ---------- Sliders ---------- */
/* app.js sets inline background gradient on the element for track fill.
   Keep element height = 6px (track size), thumb overflows via overflow:visible.
   margin-top on thumb centers it vertically over the thin track. */
input[type="range"] {
    width: 100%;
    height: 2px;
    background: var(--bg-tertiary);
    border-radius: 1px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    overflow: visible;
    margin: 12px 0; /* vertical breathing room for overflowing thumb */
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 2px;
    background: transparent; /* track fill comes from inline style on the element */
    border-radius: 1px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 32px;
    height: 35px;
    background: 
        repeating-linear-gradient(
            90deg,
            #2a2a2a 0px,
            #383838 1px,
            #454545 2px,
            #383838 3px,
            #2a2a2a 4px
        ),
        linear-gradient(to right, 
            #252525 0%, 
            #353535 20%,
            #505050 50%, 
            #353535 80%,
            #252525 100%);
    border-radius: 3px;
    cursor: pointer;
    border: 1px solid #0a0a0a;
    box-shadow: 
        0 3px 8px rgba(0, 0, 0, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        inset 0 -1px 0 rgba(0, 0, 0, 0.5);
    margin-top: -16.5px;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: translateY(-1px);
    box-shadow: 
        0 4px 10px rgba(0, 0, 0, 0.7),
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        inset 0 -1px 0 rgba(0, 0, 0, 0.5);
}

input[type="range"]::-webkit-slider-thumb:active {
    transform: translateY(0px);
    box-shadow: 
        0 2px 6px rgba(0, 0, 0, 0.8),
        inset 0 2px 3px rgba(0, 0, 0, 0.4),
        inset 0 -1px 0 rgba(255, 255, 255, 0.05);
}

input[type="range"]::-moz-range-track {
    height: 2px;
    background: var(--bg-tertiary);
    border-radius: 1px;
}

input[type="range"]::-moz-range-thumb {
    width: 32px;
    height: 35px;
    background: 
        repeating-linear-gradient(
            90deg,
            #2a2a2a 0px,
            #383838 1px,
            #454545 2px,
            #383838 3px,
            #2a2a2a 4px
        ),
        linear-gradient(to right, 
            #252525 0%, 
            #353535 20%,
            #505050 50%, 
            #353535 80%,
            #252525 100%);
    border-radius: 3px;
    cursor: pointer;
    border: 1px solid #0a0a0a;
    box-shadow: 
        0 3px 8px rgba(0, 0, 0, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        inset 0 -1px 0 rgba(0, 0, 0, 0.5);
}

input[type="range"]:focus {
    outline: none;
}

input[type="range"]:focus::-webkit-slider-thumb {
    /* Keep same appearance on focus */
}

input[type="range"]:focus::-moz-range-thumb {
    /* Keep same appearance on focus */
}

/* ---------- Inline Control Groups ---------- */
.control-group-inline {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    width: 100%;
}

.control-group-inline label {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 0;
    white-space: nowrap;
}

.control-group-inline select {
    flex: 1;
    min-width: 0;
}

/* ---------- Select Dropdowns - Pill Shape ---------- */
select,
.small-select {
    height: 32px;
    min-height: 32px;
    padding: 0 32px 0 12px;
    background: linear-gradient(to bottom, #181818 0%, #202020 50%, #181818 100%);
    color: var(--text-primary);
    border: 1px solid #0a0a0a;
    border-radius: var(--button-radius);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23808080' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 14px;
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

select:hover,
.small-select:hover {
    transform: translateY(-1px);
    box-shadow: 
        0 2px 5px rgba(0, 0, 0, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

select:active,
.small-select:active {
    transform: translateY(0px);
    box-shadow: 
        0 1px 2px rgba(0, 0, 0, 0.7),
        inset 0 1px 2px rgba(0, 0, 0, 0.3);
}

select:focus,
.small-select:focus {
    outline: none;
}

option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

optgroup {
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-weight: bold;
}

/* ---------- Text Inputs ---------- */
input[type="text"] {
    height: 32px;
    padding: 0 12px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--button-radius);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    outline: none;
    transition: border-color 0.2s var(--smooth), box-shadow 0.2s var(--smooth);
}

input[type="text"]:not(.custom-input):focus {
    border-color: #808080;
    box-shadow: 0 0 5px rgba(255, 255, 255, 0.2);
}

input[type="text"]::placeholder {
    color: var(--text-tertiary);
    font-weight: 600;
}

/* ---------- Custom Progression Input ---------- */
.custom-input {
    flex: 1;
    min-width: 120px;
    text-align: left;
    padding: 0 14px;
    height: 40px !important;
    min-height: 40px !important;
    background: #161616 !important;
    border: 1px solid #0a0a0a !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.custom-input:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.6);
}

.custom-input:focus {
    outline: none;
    border-color: #0a0a0a !important;
    background: #161616 !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.custom-input:disabled {
    opacity: 0.4;
}

/* ---------- Seed/Octave Button Groups ---------- */
.seed-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    flex: 1 1 calc(50% - 9px);
    min-width: 0;
}

.seed-container label {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
}

.seed-input-wrapper {
    display: flex;
    align-items: center;
    border: 1px solid #0a0a0a;
    border-radius: 4px;
    overflow: hidden;
    background: #161616;
    width: 100%;
    height: 32px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.seed-input-wrapper:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.6);
}

.seed-input-wrapper input[type="text"] {
    border: none;
    border-radius: 0;
    margin: 0;
    height: 32px;
    flex: 1;
    min-width: 0;
    background: transparent;
    color: var(--text-primary);
}

.seed-input-wrapper input[type="text"]:focus {
    box-shadow: none;
    outline: none;
}

.seed-btn {
    background: transparent;
    color: #808080;
    border: none;
    width: 30%;
    height: 32px;
    padding: 0;
    font-size: 14px;
    cursor: pointer;
    font-family: 'IBM Plex Mono', 'Courier New', monospace;
    font-weight: bold;
    display: flex;
    align-items: center;
}

.seed-btn:first-child {
    justify-content: flex-start;
    padding-left: 8px;
}

.seed-btn:last-child {
    justify-content: flex-end;
    padding-right: 8px;
}

.seed-btn:hover,
.seed-btn:active,
.seed-btn:focus {
    color: #808080 !important;
    background: transparent !important;
    outline: none;
}

.seed-input-wrapper .seed-btn {
    border: none;
    border-radius: 0;
    height: 32px;
    width: 36px;
    min-width: 36px;
    margin: 0;
    padding: 0 6px;
}

.seed-input-wrapper .seed-btn:hover {
    box-shadow: none;
    background: #e0e0e0;
    color: #0a0a0a;
}

/* ---------- Octave Display ---------- */
#octaveShiftValue {
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    flex: 1;
    min-width: 0;
    text-align: center;
    background: transparent;
    border: none;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---------- Toggle Switches ---------- */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
    padding: 8px 0;
    margin-right: 15px;
}

.toggle-label:last-child {
    margin-right: 0;
}

.toggle-label input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border: 2px solid #505050;
    border-radius: 3px;
    background: var(--bg-tertiary);
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.toggle-label input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

.toggle-label input[type="checkbox"]:checked + span {
    color: var(--text-primary);
}

.toggle-label:hover input[type="checkbox"] {
    border-color: #808080;
}

/* ---------- Key/Scale Group ---------- */
.key-scale-group {
    flex: 1;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.mobile-grid-wrapper {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    flex: 1;
}

.mobile-grid-wrapper select {
    flex: 1;
    min-width: 80px;
}

/* ---------- Progression Row ---------- */
.progression-row {
    flex-direction: column;
    gap: 10px;
}

.progression-input-container {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
}

/* ---------- Instrument Row ---------- */
.instrument-row {
    padding-top: 12px;
    border-top: 2px solid var(--border-light);
}

/* ---------- Transforms Row ---------- */
.transforms-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 18px;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0 0 12px 0;
}

/* ---------- Tooltip ---------- */
.label-with-tooltip {
    display: flex;
    align-items: center;
}

.tooltip-details {
    display: inline-block;
    position: relative;
    margin-left: 8px;
}

.tooltip-summary {
    cursor: pointer;
    color: var(--text-tertiary);
    font-size: 13px;
    font-weight: 800;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: 50%;
    list-style: none;
    transition: transform 0.2s var(--bounce);
}

.tooltip-summary:active {
    transform: scale(0.88);
}

.tooltip-summary::-webkit-details-marker {
    display: none;
}

.tooltip-content {
    position: absolute;
    bottom: 34px;
    left: 50%;
    transform: translateX(-50%);
    width: 250px;
    background: var(--bg-secondary);
    border-radius: var(--card-radius);
    padding: 16px;
    box-shadow: var(--card-shadow-hover);
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
    z-index: 1000;
    animation: popIn 0.3s var(--bounce);
}

.tooltip-content ul {
    padding-left: 16px;
    margin: 8px 0;
}

/* ---------- Load / Preset Dropdown ---------- */
.load-wrapper {
    position: relative;
}

.preset-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 220px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow-hover);
    z-index: 200;
    overflow: hidden;
    animation: popInDown 0.2s var(--bounce);
}

.preset-dropdown.open {
    display: block;
}

.preset-item {
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.1s;
}

.preset-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.preset-item-file {
    color: var(--accent);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

/* ---------- Volume Popup ---------- */
.volume-control-wrapper {
    position: relative;
}

.volume-popup {
    position: absolute;
    top: 56px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    padding: 18px 14px;
    border-radius: var(--card-radius);
    display: none;
    box-shadow: var(--card-shadow-hover);
    z-index: 100;
    height: 170px;
    animation: popIn 0.3s var(--bounce);
}

.volume-popup.active {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.volume-popup input[type="range"] {
    writing-mode: bt-lr;
    -webkit-appearance: slider-vertical;
    width: 28px;
    height: 130px;
    padding: 0;
    margin: 0;
}

/* ---------- Settings Panel (Collapsible) ---------- */
.settings-panel {
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: var(--card-radius);
    margin-bottom: var(--section-gap);
    overflow: hidden;
    box-shadow: var(--card-shadow);
}

.settings-panel summary {
    padding: 18px 20px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s var(--smooth);
}

.settings-panel summary:active {
    background: var(--bg-tertiary);
}

.settings-panel summary::-webkit-details-marker {
    display: none;
}

.settings-panel summary::after {
    content: '';
    width: 7px;
    height: 7px;
    border-right: 2px solid #808080;
    border-bottom: 2px solid #808080;
    transform: rotate(45deg);
    transition: transform 0.3s var(--bounce);
}

.settings-panel[open] summary::after {
    transform: rotate(-135deg);
}

.settings-content {
    padding: 0 20px 20px;
}

/* ---------- Footer ---------- */
.app-footer {
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    padding: 20px 0;
    margin-top: auto;
}

.app-footer a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
    transition: opacity 0.15s;
}

.app-footer a:hover {
    opacity: 0.8;
}

.app-footer .separator {
    margin: 0 10px;
    color: var(--text-tertiary);
}

/* ---------- Animations ---------- */
@keyframes popIn {
    0% {
        opacity: 0;
        transform: translateX(-50%) scale(0.9);
    }
    100% {
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }
}

/* About content pop-in (no translateX needed since it's right-aligned) */
.about-details[open] .about-content {
    animation: popInRight 0.3s var(--bounce);
}

@keyframes popInDown {
    0% {
        opacity: 0;
        transform: scale(0.95) translateY(-4px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes popInRight {
    0% {
        opacity: 0;
        transform: scale(0.9) translateY(-4px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ---------- Mobile Adjustments ---------- */
@media (max-width: 600px) {
    .container {
        padding: 12px;
    }

    h1 {
        font-size: 24px;
        margin-bottom: 0;
    }

    .title-row {
        flex-wrap: nowrap;
        gap: 6px;
        margin-bottom: 12px;
    }

    .title-input {
        flex: 1 1 auto;
        max-width: none;
        margin-bottom: 0;
        min-width: 60px;
        height: 40px;
        font-size: 14px;
        padding: 0 12px;
    }

    .player-controls {
        gap: 4px;
    }

    /* Touch targets for player buttons */
    .small-player-btn {
        width: 40px;
        min-width: 40px;
        height: 40px;
    }

    .visualizer {
        margin-bottom: 12px;
        border-radius: 6px;
    }

    .visualizer canvas {
        border-radius: 5px;
    }


    .algorithm-selector select {
        height: 40px;
        font-size: 15px;
        padding: 0 36px 0 14px;
        border-radius: 6px 6px 0 0;
    }

    .controls {
        padding: 14px;
        border-radius: 0 0 6px 6px;
        margin-bottom: 12px;
    }

    .control-row {
        gap: 10px;
        margin-bottom: 14px;
    }

    .control-group {
        flex: 1 1 calc(50% - 5px);
        min-width: 0;
    }

    .transforms-row .seed-container {
        flex: 1 1 calc(50% - 5px);
    }

    .toggle-label {
        flex: 0 0 auto;
    }

    .mobile-grid-wrapper {
        width: 100%;
    }

    .mobile-grid-wrapper select {
        flex: 1;
        min-width: 0;
        font-size: 13px;
        padding: 0 26px 0 10px;
    }

    #rootNote {
        flex: 0 0 auto;
        min-width: 56px;
    }

    .progression-input-container {
        width: 100%;
    }

    .progression-input-container .custom-input {
        flex: 1;
        min-width: 0;
        height: 40px !important;
    }

    .settings-panel {
        border-radius: 6px;
        margin-bottom: 12px;
    }

    .settings-panel summary {
        padding: 14px 16px;
        font-size: 15px;
    }

    .settings-content {
        padding: 0 16px 16px;
    }

    .about-details summary {
        padding: 5px 10px;
        font-size: 12px;
    }

    .about-content {
        width: 280px;
        padding: 16px;
        font-size: 13px;
    }
}

/* ---------- Desktop ---------- */
@media (min-width: 601px) {
    .container {
        max-width: 600px;
        padding: 24px;
    }

    .visualizer canvas {
        height: 200px;
    }

    .control-group {
        flex: 1 1 calc(25% - 11px);
    }

    .title-input {
        max-width: none;
        height: 40px;
    }
}

/* ---------- Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

@media (prefers-contrast: high) {
    :root {
        --border: #2D2235;
        --text-secondary: #2D2235;
        --bg-tertiary: #E0D5CC;
    }

    @media (prefers-color-scheme: dark) {
        :root {
            --border: #F0E6FF;
            --text-secondary: #F0E6FF;
            --bg-tertiary: #344270;
        }
    }
}
