.memory-widget {
    margin: 1.5rem 0;
    padding: 1.25rem;
    border-radius: 24px;
    background: linear-gradient(135deg, #f8fafc, #eef2ff);
    border: 1px solid #dbeafe;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

.memory-widget-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.memory-widget-header h3 {
    margin: 0 0 0.25rem;
    color: #172554;
}

.memory-widget-header p {
    margin: 0;
    color: #475569;
}

.memory-widget-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 3rem;
    padding: 0.45rem 0.75rem;
    border-radius: 999px;
    background: #1d4ed8;
    color: white;
    font-weight: 700;
}

.memory-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 1rem 0;
}

.memory-tab,
.memory-choice-btn,
.rom-step,
.memory-action-btn {
    border: 0;
    border-radius: 999px;
    padding: 0.65rem 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.memory-tab {
    background: white;
    color: #1e3a8a;
    border: 1px solid #bfdbfe;
}

.memory-tab.active,
.memory-choice-btn.active,
.rom-step.active {
    background: #2563eb;
    color: white;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.25);
}

.memory-tab:hover,
.memory-choice-btn:hover,
.rom-step:hover,
.memory-action-btn:hover {
    transform: translateY(-2px);
}

.memory-panel {
    display: none;
    animation: memoryFade 0.25s ease;
}

.memory-panel.active {
    display: block;
}

.memory-card-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.memory-info-card,
.memory-detail-box,
.memory-power-demo,
.buffer-side,
.buffer-queue-box {
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid #dbeafe;
    border-radius: 20px;
    padding: 1rem;
}

.memory-info-card h4,
.memory-detail-box h4,
.buffer-side h4,
.buffer-queue-box h4 {
    margin-top: 0;
    color: #172554;
}

.ram-card {
    border-left: 6px solid #2563eb;
}

.rom-card {
    border-left: 6px solid #7c3aed;
}

.memory-power-demo {
    margin-top: 1rem;
}

.memory-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.memory-chip {
    padding: 0.75rem 1rem;
    border-radius: 16px;
    font-weight: 700;
}

.ram-chip {
    background: #dbeafe;
    color: #1e3a8a;
}

.rom-chip {
    background: #ede9fe;
    color: #4c1d95;
}

.ram-chip.cleared {
    background: #fee2e2;
    color: #991b1b;
    text-decoration: line-through;
}

.memory-toggle-row,
.rom-timeline {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.memory-choice-btn,
.rom-step {
    background: #ffffff;
    color: #334155;
    border: 1px solid #cbd5e1;
}

.memory-action-btn {
    background: #1d4ed8;
    color: white;
}

.memory-action-btn.secondary {
    background: #475569;
}

.buffer-simulation {
    display: grid;
    grid-template-columns: 1fr 1.4fr 1fr;
    gap: 1rem;
    align-items: stretch;
}

.buffer-slots {
    min-height: 4rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    padding: 0.75rem;
    border: 2px dashed #93c5fd;
    border-radius: 18px;
    background: #eff6ff;
}

.buffer-item {
    width: 2.5rem;
    height: 2.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    background: #2563eb;
    color: white;
    font-weight: 800;
    animation: bufferPop 0.25s ease;
}

.buffer-status,
.buffer-explanation {
    color: #475569;
    font-weight: 600;
}

.warning-box {
    margin: 1rem 0;
    padding: 1rem;
    border-radius: 18px;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #7c2d12;
}

.exam-tip-box {
    margin: 1rem 0;
    padding: 1rem;
    border-radius: 18px;
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
    color: #14532d;
}

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

@keyframes bufferPop {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@media (max-width: 760px) {
    .memory-card-grid,
    .buffer-simulation {
        grid-template-columns: 1fr;
    }

    .memory-widget-header {
        flex-direction: column;
    }
}
