:root {
    --bg: #0f1117;
    --bg-card: #171a22;
    --bg-elevated: #1e222d;
    --border: #2a3040;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --primary: #f97316;
    --primary-dark: #ea580c;
    --success: #22c55e;
    --danger: #ef4444;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    font-family: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    min-height: 100%;
}

a { color: var(--primary); text-decoration: none; }

.app-shell {
    max-width: 480px;
    margin: 0 auto;
    padding: 12px 16px 96px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.logo {
    font-weight: 700;
    font-size: 1.1rem;
}
.logo span { color: var(--primary); }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.credits-pill {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    white-space: nowrap;
}

.icon-btn, .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.avatar {
    background: var(--primary);
    color: #111;
    font-weight: 700;
    text-decoration: none;
}

.hero h2 {
    font-size: 1.35rem;
    line-height: 1.3;
    margin: 0 0 16px;
}

.tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 6px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid transparent;
    color: var(--muted);
    text-decoration: none;
    position: relative;
}

.tab.active {
    border-color: var(--primary);
    color: var(--text);
    background: rgba(249, 115, 22, 0.08);
}

.tab span { font-size: 1.2rem; }
.tab small { font-size: 0.68rem; }

.pro-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    font-style: normal;
    font-size: 0.55rem;
    background: var(--primary);
    color: #111;
    padding: 2px 4px;
    border-radius: 4px;
    font-weight: 700;
}

.create-form {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.tab-panel { display: none; margin-bottom: 16px; }
.tab-panel.active { display: block; }

.field-label {
    display: block;
    font-weight: 600;
    margin: 16px 0 8px;
}

.optional, .required { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.required { color: var(--primary); }

textarea, input[type="text"], input[type="email"], input[type="password"] {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 12px;
    font: inherit;
    resize: vertical;
}

.field-hint {
    color: var(--muted);
    font-size: 0.78rem;
    margin-top: 6px;
}

.tip-card, .pro-card {
    margin-top: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    background: rgba(249, 115, 22, 0.1);
    border: 1px solid rgba(249, 115, 22, 0.25);
}

.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
}

.switch-row input { display: none; }

.switch {
    width: 46px;
    height: 26px;
    background: var(--border);
    border-radius: 999px;
    position: relative;
    transition: background 0.2s;
}

.switch::after {
    content: '';
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 3px;
    left: 3px;
    transition: transform 0.2s;
}

.switch-row input:checked + .switch {
    background: var(--primary);
}

.switch-row input:checked + .switch::after {
    transform: translateX(20px);
}

.chip-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    cursor: pointer;
}

.chip input { display: none; }

.chip span {
    display: inline-block;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg);
    font-size: 0.82rem;
    transition: all 0.15s;
}

.chip input:checked + span {
    background: rgba(249, 115, 22, 0.15);
    border-color: var(--primary);
    color: var(--primary);
}

.voice-toggle {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.voice-toggle label {
    flex: 1;
    min-width: 90px;
    text-align: center;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.voice-toggle input { display: none; }
.voice-toggle input:checked + span,
.voice-toggle label:has(input:checked) {
    border-color: var(--primary);
    background: rgba(249, 115, 22, 0.12);
}

.char-count {
    text-align: right;
    color: var(--muted);
    font-size: 0.75rem;
}

.btn {
    border: none;
    border-radius: 999px;
    padding: 12px 18px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #111;
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; }

.btn-create {
    width: 100%;
    margin-top: 20px;
    padding: 16px;
    font-size: 1rem;
}

.btn-record {
    width: 100%;
    background: linear-gradient(135deg, #fb923c, #f97316);
    color: #111;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
}

.cost-hint {
    text-align: center;
    color: var(--muted);
    font-size: 0.8rem;
}

.record-box {
    text-align: center;
    padding: 8px 0;
}

#wave-preview, #waveform {
    width: 100%;
    margin: 12px 0;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.library { margin-top: 24px; }

.library-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: inherit;
    margin-bottom: 16px;
}

.recent-scroll {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 8px;
}

.recent-item {
    min-width: 140px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    color: inherit;
    position: relative;
}

.recent-item .cover {
    width: 100%;
    aspect-ratio: 1;
    background: var(--bg-elevated);
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-size: 2rem;
    margin-bottom: 8px;
}

.recent-item .meta strong {
    display: block;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.recent-item .duration {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(0,0,0,0.65);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
}

.mini-player {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 12px;
    width: min(480px, calc(100% - 24px));
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow);
}

.player-cover {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--bg);
    display: grid;
    place-items: center;
}

/* Auth */
.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(420px, 100%);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
}

.brand { text-align: center; margin-bottom: 24px; }
.brand-icon { font-size: 2.5rem; }
.brand h1 { margin: 8px 0 4px; }
.brand p { color: var(--muted); margin: 0; }

.form label {
    display: block;
    margin-bottom: 14px;
    font-size: 0.9rem;
}

.alert {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.alert-error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fecaca;
}

.auth-footer, .hint {
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
}

/* Studio */
.studio-shell { max-width: 900px; }

.studio-header h2 { margin: 0 0 4px; }
.studio-meta { color: var(--muted); font-size: 0.85rem; }

.studio-grid {
    display: grid;
    gap: 16px;
}

.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.panel-wide { grid-column: 1 / -1; }

.panel h3 { margin-top: 0; }

.record-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.fx-grid {
    display: grid;
    gap: 12px;
}

.fx-control {
    display: grid;
    grid-template-columns: 120px 1fr 48px;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
}

.fx-control input[type="range"] {
    width: 100%;
    accent-color: var(--primary);
}

.instruments-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.instrument-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 12px;
    cursor: pointer;
    text-align: center;
}

.instrument-btn span { font-size: 1.5rem; display: block; }
.instrument-btn strong { display: block; font-size: 0.85rem; }
.instrument-btn small { color: var(--muted); font-size: 0.72rem; }

.tracks-list { margin: 12px 0; }
.track-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.pad-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.pad-btn, .chip-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 10px;
    cursor: pointer;
}

.chip-btn.active, .pad-btn:active {
    border-color: var(--primary);
    background: rgba(249, 115, 22, 0.15);
}

.chip-grid.compact { margin-top: 8px; }

.mix-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.production-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    display: grid;
    place-items: center;
    z-index: 1000;
}

.production-overlay[hidden] {
    display: none;
}

.production-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 32px;
    text-align: center;
    max-width: 320px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.production-status {
    color: var(--primary);
    font-size: 0.85rem;
    margin-top: 4px;
}

.vocal-playback {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.vocal-time {
    color: var(--muted);
    font-size: 0.85rem;
}

audio {
    width: 100%;
    margin-top: 8px;
}

@media (min-width: 768px) {
    .studio-grid {
        grid-template-columns: 1fr 1fr;
    }
}
