/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   PHYSARUM LAB — DESIGN SYSTEM
   Color tokens, layout, and component styles for the bio-simulation terminal.
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */

:root {
    /* Backgrounds */
    --bg:         #020509;
    --bg-panel:   #03070e;
    --bg-card:    #050c18;
    --bg-input:   #040a14;

    /* Accents */
    --cyan:       #00e5ff;
    --cyan-dim:   rgba(0, 229, 255, 0.45);
    --cyan-faint: rgba(0, 229, 255, 0.12);
    --violet:     #7c3aed;
    --green:      #00ffa3;
    --green-dim:  rgba(0, 255, 163, 0.4);
    --amber:      #ffb347;

    /* Borders */
    --border:     rgba(0, 180, 220, 0.15);
    --border-hi:  rgba(0, 229, 255, 0.50);

    /* Text */
    --txt:        #7aa8c0;
    --txt-bright: #c0dff0;
    --txt-dim:    #1e3a52;
    --txt-mono:   'Cascadia Code', 'Consolas', 'Courier New', monospace;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    width: 100%; height: 100%;
    background: var(--bg);
    color: var(--txt);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 13px;
    overflow: hidden;
}

/* ── App layout ──────────────────────────────────────────────────────────── */

.app { display: flex; width: 100%; height: 100vh; }

/* ── Canvas area ─────────────────────────────────────────────────────────── */

.canvas-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    overflow: hidden;
    position: relative;
}

/* Scanline CRT overlay */
.canvas-wrap::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px, transparent 3px,
        rgba(0, 0, 0, 0.06) 3px, rgba(0, 0, 0, 0.06) 4px
    );
    pointer-events: none;
    z-index: 10;
}

/* Corner-bracket frame around the canvas */
.canvas-frame {
    position: relative;
    display: inline-flex;
    max-width: 100%;
    max-height: 100%;
}

.canvas-frame::before,
.canvas-frame::after,
.cnr {
    position: absolute;
    width: 22px;
    height: 22px;
    pointer-events: none;
    z-index: 11;
    transition: border-color 0.3s;
}

.canvas-frame::before {
    content: '';
    top: 0; left: 0;
    border-top:  2px solid var(--border-hi);
    border-left: 2px solid var(--border-hi);
    box-shadow: -2px -2px 10px rgba(0,229,255,0.15);
}
.canvas-frame::after {
    content: '';
    bottom: 0; right: 0;
    border-bottom: 2px solid var(--border-hi);
    border-right:  2px solid var(--border-hi);
    box-shadow: 2px 2px 10px rgba(0,229,255,0.15);
}
.cnr-tr { top: 0; right: 0; border-top: 2px solid var(--border-hi); border-right: 2px solid var(--border-hi); box-shadow: 2px -2px 10px rgba(0,229,255,0.15); }
.cnr-bl { bottom: 0; left: 0; border-bottom: 2px solid var(--border-hi); border-left: 2px solid var(--border-hi); box-shadow: -2px 2px 10px rgba(0,229,255,0.15); }

.sim-canvas {
    display: block;
    max-width:  100%;
    max-height: 100%;
    aspect-ratio: 1 / 1;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    cursor: crosshair;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */

.sidebar {
    width: 280px;
    min-width: 230px;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    /* Inward glow on the left edge to echo the canvas */
    box-shadow: inset 4px 0 40px rgba(0,229,255,0.025);
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 0 16px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,229,255,0.15) transparent;
}

.sidebar::-webkit-scrollbar       { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(0,229,255,0.15); border-radius: 2px; }

/* ── Sidebar header ──────────────────────────────────────────────────────── */

.hdr {
    padding: 18px 16px 14px;
    border-bottom: 1px solid var(--border);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

/* Animated gradient scanline in header */
.hdr::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, var(--cyan-dim) 50%, transparent 100%);
    animation: hdr-scan 4s ease-in-out infinite;
}

