/* ==========================================================================
   Klang-Werkstatt – Touch-optimierte Browser-Musikwerkbank (100 % lokal)
   Alle interaktiven Kacheln & Buttons mindestens 44 × 44 px.
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

[hidden] {
    display: none !important;
}

html,
body {
    min-height: 100%;
    font-family: var(--le-font-sans);
    background: #faf5ff;
    color: var(--le-ink);
    -webkit-tap-highlight-color: transparent;
}

button,
select,
input {
    font-family: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
    transition: transform 0.1s ease, background-color 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}

button:active:not(:disabled) {
    transform: scale(0.97);
}

button:disabled {
    opacity: 0.42;
    cursor: not-allowed;
}

.mono {
    font-family: var(--le-font-mono);
    font-variant-numeric: tabular-nums;
}

.app-shell {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom);
}

/* ==========================================================================
   KOPFLEISTE
   ========================================================================== */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 35;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--le-border);
    padding: 8px 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
}

.top-bar-inner {
    max-width: 1360px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 3px 10px rgba(147, 51, 234, 0.25);
}

.brand-title-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.brand-title {
    font-size: 1.05rem;
    font-weight: 900;
    color: var(--le-ink);
}

.title-pill-input {
    min-height: 36px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--le-border-strong);
    background: #faf5ff;
    color: #581c87;
    font-size: 0.85rem;
    font-weight: 700;
    width: 170px;
    max-width: 45vw;
}

.title-pill-input:focus {
    outline: 2px solid #9333ea;
    background: #ffffff;
}

.top-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.action-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 0 12px;
    border-radius: 12px;
    border: 1px solid var(--le-border-strong);
    background: var(--le-surface);
    font-size: 0.85rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.action-btn.primary {
    background: linear-gradient(135deg, #9333ea, #e11d48);
    border-color: transparent;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(147, 51, 234, 0.28);
}

/* ==========================================================================
   TRANSPORT-LEISTE
   ========================================================================== */
.transport-bar {
    background: #ffffff;
    border-bottom: 1px solid var(--le-border);
    padding: 8px 12px;
}

.transport-inner {
    max-width: 1360px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.transport-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.play-btn {
    min-height: 46px;
    min-width: 142px;
    padding: 0 18px;
    border-radius: 14px;
    background: #16a34a;
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 900;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.25);
}

.play-btn.playing {
    background: #e11d48;
    box-shadow: 0 4px 12px rgba(225, 29, 72, 0.28);
}

.viz-canvas {
    width: 128px;
    height: 40px;
    border-radius: 10px;
    background: #1e1b4b;
    display: block;
}

.transport-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.control-pill {
    min-height: 44px;
    padding: 4px 10px;
    border-radius: 12px;
    background: var(--le-surface-alt);
    border: 1px solid var(--le-border);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.control-label {
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--le-ink-muted);
}

.mini-step-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: #ffffff;
    border: 1px solid var(--le-border-strong);
    font-weight: 900;
    font-size: 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#tempoSlider {
    width: 92px;
    accent-color: #9333ea;
}

.tempo-badge {
    min-width: 32px;
    text-align: right;
    font-weight: 900;
    font-size: 0.88rem;
    color: #7e22ce;
}

.tap-tempo-btn {
    min-height: 34px;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid #d8b4fe;
    background: #faf5ff;
    color: #6b21a8;
    font-size: 0.78rem;
    font-weight: 900;
}

.tap-tempo-btn.tap-flash {
    background: #9333ea;
    border-color: #9333ea;
    color: #ffffff;
}

.seg-group {
    display: inline-flex;
    gap: 4px;
}

.seg-btn {
    min-width: 36px;
    min-height: 34px;
    padding: 0 8px;
    border-radius: 8px;
    font-weight: 800;
    font-size: 0.84rem;
    background: #ffffff;
    border: 1px solid var(--le-border);
}

.seg-btn.active {
    background: #9333ea;
    border-color: #9333ea;
    color: #ffffff;
}

.le-select {
    min-height: 34px;
    padding: 0 8px;
    border-radius: 8px;
    border: 1px solid var(--le-border-strong);
    background: #ffffff;
    color: var(--le-ink);
    font-size: 0.84rem;
    font-weight: 700;
}

/* ==========================================================================
   HAUPTLAYOUT
   ========================================================================== */
.studio-layout {
    width: 100%;
    max-width: 1360px;
    margin: 0 auto;
    padding: 14px 12px 28px;
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 14px;
    align-items: start;
}

.card {
    background: var(--le-surface);
    border: 1px solid var(--le-border);
    border-radius: 20px;
    box-shadow: var(--le-shadow-sm);
}

.side-panel {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.panel-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--le-border);
}

.panel-group:first-child {
    padding-top: 0;
    border-top: none;
}

.group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.group-title {
    font-size: 0.78rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--le-ink-muted);
}

.group-badge,
.count-pill {
    padding: 2px 8px;
    border-radius: 999px;
    background: #f3e8ff;
    color: #7e22ce;
    font-size: 0.72rem;
    font-weight: 800;
}

