/* ============================================
   ppuzzle.dev - Swiss Glitch
   Palette: Retro-Futuristic
   Typography: Rounded-Sans (Nunito)
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --deep-space: #1a1a2e;
    --sidebar-bg: #141425;
    --neon-coral: #e43f5a;
    --electric-cyan: #1de9b6;
    --soft-lavender: #6c63a8;
    --cream-signal: #f0ece2;
    --faded-gold: #c9b458;
    --charcoal-mid: #2d2d44;
    --static-gray: #7a7a8e;

    --font-display: 'Nunito', sans-serif;
    --font-body: 'Nunito Sans', sans-serif;
    --font-mono: 'Inconsolata', monospace;

    --sidebar-width: 280px;
    --grid-columns: 8;
    --grid-gutter: 24px;
    --grid-margin: 48px;
}

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background: var(--deep-space);
    color: var(--cream-signal);
    font-family: var(--font-body);
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    line-height: 1.7;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    position: relative;
}

/* --- Grain Overlay --- */
.grain-svg {
    position: absolute;
    width: 0;
    height: 0;
    pointer-events: none;
}

body::after {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
    opacity: 0.06;
    pointer-events: none;
    z-index: 9999;
    animation: grain-shift 200ms steps(3) infinite;
    mix-blend-mode: screen;
}

@keyframes grain-shift {
    0% { transform: translate(0, 0); }
    33% { transform: translate(-5%, -5%); }
    66% { transform: translate(5%, 3%); }
    100% { transform: translate(0, 0); }
}

/* --- Scan Lines --- */
.scan-lines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        transparent,
        transparent 2px,
        rgba(0,0,0,0.05) 2px,
        rgba(0,0,0,0.05) 4px
    );
    pointer-events: none;
    z-index: 9998;
}

/* --- Ambient Shapes --- */
.ambient-shapes {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
}

.ambient-shape {
    position: absolute;
    opacity: 0.03;
    animation: ambient-drift linear infinite;
    will-change: transform;
}

.ambient-circle {
    border-radius: 50%;
    background: var(--electric-cyan);
}

.ambient-square {
    background: var(--neon-coral);
}

.ambient-triangle {
    width: 0;
    height: 0;
    border-left: 70px solid transparent;
    border-right: 70px solid transparent;
    border-bottom: 120px solid var(--faded-gold);
    background: none;
}

@keyframes ambient-drift {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(40px, -30px) rotate(90deg); }
    50% { transform: translate(-20px, 50px) rotate(180deg); }
    75% { transform: translate(30px, 20px) rotate(270deg); }
    100% { transform: translate(0, 0) rotate(360deg); }
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(to bottom, var(--sidebar-bg), var(--deep-space));
    border-right: 1px solid var(--soft-lavender);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 0;
    transform: translateX(-100%);
    transition: none;
    overflow: hidden;
}

.sidebar.visible {
    transform: translateX(0);
}

/* Scanning beam */
.sidebar-scan-beam {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: var(--electric-cyan);
    opacity: 0.4;
    animation: scan-beam 8s linear infinite;
    z-index: 1;
}

@keyframes scan-beam {
    0% { top: 0; }
    100% { top: 100%; }
}

.sidebar-scan-beam.fast {
    animation-duration: 2s;
}

/* Sidebar identity */
.sidebar-identity {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    margin-bottom: 48px;
}

.sidebar-logo {
    font-family: var(--font-display);
    font-weight: 900;
    font-size: 1.1rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--cream-signal);
    opacity: 0.7;
}

/* Sidebar navigation */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.nav-btn {
    position: relative;
    width: 48px;
    height: 48px;
    background: transparent;
    border: 1px solid var(--soft-lavender);
    color: var(--cream-signal);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 200ms, border-color 200ms;
}

.nav-btn .nav-letter {
    position: relative;
    z-index: 1;
}

.nav-btn .nav-tooltip {
    position: absolute;
    left: 56px;
    background: var(--charcoal-mid);
    color: var(--cream-signal);
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 3px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 150ms;
}

.nav-btn:hover .nav-tooltip {
    opacity: 1;
}

.nav-btn:hover {
    background: rgba(108, 99, 168, 0.15);
}

.nav-btn.active {
    border-left: 3px solid var(--electric-cyan);
}

/* Nav glitch hover */
.nav-btn.glitch-hover .nav-letter {
    animation: nav-glitch 60ms steps(1) forwards;
}

