:root {
    --navy: #07111F;
    --violet: #7C3AED;
    --lime: #B7F547;
    --porcelain: #F2F6E9;
    --persimmon: #FF5A3D;
    --cyan: #38DDF8;
    --graphite: #1D2433;
    --syne: 'Syne', sans-serif;
    --bricolage: 'Bricolage Grotesque', sans-serif;
    --recursive: 'Recursive', monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    background: var(--navy);
    color: var(--porcelain);
    font-family: var(--bricolage);
    overflow-x: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(90deg, rgba(56,221,248,.05) 1px, transparent 1px),
        linear-gradient(0deg, rgba(242,246,233,.035) 1px, transparent 1px),
        radial-gradient(circle at 70% 20%, rgba(124,58,237,.18), transparent 30%),
        radial-gradient(circle at 20% 82%, rgba(183,245,71,.09), transparent 26%);
    background-size: 76px 76px, 76px 76px, auto, auto;
    z-index: 0;
}

.cursor-hint {
    position: fixed;
    width: 18px;
    height: 18px;
    border: 2px solid var(--lime);
    border-radius: 4px;
    transform: translate(-50%, -50%) rotate(45deg);
    box-shadow: 0 0 22px rgba(183,245,71,.55);
    pointer-events: none;
    z-index: 50;
    opacity: .7;
}

.inventory {
    position: fixed;
    top: 22px;
    right: 22px;
    z-index: 40;
    display: flex;
    gap: 8px;
    padding: 8px;
    background: rgba(29,36,51,.72);
    border: 1px solid rgba(56,221,248,.4);
    clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}

.token {
    color: var(--porcelain);
    text-decoration: none;
    font-family: var(--recursive);
    font-size: 12px;
    padding: 8px 10px;
    background: var(--navy);
    border: 1px solid rgba(242,246,233,.18);
    transition: transform .2s ease, background .2s ease, color .2s ease;
}

.token.active { background: var(--lime); color: var(--navy); transform: translateY(4px); }

.constraint-cabinet { position: relative; z-index: 1; }

.stage {
    min-height: 100vh;
    position: relative;
    display: grid;
    place-items: center;
    padding: 8vw;
    isolation: isolate;
}

.stage::after {
    content: attr(data-state);
    position: absolute;
    left: 24px;
    bottom: 22px;
    font-family: var(--recursive);
    color: rgba(242,246,233,.35);
    letter-spacing: .18em;
    text-transform: uppercase;
}

.cabinet-board, .drawer-shell, .maze-cabinet, .turntable, .solved-board {
    width: min(1120px, 92vw);
    min-height: 72vh;
    position: relative;
    background: linear-gradient(135deg, var(--graphite), var(--navy) 68%);
    border: 2px solid rgba(56,221,248,.42);
    box-shadow: 0 34px 0 rgba(0,0,0,.38), inset 0 0 0 9px rgba(242,246,233,.035);
    clip-path: polygon(24px 0, calc(100% - 58px) 0, 100% 34px, 100% calc(100% - 28px), calc(100% - 28px) 100%, 58px 100%, 0 calc(100% - 34px), 0 24px);
    overflow: hidden;
}

.rail {
    position: absolute;
    background: rgba(56,221,248,.14);
    border: 1px solid rgba(56,221,248,.45);
    box-shadow: inset 0 0 20px rgba(56,221,248,.18);
}

.rail-one { width: 74%; height: 38px; top: 28%; left: 10%; transform: rotate(-8deg); }
.rail-two { width: 46%; height: 30px; top: 58%; right: 8%; transform: rotate(14deg); }
.rail-three { width: 34px; height: 68%; top: 14%; left: 48%; transform: rotate(6deg); }

.coordinate {
    position: absolute;
    font-family: var(--recursive);
    color: rgba(242,246,233,.45);
    font-size: 13px;
}

.coordinate-a { left: 9%; top: 13%; }
.coordinate-b { right: 18%; top: 18%; }
.coordinate-c { left: 18%; bottom: 14%; }

.honeycomb {
    position: absolute;
    width: 190px;
    height: 166px;
    background: repeating-radial-gradient(circle at center, transparent 0 16px, rgba(124,58,237,.2) 17px 18px);
    clip-path: polygon(25% 0,75% 0,100% 50%,75% 100%,25% 100%,0 50%);
    opacity: .75;
}

