/* =========================================================
   Chapter 3.04 Secondary Storage Media Widgets
   Magnetic, Optical, and Solid-State visual explorers
   ========================================================= */

.storage-widget {
    margin: 1.5rem 0;
    padding: 1.25rem;
    border-radius: 24px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.08);
}

.storage-widget-layout {
    display: grid;
    grid-template-columns: minmax(260px, 0.95fr) minmax(280px, 1.05fr);
    gap: 1.25rem;
    align-items: stretch;
}

.storage-visual-panel,
.storage-explanation-panel {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 22px;
    padding: 1.2rem;
    min-height: 330px;
    box-sizing: border-box;
}

.storage-visual-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.storage-button-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin-bottom: 1rem;
}

.storage-button-grid button {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #334155;
    border-radius: 999px;
    padding: 0.5rem 0.85rem;
    font-weight: 700;
    font-size: 0.86rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.storage-button-grid button:hover,
.storage-button-grid button.active {
    background: #0f172a;
    border-color: #0f172a;
    color: #ffffff;
    transform: translateY(-1px);
}

.storage-step-card {
    border-radius: 20px;
    padding: 1rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.storage-step-card h3 {
    margin-top: 0;
    color: #0f172a;
}

.storage-step-card p {
    color: #334155;
}

.storage-mini-tip {
    margin-bottom: 0;
    padding: 0.8rem;
    border-radius: 16px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e3a8a !important;
    font-weight: 650;
}

/* =========================================================
   Magnetic HDD visual
   ========================================================= */

.hdd-visual {
    width: min(360px, 100%);
    display: grid;
    gap: 1rem;
    justify-items: center;
}

.hdd-case {
    position: relative;
    width: 270px;
    height: 270px;
    border-radius: 34px;
    background: linear-gradient(145deg, #e2e8f0, #ffffff);
    border: 2px solid #cbd5e1;
    box-shadow: inset 0 0 0 8px rgba(255,255,255,0.7), 0 18px 34px rgba(15,23,42,0.12);
}

.hdd-platter {
    position: absolute;
    left: 34px;
    top: 34px;
    width: 185px;
    height: 185px;
    border-radius: 50%;
    background: radial-gradient(circle, #f8fafc 0 16%, #cbd5e1 17% 20%, #f1f5f9 21% 100%);
    border: 2px solid #94a3b8;
    animation: hddSpin 7s linear infinite;
}

.hdd-ring {
    position: absolute;
    border: 2px dashed rgba(51, 65, 85, 0.45);
    border-radius: 50%;
    inset: 16px;
}

.hdd-ring.ring-2 { inset: 42px; }
.hdd-ring.ring-3 { inset: 68px; }

.hdd-spindle {
    position: absolute;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    left: calc(50% - 16px);
    top: calc(50% - 16px);
    background: #0f172a;
    box-shadow: 0 0 0 8px #e2e8f0;
}

.hdd-sector {
    position: absolute;
    left: 50%;
    top: 12px;
    width: 38px;
    height: 82px;
    border-radius: 100% 0 0 0;
    background: rgba(59, 130, 246, 0.28);
    transform-origin: 0 82px;
    transform: rotate(32deg);
}

.hdd-arm {
    position: absolute;
    right: 35px;
    top: 118px;
    width: 120px;
    height: 18px;
    border-radius: 999px;
    background: #64748b;
    transform-origin: 100% 50%;
    transform: rotate(-22deg);
    animation: hddSeek 3.5s ease-in-out infinite alternate;
    box-shadow: 0 4px 12px rgba(15,23,42,0.2);
}

.hdd-head {
    position: absolute;
    left: -10px;
    top: -7px;
    width: 26px;
    height: 30px;
    border-radius: 8px;
    background: #0f172a;
}

.storage-bit-row {
    display: flex;
    gap: 0.35rem;
    justify-content: center;
}

.storage-bit-row span {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: #0f172a;
    color: #ffffff;
    font-weight: 800;
    animation: bitPulse 1.8s ease-in-out infinite;
}

.storage-bit-row span:nth-child(even) {
    animation-delay: 0.25s;
}

/* =========================================================
   Optical visual
   ========================================================= */

.optical-visual {
    position: relative;
    width: min(430px, 100%);
    min-height: 340px;
}

/* Disc */

.optical-disc {
    position: absolute;
    left: 30px;
    top: 48px;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    background: radial-gradient(
        circle,
        #ffffff 0 10%,
        #dbeafe 11% 34%,
        #e0f2fe 35% 58%,
        #f8fafc 59% 100%
    );
    border: 2px solid #93c5fd;
    box-shadow: 0 18px 34px rgba(37, 99, 235, 0.14);
    animation: hddSpin 11s linear infinite;
}

.spiral-track {
    position: absolute;
    inset: 24px;
    border-radius: 50%;
    border: 3px dashed rgba(30, 64, 175, 0.45);
    box-shadow:
        inset 0 0 0 30px rgba(255, 255, 255, 0.25),
        inset 0 0 0 60px rgba(59, 130, 246, 0.08);
}

.pit {
    position: absolute;
    width: 34px;
    height: 11px;
    border-radius: 999px;
    background: #1e40af;
    opacity: 0.85;
}

.pit-1 {
    left: 48px;
    top: 115px;
    transform: rotate(25deg);
}

.pit-2 {
    left: 125px;
    top: 58px;
    transform: rotate(115deg);
}

.pit-3 {
    left: 142px;
    top: 160px;
    transform: rotate(-28deg);
}

/* Hide extra clutter labels */

.disc-label,
.track-label,
.pit-label,
.reflected-label,
.laser-beam::after {
    display: none !important;
}

/* Laser */

.laser-unit {
    position: absolute;
    right: 22px;
    top: 106px;
    width: 110px;
    height: 90px;
}

.laser-label {
    position: absolute;
    right: 4px;
    top: -32px;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #334155;
    font-size: 0.75rem;
    font-weight: 800;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.laser-lens {
    position: absolute;
    right: 0;
    top: 26px;
    width: 62px;
    height: 54px;
    border-radius: 18px;
    background: #0f172a;
    box-shadow: inset 0 -8px 0 rgba(255, 255, 255, 0.18);
}

.laser-beam {
    position: absolute;
    right: 54px;
    top: 51px;
    width: 150px;
    height: 6px;
    border-radius: 999px;
    background: #ef4444;
    transform: rotate(168deg);
    transform-origin: right center;
    box-shadow: 0 0 18px rgba(239, 68, 68, 0.75);
    animation: laserPulse 1.6s ease-in-out infinite;
}

/* Reflected light */

.reflected-light {
    position: absolute;
    right: 105px;
    top: 160px;
    width: 120px;
    height: 5px;
    border-radius: 999px;
    background: #2563eb;
    transform: rotate(-16deg);
    box-shadow: 0 0 16px rgba(37, 99, 235, 0.65);
    animation: reflectedPulse 2s ease-in-out infinite;
}

/* Detector */

.detector-box {
    position: absolute;
    right: 8px;
    bottom: 70px;
    width: 160px;
    padding: 0.75rem;
    border-radius: 16px;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    color: #334155;
    font-size: 0.78rem;
    line-height: 1.45;
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.08);
}

.detector-box strong {
    display: block;
    margin-bottom: 0.25rem;
    color: #0f172a;
}

.detector-box span {
    display: block;
}

/* Binary output */

.binary-output-box {
    position: absolute;
    left: 90px;
    bottom: 18px;
    padding: 0.65rem 0.9rem;
    border-radius: 16px;
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
    color: #14532d;
    font-size: 0.82rem;
    font-weight: 800;
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.08);
}

.binary-output-box strong {
    margin-left: 0.35rem;
    letter-spacing: 0.12em;
}

/* Button highlighting */

.storage-widget.is-track .spiral-track {
    border-color: #f97316;
    box-shadow:
        0 0 0 5px rgba(249, 115, 22, 0.15),
        inset 0 0 0 30px rgba(255, 255, 255, 0.25),
        inset 0 0 0 60px rgba(59, 130, 246, 0.08);
}

.storage-widget.is-laser .laser-lens,
.storage-widget.is-laser .laser-beam {
    outline: 4px solid rgba(249, 115, 22, 0.35);
    outline-offset: 5px;
}

.storage-widget.is-reflection .reflected-light,
.storage-widget.is-reflection .detector-box,
.storage-widget.is-reflection .binary-output-box {
    outline: 4px solid rgba(37, 99, 235, 0.22);
    outline-offset: 5px;
}

.storage-widget.is-wavelength .laser-beam {
    height: 4px;
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.9);
}

@keyframes reflectedPulse {
    0%, 100% {
        opacity: 0.45;
        width: 85px;
    }

    50% {
        opacity: 1;
        width: 125px;
    }
}

/* =========================================================
   Solid-state visual
   ========================================================= */

.ssd-visual {
    width: min(360px, 100%);
    display: grid;
    gap: 1rem;
    justify-items: center;
}

.controller-chip {
    padding: 0.75rem 1.3rem;
    border-radius: 16px;
    background: #0f172a;
    color: #ffffff;
    font-weight: 800;
    box-shadow: 0 12px 24px rgba(15,23,42,0.2);
}

.flash-grid {
    display: grid;
    grid-template-columns: repeat(4, 48px);
    gap: 0.55rem;
    padding: 1rem;
    border-radius: 22px;
    background: #f1f5f9;
    border: 2px solid #cbd5e1;
}

.cell {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: #ffffff;
    border: 2px solid #cbd5e1;
    box-shadow: inset 0 -4px 0 rgba(15,23,42,0.04);
    animation: cellRead 2.6s ease-in-out infinite;
}

.cell.active {
    background: #bbf7d0;
    border-color: #22c55e;
}

.cell:nth-child(4n + 1) { animation-delay: 0.1s; }
.cell:nth-child(4n + 2) { animation-delay: 0.3s; }
.cell:nth-child(4n + 3) { animation-delay: 0.5s; }
.cell:nth-child(4n + 4) { animation-delay: 0.7s; }

.page-block-labels {
    display: flex;
    gap: 0.6rem;
}

.page-block-labels span {
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    background: #ecfeff;
    border: 1px solid #a5f3fc;
    color: #155e75;
    font-weight: 800;
}

.storage-widget.is-write .hdd-sector,
.storage-widget.is-reflection .reflection-fill,
.storage-widget.is-erase .flash-grid {
    outline: 4px solid rgba(249, 115, 22, 0.35);
    outline-offset: 6px;
}

.storage-widget.is-track .spiral-track,
.storage-widget.is-tracks .hdd-ring,
.storage-widget.is-cells .cell {
    border-color: #f97316;
}

/* =========================================================
   Animations and responsive layout
   ========================================================= */

@keyframes hddSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes hddSeek {
    from { transform: rotate(-34deg); }
    to { transform: rotate(2deg); }
}

@keyframes bitPulse {
    0%, 100% { transform: translateY(0); opacity: 0.85; }
    50% { transform: translateY(-5px); opacity: 1; }
}

@keyframes laserPulse {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 1; }
}

@keyframes reflectionChange {
    0%, 100% { width: 32%; }
    50% { width: 86%; }
}

@keyframes cellRead {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

@media (max-width: 820px) {
    .storage-widget-layout {
        grid-template-columns: 1fr;
    }

    .storage-visual-panel,
    .storage-explanation-panel {
        min-height: auto;
    }

    .hdd-case {
        width: 235px;
        height: 235px;
    }

    .hdd-platter {
        width: 160px;
        height: 160px;
    }

    .flash-grid {
        grid-template-columns: repeat(4, 40px);
    }

    .cell {
        width: 40px;
        height: 40px;
    }
}
