:root {
    --bg: #050303;
    --bg-elevated: #110a08;
    --bg-card: #180f0c;
    --border: #3d1d14;
    --border-gold: rgba(203, 178, 121, 0.34);
    --text: #f3eadb;
    --text-muted: #b5a387;
    --amber: #cbb279;
    --amber-bright: #e0cb97;
    --wood: #905431;
    --wood-dark: #5e2c15;
    --crimson: #9e1b1e;
    --crimson-deep: #591607;
    --crimson-soft: rgba(158, 27, 30, 0.2);
    --green: #3cb371;
    --green-soft: rgba(60, 179, 113, 0.16);
    --radius: 10px;
    --shadow: 0 18px 46px rgba(0, 0, 0, 0.72);
    --font-serif: Georgia, "Palatino Linotype", "Book Antiqua", Palatino, serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: radial-gradient(circle at top right, #261914 0%, var(--bg) 60%);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

a { color: var(--amber); text-decoration: none; }
a:hover { color: var(--amber-bright); }

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1.5rem;
    background: rgba(20, 15, 13, 0.92);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(8px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--crimson), var(--amber));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.05rem;
    color: #160d0a;
    letter-spacing: -0.02em;
}

.brand-title { font-weight: 700; font-size: 1.05rem; margin: 0; }
.brand-sub { font-size: 0.78rem; color: var(--text-muted); margin: 0; }

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #8a7b70;
}

.status-pill.is-online {
    border-color: rgba(60, 179, 113, 0.5);
    color: #9be8ba;
}

.status-pill.is-online .status-dot {
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
}

.container {
    width: 100%;
    max-width: 1460px;
    margin: 0 auto;
    padding: 1.5rem 1.5rem 3.5rem;
}

.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.75rem;
    flex-wrap: wrap;
}

.tab-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
    padding: 0.55rem 1rem;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.92rem;
    font-weight: 600;
    transition: all 0.15s ease;
}

.tab-btn:hover { color: var(--text); background: var(--bg-card); }
.tab-btn.is-active {
    background: linear-gradient(135deg, var(--crimson), #962b2b);
    color: #fff;
    border-color: rgba(247, 184, 84, 0.35);
}

.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.35rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
}

.card-title {
    margin: 0 0 0.35rem;
    font-size: 1.15rem;
    color: var(--amber-bright);
}

.card-sub {
    margin: 0 0 1rem;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1.25rem;
}

.ai-studio-grid {
    display: grid;
    grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
}

