:root {
    --bg: #0d0d1a;
    --card: #141428;
    --fg: #e8e8f0;
    --muted: #8888a0;
    --accent: #00d4aa;
    --accent-dim: #00d4aa40;
    --danger: #ff4757;
    --danger-dim: #ff475740;
    --warn: #ffa502;
    --warn-dim: #ffa50240;
    --border: #2a2a44;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
    --radius: 12px;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --font-sans: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f4f4f8;
        --card: #ffffff;
        --fg: #1a1a2e;
        --muted: #666680;
        --border: #dcdce8;
        --shadow: 0 4px 24px rgba(0,0,0,0.08);
    }
}

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--fg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(8px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand .logo {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-dim);
    padding: 6px 12px;
    border-radius: 8px;
}

.brand h1 { font-size: 1.1rem; font-weight: 600; }
.brand small { color: var(--muted); font-size: 0.75rem; }

.status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg);
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.status-pill .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted);
}

.status-pill.online .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.status-pill.online { border-color: var(--accent); color: var(--accent); }
.status-pill.offline .dot { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.status-pill.offline { border-color: var(--danger); color: var(--danger); }
.status-pill.starting { border-color: var(--warn); color: var(--warn); }
.status-pill.starting .dot { background: var(--warn); box-shadow: 0 0 8px var(--warn); animation: pulse 1.5s infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

main.grid {
    flex: 1;
    padding: 24px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(0,0,0,0.5); }

.card h2 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}

/* Stream Monitor */
.stream-display { display: flex; gap: 20px; align-items: flex-start; }
.waveform {
    flex: 1;
    height: 80px;
    background: var(--bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.waveform canvas { width: 100%; height: 100%; }

.stream-info { display: flex; flex-direction: column; gap: 8px; min-width: 180px; }
.info-row { display: flex; justify-content: space-between; gap: 12px; }
.info-row .k { color: var(--muted); font-size: 0.8rem; }
.info-row .v { font-family: var(--font-mono); font-size: 0.85rem; font-weight: 500; text-align: right; }

.audio-player { margin-top: 16px; width: 100%; }
.audio-player audio { width: 100%; }

/* Broadcast Control */
.controls { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-start { background: var(--accent); color: var(--bg); }
.btn-start:hover:not(:disabled) { background: #00e8bb; transform: scale(1.02); }
.btn-start:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-stop { background: var(--danger); color: white; }
.btn-stop:hover:not(:disabled) { background: #ff6b7a; transform: scale(1.02); }
.btn-stop:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-restart { background: var(--warn); color: var(--bg); }
.btn-restart:hover { background: #ffb830; transform: scale(1.02); }

.btn-add { background: var(--accent); color: var(--bg); }
.btn-add:hover { background: #00e8bb; }

.preset { margin-bottom: 16px; }
.preset label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.preset select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--fg);
    font-family: inherit;
    font-size: 0.9rem;
}

.target-config { display: flex; flex-direction: column; gap: 12px; }
.target-config label { font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; display: block; }
.target-config input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--fg);
    font-family: inherit;
    font-size: 0.9rem;
}
.target-config input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

/* Vitals */
.vitals-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.metric { display: flex; flex-direction: column; gap: 6px; }
.metric-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.metric-bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.metric-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease, background 0.3s;
    background: linear-gradient(90deg, var(--accent), #00e8bb);
}
.metric-fill.warn { background: linear-gradient(90deg, var(--warn), #ffb830); }
.metric-fill.danger { background: linear-gradient(90deg, var(--danger), #ff6b7a); }
.metric-value { font-family: var(--font-mono); font-size: 1.2rem; font-weight: 600; text-align: right; }

/* Playlist */
.playlist { min-height: 120px; max-height: 200px; overflow-y: auto; margin-bottom: 16px; }
.playlist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    transition: all 0.2s;
}
.playlist-item:hover { border-color: var(--accent); }
.playlist-item.playing { border-color: var(--accent); background: var(--accent-dim); }
.playlist-item .num { font-family: var(--font-mono); font-size: 0.8rem; color: var(--muted); width: 24px; }
.playlist-item .title { flex: 1; font-size: 0.85rem; }
.playlist-item .actions { display: flex; gap: 6px; }
.playlist-item button { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; font-size: 0.85rem; }
.playlist-item button:hover { color: var(--accent); }
.playlist-item button.danger:hover { color: var(--danger); }

.playlist-add { display: flex; gap: 10px; }
.playlist-add input { flex: 1; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--fg); font-family: inherit; }

/* Logs */
.logs {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    background: var(--bg);
    border-radius: 8px;
    padding: 12px;
    max-height: 200px;
    overflow-y: auto;
    line-height: 1.6;
}
.log-entry { border-bottom: 1px solid var(--border); padding: 4px 0; display: flex; gap: 8px; }
.log-entry:last-child { border-bottom: none; }
.log-time { color: var(--muted); white-space: nowrap; }
.log-level { font-weight: 600; text-transform: uppercase; font-size: 0.65rem; }
.log-level.info { color: var(--accent); }
.log-level.warn { color: var(--warn); }
.log-level.error { color: var(--danger); }
.log-level.debug { color: var(--muted); }
.log-message { flex: 1; color: var(--fg); }

/* Footer */
.footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--card);
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--muted);
}

#connection-state {
    font-family: var(--font-mono);
    padding: 4px 8px;
    border-radius: 4px;
    background: var(--bg);
}

#connection-state.connected { color: var(--accent); }
#connection-state.disconnected { color: var(--danger); }
#connection-state.connecting { color: var(--warn); }

/* Responsive */
@media (max-width: 768px) {
    main.grid { grid-template-columns: 1fr; padding: 16px; }
    .topbar { flex-direction: column; gap: 12px; text-align: center; }
    .vitals-grid { grid-template-columns: 1fr; }
    .stream-display { flex-direction: column; }
    .stream-info { flex-direction: row; flex-wrap: wrap; min-width: 0; }
    .info-row { flex: 1; min-width: 140px; }
}

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.card { animation: fadeIn 0.4s ease forwards; }
.card:nth-child(1) { animation-delay: 0.05s; }
.card:nth-child(2) { animation-delay: 0.1s; }
.card:nth-child(3) { animation-delay: 0.15s; }
.card:nth-child(4) { animation-delay: 0.2s; }
.card:nth-child(5) { animation-delay: 0.25s; }
.card:nth-child(6) { animation-delay: 0.3s; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }