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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: 1.1em;
    opacity: 0.9;
}

.main-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 25px;
    flex-wrap: wrap;
    justify-content: center;
}

.nav-btn {
    padding: 12px 20px;
    background: rgba(255,255,255,0.15);
    color: white;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
}

.nav-btn:hover {
    background: rgba(255,255,255,0.25);
    border-color: rgba(255,255,255,0.5);
    transform: translateY(-1px);
}

.nav-btn.active {
    background: white;
    color: #667eea;
    border-color: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.content-section {
    display: none;
}

.content-section.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

h2 {
    color: white;
    margin-bottom: 16px;
    font-size: 1.6em;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.3);
}

.lead {
    color: rgba(255,255,255,0.95);
    margin-bottom: 20px;
    font-size: 1.05em;
}

.concept-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.concept-grid.two-col {
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
}

.concept-card {
    background: white;
    border-radius: 12px;
    padding: 22px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.concept-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.12);
}

.concept-card h3 {
    color: #667eea;
    margin-bottom: 10px;
    font-size: 1.15em;
}

.concept-card p {
    margin-bottom: 10px;
    color: #555;
}

.concept-card code {
    background: #f0f0ff;
    padding: 2px 6px;
    border-radius: 4px;
    color: #764ba2;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.9em;
}

.diagram-container {
    background: white;
    border-radius: 15px;
    padding: 28px;
    margin-bottom: 25px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    overflow-x: auto;
}

.diagram-container h3 {
    color: #2c3e50;
    margin-bottom: 14px;
    font-size: 1.2em;
}

.diagram-caption {
    color: #888;
    font-size: 0.9em;
    margin-top: 12px;
    text-align: center;
}

/* ==================== CODE ==================== */
.code-comparison {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
    margin-bottom: 25px;
}

.code-block {
    background: #2c3e50;
    border-radius: 10px;
    padding: 20px;
}

.code-block h4 {
    color: #a8d8a8;
    margin-bottom: 12px;
    font-size: 1em;
}

.code-block pre, .diagram-container pre {
    margin: 0;
    overflow-x: auto;
}

.code-block code, .diagram-container code {
    color: #c5c8c6;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.85em;
    line-height: 1.6;
}

.inline-code {
    background: #f0f0ff;
    border-radius: 8px;
    padding: 12px;
    margin: 10px 0;
    overflow-x: auto;
}

.inline-code code {
    color: #764ba2;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.9em;
}

.diagram-container > pre {
    background: #2c3e50;
    border-radius: 8px;
    padding: 16px;
}

.diagram-container > pre code {
    color: #a8d8a8;
}