@keyframes nav-glitch {
    0% {
        text-shadow: -2px 0 var(--neon-coral), 2px 0 var(--electric-cyan);
    }
    50% {
        text-shadow: 2px 0 var(--neon-coral), -2px 0 var(--electric-cyan);
    }
    100% {
        text-shadow: none;
    }
}

/* Sidebar status */
.sidebar-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: auto;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--electric-cyan);
    animation: pulse-dot 2s ease-in-out infinite;
}

.status-text {
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.04em;
    color: var(--static-gray);
    text-transform: uppercase;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

/* --- Main Content --- */
.main-content {
    margin-left: var(--sidebar-width);
    position: relative;
    min-height: 100vh;
}

/* --- Grid Hairlines --- */
.grid-hairlines {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 var(--grid-margin);
    pointer-events: none;
    z-index: 1;
    opacity: 0;
    transition: opacity 400ms;
}

.grid-hairlines.visible {
    opacity: 1;
}

.grid-line {
    width: 0.5px;
    height: 100%;
    background: var(--soft-lavender);
    opacity: 0.04;
}

/* --- Hero --- */
.hero {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    padding: 0 var(--grid-margin);
}

.hero-scan-lines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        transparent,
        transparent 2px,
        rgba(0,0,0,0.12) 2px,
        rgba(0,0,0,0.12) 4px
    );
    pointer-events: none;
    z-index: 2;
}

.hero-title {
    font-family: var(--font-display);
    font-weight: 900;
    font-size: clamp(3.2rem, 8vw, 7rem);
    letter-spacing: 0.06em;
    line-height: 1.1;
    text-transform: lowercase;
    color: var(--cream-signal);
    position: relative;
    z-index: 3;
    display: flex;
    flex-wrap: nowrap;
}

.hero-letter {
    display: inline-block;
    position: relative;
    opacity: 0;
    will-change: transform;
}

.hero-letter.revealed {
    opacity: 1;
}

.hero-letter.glitch-burst {
    animation: letter-glitch-in 180ms steps(2) forwards;
}

@keyframes letter-glitch-in {
    0% {
        text-shadow:
            -4px 0 var(--neon-coral),
            4px 0 var(--electric-cyan),
            0 -3px var(--faded-gold),
            0 3px var(--soft-lavender);
        transform: translateX(5px);
        opacity: 1;
    }
    50% {
        text-shadow:
            2px 0 var(--neon-coral),
            -2px 0 var(--electric-cyan),
            0 2px var(--faded-gold);
        transform: translateX(-3px);
    }
    100% {
        text-shadow: none;
        transform: translateX(0);
        opacity: 1;
    }
}

/* Periodic glitch on hero text */
.hero-title.glitch-active {
    animation: hero-glitch 120ms steps(2) forwards;
}

@keyframes hero-glitch {
    0% {
        transform: translateX(0);
        text-shadow: none;
    }
    25% {
        transform: translateX(5px);
        text-shadow: -3px 0 var(--neon-coral), 3px 0 var(--electric-cyan);
    }
    50% {
        transform: translateX(-4px);
        text-shadow: 3px 0 var(--neon-coral), -3px 0 var(--electric-cyan);
    }
    75% {
        transform: translateX(6px);
        text-shadow: -2px 0 var(--neon-coral), 2px 0 var(--electric-cyan);
    }
    100% {
        transform: translateX(0);
        text-shadow: none;
    }
}

.hero-tagline {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    color: var(--cream-signal);
    opacity: 0;
    margin-top: 24px;
    letter-spacing: 0.04em;
    z-index: 3;
    transition: opacity 600ms ease;
}

.hero-tagline.visible {
    opacity: 0.6;
}

/* --- Interstitial Strips --- */
.interstitial-strip {
    width: 100%;
    height: 64px;
    position: relative;
    overflow: hidden;
}

.strip-shapes {
    display: flex;
    align-items: center;
    justify-content: space-around;
    width: 100%;
    height: 100%;
}

.strip-square {
    width: 24px;
    height: 24px;
    border: 1px solid var(--soft-lavender);
}

.strip-triangle {
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 14px solid var(--neon-coral);
    opacity: 0.2;
}

.strip-circle {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--electric-cyan);
    opacity: 0.15;
}

/* --- Geometric Motifs --- */
.rotating-square {
    animation: rotate-shape 20s linear infinite;
    transform: rotate(45deg);
}

