/* ============================================
   ppuzzl.win — Generative Candy Arcade
   ============================================ */

/* === CSS Custom Properties === */
:root {
    --arcade-dark: #1A0A2A;
    --soft-purple: #4A3058;
    --candy-rose: #E0508A;
    --candy-cyan: #50D0E0;
    --candy-yellow: #F0D040;
    --level-white: #FEFAFF;
    --crt-cream: #F8F4FA;
    --grain-noise: rgba(26, 10, 42, 0.03);
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', sans-serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.2vw, 1.1rem);
    line-height: 1.8;
    color: var(--soft-purple);
    background-color: var(--level-white);
    overflow-x: hidden;
    position: relative;
}

/* === Grain Overlay CRT Texture === */
#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

/* Scanline effect for CRT authenticity */
#grain-overlay::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(26, 10, 42, 0.015) 2px,
        rgba(26, 10, 42, 0.015) 4px
    );
}

/* === Generative Curves Canvas (background) === */
#generative-curves {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    opacity: 0.06;
}

/* === Level Sections (stacked-sections layout) === */
.level {
    min-height: 80vh;
    padding: clamp(40px, 8vh, 80px) clamp(24px, 5vw, 80px);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
}

/* Alternating backgrounds between candy tones at 3% opacity */
.level:nth-child(odd) {
    background-color: var(--level-white);
}

.level:nth-child(even) {
    background-color: var(--crt-cream);
}

.level-hero {
    min-height: 100vh;
}

.level-content {
    max-width: 800px;
    width: 100%;
    text-align: center;
}

/* === Typography === */
h1, h2 {
    font-family: 'Bebas Neue', sans-serif;
    font-weight: 400;
    color: var(--arcade-dark);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.hero-title {
    font-size: clamp(4rem, 12vw, 10rem);
    line-height: 0.95;
    margin-bottom: 0.2em;
    position: relative;
    text-shadow:
        3px 3px 0px var(--candy-rose),
        6px 6px 0px var(--candy-cyan);
    animation: titlePulse 3s ease-in-out infinite;
}

.hero-subtitle {
    font-family: 'Inter', sans-serif;
    font-weight: 300;
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: var(--soft-purple);
    letter-spacing: 0.3em;
    text-transform: uppercase;
    margin-bottom: 2rem;
}

.level-heading {
    font-size: clamp(2.8rem, 6vw, 5rem);
    margin-bottom: 0.8em;
    position: relative;
    display: inline-block;
}

.level-heading::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, var(--candy-rose), var(--candy-cyan), var(--candy-yellow));
}

/* === Score Labels (Space Mono, bold, candy rose) === */
.score-label {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    color: var(--candy-rose);
    font-size: 1.1rem;
    letter-spacing: 0.1em;
}

#score-counter {
    font-size: 1.3rem;
    margin-bottom: 1.5rem;
    animation: scorePulse 2s ease-in-out infinite;
}

/* === Candy Accent Dots === */
.candy-accents {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin: 2rem 0;
}

.candy-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: inline-block;
    animation: dotBounce 1.5s ease-in-out infinite;
}

.candy-dot:nth-child(1) { animation-delay: 0s; }
.candy-dot:nth-child(2) { animation-delay: 0.15s; }
.candy-dot:nth-child(3) { animation-delay: 0.3s; }
.candy-dot:nth-child(4) { animation-delay: 0.45s; }
.candy-dot:nth-child(5) { animation-delay: 0.6s; }

.candy-rose { background-color: var(--candy-rose); }
.candy-cyan { background-color: var(--candy-cyan); }
.candy-yellow { background-color: var(--candy-yellow); }

/* === Arcade Prompt Blink === */
.arcade-prompt {
    margin-top: 3rem;
}

.blink-text {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    color: var(--candy-yellow);
    font-size: 1rem;
    letter-spacing: 0.2em;
    animation: blinkArcade 1.2s step-end infinite;
}

/* === Puzzle Grid === */
.puzzle-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-width: 360px;
    margin: 2rem auto;
}