.ai-player-wide {
    width: 100%;
    background: linear-gradient(180deg, #160c09 0%, #100806 100%);
    border: 1px solid rgba(203, 178, 121, 0.48);
    border-radius: var(--radius);
    padding: 1.25rem 1.4rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

.ai-player-wide audio {
    width: 100%;
    height: 46px;
    margin: 0.85rem 0 0.5rem;
    display: block;
}

.ai-player-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.ai-player-speed {
    min-width: 210px;
}

@media (max-width: 1050px) {
    .ai-studio-grid {
        grid-template-columns: 1fr;
    }
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.58rem 1.05rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn:hover { border-color: var(--amber); color: var(--amber-bright); }
.btn-primary {
    background: linear-gradient(135deg, var(--amber), #c47d1e);
    color: #160d0a;
    border-color: transparent;
}
.btn-primary:hover { filter: brightness(1.08); color: #160d0a; }
.btn-danger {
    background: var(--crimson-soft);
    border-color: rgba(194, 59, 59, 0.5);
    color: #f39a9a;
}
.btn-danger:hover { background: var(--crimson); color: #fff; }
.btn-sm { padding: 0.38rem 0.72rem; font-size: 0.82rem; }

.alert {
    padding: 0.85rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    border: 1px solid transparent;
}
.alert-success { background: var(--green-soft); border-color: rgba(60, 179, 113, 0.4); color: #a7f0c4; }
.alert-error { background: var(--crimson-soft); border-color: rgba(194, 59, 59, 0.5); color: #f6b3b3; }

label {
    display: block;
    font-size: 0.84rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    font-weight: 600;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    font-size: 0.93rem;
    font-family: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--amber);
}

.form-row { margin-bottom: 0.9rem; }
.form-inline { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: end; }
.form-inline > div { flex: 1 1 140px; }

/* Metronome */
.beat-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(46px, 1fr));
    gap: 0.55rem;
    margin: 1.25rem 0;
}

.beat-pill {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 0.35rem;
    border-radius: 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-muted);
    transition: transform 0.06s ease, background 0.06s ease;
    user-select: none;
}

.beat-pill.is-accent {
    border-color: rgba(226, 155, 56, 0.55);
    color: var(--amber-bright);
    background: rgba(226, 155, 56, 0.1);
}

.beat-pill .beat-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-top: 0.3rem;
    background: transparent;
}

.beat-pill.is-accent .beat-dot { background: var(--amber); }

.beat-pill.is-current {
    transform: scale(1.09);
    background: var(--amber);
    color: #160d0a;
    border-color: var(--amber-bright);
    box-shadow: 0 0 18px rgba(226, 155, 56, 0.55);
}

.beat-pill.is-current.is-accent {
    background: var(--crimson);
    color: #fff;
    border-color: #ff7e7e;
    box-shadow: 0 0 20px rgba(194, 59, 59, 0.7);
}

.metro-readout {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.bpm-big {
    font-size: 2.8rem;
    font-weight: 800;
    color: var(--amber-bright);
    line-height: 1;
}

.bpm-big span { font-size: 0.95rem; font-weight: 600; color: var(--text-muted); margin-left: 0.25rem; }

.metro-controls {
    display: flex;
    gap: 0.65rem;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 1rem;
}

/* Pieces & Player */
.piece-list { display: flex; flex-direction: column; gap: 0.9rem; }

.piece-item {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.piece-head {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.piece-title { font-weight: 700; font-size: 1.02rem; margin: 0; }

.badges { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.3rem; }
.badge {
    font-size: 0.75rem;
    padding: 0.18rem 0.55rem;
    border-radius: 999px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.badge-amber { border-color: rgba(226, 155, 56, 0.45); color: var(--amber-bright); }
.badge-green { border-color: rgba(60, 179, 113, 0.45); color: #9be8ba; }
.badge-crimson { border-color: rgba(194, 59, 59, 0.55); color: #f6b3b3; background: rgba(158, 27, 30, 0.16); }

.rag-filter-bar {
    display: grid;
    grid-template-columns: minmax(200px, 1.4fr) minmax(150px, 0.8fr) minmax(150px, 0.8fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.rag-clip-box {
    margin-top: 0.9rem;
    padding-top: 0.9rem;
    border-top: 1px dashed var(--border-gold);
}

.rag-ref-box {
    background: rgba(203, 178, 121, 0.06);
    border: 1px solid var(--border-gold);
    border-radius: 8px;
    padding: 0.75rem 0.85rem;
    margin-bottom: 0.9rem;
}

.rag-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 0.9rem;
}

@media (max-width: 760px) {
    .rag-filter-bar {
        grid-template-columns: 1fr;
    }
}

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

.player-box {
    background: var(--bg-elevated);
    border: 1px solid rgba(226, 155, 56, 0.4);
    border-radius: 10px;
    padding: 1rem;
    margin-bottom: 1.25rem;
}

.player-box audio { width: 100%; margin: 0.65rem 0; }

.looper-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
    margin-top: 0.5rem;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.75rem 0 1rem;
    font-size: 0.88rem;
    color: var(--text);
}
.checkbox-row input { width: auto; }

/* Login screen — theatrical poster inspired by muestra.png */
.auth-stage {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.75rem 1.25rem;
    background:
        radial-gradient(circle at 22% 45%, rgba(144, 84, 49, 0.19) 0%, transparent 48%),
        radial-gradient(circle at 75% 28%, rgba(158, 27, 30, 0.16) 0%, transparent 45%),
        linear-gradient(180deg, #020101 0%, #0a0604 55%, #030202 100%);
}

.poster-frame {
    position: relative;
    width: 100%;
    max-width: 460px;
    padding: 14px;
    border: 1px solid rgba(158, 27, 30, 0.65);
    background: rgba(5, 3, 3, 0.92);
    box-shadow: 0 28px 70px rgba(0, 0, 0, 0.88), 0 0 42px rgba(89, 22, 7, 0.22);
}

.poster-frame::before {
    content: "";
    position: absolute;
    inset: 6px;
    border: 1px solid rgba(203, 178, 121, 0.24);
    pointer-events: none;
}

.corner {
    position: absolute;
    width: 18px;
    height: 18px;
    border-color: var(--crimson);
    border-style: solid;
    pointer-events: none;
}
.corner-tl { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.corner-tr { top: -1px; right: -1px; border-width: 2px 2px 0 0; }
.corner-bl { bottom: -1px; left: -1px; border-width: 0 0 2px 2px; }
.corner-br { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }

.auth-poster-card {
    position: relative;
    background: linear-gradient(180deg, #0b0605 0%, #070403 100%);
    border: 1px solid rgba(94, 44, 21, 0.55);
    padding: 2.1rem 2rem 1.75rem;
}

.poster-header {
    text-align: center;
    margin-bottom: 1.6rem;
}

.poster-crest {
    display: block;
    margin: 0 auto 0.65rem;
}

.poster-kicker {
    margin: 0;
    font-family: var(--font-serif);
    font-size: 0.82rem;
    letter-spacing: 0.34em;
    color: var(--amber);
    text-transform: uppercase;
}

.poster-title {
    margin: 0.18rem 0 0;
    font-family: var(--font-serif);
    font-size: 2.45rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    line-height: 1.05;
    color: var(--crimson);
    text-shadow: 0 2px 16px rgba(158, 27, 30, 0.38);
}

.poster-script {
    margin: -0.15rem 0 0.85rem;
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 1.75rem;
    font-weight: 400;
    color: var(--amber-bright);
    letter-spacing: 0.04em;
}

.poster-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    margin: 0.6rem auto 0.9rem;
    max-width: 260px;
}

.poster-line {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(158, 27, 30, 0.85), transparent);
}

.poster-diamond {
    width: 8px;
    height: 8px;
    background: var(--crimson);
    border: 1px solid var(--amber);
    transform: rotate(45deg);
}

.poster-plaque {
    display: inline-block;
    padding: 0.38rem 1.1rem;
    border: 1px solid rgba(203, 178, 121, 0.45);
    outline: 1px solid rgba(203, 178, 121, 0.18);
    outline-offset: 3px;
    background: rgba(17, 10, 8, 0.85);
    font-family: var(--font-serif);
    font-size: 0.72rem;
    letter-spacing: 0.2em;
    color: var(--amber);
}

.poster-form {
    margin-top: 1.35rem;
}

.poster-label {
    font-family: var(--font-serif);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-size: 0.74rem;
    color: var(--amber);
    margin-bottom: 0.35rem;
}

.poster-input {
    background: #0d0706;
    border: 1px solid rgba(144, 84, 49, 0.55);
    color: var(--text);
    border-radius: 4px;
    padding: 0.72rem 0.85rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.poster-input:focus {
    border-color: var(--amber);
    box-shadow: 0 0 0 2px rgba(203, 178, 121, 0.18);
}

.btn-poster-ribbon {
    width: 100%;
    margin-top: 0.65rem;
    padding: 0.8rem 1.2rem;
    border: 1px solid rgba(203, 178, 121, 0.65);
    border-radius: 4px;
    background: linear-gradient(180deg, #a61c20 0%, #741215 62%, #59100e 100%);
    color: #f9f1e2;
    font-family: var(--font-serif);
    font-size: 0.96rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: 0 8px 22px rgba(116, 18, 21, 0.45);
    transition: filter 0.15s ease, transform 0.1s ease;
}

.btn-poster-ribbon:hover {
    filter: brightness(1.12);
    border-color: var(--amber-bright);
}

.btn-poster-ribbon:active {
    transform: translateY(1px);
}

.poster-footer {
    margin-top: 1.5rem;
    padding-top: 0.9rem;
    border-top: 1px solid rgba(94, 44, 21, 0.4);
    text-align: center;
    font-family: var(--font-serif);
    font-size: 0.7rem;
    letter-spacing: 0.24em;
    color: rgba(203, 178, 121, 0.65);
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 50;
}
.modal-backdrop.is-open { display: flex; }
.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.4rem;
    width: 100%;
    max-width: 430px;
    box-shadow: var(--shadow);
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 0.86rem; }
.mt-1 { margin-top: 0.75rem; }
.mb-auth { margin-bottom: 1.4rem; }
.btn-full { width: 100%; margin-top: 0.4rem; }

/* Studio Sidebar Layout */
.studio-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 268px;
    flex-shrink: 0;
    background: linear-gradient(180deg, #0b0605 0%, #060303 100%);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 35;
    transition: width 0.2s ease, transform 0.22s ease;
}

.studio-shell.sidebar-collapsed .sidebar {
    width: 0;
    overflow: hidden;
    border-right-color: transparent;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.1rem 1.1rem 1rem;
    border-bottom: 1px solid rgba(203, 178, 121, 0.16);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 1.15rem;
}

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 0.22rem;
}

.nav-group-label {
    margin: 0 0 0.25rem 0.6rem;
    font-family: var(--font-serif);
    font-size: 0.69rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(203, 178, 121, 0.65);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    text-align: left;
    padding: 0.56rem 0.75rem;
    border-radius: 7px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.89rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.14s ease;
}

.nav-item:hover {
    color: var(--text);
    background: rgba(144, 84, 49, 0.14);
}

.nav-item.is-active {
    background: linear-gradient(90deg, rgba(158, 27, 30, 0.34), rgba(89, 22, 7, 0.18));
    border-color: rgba(203, 178, 121, 0.32);
    color: var(--amber-bright);
    font-weight: 600;
}

.nav-subitem {
    padding-left: 1.65rem;
    font-size: 0.83rem;
}

.nav-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(203, 178, 121, 0.4);
    flex-shrink: 0;
}

.nav-item.is-active .nav-dot {
    background: var(--crimson);
    box-shadow: 0 0 8px rgba(158, 27, 30, 0.85);
}

.nav-text { flex: 1; }

.nav-count {
    font-size: 0.72rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    background: rgba(203, 178, 121, 0.12);
    color: var(--amber);
    border: 1px solid rgba(203, 178, 121, 0.2);
}

.sidebar-footer {
    padding: 0.9rem;
    border-top: 1px solid rgba(203, 178, 121, 0.16);
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.status-pill-full {
    width: 100%;
    justify-content: flex-start;
}

.sidebar-account-actions {
    display: flex;
    gap: 0.5rem;
}

.sidebar-account-actions > button,
.sidebar-account-actions > form {
    flex: 1;
}
.sidebar-account-actions > form > button { width: 100%; }

.studio-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 30;
}

/* Upload progress */
.upload-progress {
    margin: 0.75rem 0 1rem;
    padding: 0.75rem 0.9rem;
    border-radius: 8px;
    background: var(--bg-elevated);
    border: 1px solid rgba(203, 178, 121, 0.35);
}

.upload-progress-head {
    display: flex;
    justify-content: space-between;
    font-size: 0.84rem;
    color: var(--amber-bright);
    margin-bottom: 0.45rem;
}

.upload-progress-track {
    width: 100%;
    height: 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.upload-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--crimson), var(--amber));
    transition: width 0.15s ease;
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        width: 268px !important;
    }
    .studio-shell.sidebar-open .sidebar {
        transform: translateX(0);
    }
    .studio-shell.sidebar-open .sidebar-overlay {
        display: block;
    }
}
