:root {
    --rack-black: #1A0A10;
    --infra-wine: #6B1D3A;
    --copper-patina: #8B3A52;
    --parchment-wash: #F2E4D8;
    --cable-cream: #D4B896;
    --patch-rose: #C4547A;
    --conduit-mauve: #9E6B80;
    --terminal-amber: #D4A853;
    color-scheme: dark;
}

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

body {
    background-color: var(--rack-black);
    color: var(--parchment-wash);
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 300;
    font-size: clamp(0.9rem, 1.1vw + 0.5rem, 1.1rem);
    line-height: 1.75;
    overflow-x: hidden;
}

/* Back plane grid */
.back-plane {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.15;
    background-image:
        linear-gradient(90deg, #2A0F1A 1px, transparent 1px),
        linear-gradient(0deg, #2A0F1A 1px, transparent 1px);
    background-size: 60px 60px;
}

/* Watercolor wash overlays */
.watercolor-wash {
    position: fixed;
    pointer-events: none;
    z-index: 2;
    border-radius: 50%;
    filter: blur(80px);
}

.wash-1 {
    width: 50vw;
    height: 50vw;
    top: -10%;
    left: -10%;
    background: radial-gradient(ellipse at 30% 40%, rgba(107, 29, 58, 0.15), transparent 70%);
}

.wash-2 {
    width: 40vw;
    height: 40vw;
    top: 40%;
    right: -5%;
    background: radial-gradient(ellipse at 50% 50%, rgba(139, 58, 82, 0.10), transparent 70%);
}

.wash-3 {
    width: 45vw;
    height: 45vw;
    bottom: -10%;
    left: 20%;
    background: radial-gradient(ellipse at 40% 60%, rgba(158, 107, 128, 0.12), transparent 70%);
}

/* Patch panel nav */
.patch-panel {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 56px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 16px 0;
    z-index: 50;
    background: linear-gradient(180deg, rgba(26, 10, 16, 0.9), rgba(42, 15, 26, 0.9));
    border-right: 1px solid rgba(107, 29, 58, 0.3);
}

.patch-dot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    text-decoration: none;
    cursor: pointer;
}

/* LED indicators */
.led {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.led-amber {
    background: var(--terminal-amber);
    box-shadow: 0 0 6px rgba(212, 168, 83, 0.5);
    animation: pulseAmber 3s ease-in-out infinite;
}

.led-rose {
    background: var(--patch-rose);
    box-shadow: 0 0 6px rgba(196, 84, 122, 0.5);
    animation: pulseRose 5s ease-in-out infinite;
}

.patch-dot.active .led {
    transform: scale(1.4);
}

@keyframes pulseAmber {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

@keyframes pulseRose {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Rack Sections */
.rack-section {
    position: relative;
    z-index: 5;
    padding: 60px 80px 60px 80px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.section-deep {
    background: linear-gradient(180deg, var(--rack-black), #1E0D14);
}

/* Section Identifier */
.section-identifier {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: clamp(1.8rem, 5vw, 4.5rem);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    word-spacing: 0.3em;
    line-height: 1.2;
    color: var(--parchment-wash);
    margin-bottom: 24px;
}

.section-identifier-inner {
    font-size: clamp(1.4rem, 3vw, 2.4rem);
    margin-bottom: 20px;
}

/* Modules */
.module {
    position: relative;
    background: rgba(26, 10, 16, 0.85);
    border: 1px solid rgba(107, 29, 58, 0.2);
    border-radius: 2px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(42, 15, 26, 0.25);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

.module:hover {
    transform: scale(1.008);
    box-shadow: 0 4px 12px rgba(107, 29, 58, 0.3);
}

.module:hover .module-accent {
    width: 6px;
}

.module-1u {
    min-height: 120px;
    display: flex;
    align-items: center;
}

.module-2u {
    min-height: 280px;
}

.module-4u {
    min-height: 560px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Module accent bar */
.module-accent {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--infra-wine);
    transition: width 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.accent-wine { background: var(--infra-wine); }
.accent-copper { background: var(--copper-patina); }
.accent-rose { background: var(--patch-rose); }

/* Module label */
.module-label {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 6px;
    background: var(--infra-wine);
    font-family: 'Space Mono', monospace;
    font-size: 0;
    line-height: 6px;
    overflow: hidden;
}

.module-label::after {
    content: attr(class);
    display: none;
}

/* For visible label text */
.module-label {
    height: auto;
    padding: 2px 8px 2px 12px;
    font-size: 0.6rem;
    color: var(--parchment-wash);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    background: var(--infra-wine);
}

/* Module body */
.module-body {
    padding: 32px 28px 28px;
    position: relative;
    z-index: 2;
}

.module-1u .module-body {
    padding: 16px 28px;
}

.module-text {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 300;
    color: var(--parchment-wash);
    max-width: 68ch;
    margin-bottom: 1rem;
    line-height: 1.75;
}

.module-text:last-child {
    margin-bottom: 0;
}

/* Display title */
.display-title {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: clamp(1.8rem, 5vw, 4.5rem);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    word-spacing: 0.3em;
    line-height: 1.2;
    color: var(--parchment-wash);
    text-align: center;
}

.surface-body {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

/* Annotations */
.annotation {
    font-family: 'Caveat', cursive;
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: var(--cable-cream);
    transform: rotate(-1.5deg);
    display: inline-block;
}

.margin-note {
    margin-top: 12px;
    padding: 8px 12px;
    border: 1px dashed var(--cable-cream);
    border-radius: 2px;
    opacity: 0.7;
}

/* Data points */
.data-point {
    font-family: 'Space Mono', monospace;
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--parchment-wash);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Module grid */
.module-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
}

.module-grid-2col {
    grid-template-columns: 1fr 1fr;
}

/* Watercolor bloom */
.watercolor-bloom {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    border-radius: 50%;
    background: radial-gradient(ellipse at center, rgba(107, 29, 58, 0.2), transparent 70%);
    transform: scale(0);
    transition: transform 4s ease-out;
}

.watercolor-bloom.expanded {
    transform: scale(2);
}

/* Patch cables */
.patch-cables {
    position: absolute;
    right: 40px;
    top: 15%;
    width: 60px;
    height: 70%;
    z-index: 3;
    pointer-events: none;
}

.cable-line {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 1.5s ease-out;
}

.cable-line.drawn {
    stroke-dashoffset: 0;
}

/* Topology map */
.topology-map {
    margin-bottom: 24px;
}

.topology-svg {
    width: 100%;
    max-width: 500px;
    height: auto;
}

.topo-node {
    opacity: 0.7;
}

.topo-path {
    transition: stroke-dashoffset 2s ease-out;
}

.topo-path.drawn {
    stroke-dashoffset: 0;
}

/* Handshake visualization */
.handshake-viz {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.hz-step {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--parchment-wash);
}

.hz-arrow {
    color: var(--conduit-mauve);
    font-size: 1.2rem;
}

/* Packet counter */
.packet-counter {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    color: var(--terminal-amber);
    min-width: 8ch;
    display: inline-block;
}

.pulse-fast {
    animation-duration: 2s;
}

/* Fiber cross section */
.fiber-cross-section {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.fiber-svg {
    width: 160px;
    height: 160px;
}

.physical-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* Zoom-focus animation */
[data-zoom] {
    opacity: 0;
    transform: scale(0.92);
    filter: blur(3px);
    transition:
        opacity 0.6s ease,
        transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1),
        filter 0.5s ease;
    transition-delay: calc(var(--module-index, 0) * 80ms);
}

[data-zoom].in-view {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
}

/* Responsive */
@media (max-width: 768px) {
    .patch-panel {
        display: none;
    }

    .rack-section {
        padding: 40px 16px;
    }

    .module-grid-2col {
        grid-template-columns: 1fr;
    }

    .module-4u {
        min-height: auto;
        padding: 20px 0;
    }

    .module-2u {
        min-height: auto;
    }

    .patch-cables {
        display: none;
    }

    .display-title {
        font-size: clamp(1.4rem, 6vw, 2.5rem);
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .led-amber,
    .led-rose {
        animation: none;
        opacity: 0.8;
    }

    [data-zoom] {
        opacity: 1;
        transform: none;
        filter: none;
        transition: none;
    }

    .cable-line {
        stroke-dashoffset: 0;
        transition: none;
    }

    .topo-path {
        stroke-dashoffset: 0;
        transition: none;
    }

    .watercolor-bloom {
        transform: scale(2);
        transition: none;
    }

    .module {
        transition: none;
    }
}