.puzzle-cell {
    aspect-ratio: 1;
    background: linear-gradient(135deg, var(--level-white), var(--crt-cream));
    border: 3px solid var(--soft-purple);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.3s ease;
    position: relative;
    overflow: hidden;
}

.puzzle-cell::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--candy-rose);
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: 9px;
}

.puzzle-cell:hover {
    transform: scale(1.05);
    border-color: var(--candy-cyan);
}

.puzzle-cell.correct {
    border-color: var(--candy-cyan);
    background: linear-gradient(135deg, rgba(80, 208, 224, 0.15), rgba(240, 208, 64, 0.15));
}

.puzzle-cell.correct .puzzle-symbol {
    color: var(--candy-cyan);
    transform: scale(1.2);
}

.puzzle-cell.incorrect {
    animation: arcadeShake 0.5s ease-in-out;
    border-color: var(--candy-rose);
}

.puzzle-cell.incorrect::before {
    opacity: 0.15;
}

.puzzle-cell-inner {
    position: relative;
    z-index: 1;
}

.puzzle-symbol {
    font-size: 2.4rem;
    color: var(--arcade-dark);
    transition: color 0.3s ease, transform 0.3s ease;
    display: block;
}

.hint-text {
    font-family: 'Inter', sans-serif;
    font-weight: 300;
    color: var(--soft-purple);
    font-style: italic;
    margin-top: 1.5rem;
}

/* === Generative Art Display === */
.generative-display {
    background: var(--arcade-dark);
    border-radius: 16px;
    padding: 4px;
    margin: 2rem auto;
    max-width: 608px;
    box-shadow:
        0 0 20px rgba(224, 80, 138, 0.2),
        0 0 40px rgba(80, 208, 224, 0.1),
        inset 0 0 30px rgba(0, 0, 0, 0.3);
}

#generative-art-canvas {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 12px;
}

.art-controls {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.arcade-btn {
    font-family: 'Bebas Neue', sans-serif;
    font-weight: 400;
    font-size: 1.3rem;
    letter-spacing: 0.1em;
    color: var(--level-white);
    background: var(--candy-rose);
    border: none;
    padding: 12px 32px;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 4px 0 #B03868, 0 6px 12px rgba(224, 80, 138, 0.3);
    position: relative;
    top: 0;
}

.arcade-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #B03868, 0 8px 16px rgba(224, 80, 138, 0.4);
}

.arcade-btn:active {
    top: 4px;
    box-shadow: 0 0 0 #B03868, 0 2px 6px rgba(224, 80, 138, 0.3);
}

.arcade-btn-alt {
    background: var(--candy-cyan);
    box-shadow: 0 4px 0 #30A0B0, 0 6px 12px rgba(80, 208, 224, 0.3);
}

.arcade-btn-alt:hover {
    box-shadow: 0 6px 0 #30A0B0, 0 8px 16px rgba(80, 208, 224, 0.4);
}

.arcade-btn-alt:active {
    box-shadow: 0 0 0 #30A0B0, 0 2px 6px rgba(80, 208, 224, 0.3);
}

/* === Leaderboard === */
.leaderboard {
    max-width: 500px;
    margin: 0 auto;
    text-align: left;
}

.leaderboard-row {
    display: grid;
    grid-template-columns: 60px 1fr 120px;
    padding: 12px 16px;
    border-bottom: 2px solid rgba(74, 48, 88, 0.1);
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--soft-purple);
    transition: background 0.2s ease, transform 0.2s ease;
}

.leaderboard-row:hover:not(.leaderboard-header) {
    background: rgba(240, 208, 64, 0.08);
    transform: translateX(4px);
}

.leaderboard-header {
    color: var(--arcade-dark);
    border-bottom: 3px solid var(--candy-rose);
    font-size: 0.85rem;
    letter-spacing: 0.15em;
}

.leaderboard-row .rank {
    color: var(--candy-cyan);
}

.leaderboard-row .lb-score {
    text-align: right;
    color: var(--candy-rose);
}

.leaderboard-row[data-rank="1"] {
    background: linear-gradient(90deg, rgba(240, 208, 64, 0.08), transparent);
}