@keyframes rotate-shape {
    from { transform: rotate(45deg); }
    to { transform: rotate(405deg); }
}

.pulsing-circle {
    animation: pulse-shape 3s ease-in-out infinite;
}

@keyframes pulse-shape {
    0%, 100% { transform: scale(0.8); }
    50% { transform: scale(1.2); }
}

.translating-triangle {
    animation: translate-shape 12s linear infinite;
}

@keyframes translate-shape {
    0% { transform: translateX(-40px); }
    100% { transform: translateX(40px); }
}

/* --- Content Sections --- */
.content-section {
    padding: 80px var(--grid-margin);
    position: relative;
}

.section-heading {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(1.6rem, 3.5vw, 2.8rem);
    letter-spacing: 0.06em;
    line-height: 1.3;
    text-transform: lowercase;
    color: var(--cream-signal);
    margin-bottom: 48px;
    position: relative;
}

/* Section heading glitch */
.section-heading.glitch-active {
    animation: heading-glitch 120ms steps(2) forwards;
}

@keyframes heading-glitch {
    0% { transform: translateX(0); text-shadow: none; }
    33% { transform: translateX(4px); text-shadow: -3px 0 var(--neon-coral), 3px 0 var(--electric-cyan); }
    66% { transform: translateX(-3px); text-shadow: 2px 0 var(--neon-coral), -2px 0 var(--electric-cyan); }
    100% { transform: translateX(0); text-shadow: none; }
}

/* --- Puzzle Grid --- */
.puzzle-grid {
    display: grid;
    grid-template-columns: repeat(var(--grid-columns), 1fr);
    gap: var(--grid-gutter);
}

/* --- Puzzle Blocks --- */
.puzzle-block {
    position: relative;
    border: 1px solid var(--soft-lavender);
    background: var(--charcoal-mid);
    padding: 24px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 200ms, background 200ms;
    /* Glitch-in animation initial state */
    max-height: 2px;
    opacity: 0;
}

.puzzle-block[data-col="1-4"] { grid-column: 1 / 5; }
.puzzle-block[data-col="5-8"] { grid-column: 5 / 9; }
.puzzle-block[data-col="1-5"] { grid-column: 1 / 6; }
.puzzle-block[data-col="6-8"] { grid-column: 6 / 9; }
.puzzle-block[data-col="1-6"] { grid-column: 1 / 7; }
.puzzle-block[data-col="7-8"] { grid-column: 7 / 9; }
.puzzle-block[data-col="1-3"] { grid-column: 1 / 4; }
.puzzle-block[data-col="4-6"] { grid-column: 4 / 7; }
.puzzle-block[data-col="1-8"] { grid-column: 1 / 9; }

/* Glitch-in reveal */
.puzzle-block.glitch-in {
    animation: block-glitch-in 250ms ease-out forwards;
}

@keyframes block-glitch-in {
    0% {
        max-height: 2px;
        opacity: 0.3;
    }
    60% {
        max-height: 600px;
        opacity: 0.5;
    }
    100% {
        max-height: 600px;
        opacity: 1;
    }
}

.puzzle-block.revealed {
    max-height: none;
    opacity: 1;
}

/* Block label */
.block-label {
    position: absolute;
    top: 6px;
    left: 8px;
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.04em;
    color: var(--static-gray);
    opacity: 0.3;
    transition: opacity 200ms;
    z-index: 2;
}

.puzzle-block:hover .block-label {
    opacity: 0.8;
}

/* Block content */
.block-content {
    position: relative;
    z-index: 1;
}

.block-content h3 {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    letter-spacing: 0.03em;
    line-height: 1.3;
    color: var(--cream-signal);
    margin-bottom: 12px;
    text-transform: lowercase;
}

.block-content p {
    color: rgba(240, 236, 226, 0.88);
    margin-bottom: 8px;
}

.block-content p:last-child {
    margin-bottom: 0;
}

.contact-link {
    color: var(--electric-cyan);
    font-weight: 600;
}

/* Block expanded content */
.block-expanded-content {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 400ms ease, opacity 300ms ease, margin 300ms ease;
    margin-top: 0;
}

.puzzle-block.expanded .block-expanded-content {
    max-height: 300px;
    opacity: 1;
    margin-top: 16px;
}

.block-expanded-content p {
    color: rgba(240, 236, 226, 0.75);
    font-size: 0.9em;
}

/* Block hover */
.puzzle-block:hover {
    border-color: var(--electric-cyan);
}