.text-link-btn {
    font-size: 0.78rem;
    font-weight: 800;
    color: #7e22ce;
    padding: 4px 6px;
}

/* Mixer-Spuren */
.mixer-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mixer-card {
    border: 1.5px solid var(--le-border);
    border-radius: 14px;
    padding: 10px;
    background: #fcfbfe;
    display: flex;
    flex-direction: column;
    gap: 8px;
    cursor: pointer;
}

.mixer-card.active {
    border-color: var(--track-color, #9333ea);
    background: #ffffff;
    box-shadow: 0 4px 14px rgba(147, 51, 234, 0.12);
}

.mixer-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.mixer-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-weight: 900;
    font-size: 0.92rem;
}

.mixer-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--track-color, #9333ea);
    flex-shrink: 0;
}

.ms-btns {
    display: flex;
    gap: 4px;
}

.ms-btn {
    min-width: 34px;
    min-height: 34px;
    border-radius: 8px;
    border: 1px solid var(--le-border-strong);
    background: #ffffff;
    font-weight: 900;
    font-size: 0.78rem;
}

.ms-btn.muted {
    background: #e11d48;
    border-color: #e11d48;
    color: #ffffff;
}

.ms-btn.soloed {
    background: #f59e0b;
    border-color: #f59e0b;
    color: #ffffff;
}

.mixer-bottom {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mixer-inst-tag {
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--le-ink-muted);
    white-space: nowrap;
}

.mixer-vol {
    flex: 1;
    accent-color: var(--track-color, #9333ea);
}

/* Effekte */
.fx-grid {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.fx-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.fx-name {
    display: flex;
    justify-content: space-between;
    font-size: 0.82rem;
    font-weight: 700;
}

.fx-row input[type="range"] {
    width: 100%;
    accent-color: #9333ea;
}

/* Gespeicherte Beats */
.library-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 220px;
    overflow-y: auto;
}

.library-empty {
    font-size: 0.8rem;
    color: var(--le-ink-soft);
    padding: 6px 2px;
}

.library-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 12px;
    border: 1px solid var(--le-border);
    background: var(--le-surface-alt);
}

.library-load-btn {
    flex: 1;
    min-height: 36px;
    text-align: left;
    font-size: 0.82rem;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.library-del-btn {
    min-width: 34px;
    min-height: 34px;
    border-radius: 8px;
    color: #be123c;
    font-weight: 900;
}

/* ==========================================================================
   SEQUENCER-BÜHNE (RECHTS)
   ========================================================================== */
.sequencer-stage {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.track-tabs-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--le-border);
}

