/* ===================================
   LSTM Interactive Playground — CSS
   =================================== */

:root {
    --primary: #4a4ae1;
    --secondary: #9c27b0;
    --bg-light: #f8faff;
    --card-bg: #ffffff;
    --text-main: #333344;
    --text-muted: #666688;
    --accent-grad: linear-gradient(135deg, #4a4ae1, #9c27b0);
    --border: #e1e4f3;
    --success: #2ecc71;
    --danger: #e74c3c;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --mono: 'Fira Code', 'Consolas', monospace;
    --nav-h: 48px;
    --radius: 8px;
}

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

body {
    font-family: var(--font);
    background-color: var(--bg-light);
    color: var(--text-main);
    line-height: 1.6;
    overflow: hidden;
    min-height: 100vh;
}

/* ─── Tab Navigation (RNN-style) ─── */
.tab-navigation {
    display: flex;
    align-items: center;
    gap: 0;
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    height: var(--nav-h);
    position: sticky;
    top: 0;
    z-index: 100;
}

.tab-navigation .logo {
    font-weight: 600;
    font-size: 0.95rem;
    margin-right: 1.5rem;
    white-space: nowrap;
}

.tab-navigation .logo span {
    color: var(--primary);
}

.tab-btn {
    background: none;
    border: none;
    padding: 0 1rem;
    height: var(--nav-h);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    white-space: nowrap;
    font-family: var(--font);
}

.tab-btn:hover {
    color: var(--text-main);
    background: #f8faff;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: #f0f7ff;
}

/* ─── Back Button ─── */
.btn-back {
    margin-left: auto;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 1rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--primary);
    background: #eef2ff;
    border: 1px solid var(--primary);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font);
}

.btn-back:hover {
    background: var(--primary);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(74, 74, 225, 0.3);
}

/* ─── Main Content ─── */
.main-content {
    height: calc(100vh - var(--nav-h));
    overflow: hidden;
}

.tab-content {
    display: none;
    height: 100%;
    overflow: hidden;
}

.tab-content.active {
    display: block;
}

/* ─── Glass Panel ─── */
.glass-panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* ─── Simulation Layout ─── */
.sim-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 0.75rem;
    height: 100%;
    overflow: hidden;
    padding: 0.75rem;
}

/* ─── Sidebar ─── */
.sim-sidebar {
    padding: 1.25rem;
    overflow-y: auto;
    height: 100%;
}

.sim-sidebar h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--text-main);
}

.sim-sidebar h3 {
    font-size: 0.75rem;
    font-weight: 600;
    margin: 0.8rem 0 0.3rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sim-sidebar p {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

/* ─── Main Area ─── */
.sim-main {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    height: 100%;
    overflow-y: auto;
}

/* ─── Observe box ─── */
.observe-box {
    padding: 0.65rem;
    background: #f8f9fb;
    margin-bottom: 0.5rem;
    border-radius: 6px;
}

.observe-box ul {
    list-style: none;
    padding: 0;
}

.observe-box li {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    padding-left: 0.75rem;
    position: relative;
}

.observe-box li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--primary);
    font-weight: bold;
}

.observe-box strong {
    color: var(--text-main);
    font-weight: 600;
}

/* ─── Sim Card ─── */
.sim-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

/* ─── Section Header (reset btns) ─── */
.section-header {
    display: flex;
    justify-content: flex-end;
    padding: 0.5rem 0;
    flex: 0 0 auto;
}

.reset-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.reset-btn:hover {
    background: #f8f9fa;
    color: var(--primary);
    border-color: var(--primary);
}

/* ─── Educational Note ─── */
.educational-note {
    background: #f0f4ff;
    border-left: 4px solid var(--primary);
    border-radius: 0 8px 8px 0;
    padding: 1rem 1.25rem;
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--text-main);
}

.educational-note strong {
    color: var(--primary);
}

/* ─── Fade Animation ─── */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================ */
/* ===== SIMULATION 1: MEMORY LOSS =====                       */
/* ============================================================ */