.hdr-title {
    font-family: var(--txt-mono);
    font-size: 15px;
    font-weight: bold;
    letter-spacing: 0.22em;
    color: var(--cyan);
    text-shadow: 0 0 14px rgba(0,229,255,0.6), 0 0 30px rgba(0,229,255,0.2);
    animation: title-glow 3.5s ease-in-out infinite;
    margin-bottom: 3px;
}

/* Blinking block cursor after title */
.hdr-title::after {
    content: '▮';
    font-size: 11px;
    margin-left: 4px;
    opacity: 1;
    animation: blink 1.1s step-start infinite;
}

.hdr-sub {
    font-family: var(--txt-mono);
    font-size: 8.5px;
    letter-spacing: 0.15em;
    color: var(--txt-dim);
    text-transform: uppercase;
    margin-bottom: 10px;
}

.hdr-status {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hdr-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #1e3040;
    border: 1px solid rgba(0,229,255,0.2);
    transition: background 0.4s, box-shadow 0.4s;
    flex-shrink: 0;
}

.hdr-dot--run {
    background: var(--green);
    border-color: var(--green);
    box-shadow: 0 0 8px var(--green), 0 0 20px rgba(0,255,163,0.3);
    animation: dot-pulse 2.2s ease-in-out infinite;
}

.hdr-meta {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.hdr-state {
    font-family: var(--txt-mono);
    font-size: 9.5px;
    letter-spacing: 0.14em;
    color: var(--txt-dim);
    text-transform: uppercase;
    transition: color 0.3s;
}

.hdr-fps {
    font-family: var(--txt-mono);
    font-size: 9px;
    color: rgba(0,229,255,0.3);
    letter-spacing: 0.1em;
}

/* ── Sidebar content padding wrapper ─────────────────────────────────────── */
.sidebar-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    flex: 1;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.btn {
    flex: 1;
    min-width: 70px;
    padding: 7px 8px;
    background: rgba(0,229,255,0.03);
    color: rgba(0,229,255,0.6);
    border: 1px solid rgba(0,229,255,0.18);
    border-radius: 2px;
    cursor: pointer;
    font-family: var(--txt-mono);
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    transition: background 0.16s, border-color 0.16s, color 0.16s, box-shadow 0.16s;
    text-align: center;
    white-space: nowrap;
}

.btn:hover {
    background: rgba(0,229,255,0.09);
    border-color: rgba(0,229,255,0.55);
    color: var(--cyan);
    box-shadow: 0 0 10px rgba(0,229,255,0.18), inset 0 0 8px rgba(0,229,255,0.04);
    text-shadow: 0 0 8px rgba(0,229,255,0.5);
}

.btn:active {
    background: rgba(0,229,255,0.06);
    transform: translateY(1px);
    box-shadow: none;
}

/* "primary" button (run/pause) has stronger presence */
.btn--primary {
    border-color: rgba(0,229,255,0.30);
    color: var(--cyan);
}
.btn--primary:hover {
    background: rgba(0,229,255,0.12);
    box-shadow: 0 0 16px rgba(0,229,255,0.25), inset 0 0 12px rgba(0,229,255,0.06);
}

/* ── Section card (reused by panel + stats) ──────────────────────────────── */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

/* Left-edge accent bar */
.card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 2px;
    background: linear-gradient(to bottom, var(--cyan-dim), transparent);
}

/* Top-right corner notch */
.card::after {
    content: '';
    position: absolute;
    top: 0; right: 0;
    border-top:   6px solid rgba(0,229,255,0.25);
    border-left:  6px solid transparent;
}

.card-header {
    padding: 7px 12px 6px 14px;
    border-bottom: 1px solid var(--border);
    font-family: var(--txt-mono);
    font-size: 9px;
    letter-spacing: 0.18em;
    color: rgba(0,229,255,0.45);
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 7px;
    background: rgba(0,229,255,0.02);
}

.card-header-icon {
    color: var(--cyan);
    font-size: 10px;
    opacity: 0.7;
}

/* ── Slider panel ────────────────────────────────────────────────────────── */

.panel { display: flex; flex-direction: column; gap: 8px; }