.leaderboard-row[data-rank="1"] .rank {
    color: var(--candy-yellow);
}

.leaderboard-row[data-rank="1"] .player {
    color: var(--arcade-dark);
}

/* === Victory / Community Section === */
.community-text {
    font-weight: 300;
    max-width: 600px;
    margin: 0 auto 3rem;
    color: var(--soft-purple);
}

.victory-stats {
    display: flex;
    justify-content: center;
    gap: clamp(24px, 5vw, 60px);
    flex-wrap: wrap;
    margin-bottom: 3rem;
}

.stat-block {
    text-align: center;
}

.stat-number {
    display: block;
    font-size: 2rem;
    margin-bottom: 0.3em;
}

.stat-label {
    font-family: 'Inter', sans-serif;
    font-weight: 300;
    font-size: 0.85rem;
    color: var(--soft-purple);
    text-transform: uppercase;
    letter-spacing: 0.15em;
}

.celebration-particles {
    position: relative;
    height: 120px;
    margin: 2rem 0;
    overflow: hidden;
}

.footer-line {
    margin-top: 2rem;
    font-size: 0.85rem;
    letter-spacing: 0.25em;
    opacity: 0.7;
}

/* === Animations === */

/* Shake-Error: bouncy horizontal wobble (6px, 3 oscillations) */
@keyframes arcadeShake {
    0%, 100% { transform: translateX(0); }
    10% { transform: translateX(-6px); }
    20% { transform: translateX(6px); }
    30% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    50% { transform: translateX(-4px); }
    60% { transform: translateX(4px); }
    70% { transform: translateX(-2px); }
    80% { transform: translateX(2px); }
    90% { transform: translateX(-1px); }
}

/* Title shadow color cycle */
@keyframes titlePulse {
    0%, 100% {
        text-shadow:
            3px 3px 0px var(--candy-rose),
            6px 6px 0px var(--candy-cyan);
    }
    50% {
        text-shadow:
            4px 4px 0px var(--candy-yellow),
            8px 8px 0px var(--candy-rose);
    }
}

/* Score counter pulse */
@keyframes scorePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Candy dot bounce */
@keyframes dotBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Arcade insert-coin blink */
@keyframes blinkArcade {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Celebration particle fall */
@keyframes particleFall {
    0% {
        transform: translateY(-20px) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(120px) rotate(360deg);
        opacity: 0;
    }
}

/* Score increment pop */
@keyframes scoreIncrement {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); color: var(--candy-yellow); }
    100% { transform: scale(1); }
}

/* Level-up pulse */
@keyframes levelUp {
    0% { transform: scale(1); opacity: 1; }
    30% { transform: scale(1.1); opacity: 0.8; }
    60% { transform: scale(0.95); }
    100% { transform: scale(1); opacity: 1; }
}

/* === Win Celebration Flash === */
.win-flash {
    animation: winFlash 0.6s ease-out;
}

@keyframes winFlash {
    0% { box-shadow: 0 0 0 0 rgba(80, 208, 224, 0.6); }
    50% { box-shadow: 0 0 30px 10px rgba(240, 208, 64, 0.4); }
    100% { box-shadow: 0 0 0 0 rgba(80, 208, 224, 0); }
}

/* === Score Pop Animation === */
.score-pop {
    animation: scoreIncrement 0.4s ease-out;
}

/* === Section entrance animation === */
.level-content {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

.level-content.visible {
    opacity: 1;
    transform: translateY(0);
}

/* === Responsive === */
@media (max-width: 600px) {
    .puzzle-grid {
        max-width: 280px;
        gap: 8px;
    }

    .puzzle-symbol {
        font-size: 1.8rem;
    }

    .leaderboard-row {
        grid-template-columns: 50px 1fr 90px;
        font-size: 0.8rem;
        padding: 10px 12px;
    }

    .victory-stats {
        gap: 20px;
    }

    .stat-number {
        font-size: 1.5rem;
    }

    .hero-title {
        font-size: clamp(3rem, 14vw, 6rem);
    }

    .art-controls {
        flex-direction: column;
        align-items: center;
    }
}