/* ==================== CONTROLS ==================== */
.controls {
    background: #f7f9fc;
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.controls select {
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.btn-primary {
    padding: 10px 22px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: background 0.3s, transform 0.2s;
}

.btn-primary:hover { background: #5a6fd8; transform: translateY(-1px); }

.btn-secondary {
    padding: 10px 22px;
    background: #e0e0e0;
    color: #555;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: background 0.3s, transform 0.2s;
}

.btn-secondary:hover { background: #d0d0d0; transform: translateY(-1px); }

.btn-warning {
    padding: 10px 22px;
    background: #ff9800;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: background 0.3s, transform 0.2s;
}

.btn-warning:hover { background: #e68900; transform: translateY(-1px); }

.btn-warning.stalled { background: #4caf50; }

.mode-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    color: #555;
}

/* ==================== PIPELINE DIAGRAM ==================== */
.pipeline-diagram {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.pipe-node {
    background: #f0f0ff;
    border: 2px solid #667eea;
    border-radius: 10px;
    padding: 14px 18px;
    font-weight: 600;
    color: #2c3e50;
    text-align: center;
}

.pipe-node.lock { background: #fff3e0; border-color: #ff9800; }
.pipe-node.buffer { background: #e3f2fd; border-color: #2196f3; }
.pipe-node.consumer { background: #e8f5e9; border-color: #4caf50; }

.pipe-arrow {
    font-size: 1.6em;
    color: #764ba2;
}

/* ==================== THEORY FLOW ==================== */
.theory-flow {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.theory-step {
    background: #f0f0ff;
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 0.92em;
    color: #2c3e50;
    max-width: 220px;
}

.theory-step.danger { background: #ffebee; border: 2px solid #f44336; }

.step-num {
    display: inline-block;
    background: #667eea;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    font-weight: 700;
    margin-right: 8px;
}

.theory-arrow { font-size: 1.4em; color: #764ba2; }

/* ==================== FREEZE DIAGRAM ==================== */
.freeze-diagram {
    display: grid;
    grid-template-columns: 1fr auto 1fr auto 1fr;
    gap: 14px;
    align-items: center;
    margin-bottom: 18px;
}

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

.freeze-worker {
    background: #f0f0ff;
    border: 2px solid #667eea;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.85em;
    font-weight: 500;
    transition: all 0.3s;
}

.freeze-worker.waiting { background: #fff3e0; border-color: #ff9800; }
.freeze-worker.blocked { background: #ffebee; border-color: #f44336; }

.freeze-lock {
    background: #fff3e0;
    border: 2px solid #ff9800;
    border-radius: 10px;
    padding: 12px;
    font-weight: 700;
    text-align: center;
}

.freeze-pipe {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    min-width: 180px;
}

.freeze-slot {
    background: #e0e0e0;
    border-radius: 6px;
    height: 30px;
    transition: background 0.2s;
}

.freeze-slot.full { background: #2196f3; }

.freeze-consumer {
    background: #e8f5e9;
    border: 2px solid #4caf50;
    border-radius: 10px;
    padding: 12px;
    font-weight: 600;
    text-align: center;
}

.freeze-consumer.stalled { background: #ffebee; border-color: #f44336; }

/* ==================== SIMULATOR ==================== */
.simulator {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 20px;
    align-items: center;
    margin-bottom: 18px;
}

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

.sim-worker {
    background: #f0f0ff;
    border: 2px solid #667eea;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.85em;
    font-weight: 500;
    transition: all 0.3s;
}

.sim-worker.waiting { background: #fff3e0; border-color: #ff9800; }
.sim-worker.blocked { background: #ffebee; border-color: #f44336; }

.sim-middle {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.sim-lock {
    background: #fff3e0;
    border: 2px solid #ff9800;
    border-radius: 10px;
    padding: 10px 14px;
    font-weight: 700;
}

.sim-lock.held { background: #ff9800; color: white; }

.sim-buffer {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 3px;
    min-width: 220px;
}

.sim-slot {
    background: #e0e0e0;
    border-radius: 4px;
    height: 22px;
    transition: background 0.15s;
}

.sim-slot.full { background: #2196f3; }
.sim-slot.full.warn { background: #ff9800; }

.sim-consumer {
    background: #e8f5e9;
    border: 2px solid #4caf50;
    border-radius: 10px;
    padding: 12px;
    font-weight: 600;
    text-align: center;
    transition: all 0.3s;
}

.sim-consumer.stalled { background: #ffebee; border-color: #f44336; }

/* ==================== STATUS LOG ==================== */
.status-log {
    background: #1e1e2e;
    border-radius: 12px;
    overflow: hidden;
    margin-top: 16px;
}

.log-header {
    background: #2c2c3e;
    color: #a8d8a8;
    padding: 10px 16px;
    font-weight: 600;
    font-size: 0.9em;
    border-bottom: 1px solid #3c3c4e;
}

.log-content {
    padding: 12px 16px;
    max-height: 180px;
    overflow-y: auto;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.8em;
    color: #c5c8c6;
    line-height: 1.8;
}

.log-content .log-entry { padding: 2px 0; }
.log-content .log-success { color: #4caf50; }
.log-content .log-warning { color: #ff9800; }
.log-content .log-error { color: #f44336; }
.log-content .log-info { color: #64b5f6; }

/* ==================== COMPARISON TABLE ==================== */
.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
}

.comparison-table thead th {
    background: #667eea;
    color: white;
    padding: 14px 16px;
    text-align: left;
    font-weight: 600;
}

.comparison-table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
}

.comparison-table tbody tr:last-child td { border-bottom: none; }

footer {
    text-align: center;
    margin-top: 40px;
    color: rgba(255,255,255,0.75);
    font-size: 0.85em;
}

@media (max-width: 768px) {
    header h1 { font-size: 1.8em; }
    .freeze-diagram, .simulator { grid-template-columns: 1fr; }
    .concept-grid.two-col { grid-template-columns: 1fr; }
}
