:root {
    --bg-color: #0c0d14;
    --card-bg: rgba(22, 24, 38, 0.88);
    --accent-color: #ff6b6b;
    --text-primary: #e6edf3;
    --text-secondary: #9da7b3;
    --highlight: #ffd43b;
    --font-main: 'Outfit', sans-serif;
    --font-zh: 'Noto Sans TC', sans-serif;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-main), var(--font-zh);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 12px 18px;
}

.app-container {
    width: 100%;
    max-width: 1780px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    background: rgba(22, 24, 38, 0.92);
    padding: 10px 18px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.07);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

h1 {
    font-size: 1.6rem;
    font-weight: 600;
    background: linear-gradient(45deg, #ff6b6b, #fcc419);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 0.95rem;
    font-weight: 300;
    color: var(--text-secondary);
    -webkit-text-fill-color: var(--text-secondary);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.toggle-labels-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.08);
    padding: 5px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.84rem;
    font-weight: 600;
    user-select: none;
    border: 1px solid rgba(255,255,255,0.18);
    transition: 0.2s;
}
.toggle-labels-btn:hover {
    background: rgba(255,255,255,0.16);
}
.toggle-labels-btn input {
    accent-color: #2ecc71;
    cursor: pointer;
}
#label-toggle-fluid.active {
    background: rgba(14, 165, 233, 0.22);
    border-color: #38bdf8;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.35);
    color: #e0f2fe;
}

.speed-control-group {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.08);
    padding: 3px 8px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    font-size: 0.82rem;
    font-weight: 600;
    user-select: none;
}

.speed-title {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.speed-btns {
    display: flex;
    gap: 3px;
}

.speed-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-primary);
    padding: 2px 7px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    transition: 0.15s ease;
}

.speed-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.speed-btn.active {
    background: #3b82f6;
    color: #fff;
    border-color: #60a5fa;
    box-shadow: 0 0 6px rgba(59, 130, 246, 0.5);
}

#nerve-network {
    transition: opacity 0.3s ease;
}

#nerve-network.dimmed {
    opacity: 0.18;
}

.stats-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.stat-pill {
    font-size: 0.8rem;
    background: rgba(0,0,0,0.4);
    padding: 4px 10px;
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.08);
}
.stat-pill span {
    font-weight: 700;
    color: #f1c40f;
}

.stat-pill.lymph-node-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(6, 78, 59, 0.45);
    border: 1px solid #10b981;
    color: #a7f3d0;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.35);
    animation: lymphPillPulse 1.8s infinite ease-in-out;
}

@keyframes lymphPillPulse {
    0%, 100% { box-shadow: 0 0 8px rgba(16, 185, 129, 0.3); border-color: #10b981; }
    50% { box-shadow: 0 0 16px rgba(52, 211, 153, 0.65); border-color: #34d399; }
}

.lymph-badge {
    font-weight: 700;
    color: #34d399;
}

.lymph-progress-bar {
    display: inline-block;
    width: 48px;
    height: 6px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
    overflow: hidden;
    vertical-align: middle;
}

#lymph-progress-fill {
    display: block;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #10b981, #34d399);
    transition: width 0.1s linear;
}

main {
    display: grid;
    grid-template-columns: 370px 1fr;
    gap: 16px;
    align-items: stretch;
}

@media (max-width: 1200px) {
    main {
        grid-template-columns: 1fr;
    }
}

.controls-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    padding-right: 4px;
}

/* Custom Scrollbar for controls panel */
.controls-panel::-webkit-scrollbar {
    width: 6px;
}
.controls-panel::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
}

.panel-section {
    background: rgba(22, 24, 38, 0.94);
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.06);
}

.section-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: #e6edf3;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding-bottom: 4px;
}

.coagulation-stepper {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.coag-btn {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--text-primary);
    padding: 8px 10px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 0.84rem;
    text-align: left;
    transition: all 0.2s ease;
    font-weight: 600;
}

.coag-btn:hover {
    background: rgba(255,255,255,0.14);
    transform: translateX(3px);
}

.coag-btn.active {
    background: linear-gradient(90deg, rgba(220,38,38,0.4), rgba(245,158,11,0.25));
    border-left: 4px solid #ef4444;
    color: #fff;
    box-shadow: 0 0 10px rgba(239,68,68,0.3);
}
.stage-buttons-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.stage-btn {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--text-primary);
    padding: 9px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.88rem;
    text-align: center;
    transition: all 0.2s ease;
    font-weight: 600;
}

.stage-btn:hover {
    background: rgba(255,255,255,0.12);
}

.stage-btn.active {
    background: linear-gradient(90deg, rgba(255,107,107,0.35), rgba(252,196,25,0.2));
    border: 1px solid var(--accent-color);
    color: #fff;
    box-shadow: 0 0 12px rgba(255,107,107,0.3);
}

.stage-btn.reset-btn {
    width: 100%;
    margin-top: 8px;
    background: rgba(255,255,255,0.03);
    border-color: rgba(255,255,255,0.1);
    color: var(--text-secondary);
}
.stage-btn.reset-btn:hover {
    color: #fff;
    background: rgba(255,255,255,0.1);
}

.btn-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