.honey-one { right: 9%; top: 10%; }
.honey-two { left: 8%; bottom: 10%; transform: scale(.75) rotate(18deg); }

.glyph-rig { position: absolute; inset: 0; transform-style: preserve-3d; }

.piece {
    position: absolute;
    background: var(--porcelain);
    color: var(--navy);
    border: 3px solid var(--navy);
    font-family: var(--syne);
    box-shadow: 12px 12px 0 var(--lime), -8px -8px 0 rgba(124,58,237,.8), 0 0 0 1px rgba(242,246,233,.4);
    transition: transform .28s cubic-bezier(.2,1.4,.32,1), filter .2s ease;
    will-change: transform;
}

.piece:hover, .piece.legal-nudge { filter: brightness(1.08); }

.p-piece {
    width: clamp(150px, 21vw, 270px);
    height: clamp(190px, 29vw, 360px);
    display: grid;
    place-items: center;
    clip-path: polygon(0 0, 76% 0, 100% 18%, 100% 54%, 76% 74%, 54% 74%, 54% 100%, 0 100%);
}

.p-piece span { font-size: clamp(140px, 22vw, 310px); line-height: .72; }
.p-piece small { position: absolute; bottom: 18px; left: 18px; font-family: var(--recursive); font-size: 13px; }
.p-left { left: 18%; top: 20%; transform: translate(-16px, 12px) rotate(-3deg); }
.p-right { left: 38%; top: 17%; transform: translate(22px, -6px) rotate(2deg); box-shadow: 12px 12px 0 var(--cyan), -8px -8px 0 rgba(255,90,61,.8); }

.gap-lock {
    position: absolute;
    left: 39%;
    top: 52%;
    font-family: var(--recursive);
    color: var(--persimmon);
    border: 1px dashed var(--persimmon);
    padding: 10px 14px;
    transform: rotate(-9deg);
}

.word-piece { padding: 18px 34px; font-size: clamp(38px, 6vw, 86px); clip-path: polygon(10px 0,100% 0,calc(100% - 14px) 100%,0 100%,0 12px); }
.word-u { right: 17%; top: 38%; transform: rotate(9deg); }
.word-l { right: 28%; bottom: 20%; transform: rotate(-5deg); box-shadow: 12px 12px 0 var(--persimmon), -8px -8px 0 rgba(56,221,248,.8); }
.dot-piece { right: 12%; bottom: 30%; padding: 18px 22px; font-size: clamp(22px, 3vw, 42px); transform: rotate(3deg); }

.clue-strip {
    position: absolute;
    left: 8%;
    top: 66%;
    max-width: 330px;
    padding: 18px 22px;
    background: rgba(7,17,31,.82);
    border-left: 8px solid var(--lime);
    box-shadow: 10px 10px 0 rgba(56,221,248,.18);
}

.clue-strip span, .drawer-pull, .rule-tab, .warning-stamp, .turn-handle, .glow-label { font-family: var(--recursive); text-transform: uppercase; letter-spacing: .08em; }
.clue-strip p { margin: 8px 0 0; font-size: 22px; }
.drawer-pull { position: absolute; right: 7%; bottom: 8%; color: var(--cyan); border-bottom: 2px solid var(--cyan); padding-bottom: 8px; }

.rule-drawer { background: radial-gradient(circle at 22% 30%, rgba(124,58,237,.24), transparent 28%); }
.drawer-face { position: absolute; left: 7%; top: 12%; width: 38%; transform: rotate(-4deg); z-index: 2; }
.drawer-face h1, .deadlock-note h2, .turntable-copy h2 { font-family: var(--syne); font-size: clamp(56px, 8vw, 118px); line-height: .84; margin: 0; }
.clue, .deadlock-note p, .turntable-copy p, .compiled-clue { font-size: clamp(20px, 2.4vw, 34px); line-height: 1.08; }

