/* === Beach Boys Palette === */
:root {
    --bg: #FFF8E7;
    --coral: #FF6B6B;
    --turquoise: #4ECDC4;
    --sky: #45B7D1;
    --navy: #2C3E50;
    --gray: #5D5D5D;
    --card-bg: #FFFFFF;
    --card-shadow: rgba(0, 0, 0, 0.08);
    --card-radius: 16px;
    --sunset-top: #FFECD2;
    --sunset-bottom: #FCB69F;
}

/* === Reset & Base === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(180deg, var(--sunset-top) 0%, var(--bg) 40%);
    color: var(--navy);
    min-height: 100dvh;
    overflow-x: hidden;
}

/* === Header === */
.header {
    text-align: center;
    padding: 2rem 1rem 1rem;
    background: linear-gradient(135deg, #FFECD2 0%, #FCB69F 50%, #FF9A9E 100%);
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 6px;
    background: repeating-linear-gradient(
        90deg,
        var(--coral) 0px,
        var(--coral) 20px,
        var(--turquoise) 20px,
        var(--turquoise) 40px,
        var(--sky) 40px,
        var(--sky) 60px,
        #FFD93D 60px,
        #FFD93D 80px
    );
}

.title {
    font-family: 'Pacifico', cursive;
    font-size: clamp(2.5rem, 6vw, 4rem);
    color: var(--navy);
    text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.5);
    letter-spacing: 0.02em;
}

.subtitle {
    font-size: 0.95rem;
    color: var(--gray);
    margin-top: 0.25rem;
    font-weight: 400;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* === Main Layout === */
.main {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 1.5rem;
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    align-items: start;
}

/* === Webcam Panel === */
.webcam-panel {
    position: sticky;
    top: 1.5rem;
}

.webcam-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: var(--card-radius);
    overflow: hidden;
    box-shadow: 0 8px 32px var(--card-shadow), 0 2px 8px rgba(0, 0, 0, 0.04);
    background: #1a1a2e;
}

#webcam {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: scaleX(-1);
    pointer-events: none;
}

.no-camera {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #ccc;
    font-size: 1.1rem;
    gap: 0.5rem;
}

.no-camera .small {
    font-size: 0.85rem;
    opacity: 0.7;
}

.fullscreen-btn {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
    z-index: 10;
}

.fullscreen-btn:hover {
    background: rgba(255, 107, 107, 0.8);
    transform: scale(1.1);
}

.fullscreen-icon {
    font-size: 1.3rem;
    line-height: 1;
}

.webcam-container:fullscreen {
    border-radius: 0;
}

.webcam-container:fullscreen .fullscreen-btn {
    bottom: 20px;
    right: 20px;
}

/* === Cards === */
.card {
    background: var(--card-bg);
    border-radius: var(--card-radius);
    padding: 1.5rem 2rem;
    box-shadow: 0 4px 20px var(--card-shadow), 0 1px 4px rgba(0, 0, 0, 0.04);
}

.controls-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* === Metrics === */
.metrics-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    text-align: center;
}

.metric {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.metric-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--gray);
    font-weight: 600;
}

.metric-value {
    font-size: clamp(1.4rem, 2.5vw, 2rem);
    font-weight: 700;
    transition: color 0.3s ease;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.frequency-value {
    color: var(--coral);
    font-variant-numeric: tabular-nums;
}

.volume-value {
    color: var(--turquoise);
    font-variant-numeric: tabular-nums;
}

.filter-value {
    color: var(--sky);
}

.metric-hint {
    font-size: 0.7rem;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* === Hand Rows === */
.hand-row {
    padding: 0.75rem 0;
    transition: opacity 0.3s;
}

.hand-row + .hand-row {
    border-top: 1px solid #f0e8d8;
}

.hand-row.hidden {
    display: none;
}

.hand-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    margin-bottom: 0.4rem;
}

.hand-badge.coral {
    background: rgba(255, 107, 107, 0.15);
    color: var(--coral);
}

.hand-badge.turquoise {
    background: rgba(78, 205, 196, 0.15);
    color: var(--turquoise);
}

/* === Settings Card === */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.75rem;
}

.setting {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.setting-wide {
    grid-column: span 2;
}

.setting label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--gray);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.setting-hint {
    font-weight: 400;
    font-size: 0.65rem;
    color: #aaa;
    text-transform: none;
    letter-spacing: 0;
}

.setting select {
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    padding: 0.35rem 0.5rem;
    border: 2px solid #f0e8d8;
    border-radius: 8px;
    background: var(--bg);
    color: var(--navy);
    cursor: pointer;
    transition: border-color 0.2s;
}

.setting select:hover {
    border-color: var(--turquoise);
}

.setting select:focus {
    outline: none;
    border-color: var(--coral);
}

/* === Glide Slider === */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #f0e8d8;
    outline: none;
    margin-top: 0.2rem;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--coral);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--coral);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

/* === Toggle Switch === */
.toggle {
    position: relative;
    cursor: pointer;
}

.toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-track {
    display: flex;
    align-items: center;
    width: 56px;
    height: 28px;
    background: #f0e8d8;
    border-radius: 14px;
    position: relative;
    transition: background 0.3s;
    padding: 0 6px;
    justify-content: space-between;
}

.toggle input:checked + .toggle-track {
    background: var(--turquoise);
}