.experiment-layout {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.main-controls {
    flex: 1;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    font-weight: 600;
}

input[type="text"] {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
    font-family: var(--font);
}

input[type="text"]:focus {
    border-color: var(--primary);
}

.control-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin: 1.5rem 0;
}

.param-slider label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.param-slider input[type="range"] {
    width: 100%;
    accent-color: var(--primary);
}

.action-row {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

/* Buttons */
button {
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
    font-family: var(--font);
}

.action-btn {
    background: var(--primary);
    color: white;
}

.action-btn:hover {
    opacity: 0.9;
}

.action-btn.secondary {
    background: #eef2f8;
    color: var(--primary);
}

.action-btn.ghost {
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-muted);
}

.action-btn.ghost:disabled {
    background: #f5f5f5;
    color: #bbb;
    border-color: #ddd;
    border-style: solid;
    cursor: not-allowed;
}

.toggle-group button {
    background: #eef2f8;
    color: var(--text-muted);
    padding: 0.5rem 1rem;
}

.toggle-group button.active {
    background: var(--accent-grad);
    color: white;
}

.analytics-panel {
    background: #fbfcfe;
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border);
}

.analytics-panel h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.chart-wrapper {
    height: 180px;
    width: 100%;
}

/* Timeline Visualization */
.viz-container {
    padding: 1.5rem 0;
}

.timeline-row {
    display: flex;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.row-label {
    width: 100px;
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.timeline {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    flex: 1;
}

.token {
    padding: 0.5rem 0.8rem;
    border-radius: 4px;
    background: #eee;
    font-size: 0.9rem;
    transition: all 0.5s;
    position: relative;
    min-width: 40px;
    text-align: center;
    cursor: default;
    user-select: none;
}

.token .memory-bar {
    position: absolute;
    bottom: -5px;
    left: 0;
    height: 3px;
    background: var(--primary);
    transition: width 0.5s;
}

/* Backprop Pulse */
@keyframes backpropPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(74, 74, 225, 0.4);
    }

    50% {
        transform: scale(1.1);
        box-shadow: 0 0 20px 10px rgba(74, 74, 225, 0);
    }

    100% {
        transform: scale(1);
    }
}

.token.pulse {
    animation: backpropPulse 0.5s ease-out;
}

/* ============================================================ */
/* ===== SIMULATION 2: LSTM CELL =====                         */
/* ============================================================ */

.gate-area {
    margin-bottom: 2rem;
}

.gate-grid {
    display: grid;
    gap: 1.2rem;
    margin-bottom: 1.5rem;
}

.gate-slider label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    font-weight: 600;
}

.gate-slider input[type="range"] {
    width: 100%;
    accent-color: var(--primary);
}

.gate-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
    line-height: 1.2;
}