.panel-group { composes: card; }

.panel-group {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 2px;
    position: relative;
    overflow: hidden;
}

.panel-group::before {
    content: '';
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 2px;
    background: linear-gradient(to bottom, var(--cyan-dim), transparent);
}

.panel-group::after {
    content: '';
    position: absolute;
    top: 0; right: 0;
    border-top:  6px solid rgba(0,229,255,0.25);
    border-left: 6px solid transparent;
}

.panel-group-title {
    padding: 7px 12px 6px 14px;
    border-bottom: 1px solid var(--border);
    font-family: var(--txt-mono);
    font-size: 9px;
    letter-spacing: 0.18em;
    color: rgba(0,229,255,0.45);
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 7px;
    background: rgba(0,229,255,0.02);
}

.panel-group-title::before {
    content: '▎';
    color: var(--cyan);
    opacity: 0.6;
    font-size: 11px;
    line-height: 1;
}

.panel-rows { padding: 8px 12px 10px 14px; }

.panel-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 9px;
}
.panel-row:last-child { margin-bottom: 0; }

.panel-label {
    flex: 1;
    font-size: 11px;
    color: var(--txt);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: help;
}

.panel-value {
    font-family: var(--txt-mono);
    font-size: 10.5px;
    color: var(--cyan);
    width: 38px;
    text-align: right;
    text-shadow: 0 0 6px rgba(0,229,255,0.35);
    flex-shrink: 0;
}

/* ── Custom range slider ─────────────────────────────────────────────────── */

input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 88px;
    height: 2px;
    flex-shrink: 0;
    background: linear-gradient(
        to right,
        var(--cyan) 0%,
        var(--cyan) var(--val, 0%),
        rgba(0,229,255,0.12) var(--val, 0%),
        rgba(0,229,255,0.12) 100%
    );
    border-radius: 1px;
    outline: none;
    cursor: pointer;
    box-shadow: 0 0 6px rgba(0,229,255,0.08);
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    background: var(--cyan);
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    box-shadow: 0 0 8px rgba(0,229,255,0.8), 0 0 16px rgba(0,229,255,0.3);
    cursor: pointer;
    transition: box-shadow 0.15s;
}

input[type=range]::-moz-range-thumb {
    width: 9px; height: 9px;
    background: var(--cyan);
    border: none;
    border-radius: 1px;
    transform: rotate(45deg);
    box-shadow: 0 0 8px rgba(0,229,255,0.8);
    cursor: pointer;
}

input[type=range]::-moz-range-track {
    height: 2px;
    background: rgba(0,229,255,0.12);
    border-radius: 1px;
}

input[type=range]:focus::-webkit-slider-thumb {
    box-shadow: 0 0 12px rgba(0,229,255,1), 0 0 24px rgba(0,229,255,0.4);
}

/* ── Stats panel ─────────────────────────────────────────────────────────── */

.stats {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 2px;
    position: relative;
    overflow: hidden;
}

.stats::before {
    content: '';
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 2px;
    background: linear-gradient(to bottom, var(--green-dim), transparent);
}

.stats::after {
    content: '';
    position: absolute;
    top: 0; right: 0;
    border-top:  6px solid rgba(0,255,163,0.2);
    border-left: 6px solid transparent;
}

.stats-header {
    padding: 7px 12px 6px 14px;
    border-bottom: 1px solid var(--border);
    font-family: var(--txt-mono);
    font-size: 9px;
    letter-spacing: 0.18em;
    color: rgba(0,255,163,0.45);
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 7px;
    background: rgba(0,255,163,0.02);
}

.stats-header-icon { color: var(--green); font-size: 10px; opacity: 0.7; }

.stats-body { padding: 8px 12px 10px 14px; display: flex; flex-direction: column; gap: 5px; }

.stats-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 1px 0;
}

.stats-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--txt-dim);
}

.stats-value {
    font-family: var(--txt-mono);
    font-size: 12px;
    color: var(--green);
    text-shadow: 0 0 8px rgba(0,255,163,0.35);
    font-variant-numeric: tabular-nums;
}