.toggle-track::after {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    background: white;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle input:checked + .toggle-track::after {
    transform: translateX(28px);
}

.toggle-label-off,
.toggle-label-on {
    font-size: 0.65rem;
    font-weight: 700;
    z-index: 1;
    color: var(--gray);
    transition: color 0.3s;
}

.toggle input:checked + .toggle-track .toggle-label-on {
    color: white;
}

.toggle input:checked + .toggle-track .toggle-label-off {
    color: rgba(78, 205, 196, 0.5);
}

/* === Status === */
.status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--gray);
    transition: color 0.3s;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ccc;
    transition: background 0.3s;
}

.status.active {
    color: var(--turquoise);
}

.status.active .status-dot {
    background: var(--coral);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.3); }
}

/* === How to Play === */
.card-title {
    font-family: 'Pacifico', cursive;
    font-size: 1.4rem;
    color: var(--navy);
    margin-bottom: 1rem;
}

.instructions {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.instructions li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    background: linear-gradient(135deg, #fef9f0, #fdf4e3);
    border-radius: 10px;
    border-left: 4px solid var(--turquoise);
}

.instructions li:nth-child(1) {
    border-left-color: var(--coral);
}

.instructions li:nth-child(3) {
    border-left-color: var(--sky);
}

.instruction-icon {
    font-size: 1.4rem;
    width: 2rem;
    text-align: center;
    flex-shrink: 0;
}

.instructions li div {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.instructions li strong {
    font-size: 0.85rem;
    color: var(--navy);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.instructions li span {
    font-size: 0.8rem;
    color: var(--gray);
}

/* === Wave Table === */
.wavetable-container {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #f0e8d8;
}

.wavetable-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--gray);
    margin-bottom: 0.5rem;
}

#wavetable-canvas {
    width: 100%;
    height: 150px;
    border: 2px solid #f0e8d8;
    border-radius: 8px;
    cursor: crosshair;
    background: var(--bg);
}

.wt-button {
    flex: 1;
    padding: 8px 12px;
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border: 2px solid #f0e8d8;
    border-radius: 8px;
    background: white;
    color: var(--gray);
    transition: all 0.2s;
}

.wt-button:hover {
    border-color: var(--turquoise);
    color: var(--turquoise);
}

.wt-button-primary {
    background: var(--coral);
    color: white;
    border-color: var(--coral);
}

.wt-button-primary:hover {
    background: #ff5555;
    border-color: #ff5555;
}

/* === Panic Button === */
.panic-button {
    width: 100%;
    padding: 10px 16px;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border: 2px solid var(--coral);
    border-radius: 8px;
    background: white;
    color: var(--coral);
    transition: all 0.2s;
}

.panic-button:hover {
    background: var(--coral);
    color: white;
    transform: scale(1.02);
}

.panic-button:active {
    transform: scale(0.98);
}

/* === Randomize Button === */
.randomize-button {
    width: 100%;
    padding: 10px 16px;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border: 2px solid var(--turquoise);
    border-radius: 8px;
    background: white;
    color: var(--turquoise);
    transition: all 0.2s;
}

.randomize-button:hover {
    background: var(--turquoise);
    color: white;
    transform: scale(1.02);
}

.randomize-button:active {
    transform: scale(0.98);
}

/* === Recording === */
.recording-controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: stretch;
}

.record-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border: 2px solid var(--coral);
    border-radius: 12px;
    background: white;
    color: var(--coral);
    transition: all 0.2s;
}

.record-button:hover:not(:disabled) {
    background: var(--coral);
    color: white;
}

.record-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.record-button.recording {
    background: var(--coral);
    color: white;
    animation: pulse-record 1.5s ease-in-out infinite;
}

@keyframes pulse-record {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.record-icon {
    font-size: 1.2rem;
}

.recording-timer {
    text-align: center;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--coral);
    font-variant-numeric: tabular-nums;
}

.recording-status {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: var(--gray);
    text-align: center;
    min-height: 1.5rem;
}

/* ══════════════════════════════════════════════════════════════════
   TAB NAVIGATION
══════════════════════════════════════════════════════════════════ */
.tab-nav {
    display: flex;
    justify-content: center;
    background: linear-gradient(135deg, #FFECD2 0%, #FCB69F 50%, #FF9A9E 100%);
    padding: 0 1.5rem;
    gap: 0.25rem;
    padding-bottom: 0;
}

.tab-btn {
    padding: 0.7rem 2.2rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    cursor: pointer;
    border: none;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: rgba(44, 62, 80, 0.55);
    transition: color 0.2s, border-color 0.2s;
    margin-bottom: -1px;
}

.tab-btn:hover {
    color: var(--navy);
}

.tab-btn.active {
    color: var(--navy);
    border-bottom-color: var(--coral);
}

/* ══════════════════════════════════════════════════════════════════
   DRUM MACHINE PANEL
══════════════════════════════════════════════════════════════════ */
.dm-panel {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.dm-card-title {
    font-size: 1.1rem;
    margin-bottom: 0.85rem;
}

/* ── Top row: Transport + Patterns ──────────────────────────────── */
.dm-top-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.dm-transport-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.dm-divider {
    width: 1px;
    height: 28px;
    background: #e8e0d4;
    margin: 0 0.25rem;
}

/* Play / Stop buttons */
.dm-play-btn,
.dm-stop-btn {
    padding: 0.55rem 1.3rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    white-space: nowrap;
}

.dm-play-btn {
    background: var(--turquoise);
    color: white;
    border: 2px solid var(--turquoise);
}

.dm-play-btn:hover {
    background: #3bb8af;
    border-color: #3bb8af;
}

.dm-play-btn.dm-active {
    animation: pulse-record 1.2s ease-in-out infinite;
}

/* Timeline button — amber tint when idle, pulses amber when active */
.dm-play-tl-btn {
    background: white;
    color: #FF9F43;
    border: 2px solid #FF9F43;
}

.dm-play-tl-btn:hover {
    background: #FF9F43;
    color: white;
    border-color: #FF9F43;
}

.dm-play-tl-btn.dm-active {
    background: #FF9F43;
    border-color: #FF9F43;
    color: white;
}

.dm-stop-btn {
    background: white;
    color: var(--coral);
    border: 2px solid var(--coral);
}

.dm-stop-btn:hover:not(:disabled) {
    background: var(--coral);
    color: white;
}

.dm-stop-btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}

/* Control groups (label + input) */
.dm-control-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.dm-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--gray);
    white-space: nowrap;
}