.track-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.track-tab {
    min-height: 44px;
    padding: 0 14px;
    border-radius: 12px;
    border: 1.5px solid var(--le-border-strong);
    background: var(--le-surface-alt);
    font-weight: 800;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.track-tab.active {
    background: var(--track-color, #9333ea);
    border-color: var(--track-color, #9333ea);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.14);
}

.track-settings-inline {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.inline-field {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--le-ink-muted);
}

.len-pills {
    display: inline-flex;
    gap: 3px;
    background: var(--le-surface-alt);
    padding: 2px;
    border-radius: 9px;
    border: 1px solid var(--le-border);
}

.len-btn {
    min-height: 30px;
    padding: 0 9px;
    border-radius: 7px;
    font-size: 0.76rem;
    font-weight: 800;
    color: var(--le-ink-muted);
}

.len-btn.active {
    background: var(--track-color, #9333ea);
    color: #ffffff;
}

/* Takt-Toolbar */
.bar-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.bar-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.bar-pill {
    min-height: 40px;
    padding: 0 14px;
    border-radius: 10px;
    border: 1px solid var(--le-border-strong);
    background: #ffffff;
    font-size: 0.84rem;
    font-weight: 800;
}

.bar-pill.active {
    background: #1e1b4b;
    border-color: #1e1b4b;
    color: #ffffff;
}

.bar-pill.playing-bar {
    box-shadow: 0 0 0 2px #f59e0b;
}

.bar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.small-btn {
    min-height: 40px;
    padding: 0 11px;
    border-radius: 10px;
    border: 1px solid var(--le-border-strong);
    background: var(--le-surface-alt);
    font-size: 0.8rem;
    font-weight: 800;
}

.small-btn[aria-pressed="true"] {
    background: #e0f2fe;
    border-color: #0284c7;
    color: #0369a1;
}

.small-btn.danger {
    color: #be123c;
}

.scale-banner {
    padding: 8px 12px;
    border-radius: 12px;
    background: #f5f3ff;
    border: 1px solid #ddd6fe;
    color: #5b21b6;
    font-size: 0.82rem;
    font-weight: 700;
}

/* Sequencer-Raster */
.grid-scroll-wrap {
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
}

.step-header,
.seq-row {
    display: grid;
    grid-template-columns: 118px repeat(16, minmax(38px, 1fr));
    gap: 4px;
    align-items: center;
    min-width: 740px;
}

.step-header {
    margin-bottom: 6px;
}

.step-num {
    height: 24px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 900;
    color: var(--le-ink-soft);
    background: #f8fafc;
}

.step-num.beat-start {
    color: var(--le-ink);
    background: #ede9fe;
}

.step-num.now {
    background: #f59e0b;
    color: #ffffff;
}

.sequencer-grid {
    display: flex;
    flex-direction: column;
    gap: 5px;
    touch-action: pan-x pan-y;
}

.row-label-btn {
    min-height: 44px;
    padding: 0 10px;
    border-radius: 10px;
    border: 1px solid var(--le-border);
    background: var(--le-surface-alt);
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.82rem;
    font-weight: 800;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.row-label-btn:hover {
    border-color: var(--row-color, #9333ea);
}

.step-cell {
    min-height: 44px;
    border-radius: 9px;
    border: 1.5px solid rgba(74, 53, 32, 0.14);
    background: #f8f5ff;
    position: relative;
}

.step-cell.beat-alt {
    background: #efeaff;
}

.step-cell.active {
    background: var(--cell-color, #9333ea);
    border-color: rgba(0, 0, 0, 0.14);
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16);
}

.step-cell.playhead {
    box-shadow: 0 0 0 2.5px #f59e0b;
}

.step-cell.active.playhead {
    transform: scale(1.06);
}

/* Live-Pads */
.live-pads-box {
    margin-top: 4px;
    padding-top: 12px;
    border-top: 1px solid var(--le-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.live-hint {
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--le-ink-soft);
}

.live-pads-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(94px, 1fr));
    gap: 8px;
}

.live-pad-btn {
    min-height: 54px;
    padding: 8px 10px;
    border-radius: 14px;
    border: 2px solid var(--pad-color, #9333ea);
    background: #ffffff;
    font-weight: 900;
    font-size: 0.86rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    box-shadow: 0 3px 0 var(--pad-color, #9333ea);
}

.live-pad-btn.hit,
.live-pad-btn:active {
    background: var(--pad-color, #9333ea);
    color: #ffffff;
    transform: translateY(2px);
    box-shadow: none;
}

/* ==========================================================================
   MODAL (EXPORT & TEILEN)
   ========================================================================== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-dialog {
    width: 100%;
    max-width: 480px;
    background: #ffffff;
    border-radius: 22px;
    padding: 20px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.28);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.modal-title {
    font-size: 1.15rem;
    font-weight: 900;
}

.modal-sub,
.modal-desc {
    font-size: 0.84rem;
    color: var(--le-ink-muted);
    line-height: 1.4;
}

.close-btn {
    min-width: 44px;
    min-height: 44px;
    border-radius: 12px;
    background: var(--le-surface-alt);
    font-size: 1.1rem;
    font-weight: 900;
}

.modal-section {
    padding: 14px;
    border-radius: 16px;
    background: var(--le-surface-alt);
    border: 1px solid var(--le-border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal-section-title {
    font-size: 0.94rem;
    font-weight: 900;
}

.loop-choice-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.loop-btn {
    min-height: 44px;
    padding: 6px;
    border-radius: 10px;
    border: 1px solid var(--le-border-strong);
    background: #ffffff;
    font-size: 0.8rem;
    font-weight: 800;
}

.loop-btn.active {
    background: #9333ea;
    border-color: #9333ea;
    color: #ffffff;
}

.modal-primary-btn {
    min-height: 48px;
    padding: 0 16px;
    border-radius: 14px;
    background: linear-gradient(135deg, #9333ea, #e11d48);
    color: #ffffff;
    font-weight: 900;
    font-size: 0.94rem;
}

.project-io-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.modal-sec-btn {
    min-height: 46px;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid var(--le-border-strong);
    background: #ffffff;
    font-size: 0.82rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
}

.tips-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tip-card {
    padding: 11px 13px;
    border-radius: 14px;
    background: var(--le-surface-alt);
    border: 1px solid var(--le-border);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tip-card strong {
    font-size: 0.88rem;
    color: #581c87;
}

.tip-card p {
    font-size: 0.82rem;
    line-height: 1.45;
    color: var(--le-ink-muted);
}

/* Toast */
.studio-toast {
    position: fixed;
    left: 50%;
    bottom: max(20px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 80;
    background: #1e1b4b;
    color: #ffffff;
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 0.86rem;
    font-weight: 800;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.3);
    max-width: calc(100vw - 32px);
    text-align: center;
}

/* ==========================================================================
   RESPONSIVE (TABLET & SMARTPHONE)
   ========================================================================== */
@media (max-width: 980px) {
    .studio-layout {
        grid-template-columns: 1fr;
    }

    .side-panel {
        order: 2;
    }

    .sequencer-stage {
        order: 1;
    }
}

@media (max-width: 640px) {
    .hide-sm {
        display: none;
    }

    .viz-canvas {
        width: 84px;
    }

    .play-btn {
        min-width: 118px;
        padding: 0 12px;
    }

    .project-io-row {
        grid-template-columns: 1fr;
    }

    .step-header,
    .seq-row {
        grid-template-columns: 92px repeat(16, minmax(40px, 1fr));
        min-width: 730px;
    }
}
