/* ===== RESET & BASE ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    overflow-x: hidden;
    scroll-behavior: smooth;
}

:root {
    --bg: #050505;
    --surface: #0f0f0f;
    --surface2: #181818;
    --border: rgba(251, 191, 36, 0.12);
    --border-bright: rgba(251, 191, 36, 0.3);
    --primary: #fbbf24;
    --primary-glow: rgba(251, 191, 36, 0.4);
    --cyan: #f59e0b;
    --cyan-glow: rgba(245, 158, 11, 0.3);
    --accent: #ffffff;
    --green: #10b981;
    --red: #ff4d4d;
    --text: #ffffff;
    --text-muted: #94a3b8;
    --text-dim: #475569;
    --radius: 20px;
    --radius-sm: 12px;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    align-items: stretch;
    justify-content: center;
}

/* ===== BACKGROUND ===== */
.bg-layer {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.particle {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.35;
}

.p1 {
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, #451a03, transparent 70%);
    top: -20%;
    left: -15%;
    animation: drift1 25s infinite alternate ease-in-out;
}

.p2 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, #1e1b4b, transparent 70%);
    bottom: -15%;
    right: -15%;
    animation: drift2 30s infinite alternate ease-in-out;
}

.p3 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, #1c1917, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: drift3 20s infinite alternate ease-in-out;
}

@keyframes drift1 { from { transform: translate(0, 0); } to { transform: translate(60px, 40px); } }
@keyframes drift2 { from { transform: translate(0, 0); } to { transform: translate(-60px, -40px); } }
@keyframes drift3 { from { transform: translate(-50%, -50%); } to { transform: translate(-45%, -55%); } }

/* ===== APP SHELL ===== */
.app {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 900px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    gap: 0.75rem;
}

/* ===== HEADER ===== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    background: rgba(15, 15, 15, 0.9);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(25px);
    flex-shrink: 0;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

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

.brand-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--cyan));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 0 20px var(--primary-glow);
}

.brand-icon svg {
    width: 20px;
    height: 20px;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.brand-name {
    font-size: 0.95rem;
    font-weight: 900;
    letter-spacing: 2px;
    color: var(--text);
}

.brand-tag {
    font-size: 0.6rem;
    color: var(--primary);
    letter-spacing: 1px;
    font-weight: 600;
}

.status-pill {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.9rem;
    border-radius: 100px;
    background: rgba(255,255,255, 0.04);
    border: 1px solid var(--border);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    transition: all 0.3s ease;
}

.status-pill.active {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.4);
    color: var(--green);
}

.status-pill.extreme {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.4);
    color: var(--red);
    animation: statusPulse 1s infinite;
}

@keyframes statusPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
    50% { box-shadow: 0 0 10px 5px rgba(239, 68, 68, 0); }
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    animation: blink 2s infinite;
}

.status-pill.active .status-dot {
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ===== DASHBOARD ===== */
.dashboard {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex: 1;
}

/* ===== STAT CARDS ===== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.stat-card {
    background: rgba(14, 20, 32, 0.8);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: border-color 0.3s, transform 0.3s;
    min-width: 0;
}

.stat-card:hover {
    border-color: var(--border-bright);
    transform: translateY(-2px);
}

.active-card {
    border-color: rgba(59, 130, 246, 0.3);
    background: rgba(59, 130, 246, 0.06);
}

.stat-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
    line-height: 1;
}

.stat-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    margin-bottom: 0.2rem;
    white-space: nowrap;
}

.stat-value {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.1;
}

.active-card .stat-value {
    color: var(--primary);
    text-shadow: 0 0 20px var(--primary-glow);
}

.stat-unit {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
}

.mono {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem !important;
}

/* ===== CHART CARD ===== */
.chart-card {
    background: rgba(14, 20, 32, 0.8);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    backdrop-filter: blur(20px);
    flex-shrink: 0;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.chart-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.live-badge {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--red);
    letter-spacing: 1px;
}

.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--red);
    animation: blink 1s infinite;
}

.chart-body {
    height: 130px;
    position: relative;
}

canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    border-radius: 8px;
}

/* ===== CONTROLS CARD ===== */
.controls-card {
    background: rgba(14, 20, 32, 0.8);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    backdrop-filter: blur(20px);
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
    align-items: center;
    flex-shrink: 0;
}

.control-item label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.ctrl-val {
    color: var(--primary);
    font-weight: 700;
    font-size: 0.75rem;
}

input[type="range"] {
    width: 100%;
    height: 4px;
    appearance: none;
    -webkit-appearance: none;
    background: var(--surface2);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 0 8px var(--primary-glow);
    transition: transform 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.3);
}

.mode-toggle {
    display: flex;
    gap: 0.4rem;
    background: rgba(255,255,255,0.03);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.mode-btn {
    flex: 1;
    padding: 0.4rem 0.5rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.mode-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 0 12px var(--primary-glow);
}

.mode-btn:nth-child(2).active {
    background: linear-gradient(135deg, #ef4444, #f97316);
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
}

.control-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.btn-start, .btn-stop {
    width: 100%;
    padding: 0.65rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-start {
    background: linear-gradient(135deg, var(--primary), #d97706);
    color: #000;
    box-shadow: 0 4px 20px var(--primary-glow);
}

.btn-start:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 8px 25px var(--primary-glow);
}

.btn-start:disabled {
    background: var(--surface2);
    color: var(--text-dim);
    box-shadow: none;
    cursor: not-allowed;
}

.btn-stop {
    background: rgba(239, 68, 68, 0.1);
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-stop:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.2);
}

.btn-stop:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ===== FOOTER ===== */
.footer {
    text-align: center;
    font-size: 0.65rem;
    color: var(--text-dim);
    padding: 0.25rem;
    flex-shrink: 0;
}

/* ===== ACTIVE STATE OVERRIDES ===== */
body.running .stats-row .active-card {
    border-color: rgba(16, 185, 129, 0.4);
    background: rgba(16, 185, 129, 0.06);
}

body.running .stats-row .active-card .stat-value {
    color: var(--green);
    text-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
    animation: glow 2s infinite;
}

@keyframes glow {
    0%, 100% { text-shadow: 0 0 10px rgba(16, 185, 129, 0.3); }
    50% { text-shadow: 0 0 20px rgba(16, 185, 129, 0.8); }
}

body.extreme .bg-layer .p1 { background: radial-gradient(circle, #7f1d1d, transparent 70%); }
body.extreme .bg-layer .p2 { background: radial-gradient(circle, #92400e, transparent 70%); }

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
    .app {
        padding: 0.6rem;
        gap: 0.6rem;
    }

    .header {
        padding: 0.6rem 0.9rem;
    }

    .brand-name { font-size: 0.8rem; }
    .brand-tag { display: none; }
    .brand-icon { width: 30px; height: 30px; }
    .brand-icon svg { width: 16px; height: 16px; }

    .status-pill { padding: 0.35rem 0.65rem; font-size: 0.6rem; }

    .stats-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .stat-card { padding: 0.75rem; gap: 0.5rem; }
    .stat-icon { font-size: 1.1rem; }
    .stat-value { font-size: 1.05rem; }
    .stat-label { font-size: 0.55rem; }
    .mono { font-size: 0.9rem !important; }

    .chart-card { padding: 0.75rem; }
    .chart-body { height: 100px; }

    .controls-card {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        padding: 0.9rem;
    }

    .control-actions {
        flex-direction: row;
    }
}

@media (max-width: 380px) {
    .stat-value { font-size: 0.9rem; }
    .stat-icon { display: none; }
}