.dm-bpm-input {
    width: 58px;
    padding: 0.28rem 0.35rem;
    font-family: 'Inter', sans-serif;
    font-size: 1.05rem;
    font-weight: 700;
    border: 2px solid #f0e8d8;
    border-radius: 8px;
    background: var(--bg);
    color: var(--navy);
    text-align: center;
    -moz-appearance: textfield;
}

.dm-bpm-input::-webkit-outer-spin-button,
.dm-bpm-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.dm-bpm-input:focus {
    outline: none;
    border-color: var(--coral);
}

.dm-select {
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    padding: 0.32rem 0.5rem;
    border: 2px solid #f0e8d8;
    border-radius: 8px;
    background: var(--bg);
    color: var(--navy);
    cursor: pointer;
    transition: border-color 0.2s;
}

.dm-select:focus {
    outline: none;
    border-color: var(--coral);
}

/* Pattern section */
.dm-pattern-row {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 0.6rem;
}

.dm-pattern-select {
    flex: 0 0 auto;
    min-width: 130px;
}

.dm-text-input {
    flex: 1;
    padding: 0.35rem 0.6rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    border: 2px solid #f0e8d8;
    border-radius: 8px;
    background: var(--bg);
    color: var(--navy);
    transition: border-color 0.2s;
}

.dm-text-input:focus {
    outline: none;
    border-color: var(--turquoise);
}

.dm-pattern-buttons {
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
}

/* Generic small buttons */
.dm-btn {
    padding: 0.42rem 0.85rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    white-space: nowrap;
}

.dm-btn-outline {
    background: white;
    border: 2px solid #e8e0d4;
    color: var(--gray);
}

.dm-btn-outline:hover {
    border-color: var(--turquoise);
    color: var(--turquoise);
}

.dm-btn-primary {
    background: var(--coral);
    border: 2px solid var(--coral);
    color: white;
}

.dm-btn-primary:hover {
    background: #ff5555;
    border-color: #ff5555;
}

.dm-btn-danger:hover {
    border-color: var(--coral);
    color: var(--coral);
}

.dm-btn-turquoise {
    background: var(--turquoise);
    border: 2px solid var(--turquoise);
    color: white;
}

.dm-btn-turquoise:hover {
    background: #3bb8af;
    border-color: #3bb8af;
}

/* Generate row */
.dm-generate-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.65rem;
    padding-top: 0.65rem;
    border-top: 1px solid #f0e8d8;
}

/* ── FX Card ────────────────────────────────────────────────────── */
.dm-fx-card {
    padding: 1rem 1.5rem;
}

.dm-fx-row {
    display: flex;
    align-items: flex-start;
    gap: 0;
}

.dm-fx-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    padding: 0 1.25rem;
}

.dm-fx-section:first-child { padding-left: 0; }
.dm-fx-section:last-child  { padding-right: 0; }

.dm-fx-sep {
    width: 1px;
    align-self: stretch;
    background: #f0e8d8;
    flex-shrink: 0;
}

.dm-fx-toggle-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    cursor: pointer;
}

.dm-fx-toggle-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--turquoise);
    cursor: pointer;
}

.dm-fx-name {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--navy);
}