.btn-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.action-btn {
    padding: 8px 6px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    transition: all 0.15s ease;
    color: #fff;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.action-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.1);
    box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}
.action-btn:active {
    transform: translateY(0);
}

.btn-bacteria { background-color: #27ae60; }
.btn-virus { background-color: #8e44ad; }
.btn-parasite { background-color: #b7950b; }

.btn-bacteria.active {
    box-shadow: 0 0 0 2px #ffffff, 0 0 12px rgba(39, 174, 96, 0.85);
    filter: brightness(1.2);
    font-weight: 700;
}
.btn-virus.active {
    box-shadow: 0 0 0 2px #ffffff, 0 0 12px rgba(142, 68, 173, 0.85);
    filter: brightness(1.2);
    font-weight: 700;
}
.btn-parasite.active {
    box-shadow: 0 0 0 2px #ffffff, 0 0 12px rgba(183, 149, 11, 0.85);
    filter: brightness(1.2);
    font-weight: 700;
}

.btn-neutro { background-color: #2980b9; }
.btn-mono { background-color: #6c5ce7; }
.btn-eosino { background-color: #e84393; }
.btn-baso { background-color: #34495e; }
.btn-bcell { background-color: #d35400; }
.btn-tcell { background-color: #16a085; }

/* 專一性免疫記憶 Toggle 開關 */
.memory-toggle-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.memory-toggle-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 8px 12px;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.memory-toggle-card:hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.22);
}

.memory-toggle-card.active#card-memory-bacteria {
    background: linear-gradient(135deg, rgba(5, 150, 105, 0.28), rgba(16, 185, 129, 0.12));
    border-color: #10b981;
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.3);
}

.memory-toggle-card.active#card-memory-virus {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.28), rgba(139, 92, 246, 0.12));
    border-color: #8b5cf6;
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.3);
}

.memory-toggle-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.memory-icon-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.memory-icon {
    font-size: 1.35rem;
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.memory-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.memory-title {
    font-size: 0.83rem;
    font-weight: 700;
    color: var(--text-primary);
}

.memory-subtitle {
    font-size: 0.72rem;
    color: var(--text-secondary);
    transition: color 0.2s ease;
}

/* Switch Toggle UI */
.switch-toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
    cursor: pointer;
}

.switch-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.switch-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 24px;
    transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: #ffffff;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
    transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.switch-toggle input:checked + .switch-slider.switch-bac {
    background-color: #10b981;
    border-color: #059669;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.switch-toggle input:checked + .switch-slider.switch-vir {
    background-color: #8b5cf6;
    border-color: #7c3aed;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
}

.switch-toggle input:checked + .switch-slider:before {
    transform: translateX(20px);
}

.info-card {
    background: var(--card-bg);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.06);
    flex: 1;
    min-height: 200px;
    max-height: 240px;
    overflow-y: auto;
}

.info-card::-webkit-scrollbar {
    width: 6px;
}
.info-card::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
}

.info-card h2 {
    color: var(--accent-color);
    margin-bottom: 6px;
    font-size: 1.15rem;
}

.info-card p {
    line-height: 1.5;
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-size: 0.86rem;
}

.mechanism-box {
    background: rgba(0,0,0,0.35);
    padding: 10px 12px;
    border-radius: 8px;
    border-left: 3px solid var(--highlight);
}

.mechanism-box h3 {
    color: var(--highlight);
    font-size: 0.82rem;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.mechanism-box div, .mechanism-box p {
    font-size: 0.85rem;
    line-height: 1.45;
    color: #e0e0e0;
}

/* Central Canvas Area */
.visualization-container {
    background: #090a10;
    border-radius: 16px;
    box-shadow: 0 12px 36px rgba(0,0,0,0.5);
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.08);
    position: relative;
    width: 100%;
    min-height: 600px;
    height: calc(100vh - 120px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: crosshair;
    user-select: none;
    contain: layout style paint;
    transform: translateZ(0);
}

svg#inflammation-viz {
    width: 100%;
    height: 100%;
    display: block;
    transform-origin: center center;
    text-rendering: optimizeSpeed;
}

#viewport-group {
    pointer-events: none;
    will-change: transform;
}

.zoom-controls {
    position: absolute;
    bottom: 18px;
    right: 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 20;
    background: rgba(18, 20, 32, 0.94);
    padding: 6px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.12);
}

.zoom-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    color: #e6edf3;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.15s;
}

.zoom-btn:hover {
    background: rgba(255,255,255,0.18);
    color: #fff;
    transform: scale(1.05);
}

.pan-hint {
    position: absolute;
    top: 14px;
    right: 18px;
    background: rgba(9, 10, 16, 0.85);
    color: var(--text-secondary);
    font-size: 0.8rem;
    padding: 5px 12px;
    border-radius: 20px;
    pointer-events: none;
    border: 1px solid rgba(255,255,255,0.08);
    z-index: 10;
}
#tissue-bg {
    transition: opacity 0.3s ease;
}
#tissue-bg.fluid-active {
    opacity: 0.35;
}
#collagen-fibers-group {
    transition: opacity 0.3s ease;
}
#collagen-fibers-group.fluid-active {
    opacity: 0.12;
}
