/* ppuzzl.win - Puzzle-as-UI Immersive Experience */

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

:root {
    --primary: #1E1B4B;
    --lime: #BFFF00;
    --cream: #FFF8E7;
    --coral: #FF6B6B;
    --cyan: #00D9FF;
    --gray: #9CA3AF;
    --grid-unit: 12px;
    --cell-size: 24px;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', sans-serif;
    font-weight: 400;
    font-size: 16px;
    line-height: 1.6;
    letter-spacing: 0.005em;
    background-color: var(--primary);
    color: var(--cream);
    overflow-x: hidden;
}

h1, h2, .zone-title, .maze-title, .final-title, .intro-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    letter-spacing: -0.015em;
    font-size: clamp(2.8rem, 7vw, 5.2rem);
}

h3 {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 600;
    font-size: clamp(1.4rem, 3.5vw, 2.4rem);
    margin-bottom: 1rem;
}

.box-hint, .zone-subtitle, .maze-description, .intro-hint {
    font-family: 'Courier Prime', monospace;
    font-weight: 400;
    color: var(--gray);
}

/* Cursor Trails Container */
#cursor-trails {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

.cursor-trail {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--cyan);
    pointer-events: none;
    opacity: 0.7;
    transition: opacity 0.8s ease-out;
}

/* ===== INTRO SCREEN ===== */
.fullscreen {
    min-height: 100vh;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#intro-screen {
    background: var(--primary);
    flex-direction: column;
    overflow: hidden;
}

.intro-content {
    text-align: center;
    z-index: 2;
    position: relative;
}

.intro-title {
    color: var(--cream);
    margin-bottom: 1.5rem;
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.8s ease-out 0.3s forwards;
}

.intro-title .char {
    display: inline-block;
    opacity: 0;
    animation: charReveal 0.4s ease-out forwards;
}

.intro-hint {
    font-size: 1.1rem;
    opacity: 0;
    animation: fadeInUp 0.8s ease-out 1.2s forwards;
}

.scroll-indicator {
    margin-top: 2rem;
    opacity: 0;
    animation: fadeInUp 0.8s ease-out 1.5s forwards;
}

.scroll-dot {
    animation: scrollBounce 1.5s ease-in-out infinite;
}

.intro-grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(rgba(191, 255, 0, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(191, 255, 0, 0.03) 1px, transparent 1px);
    background-size: var(--cell-size) var(--cell-size);
    pointer-events: none;
    z-index: 1;
}

/* ===== PUZZLE GRID ===== */
#puzzle-grid {
    min-height: 100vh;
    padding: 4rem 2rem;
    align-items: flex-start;
    padding-top: 6rem;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: calc(var(--grid-unit) * 2);
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
}

@media (max-width: 900px) {
    .grid-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 560px) {
    .grid-container {
        grid-template-columns: 1fr;
    }
}