.cell-viz-container {
    flex: 3;
    background: #fbfcfe;
    border-radius: 12px;
    height: auto;
    min-height: 420px;
    position: relative;
    border: 1px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.process-log-container {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    height: 150px;
    overflow-y: auto;
    max-width: 560px;
}

.process-log-container h3 {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.pipeline-log {
    font-family: monospace;
    font-size: 0.85rem;
}

.log-entry {
    padding: 0.3rem 0;
    border-bottom: 1px solid #f0f0f0;
    color: var(--text-main);
}

.log-entry.pos {
    color: #2ecc71;
}

.log-entry.neg {
    color: #e74c3c;
}

.btn-group {
    display: flex;
    gap: 1rem;
}

.pos-btn {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #c8e6c9;
}

.neg-btn {
    background: #ffebee;
    color: #c62828;
    border: 1px solid #ffcdd2;
}

.pos-btn:hover {
    background: #c8e6c9;
}

.neg-btn:hover {
    background: #ffcdd2;
}

/* SVG Node Classes */
.gate-activation {
    transition: all 0.3s;
}

.math-op {
    font-weight: bold;
    font-family: sans-serif;
}

/* ============================================================ */
/* ===== SIMULATION 3: SENTIMENT TIMELINE =====                */
/* ============================================================ */

.sim-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: center;
}

.viz-row {
    display: flex;
    gap: 2rem;
    align-items: stretch;
}

.viz-row .chart-container {
    flex: 2;
    min-height: 280px;
    position: relative;
}

.chart-container {
    position: relative;
}

.gauge-container {
    flex: 1;
    max-width: 220px;
    text-align: center;
    padding: 1rem;
    background: #fbfcfe;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.gauge-container h4 {
    margin-bottom: 1rem;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.gauge-wrapper {
    position: relative;
}

.gauge-semicircle {
    width: 160px;
    height: 80px;
    margin: 0 auto;
    background: conic-gradient(from 180deg, #ef4444 0deg, #f59e0b 90deg, #22c55e 180deg);
    border-radius: 80px 80px 0 0;
    position: relative;
    overflow: hidden;
}

.gauge-semicircle::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 60px;
    background: #fbfcfe;
    border-radius: 60px 60px 0 0;
}

.gauge-needle {
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 3px;
    height: 55px;
    background: #333;
    transform-origin: bottom center;
    transform: translateX(-50%) rotate(0deg);
    transition: transform 0.6s ease;
    z-index: 5;
    border-radius: 2px;
}

.gauge-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.gauge-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main);
}

/* Heatmap */
.heatmap {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 1rem 0;
}

.heat-token {
    padding: 0.4rem 0.7rem;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s;
    background: #f3f4f6;
    border: 1px solid transparent;
}

.heat-token:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.heat-token.processing {
    animation: tokenProcess 0.3s ease;
}

@keyframes tokenProcess {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.15);
        box-shadow: 0 0 12px rgba(74, 74, 225, 0.4);
    }
}

.word-tooltip {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.8rem 1rem;
    font-size: 0.85rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    line-height: 1.5;
}

