/**
 * NN-Playground CSS — SVG-Merged Data-Flow Layout + Sidebar Tabs
 *
 * Phase 2: Verschmolzenes SVG (Input/Output als Rects im SVG),
 *          Zoom/Pan, Weight-Filter, Trainer-Tab, Charts.
 *
 * Layout: viewport-full mit SVG-Area (70%) + Sidebar-Tabs (30%)
 * Paradigma: Progressive Disclosure — Hauptansicht zeigt nur den Datenfluss.
 *
 * @see css/layouts/viewport-full.css (Basis-Layout)
 * @see ToDos/NN_PLAYGROUND_PLAN_v2.md
 */

/* =========================================
   0. CUSTOM PROPERTIES (Namespace: --nn-*)
   ========================================= */

.nn-playground {
    --nn-neuron-fill: #1a1a2e;
    --nn-neuron-stroke: rgba(96, 165, 250, 0.5);
    --nn-input-x: #3498db;
    --nn-input-o: #e74c3c;
    --nn-label-color: #9ca3af;
    --nn-sidebar-bg: rgba(15, 15, 30, 0.65);
    --nn-sidebar-border: rgba(96, 165, 250, 0.12);
    --nn-tab-active: rgba(96, 165, 250, 0.9);
    --nn-tab-inactive: rgba(156, 163, 175, 0.7);
    --nn-cell-bg: rgba(255, 255, 255, 0.04);
    --nn-cell-border: rgba(255, 255, 255, 0.1);
    --nn-cell-hover: rgba(96, 165, 250, 0.15);
    --nn-best-glow: rgba(46, 204, 113, 0.4);
}


/* =========================================
   1. MAIN DATA-FLOW GRID
   ========================================= */

.nn-playground .lab-grid {
    display: flex;
    flex-direction: row;
    height: 100%;
    overflow: hidden;
}

.nn-dataflow {
    flex: 7;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: center;
    gap: 0;
    padding: var(--space-sm, 0.5rem);
    min-width: 0;
    overflow: hidden;
    position: relative;
}


/* =========================================
   2. GAME STATUS OVERLAY
   ========================================= */

.nn-game-status {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 700;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 10;
}

.nn-game-status--visible {
    opacity: 1;
}

.nn-game-status--win {
    background: rgba(46, 204, 113, 0.2);
    border: 1px solid rgba(46, 204, 113, 0.4);
    color: #2ecc71;
}

.nn-game-status--draw {
    background: rgba(241, 196, 15, 0.2);
    border: 1px solid rgba(241, 196, 15, 0.4);
    color: #f1c40f;
}

.nn-game-status__restart {
    display: inline-block;
    margin-left: 0.5rem;
    font-size: 0.85em;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.nn-game-status:hover .nn-game-status__restart {
    opacity: 1;
}


/* =========================================
   3. NETWORK SVG CONTAINER
   ========================================= */

.nn-network-container {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: stretch;
    justify-content: center;
    overflow: hidden;
}

.nn-mlp-svg {
    max-height: 100%;
    cursor: grab;
}

.nn-mlp-svg:active {
    cursor: grabbing;
}

/* --- SVG Neuron Styles --- */
.nn-neuron {
    transition: fill 0.3s, stroke 0.3s;
}

.nn-neuron--interactive {
    cursor: pointer;
}

.nn-neuron--interactive:hover {
    filter: url(#nn-glow);
    stroke-width: 2.5;
}

.nn-connection {
    transition: stroke-width 0.4s, stroke 0.4s, stroke-opacity 0.4s;
}

.nn-connection--hidden {
    display: none;
}

/* --- SVG Output Best Cell Glow --- */
.nn-output-rect--best {
    filter: url(#nn-best-glow);
    stroke-width: 2;
}


/* =========================================
   4. SIDEBAR (30%)
   ========================================= */

.nn-sidebar {
    flex: 3;
    max-width: 380px;
    min-width: 260px;
    display: flex;
    flex-direction: column;
    background: var(--nn-sidebar-bg);
    border-left: 1px solid var(--nn-sidebar-border);
    overflow: hidden;
}

/* --- Tab Buttons --- */
.nn-sidebar__tabs {
    display: flex;
    flex-shrink: 0;
    border-bottom: 1px solid var(--nn-sidebar-border);
    background: rgba(0, 0, 0, 0.2);
}

.nn-sidebar__tab-btn {
    flex: 1;
    padding: 0.65rem 0.25rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--nn-tab-inactive);
    font-size: 0.85rem;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
    white-space: nowrap;
    min-height: 44px;
}

.nn-sidebar__tab-btn:hover {
    color: rgba(255, 255, 255, 0.7);
}

.nn-sidebar__tab-btn.active {
    color: var(--nn-tab-active);
    border-bottom-color: var(--nn-tab-active);
}

/* --- Tab Panels --- */
.nn-sidebar__body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-md, 1rem);
}

.nn-sidebar__tab-panel {
    display: none;
}

.nn-sidebar__tab-panel.active {
    display: block;
}


/* =========================================
   5. TAB CONTENT STYLES
   ========================================= */

/* --- Metrics Tab --- */
.nn-metrics-placeholder {
    text-align: center;
    color: var(--nn-label-color);
    padding: 2rem 1rem;
    font-size: 0.9rem;
    line-height: 1.6;
}

.nn-metrics-placeholder__icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    opacity: 0.55;
}

/* --- Architecture Tab --- */
.nn-arch-group {
    margin-bottom: 1.25rem;
}

.nn-arch-group__label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--nn-label-color);
    margin-bottom: 0.4rem;
}

.nn-arch-group select,
.nn-arch-group input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    color: #e5e7eb;
    font-size: 0.9rem;
    min-height: 44px;
}