.puzzle-box {
    position: relative;
    aspect-ratio: 1;
    border: 1.5px solid rgba(191, 255, 0, 0.2);
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.puzzle-box:nth-child(odd) {
    transform: translateX(0);
}

.grid-container > .puzzle-box:nth-child(3n+1) {
    transform: translateX(0);
}

.grid-container > .puzzle-box:nth-child(3n+2) {
    transform: translateX(24px);
}

.grid-container > .puzzle-box:nth-child(3n) {
    transform: translateX(0);
}

.puzzle-box:hover {
    border-color: var(--cyan);
    box-shadow: 0 0 20px rgba(0, 217, 255, 0.15), inset 0 0 20px rgba(0, 217, 255, 0.05);
}

.puzzle-box:hover .box-locked {
    transform: rotate(0.5deg);
}

.puzzle-box.unlocked {
    border-color: var(--cyan);
    background: rgba(0, 217, 255, 0.05);
}

.puzzle-box.unlocking {
    animation: unlockFlash 0.5s ease-out;
}

/* Locked State */
.box-locked {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    transition: opacity 0.4s ease, transform 0.3s ease;
    z-index: 2;
    padding: 1.5rem;
}

.puzzle-box.unlocked .box-locked {
    opacity: 0;
    pointer-events: none;
    transform: scale(1.05);
}

.lock-grid {
    width: 48px;
    height: 48px;
    border: 1.5px solid var(--lime);
    position: relative;
    margin-bottom: 1rem;
    transition: transform 0.3s ease, border-color 0.3s ease;
}

.lock-grid::before,
.lock-grid::after {
    content: '';
    position: absolute;
    background: var(--lime);
}

.lock-grid::before {
    width: 1px;
    height: 100%;
    left: 50%;
    top: 0;
}

.lock-grid::after {
    width: 100%;
    height: 1px;
    top: 50%;
    left: 0;
}

.puzzle-box:hover .lock-grid {
    transform: rotate(15deg);
    border-color: var(--cyan);
}

.puzzle-box:hover .lock-grid::before,
.puzzle-box:hover .lock-grid::after {
    background: var(--cyan);
}

.box-hint {
    text-align: center;
    font-size: 0.9rem;
    line-height: 1.4;
}

.progress-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: linear-gradient(to top, rgba(191, 255, 0, 0.08), transparent);
    transition: height 0.5s ease;
    pointer-events: none;
}

/* Unlocked Content */
.box-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 1.5rem;
    opacity: 0;
    transition: opacity 0.5s ease 0.2s;
    background: var(--cream);
    color: var(--primary);
    z-index: 1;
}

.puzzle-box.unlocked .box-content {
    opacity: 1;
}

.box-content h2 {
    font-size: clamp(1.2rem, 2.5vw, 1.6rem);
    margin-bottom: 0.75rem;
    color: var(--primary);
}

.box-content p {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--primary);
    opacity: 0.85;
}

/* Unlock Particles */
.unlock-particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--coral);
    pointer-events: none;
    z-index: 10;
    animation: particleBurst 0.6s ease-out forwards;
}

/* ===== INTERACTIVE ZONE ===== */
#interactive-zone {
    padding: 8rem 2rem;
    background: var(--primary);
    text-align: center;
}

.zone-header {
    margin-bottom: 4rem;
}

.zone-title {
    color: var(--cream);
    margin-bottom: 1rem;
}

.zone-subtitle {
    font-size: 1rem;
}

.word-puzzle-grid {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    max-width: 600px;
    margin: 0 auto;
}

.word-tile {
    width: 72px;
    height: 72px;
    perspective: 600px;
    cursor: pointer;
}

.word-tile .tile-face {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    backface-visibility: hidden;
    transition: transform 0.5s ease;
    border: 1.5px solid var(--lime);
    border-radius: 4px;
}

.tile-front {
    background: var(--primary);
    transform: rotateY(0deg);
}

.tile-back {
    background: var(--cyan);
    color: var(--primary);
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 2rem;
    transform: rotateY(180deg);
}

.word-tile.flipped .tile-front {
    transform: rotateY(180deg);
}

.word-tile.flipped .tile-back {
    transform: rotateY(0deg);
}

.word-tile:hover:not(.flipped) {
    transform: scale(1.05);
}

.word-tile:hover:not(.flipped) .tile-front {
    border-color: var(--cyan);
    box-shadow: 0 0 12px rgba(0, 217, 255, 0.3);
}

.tile-icon {
    width: 36px;
    height: 36px;
}

.puzzle-message {
    margin-top: 3rem;
    min-height: 3rem;
}

.message-text {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(1.6rem, 4vw, 2.8rem);
    color: var(--lime);
    opacity: 0;
    transition: opacity 0.5s ease;
}

.message-text.visible {
    opacity: 1;
}

/* ===== PHILOSOPHY SECTION ===== */
#philosophy-section {
    padding: 6rem 2rem;
    background: var(--cream);
    color: var(--primary);
}

.philosophy-container {
    max-width: 900px;
    margin: 0 auto;
}