.model-toggles {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.small-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.heatmap-title-group {
    display: flex;
    align-items: baseline;
    gap: 1rem;
}

/* Toggle Buttons */
.toggle-btn {
    padding: 0.6rem 1.2rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    border: 2px solid transparent;
}

.toggle-btn.rnn {
    background: #fee2e2;
    color: #b91c1c;
}

.toggle-btn.lstm {
    background: #dbeafe;
    color: #1d4ed8;
}

.toggle-btn.rnn.active {
    border-color: #ef4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

.toggle-btn.lstm.active {
    border-color: #3b82f6;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

.toggle-btn:not(.active) {
    opacity: 0.5;
    background: #f3f4f6;
    color: #6b7280;
}

/* ============================================================ */
/* ===== SIMULATION 4: TRAINING DYNAMICS =====                 */
/* ============================================================ */

.split-screen {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 2rem;
}

.lab-sidebar {
    background: #fbfcfe;
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.lab-sidebar h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
}

.sim4-select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    background: #fff;
    cursor: pointer;
    font-family: var(--font);
}

.training-grids {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.model-column {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.model-column h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.model-column .chart-container {
    height: 180px;
    position: relative;
}

.grad-section,
.cm-section {
    margin-top: 0.5rem;
}

.grad-section h4,
.cm-section h4 {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.progress-container {
    height: 20px;
    background: #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 10px;
    transition: width 0.15s linear;
    width: 100%;
}

.progress-fill.rnn-grad {
    background: linear-gradient(90deg, #fca5a5, #ef4444);
}

.progress-fill.lstm-grad {
    background: linear-gradient(90deg, #93c5fd, #3b82f6);
}

/* Confusion Matrix */
.cm-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    max-width: 200px;
}

.cm-cell {
    padding: 0.6rem;
    border-radius: 6px;
    text-align: center;
    font-size: 0.8rem;
}

.cm-cell .cm-label {
    display: block;
    font-weight: 700;
    font-size: 0.7rem;
    opacity: 0.7;
}

.cm-cell .cm-val {
    display: block;
    font-size: 1.1rem;
    font-weight: 700;
}

.cm-tp {
    background: #dcfce7;
    color: #166534;
}

.cm-tn {
    background: #dbeafe;
    color: #1e40af;
}

.cm-fp {
    background: #fef3c7;
    color: #92400e;
}

.cm-fn {
    background: #fee2e2;
    color: #991b1b;
}

.cm-accuracy {
    grid-column: span 2;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
    font-weight: 600;
}

.experiment-info h4 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.usage-list {
    list-style: none;
    padding: 0;
}

.usage-list li {
    font-size: 0.85rem;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    padding-left: 1rem;
    position: relative;
}

.usage-list li::before {
    content: "→";
    color: var(--success);
    position: absolute;
    left: 0;
    font-weight: bold;
}

/* ============================================================ */
/* ===== SIMULATION 5: FEATURE ATTRIBUTION =====               */
/* ============================================================ */

.top-bar {
    display: flex;
    gap: 1.5rem;
    align-items: flex-end;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.attribution-viz.vertical {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 1rem 0;
    min-height: 320px;
    border-bottom: 2px solid var(--border);
}

.att-word {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    flex: 1;
    min-width: 40px;
    transition: opacity 0.3s;
}

.att-bar {
    width: 28px;
    min-height: 10px;
    border-radius: 4px 4px 0 0;
    transition: height 0.5s ease;
    position: relative;
}

.att-bar::after {
    content: attr(data-score);
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.65rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.att-word span {
    font-size: 0.75rem;
    color: var(--text-main);
    text-align: center;
    word-break: break-word;
}

.cell-state-viz {
    margin-top: 1rem;
}

.cell-state-viz .chart-container {
    height: 160px;
}

/* ============================================================ */
/* ===== SIMULATION 6: MODEL COMPARISON DASHBOARD =====        */
/* ============================================================ */

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.dash-card {
    background: #fbfcfe;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
}

.dash-card h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.dash-card canvas {
    max-height: 240px;
}

.dash-card.f1 {
    grid-column: span 2;
}

.dash-card table {
    width: 100%;
    border-collapse: collapse;
}

.dash-card table th,
.dash-card table td {
    padding: 0.6rem 0.8rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.dash-card table th {
    font-weight: 700;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
}

.f1-bars {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.f1-bar-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.f1-bar-row .label {
    font-weight: 700;
    font-size: 0.9rem;
    min-width: 50px;
}

.bar-track {
    flex: 1;
    height: 32px;
    background: #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 0.8rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: white;
    transition: width 1s ease;
}

.bar-fill.rnn {
    background: linear-gradient(90deg, #fca5a5, #ef4444);
}

.bar-fill.lstm {
    background: linear-gradient(90deg, #93c5fd, #3b82f6);
}

.counter {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ============================================================ */
/* ===== RESPONSIVE =====                                       */
/* ============================================================ */

@media (max-width: 1100px) {
    .experiment-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .sim-layout {
        grid-template-columns: 1fr;
        height: auto;
        overflow: auto;
    }

    .sim-sidebar {
        height: auto;
    }

    .main-content {
        height: auto;
        overflow: auto;
    }

    .tab-content {
        height: auto;
        overflow: auto;
    }

    .tab-navigation {
        overflow-x: auto;
    }
}

@media (max-width: 820px) {
    .viz-row {
        flex-direction: column;
    }

    .gauge-container {
        max-width: 100%;
    }

    .split-screen {
        grid-template-columns: 1fr;
    }

    .training-grids {
        grid-template-columns: 1fr;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .dash-card.f1 {
        grid-column: span 1;
    }

    .top-bar {
        flex-direction: column;
    }
}

@media (max-width: 600px) {
    .tab-content {
        padding: 0.5rem;
    }

    .tab-btn {
        font-size: 0.72rem;
        padding: 0 0.5rem;
    }
}