.dm-fx-params {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.dm-fx-param {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.dm-fx-param .dm-label {
    font-size: 0.6rem;
}

/* ── Sequencer ──────────────────────────────────────────────────── */
.dm-sequencer-card {
    overflow-x: auto;
}

.dm-seq-top-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.dm-seq-label-col {
    width: 92px;
    flex-shrink: 0;
}

.dm-step-numbers {
    display: flex;
    flex: 1;
    gap: 2px;
}

.dm-step-num {
    flex: 1;
    text-align: center;
    font-size: 0.58rem;
    font-weight: 600;
    color: #ccc;
    min-width: 26px;
    user-select: none;
}

.dm-beat-start {
    color: var(--gray);
}

.dm-seq-vol-col {
    width: 80px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dm-sequencer-rows {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dm-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dm-instrument-label {
    width: 92px;
    flex-shrink: 0;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--navy);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.dm-instr-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dm-steps {
    display: flex;
    flex: 1;
    gap: 2px;
}

.dm-step-btn {
    flex: 1;
    min-width: 26px;
    height: 34px;
    border: 2px solid #e4ddd4;
    border-radius: 5px;
    background: #f5f0e8;
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s, transform 0.05s;
    position: relative;
    overflow: hidden;
}

.dm-group-start {
    margin-left: 5px;
}

.dm-step-btn:hover {
    border-color: var(--instr-color, #4ECDC4);
    background: #ede8df;
}

.dm-step-btn:active {
    transform: scale(0.92);
}

.dm-step-btn.dm-step-active {
    background: var(--instr-color, #4ECDC4);
    border-color: var(--instr-color, #4ECDC4);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

/* Playhead needle */
.dm-step-btn.dm-playhead::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--navy);
    border-radius: 3px 3px 0 0;
}

.dm-step-btn.dm-step-active.dm-playhead {
    filter: brightness(1.25);
}

.dm-row-vol {
    width: 80px;
    flex-shrink: 0;
}

.dm-vol-slider {
    width: 100%;
}

/* Mute button */
.dm-instr-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dm-mute-btn {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: 3px;
    border: 1.5px solid #d8d0c8;
    background: transparent;
    font-size: 0.55rem;
    font-weight: 800;
    letter-spacing: 0;
    cursor: pointer;
    color: #bbb;
    padding: 0;
    line-height: 1;
    transition: all 0.15s;
}

.dm-mute-btn:hover {
    border-color: var(--coral);
    color: var(--coral);
}

.dm-mute-btn.dm-muted {
    background: var(--coral);
    border-color: var(--coral);
    color: white;
}

.dm-row-muted .dm-steps .dm-step-btn {
    opacity: 0.3;
}

.dm-row-muted .dm-instr-name,
.dm-row-muted .dm-instr-dot {
    opacity: 0.45;
}

/* Tap tempo button */
.dm-tap-btn {
    flex-shrink: 0;
}

/* Randomize row button */
.dm-rand-btn {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: 3px;
    border: 1.5px solid #d8d0c8;
    background: transparent;
    font-size: 0.75rem;
    cursor: pointer;
    color: #bbb;
    padding: 0;
    line-height: 1;
    transition: all 0.15s;
}

.dm-rand-btn:hover {
    border-color: var(--turquoise);
    color: var(--turquoise);
}

/* Ghost step — quieter hit */
.dm-step-btn.dm-step-active.dm-step-ghost {
    background: color-mix(in srgb, var(--instr-color, #4ECDC4) 38%, #f5f0e8);
    border-color: color-mix(in srgb, var(--instr-color, #4ECDC4) 38%, #e4ddd4);
    box-shadow: none;
}

/* Probability step — shows a % badge */
.dm-step-btn.dm-step-active.dm-step-prob::before {
    content: attr(data-prob) '%';
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 0.45rem;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1;
    pointer-events: none;
    letter-spacing: 0;
}

/* Timeline slot — use direct style colors now, not hsl var */
.dm-timeline-slot.dm-timeline-slot-filled {
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

/* Slot picker popover */
.dm-slot-picker {
    position: absolute;
    display: none;
    background: var(--card-bg);
    border: 2px solid #e8e0d4;
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.14), 0 2px 8px rgba(0, 0, 0, 0.06);
    z-index: 9999;
    min-width: 168px;
}

.dm-slot-picker-title {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--gray);
    padding: 2px 8px 6px;
    border-bottom: 1px solid #f0e8d8;
    margin-bottom: 4px;
}

.dm-slot-picker-options {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 220px;
    overflow-y: auto;
}

.dm-slot-picker-option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 7px 10px 7px 12px;
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    border-left: 3px solid transparent;
    background: transparent;
    border-radius: 6px;
    color: var(--navy);
    transition: background 0.1s;
}

.dm-slot-picker-option:hover {
    background: #f5f0e8;
}

.dm-slot-picker-option.active {
    background: rgba(78, 205, 196, 0.12);
    color: var(--turquoise);
}

.dm-slot-picker-remove {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 6px 10px;
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--coral);
    border-radius: 6px;
    text-align: left;
    border-top: 1px solid #f0e8d8;
    transition: background 0.1s;
}

.dm-slot-picker-remove:hover {
    background: rgba(255, 107, 107, 0.08);
}

/* Theremin mute button */
.status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1rem;
    gap: 0.75rem;
}

.status-row .status {
    margin-top: 0;
    flex: 1;
}

.theremin-mute-btn {
    flex-shrink: 0;
    padding: 0.32rem 0.75rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    cursor: pointer;
    border: 2px solid #e8e0d4;
    border-radius: 8px;
    background: white;
    color: var(--gray);
    transition: all 0.2s;
    white-space: nowrap;
}

.theremin-mute-btn:hover {
    border-color: var(--turquoise);
    color: var(--turquoise);
}

.theremin-mute-btn.theremin-muted {
    background: var(--coral);
    border-color: var(--coral);
    color: white;
}

/* ── Timeline ───────────────────────────────────────────────────── */
.dm-timeline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.dm-timeline-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.dm-timeline-loop-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--gray);
    cursor: pointer;
}

.dm-timeline-wrapper {
    overflow-x: auto;
    padding-bottom: 4px;
}

.dm-timeline-track {
    display: flex;
    gap: 4px;
    min-width: max-content;
    padding: 4px 0;
}

.dm-timeline-slot {
    width: 72px;
    height: 52px;
    border: 2px solid #e4ddd4;
    border-radius: 8px;
    background: #f5f0e8;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.58rem;
    font-weight: 700;
    text-align: center;
    padding: 4px;
    color: #ccc;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    word-break: break-word;
    overflow: hidden;
    line-height: 1.3;
    user-select: none;
}

.dm-timeline-slot:hover {
    border-color: var(--turquoise);
}

.dm-timeline-slot.dm-timeline-slot-filled {
    background: hsla(var(--slot-hue, 0), 62%, 54%, 0.88);
    border-color: hsla(var(--slot-hue, 0), 62%, 44%, 1);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
}

.dm-timeline-slot.dm-timeline-slot-current-pat {
    outline: 2px dashed rgba(255,255,255,0.7);
    outline-offset: -4px;
}

.dm-timeline-slot.dm-timeline-slot-playing {
    box-shadow: 0 0 0 3px var(--navy);
    transform: scale(1.07);
    z-index: 2;
}

.dm-timeline-hint {
    margin-top: 0.6rem;
    font-size: 0.72rem;
    color: #bbb;
    text-align: center;
    font-style: italic;
}

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE (drum machine)
══════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
    .dm-top-row {
        grid-template-columns: 1fr;
    }

    .dm-transport-row {
        gap: 0.5rem;
    }

    .dm-step-btn {
        min-width: 22px;
        height: 30px;
    }

    .dm-instrument-label {
        width: 72px;
        font-size: 0.62rem;
    }

    .dm-seq-label-col {
        width: 72px;
    }

    .dm-row-vol,
    .dm-seq-vol-col {
        width: 60px;
    }
}

@media (max-width: 600px) {
    .dm-panel {
        padding: 1rem;
        gap: 1rem;
    }

    .dm-instrument-label {
        width: 58px;
        font-size: 0.56rem;
    }

    .dm-seq-label-col {
        width: 58px;
    }

    .dm-step-btn {
        min-width: 18px;
        height: 28px;
        border-radius: 3px;
    }
}

/* === Responsive === */
@media (max-width: 900px) {
    .main {
        grid-template-columns: 1fr;
    }

    .webcam-panel {
        position: static;
    }

    .metrics-row {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 500px) {
    .header {
        padding: 1.5rem 1rem 0.75rem;
    }

    .main {
        padding: 1rem;
        gap: 1rem;
    }

    .card {
        padding: 1rem;
    }

    .metrics-row {
        gap: 0.5rem;
    }
}

/* ══════════════════════════════════════════════════════════════════
   SONG ARRANGER
══════════════════════════════════════════════════════════════════ */
.sa-panel {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.sa-card-title {
    font-size: 1.1rem;
    margin-bottom: 0.85rem;
}

/* ── Transport ───────────────────────────────────────────────────── */
.sa-transport-card { }

.sa-transport-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.sa-play-btn {
    padding: 0.55rem 1.4rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    background: #A29BFE;
    color: white;
    border: 2px solid #A29BFE;
    white-space: nowrap;
}

.sa-play-btn:hover    { background: #8c84ee; border-color: #8c84ee; }
.sa-play-btn.sa-active { background: #8c84ee; border-color: #8c84ee; animation: pulse-record 1.2s ease-in-out infinite; }

.sa-stop-btn {
    padding: 0.55rem 1.3rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    background: white;
    color: var(--coral);
    border: 2px solid var(--coral);
    white-space: nowrap;
}
.sa-stop-btn:hover:not(:disabled) { background: var(--coral); color: white; }
.sa-stop-btn:disabled { opacity: 0.38; cursor: not-allowed; }

/* ── Main row ────────────────────────────────────────────────────── */
.sa-main-row {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* ── Section list ────────────────────────────────────────────────── */
.sa-sections-card { }

.sa-section-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 0.75rem;
    max-height: 320px;
    overflow-y: auto;
}

.sa-section-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: background 0.15s, border-color 0.15s;
    background: #f7f3ec;
}

.sa-section-item:hover { background: #f0e8d8; }

.sa-section-item.sa-section-active {
    background: #f0e8d8;
    border-color: #d8d0c8;
}

.sa-section-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.sa-section-name {
    flex: 1;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--navy);
    outline: none;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: text;
}

.sa-section-name:focus {
    background: white;
    border-radius: 3px;
    padding: 1px 3px;
    white-space: nowrap;
    overflow: visible;
}

.sa-section-add-btn {
    width: 20px; height: 20px;
    border: 1.5px solid var(--turquoise);
    color: var(--turquoise);
    background: white;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: all 0.15s;
    flex-shrink: 0;
}
.sa-section-add-btn:hover { background: var(--turquoise); color: white; }

.sa-section-del-btn {
    width: 18px; height: 18px;
    border: none; background: transparent;
    color: #ccc; font-size: 0.9rem;
    cursor: pointer; padding: 0; line-height: 1;
    flex-shrink: 0; transition: color 0.15s;
}
.sa-section-del-btn:hover { color: var(--coral); }

.sa-add-btn {
    width: 100%;
    text-align: center;
}

/* ── Chord Editor ────────────────────────────────────────────────── */
.sa-editor-card { }

.sa-editor-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.9rem;
}

.sa-preset-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sa-chord-editor {
    display: flex;
    align-items: stretch;
    gap: 6px;
    flex-wrap: wrap;
    min-height: 90px;
    padding: 4px 0;
}

.sa-chord-block {
    flex: var(--bars, 1);
    min-width: 72px;
    max-width: 180px;
    border: 2px solid #e4ddd4;
    border-radius: 10px;
    background: #f7f3ec;
    cursor: pointer;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: border-color 0.15s, background 0.15s;
    user-select: none;
}

.sa-chord-block:hover {
    border-color: #A29BFE;
    background: #f0ecff;
}

.sa-chord-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sa-chord-name {
    font-family: 'Pacifico', cursive;
    font-size: 1.1rem;
    color: var(--navy);
}

.sa-chord-del {
    width: 16px; height: 16px;
    border: none; background: transparent;
    color: #ccc; font-size: 0.85rem;
    cursor: pointer; padding: 0; line-height: 1;
    transition: color 0.1s;
}
.sa-chord-del:hover { color: var(--coral); }

.sa-chord-bars-row {
    display: flex;
    align-items: center;
    gap: 5px;
}

.sa-chord-bars-label {
    font-size: 0.58rem;
    font-weight: 700;
    color: #bbb;
    min-width: 14px;
    text-align: right;
}

.sa-chord-bars-slider {
    flex: 1;
    margin: 0;
    height: 3px;
    background: #e4ddd4;
}

.sa-chord-add {
    align-self: center;
    padding: 0.4rem 0.9rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    border: 2px dashed #d8d0c8;
    border-radius: 10px;
    background: transparent;
    color: #bbb;
    transition: all 0.15s;
    min-height: 70px;
    min-width: 60px;
}
.sa-chord-add:hover { border-color: #A29BFE; color: #A29BFE; }

/* ── Instruments ─────────────────────────────────────────────────── */
.sa-instruments-section {
    margin-top: 1rem;
    padding-top: 0.9rem;
    border-top: 1px solid #f0e8d8;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.sa-instr-toggles {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    flex: 1;
}

.sa-instr-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 72px;
}

.sa-instr-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.sa-instr-toggle input[type="checkbox"] {
    width: 13px;
    height: 13px;
    cursor: pointer;
}

.sa-instr-vol {
    width: 100%;
    height: 4px;
    margin: 0;
}

/* Instrument top row: toggle + piano roll button */
.sa-instr-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}

/* Piano roll open button on each instrument */
.sa-pr-open-btn {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border: 1.5px solid #d8d0c8;
    background: transparent;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sa-pr-open-btn:hover {
    border-color: var(--pr-color, #A29BFE);
    background: rgba(162, 155, 254, 0.1);
}
.sa-pr-open-btn.sa-pr-btn-active {
    background: var(--pr-color, #A29BFE);
    border-color: var(--pr-color, #A29BFE);
}

/* ── Arrangement track ───────────────────────────────────────────── */
.sa-arrangement-card { }

.sa-arr-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.sa-arr-actions {
    display: flex;
    gap: 0.5rem;
}

.sa-arr-track-wrapper {
    overflow-x: auto;
    padding-bottom: 4px;
}

.sa-arr-track {
    display: flex;
    gap: 5px;
    min-height: 64px;
    padding: 4px 0;
    min-width: max-content;
    align-items: stretch;
}

.sa-arr-block {
    flex: var(--arr-bars, 1);
    min-width: 80px;
    border: 2px solid transparent;
    border-radius: 10px;
    padding: 8px 10px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    color: white;
    position: relative;
    user-select: none;
}

.sa-arr-block:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.sa-arr-block.sa-arr-playing {
    box-shadow: 0 0 0 3px var(--navy);
    transform: scale(1.03) translateY(-2px);
    z-index: 2;
}

.sa-arr-block-name {
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sa-arr-block-bars {
    font-size: 0.58rem;
    font-weight: 600;
    opacity: 0.75;
    margin-top: auto;
}

.sa-arr-block-del {
    position: absolute;
    top: 4px; right: 5px;
    width: 16px; height: 16px;
    border: none; background: rgba(255,255,255,0.25);
    border-radius: 3px;
    color: white; font-size: 0.8rem;
    cursor: pointer; padding: 0; line-height: 1;
    opacity: 0; transition: opacity 0.15s;
}
.sa-arr-block:hover .sa-arr-block-del { opacity: 1; }
.sa-arr-block-del:hover { background: rgba(255,255,255,0.4); }

.sa-arr-empty {
    font-size: 0.78rem;
    color: #bbb;
    font-style: italic;
    padding: 1rem;
    align-self: center;
}

/* ── Chord Picker ────────────────────────────────────────────────── */
.sa-chord-picker {
    position: absolute;
    display: none;
    background: var(--card-bg);
    border: 2px solid #e8e0d4;
    border-radius: 14px;
    padding: 12px;
    box-shadow: 0 10px 32px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.06);
    z-index: 9999;
    min-width: 256px;
}

.sa-picker-label {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--gray);
    margin-bottom: 6px;
}

.sa-picker-roots {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 3px;
}

.sa-picker-types {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.sa-picker-btn {
    padding: 5px 4px;
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    border: 1.5px solid #e8e0d4;
    border-radius: 6px;
    background: #f7f3ec;
    color: var(--navy);
    transition: all 0.1s;
    text-align: center;
    min-width: 28px;
}
.sa-picker-btn:hover { border-color: #A29BFE; background: #f0ecff; }
.sa-picker-btn.sa-picker-active { background: #A29BFE; border-color: #A29BFE; color: white; }

.sa-picker-type-btn {
    min-width: 36px;
    font-size: 0.68rem;
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .sa-main-row {
        grid-template-columns: 1fr;
    }
    .sa-sections-card {
        max-height: none;
    }
}

/* ══════════════════════════════════════════════════════════════════
   PIANO ROLL MODAL
══════════════════════════════════════════════════════════════════ */
.dm-pr-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(44, 62, 80, 0.45);
    z-index: 10001;
    align-items: flex-end;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.dm-pr-modal.dm-pr-open {
    display: flex;
}

.dm-pr-panel {
    background: var(--card-bg);
    width: 100%;
    max-width: 1200px;
    border-radius: 20px 20px 0 0;
    padding: 1.5rem 2rem 2rem;
    box-shadow: 0 -8px 40px rgba(0,0,0,0.18);
    animation: prSlideUp 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes prSlideUp {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.dm-pr-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.dm-pr-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dm-pr-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dm-pr-name {
    font-family: 'Pacifico', cursive;
    font-size: 1.4rem;
    color: var(--navy);
}

.dm-pr-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.dm-pr-close-btn {
    width: 32px; height: 32px;
    border: none; background: #f0e8d8;
    border-radius: 50%;
    font-size: 0.9rem; cursor: pointer;
    color: var(--gray); transition: all 0.15s;
    display: flex; align-items: center; justify-content: center;
}
.dm-pr-close-btn:hover { background: var(--coral); color: white; }

/* Beat labels row */
.dm-pr-beat-labels {
    display: flex;
    gap: 3px;
    margin-bottom: 5px;
    padding: 0 3px;
}

.dm-pr-beat-label {
    flex: 1;
    text-align: center;
    font-size: 0.58rem;
    font-weight: 600;
    color: #ccc;
    min-width: 18px;
    user-select: none;
}
.dm-pr-beat-label.dm-pr-downbeat { color: var(--gray); font-size: 0.65rem; }
.dm-pr-sep { width: 6px; flex-shrink: 0; }

/* Velocity grid */
.dm-pr-grid {
    display: flex;
    gap: 3px;
    height: 160px;
    align-items: flex-end;
    background: linear-gradient(180deg, #f2ede4 0%, #faf7f2 100%);
    border-radius: 12px;
    padding: 8px;
    cursor: ns-resize;
    user-select: none;
    position: relative;
}

/* Horizontal guide lines */
.dm-pr-grid::before {
    content: '';
    position: absolute;
    inset: 8px;
    background: repeating-linear-gradient(
        180deg,
        transparent 0%,
        transparent calc(25% - 1px),
        rgba(0,0,0,0.04) calc(25% - 1px),
        rgba(0,0,0,0.04) 25%
    );
    border-radius: 6px;
    pointer-events: none;
}

.dm-pr-col {
    flex: 1;
    height: 100%;
    min-width: 18px;
    background: rgba(228, 221, 212, 0.5);
    border-radius: 5px;
    position: relative;
    display: flex;
    align-items: flex-end;
    transition: background 0.1s;
}
.dm-pr-col:hover { background: rgba(228, 221, 212, 0.85); }
.dm-pr-col.dm-pr-playing {
    background: rgba(44, 62, 80, 0.12);
    border: 1px solid rgba(44, 62, 80, 0.25);
}

.dm-pr-bar {
    width: 100%;
    border-radius: 4px 4px 3px 3px;
    background: var(--instr-color, #4ECDC4);
    position: absolute;
    bottom: 0;
    min-height: 5px;
    transition: height 0.05s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.dm-pr-bar.dm-pr-ghost {
    opacity: 0.45;
    background: color-mix(in srgb, var(--instr-color, #4ECDC4) 55%, #f5f0e8);
}

.dm-pr-prob-label {
    position: absolute;
    bottom: 3px;
    left: 0; right: 0;
    text-align: center;
    font-size: 0.42rem;
    font-weight: 800;
    color: rgba(255,255,255,0.85);
    pointer-events: none;
}

.dm-pr-hint {
    margin-top: 0.65rem;
    font-size: 0.7rem;
    color: #bbb;
    text-align: center;
    font-style: italic;
}

/* ══════════════════════════════════════════════════════════════════
   SA (SONG ARRANGER) PIANO ROLL MODAL
══════════════════════════════════════════════════════════════════ */
.sa-pr-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(44, 62, 80, 0.45);
    z-index: 10002;
    align-items: flex-end;
    justify-content: center;
    backdrop-filter: blur(2px);
}
.sa-pr-modal.sa-pr-open { display: flex; }

.sa-pr-panel {
    background: var(--card-bg);
    width: 100%;
    max-width: 1400px;
    border-radius: 20px 20px 0 0;
    padding: 1.5rem 2rem 1.5rem;
    box-shadow: 0 -8px 40px rgba(0,0,0,0.18);
    animation: prSlideUp 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    flex-direction: column;
    max-height: 82vh;
    gap: 0.75rem;
}

.sa-pr-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    flex-shrink: 0;
}

.sa-pr-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.sa-pr-mode-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--navy);
    cursor: pointer;
    padding: 0.32rem 0.7rem;
    border: 2px solid #e8e0d4;
    border-radius: 8px;
    transition: border-color 0.15s;
}
.sa-pr-mode-label:has(input:checked) { border-color: #A29BFE; background: #f0ecff; }
.sa-pr-mode-label:hover { border-color: #A29BFE; }
.sa-pr-mode-label input { accent-color: #A29BFE; width: 13px; height: 13px; cursor: pointer; }

/* ── Toolbar (duration picker + fill row) ────────────────────────── */
.sa-pr-toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.5rem 0.6rem;
    background: #f7f3ec;
    border-radius: 10px;
    flex-shrink: 0;
}

.sa-pr-dur-row,
.sa-pr-fill-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.sa-pr-dur-btns {
    display: flex;
    gap: 3px;
}

.sa-pr-dur-btn {
    padding: 0.28rem 0.55rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.65rem;
    font-weight: 700;
    cursor: pointer;
    border: 1.5px solid #d8d0c8;
    border-radius: 6px;
    background: white;
    color: var(--gray);
    transition: all 0.12s;
    white-space: nowrap;
}
.sa-pr-dur-btn:hover { border-color: #A29BFE; color: #A29BFE; }
.sa-pr-dur-btn.active { background: #A29BFE; border-color: #A29BFE; color: white; }

.sa-pr-fill-slider {
    width: 80px;
    height: 3px;
}

.sa-pr-fill-val {
    font-size: 0.62rem;
    font-weight: 700;
    color: var(--gray);
    min-width: 26px;
}

/* ── Step area (relative container for cells + note blocks) ──────── */
.sa-pr-step-area {
    position: relative;
    display: flex;
    flex-shrink: 0;
    height: 100%;
    align-items: stretch;
}

/* ── Note blocks (absolutely positioned in step area) ───────────── */
.sa-pr-note-block {
    position: absolute;
    top: 1px;
    height: 16px;
    background: var(--instr-color, #A29BFE);
    border-radius: 3px;
    z-index: 1;
    cursor: pointer;
    box-shadow: 0 1px 5px rgba(0,0,0,0.22);
    min-width: 10px;
    transition: filter 0.08s;
    user-select: none;
}
.sa-pr-note-block:hover { filter: brightness(1.15); }

.sa-pr-note-resize {
    position: absolute;
    right: 0;
    top: 0;
    width: 7px;
    height: 100%;
    cursor: e-resize;
    background: rgba(255,255,255,0.35);
    border-radius: 0 3px 3px 0;
    z-index: 2;
}
.sa-pr-note-resize:hover { background: rgba(255,255,255,0.6); }

/* ── Voice selector ──────────────────────────────────────────────── */
.sa-voice-row {
    display: flex;
    gap: 3px;
    margin: 2px 0;
}

.sa-voice-btn {
    flex: 1;
    padding: 0.2rem 0;
    font-family: 'Inter', sans-serif;
    font-size: 0.58rem;
    font-weight: 700;
    cursor: pointer;
    border: 1.5px solid #d8d0c8;
    border-radius: 4px;
    background: white;
    color: #aaa;
    transition: all 0.12s;
    white-space: nowrap;
    text-align: center;
}
.sa-voice-btn:hover  { border-color: var(--vc, #A29BFE); color: var(--vc, #A29BFE); }
.sa-voice-btn.active { background: var(--vc, #A29BFE); border-color: var(--vc, #A29BFE); color: white; }

/* ── Theremin sync label ──────────────────────────────────────────── */
.sa-theremin-sync-label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--gray);
    cursor: pointer;
    padding: 0.28rem 0.65rem;
    border: 2px solid #e8e0d4;
    border-radius: 8px;
    transition: border-color 0.15s;
    white-space: nowrap;
}
.sa-theremin-sync-label:hover { border-color: #A29BFE; }
.sa-theremin-sync-label:has(input:checked) { border-color: #A29BFE; background: #f0ecff; color: var(--navy); }
.sa-theremin-sync-label input { accent-color: #A29BFE; width: 13px; height: 13px; }

/* Drum link row in instruments section */
.sa-drum-link-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid #f0e8d8;
    width: 100%;
}

.sa-drum-link-select { min-width: 130px; }

/* Drum indicator on arrangement blocks */
.sa-arr-drum-indicator {
    font-size: 0.65rem;
    margin-left: 4px;
    opacity: 0.85;
}

/* ── Grid area ───────────────────────────────────────────────────── */
.sa-pr-grid-area {
    overflow: auto;
    flex: 1;
    min-height: 0;
    border-radius: 10px;
    border: 1px solid #e8e0d4;
    background: #faf7f2;
}

.sa-pr-grid {
    display: flex;
    flex-direction: column;
    min-width: max-content;
    user-select: none;
}

/* ── Header row ──────────────────────────────────────────────────── */
.sa-pr-header-row {
    height: 24px;
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--card-bg);
    border-bottom: 2px solid #e8e0d4;
}

.sa-pr-hdr-key {
    background: var(--card-bg) !important;
    font-size: 0.52rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--gray);
    justify-content: center;
    border-right: 2px solid #e8e0d4 !important;
}

.sa-pr-hdr-cell {
    width: 14px;
    min-width: 14px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.5rem;
    font-weight: 700;
    color: var(--gray);
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
}

/* ── Pitch rows ──────────────────────────────────────────────────── */
.sa-pr-row {
    display: flex;
    height: 20px;
    align-items: stretch;
}

.sa-pr-key-label {
    width: 40px;
    min-width: 40px;
    position: sticky;
    left: 0;
    z-index: 2;
    background: #f7f3ec;
    border-right: 2px solid #e8e0d4;
    font-size: 0.56rem;
    font-weight: 700;
    color: var(--gray);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 5px;
    flex-shrink: 0;
}
.sa-pr-key-label.sa-pr-key-black { background: #ede9e0; }
.sa-pr-row-c .sa-pr-key-label    { color: var(--navy); font-weight: 800; }
.sa-pr-row-c                     { border-bottom: 1px solid rgba(0,0,0,0.07); }

/* ── Step cells ──────────────────────────────────────────────────── */
.sa-pr-cell {
    width: 14px;
    min-width: 14px;
    height: 20px;
    background: #faf7f2;
    border-right: 1px solid rgba(0,0,0,0.04);
    cursor: crosshair;
    flex-shrink: 0;
    transition: background 0.06s;
}

.sa-pr-row-black .sa-pr-cell { background: #f0ece4; }
.sa-pr-cell.sa-pr-beat-start { border-left: 1px solid rgba(0,0,0,0.12); }
.sa-pr-cell:hover             { background: rgba(162, 155, 254, 0.2); }

.sa-pr-cell.sa-pr-cell-active {
    background: var(--instr-color, #A29BFE);
    border-right-color: rgba(0,0,0,0.08);
    border-radius: 2px;
}

/* Bar separator (thick gap between bars) */
.sa-pr-bar-sep {
    width: 4px;
    min-width: 4px;
    background: #e4ddd4;
    flex-shrink: 0;
}
.sa-pr-header-row .sa-pr-bar-sep { background: #d8d0c8; }
