:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --text: #0f172a;
    --text-muted: #64748b;
    --brand: #10b981;
    --brand-hover: #059669;
    --border: #e2e8f0;
    --player-bg: rgba(255, 255, 255, 0.9);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --error: #ef4444;
    --success: #10b981;
    --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

a { text-decoration: none; transition: color 0.2s; }

/* Header / Topbar */
.topbar {
    position: sticky; top: 0; z-index: 100;
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    background: rgba(255, 255, 255, 0.8);
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 2rem;
}

.topbar-logo { font-size: 1.4rem; font-weight: 800; color: var(--text); letter-spacing: -0.02em; }
.auth-info { font-size: 0.9rem; color: var(--text-muted); }
.auth-info a { color: var(--text); font-weight: 500; }
.auth-info a:hover { color: var(--brand); }
.logout { color: var(--error) !important; }

/* Layout Containers */
.wrap { max-width: 900px; margin: 2rem auto; padding: 0 1rem; }
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}
.card-title {
    font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 1px; color: var(--text-muted); margin-bottom: 1rem;
}

/* Typography */
h1 { font-size: 2rem; font-weight: 800; margin-bottom: 0.5rem; letter-spacing: -0.03em; }
.subtitle { color: var(--text-muted); margin-bottom: 2rem; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.7rem 1.4rem; border-radius: var(--radius); font-weight: 600;
    cursor: pointer; transition: all 0.2s; border: none; font-size: 0.95rem;
}
.btn-primary {
    background: var(--brand); color: white;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.2);
}
.btn-primary:hover:not(:disabled) {
    background: var(--brand-hover); transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}
.btn-secondary { background: var(--surface-hover); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Forms */
.field { margin-bottom: 1.2rem; }
label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.4rem; }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
    width: 100%; padding: 0.75rem 1rem; border-radius: 10px;
    border: 1px solid var(--border); background: var(--bg);
    font-size: 0.95rem; color: var(--text); transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1); }

/* Steps Component (Generate Page) */
.step { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem; overflow: hidden; background: var(--surface); }
.step-head { display: flex; align-items: center; gap: 1rem; padding: 1rem; background: var(--surface-hover); }
.step-num {
    width: 2rem; height: 2rem; border-radius: 50%; background: var(--border); color: var(--text-muted);
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem;
}
.step-num.running { background: var(--brand); color: white; }
.step-num.done { background: var(--success); color: white; }
.step-num.error { background: var(--error); color: white; }
.step-title { flex: 1; font-weight: 600; }
.step-body { padding: 1.2rem; display: none; border-top: 1px solid var(--border); }

/* Toggle Switch (Settings Page) */
.toggle-row { display: flex; align-items: center; gap: 1rem; }
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; inset: 0; cursor: pointer; background: var(--border);
    border-radius: 24px; transition: background .2s;
}
.slider::before {
    content: ''; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px;
    background: white; border-radius: 50%; transition: transform .2s;
}
.toggle input:checked + .slider { background: var(--brand); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* Progress Bars */
.progress-bar { height: 4px; background: var(--border); border-radius: 2px; margin: 1rem 0; overflow: hidden; }
.progress-fill { height: 100%; background: var(--brand); width: 0%; transition: width 0.3s; }
.progress-fill.loading { animation: pulse 1.5s infinite; width: 40% !important; }
@keyframes pulse { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }

/* Player Panel (Index Page) */
#player-panel {
    display: none; position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px;
    width: min(900px, 95%); background: var(--player-bg); backdrop-filter: blur(20px);
    border: 1px solid var(--border); box-shadow: var(--shadow-lg);
    border-radius: 24px; padding: 1.2rem; z-index: 999;
}

/* Playlist (Index Page) */
.track-row {
    display: grid; grid-template-columns: 50px 1fr 120px 60px;
    align-items: center; padding: 0.75rem 1rem; border-radius: var(--radius);
    cursor: pointer; transition: background 0.2s;
}
.track-row:hover { background: var(--surface-hover); }
.track-row.active { background: rgba(16, 185, 129, 0.08); color: var(--brand); }

/* Login specific */
.login-card { max-width: 400px; margin: 10vh auto; }
.error-box { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; padding: 0.8rem; border-radius: 10px; margin-bottom: 1rem; font-size: 0.9rem; }

/* Helpers */
.mt-2 { margin-top: 0.5rem; }
.text-center { text-align: center; }
.log { background: #1e293b; color: #e2e8f0; padding: 1rem; border-radius: 8px; font-family: monospace; font-size: 0.8rem; overflow-y: auto; max-height: 200px; margin-top: 1rem; }
.l-run { color: #60a5fa; }
.l-done { color: #34d399; }
.l-err { color: #f87171; }