/* Block shape decoration */
.block-shape {
    position: absolute;
    bottom: 12px;
    right: 12px;
    z-index: 0;
    opacity: 0.08;
}

.block-shape.rotating-square {
    width: 48px;
    height: 48px;
    border: 1px solid var(--soft-lavender);
    background: none;
}

.block-shape.pulsing-circle {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--electric-cyan);
}

/* Block hover shape acceleration */
.puzzle-block:hover .rotating-square {
    animation-duration: 10s;
}

.puzzle-block:hover .pulsing-circle {
    animation-duration: 1.5s;
}

/* Expanded block styling */
.puzzle-block.expanded {
    grid-column: 1 / -1 !important;
    border-color: var(--electric-cyan);
}

/* Block corruption effect */
.puzzle-block.corrupted {
    animation: block-corrupt 200ms steps(2) forwards;
}

@keyframes block-corrupt {
    0% {
        background: var(--charcoal-mid);
        transform: translateY(0);
    }
    25% {
        background: rgba(228, 63, 90, 0.2);
        transform: translateY(-2px);
        border-color: var(--neon-coral);
    }
    50% {
        background: rgba(228, 63, 90, 0.15);
        transform: translateY(1px);
    }
    75% {
        background: rgba(228, 63, 90, 0.1);
        transform: translateY(-1px);
    }
    100% {
        background: var(--charcoal-mid);
        transform: translateY(0);
        border-color: var(--soft-lavender);
    }
}

/* Block flash on click */
.puzzle-block.flash {
    animation: block-flash 100ms ease forwards;
}

@keyframes block-flash {
    0% { border-color: var(--neon-coral); box-shadow: 0 0 12px rgba(228, 63, 90, 0.3); }
    100% { border-color: var(--electric-cyan); box-shadow: none; }
}

/* --- Footer Spacer --- */
.footer-spacer {
    height: 120px;
}

/* --- Responsive: Tablet --- */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 48px;
        --grid-columns: 4;
        --grid-gutter: 16px;
        --grid-margin: 24px;
    }

    .sidebar-identity {
        display: none;
    }

    .nav-btn .nav-tooltip {
        left: 52px;
    }

    .sidebar-status .status-text {
        display: none;
    }

    .puzzle-block[data-col="1-4"],
    .puzzle-block[data-col="5-8"],
    .puzzle-block[data-col="1-5"],
    .puzzle-block[data-col="6-8"],
    .puzzle-block[data-col="1-6"],
    .puzzle-block[data-col="7-8"],
    .puzzle-block[data-col="1-3"],
    .puzzle-block[data-col="4-6"] {
        grid-column: 1 / -1;
    }

    .grid-hairlines {
        left: 48px;
    }
}

/* --- Responsive: Mobile --- */
@media (max-width: 640px) {
    :root {
        --sidebar-width: 0px;
        --grid-columns: 2;
        --grid-gutter: 16px;
        --grid-margin: 16px;
    }

    .sidebar {
        top: auto;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 56px;
        flex-direction: row;
        padding: 0;
        border-right: none;
        border-top: 1px solid var(--soft-lavender);
        transform: translateY(100%);
    }

    .sidebar.visible {
        transform: translateY(0);
    }

    .sidebar-identity,
    .sidebar-status,
    .sidebar-scan-beam {
        display: none;
    }

    .sidebar-nav {
        flex-direction: row;
        width: 100%;
        justify-content: space-around;
        align-items: center;
        gap: 0;
    }

    .nav-btn {
        width: 40px;
        height: 40px;
        font-size: 0.85rem;
    }

    .nav-btn .nav-tooltip {
        display: none;
    }

    .main-content {
        margin-left: 0;
        margin-bottom: 56px;
    }

    .grid-hairlines {
        left: 0;
        display: none;
    }

    .hero-title {
        flex-wrap: wrap;
        justify-content: center;
    }

    .puzzle-block[data-col="1-4"],
    .puzzle-block[data-col="5-8"],
    .puzzle-block[data-col="1-5"],
    .puzzle-block[data-col="6-8"],
    .puzzle-block[data-col="1-6"],
    .puzzle-block[data-col="7-8"],
    .puzzle-block[data-col="1-3"],
    .puzzle-block[data-col="4-6"] {
        grid-column: 1 / -1;
    }

    .content-section {
        padding: 48px var(--grid-margin);
    }

    .section-heading {
        margin-bottom: 24px;
    }
}