.philosophy-block {
    padding: 3rem 0;
    position: relative;
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.philosophy-block.visible {
    opacity: 1;
    transform: translateY(0);
}

.philosophy-block.left {
    padding-right: 20%;
}

.philosophy-block.right {
    padding-left: 20%;
    text-align: right;
}

.philosophy-block h3 {
    color: var(--primary);
}

.philosophy-block p {
    color: var(--primary);
    opacity: 0.8;
    font-size: 1rem;
    line-height: 1.7;
}

.connector-svg {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 30px;
}

.connector-svg svg {
    width: 100%;
    height: 100%;
}

.jigsaw-edge {
    animation: rotateSlow 20s linear infinite;
    transform-origin: center center;
}

/* ===== MAZE SECTION ===== */
#maze-section {
    height: 80vh;
    position: relative;
    overflow: hidden;
}

.maze-container {
    position: relative;
    width: 100%;
    height: 100%;
}

#mazeCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.maze-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 2;
    pointer-events: none;
}

.maze-title {
    color: var(--cream);
    margin-bottom: 1rem;
    text-shadow: 0 0 40px rgba(30, 27, 75, 0.8);
}

.maze-description {
    font-size: 1rem;
    text-shadow: 0 0 20px rgba(30, 27, 75, 0.8);
}

/* ===== FINAL SECTION ===== */
#final-section {
    padding: 8rem 2rem;
    background: var(--primary);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.final-container {
    position: relative;
    z-index: 2;
    max-width: 800px;
    margin: 0 auto;
}

.final-content {
    position: relative;
}

.final-title {
    color: var(--cream);
    margin-bottom: 1.5rem;
    font-size: clamp(2rem, 5vw, 4rem);
}

.final-text {
    font-family: 'Courier Prime', monospace;
    font-size: 1.1rem;
    color: var(--gray);
    margin-bottom: 3rem;
}

.logic-icons {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-top: 2rem;
}

.logic-icon {
    width: 48px;
    height: 48px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.logic-icon.visible {
    opacity: 1;
    transform: translateY(0);
}

.puzzle-piece-connector {
    margin-top: 4rem;
}

.connector-piece {
    width: 100%;
    max-width: 400px;
    height: auto;
    animation: rotateSlow 20s linear infinite;
}

/* Data Dots */
#dataDots {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.data-dot {
    position: absolute;
    border-radius: 50%;
    background: var(--cream);
    opacity: 0;
    transition: opacity 1s ease;
}

.data-dot.visible {
    opacity: 0.15;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@keyframes scrollBounce {
    0%, 100% { cy: 10; }
    50% { cy: 24; }
}

@keyframes unlockFlash {
    0% { border-color: var(--coral); box-shadow: 0 0 30px rgba(255, 107, 107, 0.4); }
    50% { border-color: var(--lime); box-shadow: 0 0 20px rgba(191, 255, 0, 0.3); }
    100% { border-color: var(--cyan); box-shadow: none; }
}

@keyframes particleBurst {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) scale(0);
    }
}

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

/* ===== TYPEWRITER STYLES ===== */
[data-typewriter] .tw-char {
    display: inline-block;
    opacity: 0;
}

[data-typewriter].tw-active .tw-char {
    animation: twFadeIn 0.15s ease-out forwards;
}

@keyframes twFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Maze path traces */
.maze-trace {
    position: absolute;
    pointer-events: none;
    z-index: 1;
}

/* Responsive adjustments */
@media (max-width: 560px) {
    #puzzle-grid {
        padding: 3rem 1rem;
        padding-top: 4rem;
    }

    .puzzle-box {
        aspect-ratio: auto;
        min-height: 200px;
    }

    .grid-container > .puzzle-box:nth-child(3n+2) {
        transform: translateX(0);
    }

    .word-tile {
        width: 56px;
        height: 56px;
    }

    .philosophy-block.left {
        padding-right: 0;
    }

    .philosophy-block.right {
        padding-left: 0;
        text-align: left;
    }

    #maze-section {
        height: 60vh;
    }
}