.nn-arch-group select:focus,
.nn-arch-group input:focus {
    outline: none;
    border-color: var(--nn-tab-active);
}

.nn-preset-desc {
    font-size: 0.8rem;
    color: var(--nn-label-color);
    line-height: 1.5;
    margin-top: 0.4rem;
    font-style: italic;
}

.nn-arch-group p {
    font-size: 0.82rem;
    color: var(--nn-label-color);
    line-height: 1.5;
}

.nn-param-count {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.75rem;
    background: rgba(96, 165, 250, 0.06);
    border-radius: 8px;
    border: 1px solid rgba(96, 165, 250, 0.1);
}

.nn-param-count__label {
    font-size: 0.8rem;
    color: var(--nn-label-color);
}

.nn-param-count__value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--nn-tab-active);
    font-variant-numeric: tabular-nums;
}

/* --- Learning Rule Tab --- */
.nn-learnrule-formula {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    font-family: 'KaTeX_Math', serif;
    font-size: 0.95rem;
    color: #e5e7eb;
    line-height: 1.8;
    text-align: center;
}

.nn-learnrule-hint {
    margin-top: 1rem;
    font-size: 0.8rem;
    color: var(--nn-label-color);
    line-height: 1.5;
}

.nn-learnrule-hint__note { margin-top: 0.5rem; }

/* --- Arena Tab --- */
.nn-arena-placeholder {
    text-align: center;
    color: var(--nn-label-color);
    padding: 2rem 1rem;
    font-size: 0.9rem;
    line-height: 1.6;
}

.nn-arena-placeholder__note {
    margin-top: 0.5rem;
    font-size: 0.8rem;
}

/* --- Trainer Tab --- */
.nn-trainer {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.nn-trainer__boards {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.nn-trainer__board-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}

.nn-trainer__board-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--nn-label-color);
}

.nn-trainer__grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    width: 96px;
    height: 96px;
}

.nn-trainer__cell {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--nn-cell-bg);
    border: 1px solid var(--nn-cell-border);
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
}

.nn-trainer__cell--x {
    color: var(--nn-input-x);
    background: rgba(52, 152, 219, 0.1);
}

.nn-trainer__cell--o {
    color: var(--nn-input-o);
    background: rgba(231, 76, 60, 0.1);
}

.nn-trainer__result {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.nn-trainer__result-line {
    font-size: 0.8rem;
    color: var(--nn-label-color);
}

.nn-trainer__hint {
    padding-top: 0.5rem;
}

.nn-trainer__hint-text {
    font-size: 0.78rem;
    color: var(--nn-label-color);
    line-height: 1.4;
}

.nn-arch-group--mt { margin-top: 1rem; }

/* --- Training Charts --- */
.nn-charts-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.nn-chart-section {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.nn-chart-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--nn-label-color);
}

.nn-chart-canvas {
    width: 100%;
    height: auto;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
}


/* =========================================
   6. TOOLBAR OVERRIDES
   ========================================= */

.nn-playground .lab-toolbar {
    gap: var(--space-sm, 0.5rem);
    flex-wrap: wrap;
    padding: 0 var(--space-md, 1rem);
}

.nn-toolbar__group {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.nn-toolbar__group .btn {
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.05);
    color: #e5e7eb;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    min-height: 36px;
}

.nn-toolbar__group .btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(96, 165, 250, 0.4);
}

.nn-toolbar__group .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.nn-toolbar__group .btn--primary {
    background: rgba(96, 165, 250, 0.2);
    border-color: rgba(96, 165, 250, 0.4);
}

.nn-toolbar__stats {
    margin-left: auto;
    display: flex;
    gap: 1rem;
    align-items: center;
    font-size: 0.8rem;
    color: var(--nn-label-color);
    flex-wrap: wrap;
}

.nn-toolbar__progress {
    width: 60px;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}

.nn-toolbar__progress-bar {
    height: 100%;
    background: var(--nn-tab-active);
    border-radius: 3px;
    transition: width 0.3s;
}

.nn-toolbar__stat-value {
    font-weight: 700;
    color: #e5e7eb;
    font-variant-numeric: tabular-nums;
}

.nn-toolbar__speed {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    color: var(--nn-label-color);
}

.nn-toolbar__speed input[type="range"] {
    width: 60px;
    accent-color: var(--nn-tab-active);
}

/* --- Weight Filter --- */
.nn-toolbar__filter {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    color: var(--nn-label-color);
}

.nn-toolbar__filter-label {
    white-space: nowrap;
}

.nn-toolbar__filter input[type="range"] {
    width: 70px;
    accent-color: var(--nn-tab-active);
}

.nn-toolbar__filter-value {
    min-width: 2.5em;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: #e5e7eb;
}


/* =========================================
   7. RESPONSIVE
   ========================================= */

/* Tablet: sidebar below */
@media (max-width: 1024px) {
    .nn-playground .lab-grid {
        flex-direction: column;
    }

    .nn-sidebar {
        max-width: none;
        min-width: auto;
        max-height: 35vh;
        border-left: none;
        border-top: 1px solid var(--nn-sidebar-border);
    }

    .nn-dataflow {
        flex: 1;
    }
}

/* Phone: sidebar as bottom sheet */
@media (max-width: 768px) {
    .nn-dataflow {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .nn-network-container {
        max-height: 250px;
    }

    .nn-sidebar {
        max-height: 40vh;
    }

    .nn-sidebar__tab-btn {
        font-size: 0.75rem;
        padding: 0.5rem 0.15rem;
    }

    .nn-toolbar__stats {
        display: none; /* Show in sidebar instead */
    }
}