.stats-value--cyan  { color: var(--cyan);  text-shadow: 0 0 8px rgba(0,229,255,0.35); }
.stats-value--amber { color: var(--amber); text-shadow: 0 0 8px rgba(255,179,71,0.35); }
.stats-value--dim   { color: rgba(0,229,255,0.3); text-shadow: none; }

.stats-sep {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.stats-sp-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--txt-dim);
    margin-bottom: 5px;
}

.stats-sp-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 5px;
}
.stats-sp-row:last-child { margin-bottom: 0; }

.stats-sp-dot  { font-size: 9px; flex-shrink: 0; filter: drop-shadow(0 0 3px currentColor); }
.stats-sp-name { font-family: var(--txt-mono); color: var(--txt-dim); font-size: 10px; width: 38px; flex-shrink: 0; letter-spacing: 0.05em; }

.stats-sp-pct {
    font-family: var(--txt-mono);
    font-size: 10px;
    width: 48px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    opacity: 0.85;
}

.stats-sp-bar-bg {
    flex: 1;
    height: 3px;
    background: rgba(255,255,255,0.05);
    border-radius: 1px;
    overflow: hidden;
}

.stats-sp-bar-fill {
    height: 100%;
    border-radius: 1px;
    transition: width 0.1s linear;
}

/* ── Divider ─────────────────────────────────────────────────────────────── */

.sidebar-divider {
    height: 1px;
    margin: 0 12px;
    background: linear-gradient(90deg, transparent, var(--border), transparent);
}

/* ── Keyframe animations ─────────────────────────────────────────────────── */

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

@keyframes title-glow {
    0%, 100% { text-shadow: 0 0 10px rgba(0,229,255,0.5), 0 0 24px rgba(0,229,255,0.15); }
    50%       { text-shadow: 0 0 18px rgba(0,229,255,0.85), 0 0 40px rgba(0,229,255,0.30); }
}

@keyframes dot-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 8px var(--green), 0 0 20px rgba(0,255,163,0.3); }
    50%       { opacity: 0.5; box-shadow: 0 0 4px var(--green); }
}

@keyframes hdr-scan {
    0%   { background-position: -100% 0; opacity: 0; }
    20%  { opacity: 1; }
    80%  { opacity: 1; }
    100% { background-position: 200% 0; opacity: 0; }
}

/* ── Mobile — portrait ───────────────────────────────────────────────────── */
@media (max-width: 640px) and (orientation: portrait) {

    .app { flex-direction: column; }

    .canvas-wrap {
        width: 100%;
        flex: 0 0 min(100vw, 52vh);
        height: min(100vw, 52vh);
    }

    .sidebar {
        width: 100%;
        min-width: 0;
        flex: 1;
        border-left: none;
        border-top: 1px solid var(--border);
        box-shadow: inset 0 4px 30px rgba(0, 229, 255, 0.025);
        overflow-y: auto;
    }

    /* Compact header */
    .hdr { padding: 9px 14px 8px; }
    .hdr-sub { display: none; }
    .hdr-title { font-size: 13px; margin-bottom: 3px; }
    .hdr-state, .hdr-fps { font-size: 10px; }

    /* 2-column button grid for comfortable touch targets */
    .btn-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .btn {
        min-height: 44px;
        font-size: 12px;
        padding: 10px 6px;
        min-width: 0;
    }

    /* Sliders fill available space */
    .panel-label {
        flex: 0 0 auto;
        max-width: 44%;
        font-size: 12px;
    }
    input[type=range] {
        flex: 1;
        width: auto;
        min-width: 70px;
        height: 4px;
    }
    input[type=range]::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }
    input[type=range]::-moz-range-thumb {
        width: 18px;
        height: 18px;
    }
    .panel-value { font-size: 11px; width: 32px; }

    /* Stats */
    .stats-label { font-size: 11px; }
    .stats-value { font-size: 13px; }
    .stats-sp-name { font-size: 11px; }
    .stats-sp-pct  { font-size: 11px; }
}