.rule-tray { position: absolute; right: 8%; top: 17%; width: 48%; height: 62%; border: 2px solid var(--cyan); background: rgba(56,221,248,.08); transform: skewY(-5deg); }
.rule-tab { position: absolute; padding: 18px 22px; color: var(--navy); font-weight: 700; box-shadow: 10px 10px 0 rgba(0,0,0,.34); transition: transform .24s ease; }
.rule-tab:hover, .rule-tab.rule-active { transform: translateX(-24px) rotate(-2deg); }
.rule-tab.lime { background: var(--lime); top: 10%; left: 12%; }
.rule-tab.cyan { background: var(--cyan); top: 33%; right: 9%; }
.rule-tab.violet { background: var(--violet); color: var(--porcelain); bottom: 23%; left: 18%; }
.rule-tab.persimmon { background: var(--persimmon); bottom: 6%; right: 15%; }

.nonogram-edge { position: absolute; display: flex; gap: 12px; font-family: var(--recursive); color: var(--cyan); }
.nonogram-edge span { border: 1px solid rgba(56,221,248,.45); padding: 8px; }
.nonogram-edge.top { right: 15%; top: 8%; }
.nonogram-edge.side { left: 3%; bottom: 13%; flex-direction: column; }
.poly-hole { position: absolute; background: var(--navy); box-shadow: inset 0 0 0 2px rgba(242,246,233,.18); }
.hole-one { width: 150px; height: 110px; right: 40%; bottom: 13%; clip-path: polygon(0 0, 58% 0, 58% 38%, 100% 38%, 100% 100%, 0 100%); }
.hole-two { width: 120px; height: 150px; left: 42%; top: 13%; clip-path: polygon(0 0, 100% 0, 100% 55%, 62% 55%, 62% 100%, 0 100%); }

.maze-cabinet { background: var(--graphite); }
.maze-wall { position: absolute; background: var(--porcelain); box-shadow: 10px 10px 0 var(--persimmon); }
.wall-a { width: 48%; height: 38px; left: 7%; top: 22%; }
.wall-b { width: 36px; height: 46%; left: 32%; top: 22%; }
.wall-c { width: 48%; height: 38px; right: 8%; bottom: 28%; }
.wall-d { width: 36px; height: 36%; right: 25%; top: 16%; }
.warning-stamp { position: absolute; right: 10%; top: 12%; color: var(--persimmon); border: 5px solid var(--persimmon); padding: 14px 22px; font-size: 28px; transform: rotate(11deg); }
.bug-glass { position: absolute; left: 12%; bottom: 14%; width: 280px; padding: 26px; background: rgba(56,221,248,.16); border: 2px solid var(--cyan); box-shadow: inset 0 0 32px rgba(56,221,248,.2); }
.sprite-bug { width: 52px; height: 38px; color: var(--lime); font-size: 44px; animation: bugTap 1.6s infinite steps(2); }
.bug-glass span { display: block; margin-top: 16px; font-size: 22px; }
.crate { position: absolute; display: grid; place-items: center; width: 92px; height: 92px; background: var(--lime); color: var(--navy); font: 700 28px var(--recursive); box-shadow: 9px 9px 0 rgba(0,0,0,.42); transition: transform .18s ease; }
.crate.blocked { animation: blocked .32s ease; }
.crate-one { left: 45%; top: 34%; }
.crate-two { left: 57%; top: 49%; background: var(--cyan); }
.crate-three { left: 72%; top: 35%; background: var(--persimmon); }
.deadlock-note { position: absolute; right: 8%; bottom: 8%; width: 38%; }

.turntable { display: grid; place-items: center; background: radial-gradient(circle, rgba(124,58,237,.22) 0 30%, var(--graphite) 31%); }
.turn-ring { position: absolute; width: min(56vw, 560px); height: min(56vw, 560px); border-radius: 50%; border: 3px solid var(--cyan); box-shadow: inset 0 0 0 40px rgba(7,17,31,.75), 0 0 44px rgba(124,58,237,.36); transition: transform .7s cubic-bezier(.2,1,.2,1); }
.turntable.rotated .turn-ring { transform: rotate(90deg); }
.turn-handle { position: absolute; right: 12%; top: 14%; background: var(--violet); padding: 16px 22px; cursor: pointer; box-shadow: 8px 8px 0 var(--cyan); }
.shard { position: absolute; padding: 26px 34px; font: 700 26px var(--recursive); color: var(--navy); background: var(--porcelain); clip-path: polygon(0 18%, 70% 0, 100% 55%, 62% 100%, 8% 78%); transition: transform .7s cubic-bezier(.2,1,.2,1); }
.shard-a { left: 27%; top: 24%; background: var(--lime); }
.shard-b { right: 28%; top: 28%; background: var(--cyan); }
.shard-c { left: 32%; bottom: 22%; background: var(--persimmon); }
.shard-d { right: 31%; bottom: 24%; background: var(--porcelain); }
.turntable.rotated .shard-a { transform: translate(56px, 90px) rotate(90deg); }
.turntable.rotated .shard-b { transform: translate(-78px, 48px) rotate(90deg); }
.turntable.rotated .shard-c { transform: translate(86px, -62px) rotate(90deg); }
.turntable.rotated .shard-d { transform: translate(-54px, -84px) rotate(90deg); }
.turntable-copy { position: absolute; left: 8%; bottom: 8%; width: 42%; }

.solved-board { display: grid; place-items: center; background: radial-gradient(circle at center, rgba(124,58,237,.36), var(--navy) 54%); }
.compiled-mark { position: relative; z-index: 2; font-family: var(--syne); font-weight: 800; font-size: clamp(48px, 11vw, 170px); letter-spacing: -.08em; text-shadow: 0 0 18px rgba(183,245,71,.65), 8px 8px 0 rgba(56,221,248,.25); animation: solvedPulse 2.8s infinite ease-in-out; }
.solved-p { display: inline-block; background: var(--porcelain); color: var(--navy); padding: 0 .05em; clip-path: polygon(0 0, 78% 0, 100% 18%, 100% 74%, 72% 100%, 0 100%); }
.solved-p.one { transform: translateX(8px); box-shadow: -8px 8px 0 var(--lime); }
.solved-p.two { transform: translateX(-2px); box-shadow: 8px 8px 0 var(--violet); }
.solved-word { color: var(--porcelain); letter-spacing: -.06em; }
.socket-grid { position: absolute; inset: 12%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; opacity: .25; }
.socket-grid i { border: 1px solid var(--cyan); clip-path: polygon(25% 0,75% 0,100% 50%,75% 100%,25% 100%,0 50%); }
.compiled-clue { position: absolute; bottom: 12%; max-width: 560px; text-align: center; }
.glow-label { position: absolute; top: 15%; color: var(--lime); }

.stage.in-view .drawer-shell { animation: drawerClick .8s ease both; }
.stage.in-view .maze-cabinet { animation: ruleFlash .7s ease both; }
.stage.in-view .solved-board { animation: finalSnap .7s ease both; }

@keyframes drawerClick { from { transform: translateY(50px); } to { transform: translateY(0); } }
@keyframes ruleFlash { 0%, 100% { box-shadow: 0 34px 0 rgba(0,0,0,.38), inset 0 0 0 9px rgba(242,246,233,.035); } 45% { box-shadow: 0 34px 0 rgba(0,0,0,.38), inset 0 0 0 9px rgba(255,90,61,.45); } }
@keyframes finalSnap { from { transform: scale(.96) rotate(-1deg); } to { transform: scale(1) rotate(0); } }
@keyframes blocked { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-12px); } 55% { transform: translateX(10px); } }
@keyframes bugTap { 0% { transform: translateX(0); } 100% { transform: translateX(16px); } }
@keyframes solvedPulse { 0%,100% { filter: drop-shadow(0 0 8px rgba(183,245,71,.38)); } 50% { filter: drop-shadow(0 0 28px rgba(183,245,71,.9)); } }

@media (max-width: 760px) {
    .inventory { left: 12px; right: 12px; justify-content: center; }
    .stage { padding: 70px 4vw 8vw; }
    .p-left { left: 8%; top: 18%; }
    .p-right { left: 31%; top: 24%; }
    .word-u { right: 7%; top: 55%; }
    .word-l { right: 42%; bottom: 12%; }
    .dot-piece { right: 7%; bottom: 15%; }
    .drawer-face, .deadlock-note, .turntable-copy { width: 82%; left: 8%; }
    .rule-tray { width: 86%; left: 7%; right: auto; top: 34%; }
    .bug-glass { left: 8%; bottom: 9%; width: 230px; }
    .crate-three { left: 60%; }
}
