/* ========================================
   penclos.com — Privacy Encloser
   Wabi-Sabi HUD Design System
   ======================================== */

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

:root {
    --enclosure-dark: #0e0f0d;
    --stone-surface: #2a2b28;
    --lichen-green: #8b9a7c;
    --crack-light: #d4cbbf;
    --alert-amber: #c4923a;
    --repair-teal: #4a8b82;
    --hud-border: #5a5b57;
}

html {
    scroll-behavior: auto;
}

body {
    background: var(--enclosure-dark);
    color: var(--crack-light);
    font-family: 'Cormorant Garamond', serif;
    overflow-x: hidden;
    min-height: 500vh;
}

/* --- Background Canvas --- */
#mesh {
    position: fixed;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
}

/* --- Noise Overlay --- */
#noise-overlay {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    opacity: 0.08;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* --- Scan Line --- */
#scan-line {
    position: fixed;
    left: 0;
    width: 100%;
    height: 1px;
    background: var(--lichen-green);
    opacity: 0;
    z-index: 25;
    pointer-events: none;
    transition: opacity 0.3s;
}

body.state-2 #scan-line,
body.state-3 #scan-line {
    opacity: 0.05;
    animation: scanSweep 6s linear infinite;
}

@keyframes scanSweep {
    0% { top: 0; }
    100% { top: 100vh; }
}

/* --- SVG Circuits --- */
.circuits {
    position: fixed;
    inset: 0;
    z-index: 10;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.circuit-path {
    fill: none;
    stroke: var(--hud-border);
    stroke-width: 1.5;
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke 0.6s ease, stroke-dashoffset 1.2s ease;
}

body.state-1 .cp-1,
body.state-1 .cp-2,
body.state-1 .cp-3 {
    stroke-dashoffset: 0;
}

body.state-2 .circuit-path,
body.state-3 .circuit-path,
body.state-4 .circuit-path {
    stroke-dashoffset: 0;
    stroke: var(--lichen-green);
}

.node {
    fill: var(--hud-border);
    opacity: 0;
    transition: opacity 0.8s ease, fill 0.6s ease;
}

body.state-1 .node,
body.state-2 .node,
body.state-3 .node {
    opacity: 1;
}

body.state-2 .node,
body.state-3 .node {
    fill: var(--lichen-green);
}

/* --- Crack Patterns --- */
.crack {
    fill: none;
    stroke: var(--stone-surface);
    stroke-width: 0.5;
    opacity: 0.3;
    transition: stroke 0.8s ease, opacity 0.8s ease;
}

body.state-3 .crack {
    stroke: var(--alert-amber);
    opacity: 1;
    animation: crackRepair 2.4s ease forwards;
}

@keyframes crackRepair {
    0% { stroke: var(--alert-amber); }
    40% { stroke: var(--alert-amber); }
    100% { stroke: var(--repair-teal); opacity: 0.6; }
}

/* --- Data Particles --- */
#particles {
    position: fixed;
    inset: 0;
    z-index: 11;
    pointer-events: none;
}

.particle {
    position: absolute;
    width: 3px;
    height: 3px;
    background: var(--lichen-green);
    opacity: 0;
    transition: opacity 0.5s;
}

body.state-2 .particle,
body.state-3 .particle {
    opacity: 0.4;
}

body.state-4 .particle {
    opacity: 0.2;
}

/* --- Viewport Corner Brackets --- */
.viewport-brackets {
    position: fixed;
    inset: 0;
    z-index: 20;
    pointer-events: none;
}

.vb {
    position: absolute;
    width: 24px;
    height: 24px;
    transition: border-color 0.6s ease, width 0.3s ease, height 0.3s ease;
}

.vb-tl {
    top: 20px; left: 20px;
    border-top: 1.5px solid var(--hud-border);
    border-left: 1.5px solid var(--hud-border);
}

.vb-tr {
    top: 20px; right: 20px;
    border-top: 1.5px solid var(--hud-border);
    border-right: 1.5px solid var(--hud-border);
}

.vb-bl {
    bottom: 20px; left: 20px;
    border-bottom: 1.5px solid var(--hud-border);
    border-left: 1.5px solid var(--hud-border);
}

.vb-br {
    bottom: 20px; right: 20px;
    border-bottom: 1.5px solid var(--hud-border);
    border-right: 1.5px solid var(--hud-border);
}

body.state-0 .vb {
    animation: bracketBreathe 3s ease-in-out infinite;
}

body.state-3 .vb {
    border-color: var(--alert-amber);
    animation: bracketPulse 1.5s ease-in-out infinite;
}

@keyframes bracketBreathe {
    0%, 100% { width: 24px; height: 24px; }
    50% { width: 26px; height: 26px; }
}

@keyframes bracketPulse {
    0%, 100% { width: 24px; height: 24px; }
    50% { width: 28px; height: 28px; }
}

/* --- Scroll Container --- */
.scroll-container {
    position: relative;
    z-index: 15;
    min-height: 500vh;
}

.state-content {
    position: relative;
    height: 100vh;
    width: 100%;
}

/* --- Brand Center (State 0) --- */
.brand-center {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 30;
    opacity: 1;
    transition: opacity 0.8s ease;
}

body:not(.state-0) .brand-center {
    opacity: 0;
    pointer-events: none;
}

.brand-name {
    font-family: 'Jost', sans-serif;
    font-weight: 600;
    font-size: clamp(2.5rem, 5vw, 4.5rem);
    letter-spacing: 0.4em;
    color: var(--crack-light);
    margin-bottom: 1rem;
}

.brand-tagline {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1rem, 2vw, 1.5rem);
    color: var(--lichen-green);
    letter-spacing: 0.1em;
}

/* --- HUD Panels --- */
.hud-panel {
    position: fixed;
    background: rgba(14, 15, 13, 0.72);
    backdrop-filter: blur(8px) saturate(0.9);
    border: 1px solid var(--hud-border);
    padding: 2rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.8s ease, border-color 0.6s ease, transform 1.2s cubic-bezier(0.23, 1, 0.32, 1);
    will-change: transform, opacity;
    z-index: 20;
    max-width: 380px;
}

.hud-panel.active {
    opacity: 1;
    pointer-events: auto;
    border-color: var(--lichen-green);
}

/* Panel inner wrapper for corner brackets */
.panel-inner {
    position: relative;
    padding: 0.5rem;
}

.panel-inner::before,
.panel-inner::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    transition: border-color 0.6s ease;
}

.panel-inner::before {
    top: -8px;
    left: -8px;
    border-top: 1.5px solid var(--hud-border);
    border-left: 1.5px solid var(--hud-border);
}

.panel-inner::after {
    bottom: -8px;
    right: -8px;
    border-bottom: 1.5px solid var(--hud-border);
    border-right: 1.5px solid var(--hud-border);
}

.hud-panel.active .panel-inner::before,
.hud-panel.active .panel-inner::after {
    border-color: var(--alert-amber);
}

/* Panel positions - State 1 */
.panel-1 { left: 8%; top: 15%; }
.panel-2 { right: 8%; top: 35%; left: auto; }
.panel-3 { left: 25%; top: 65%; }

/* Panel positions - State 2 */
.panel-4 { left: 5%; top: 20%; }
.panel-5 { right: 5%; top: 55%; left: auto; }

/* Panel positions - State 3 */
.panel-6 { left: 50%; top: 50%; transform: translate(-50%, -50%); }

/* State 4: converge panels to center */
body.state-4 .hud-panel {
    left: 50% !important;
    right: auto !important;
    top: 50% !important;
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0;
}

/* --- Panel Typography --- */
.panel-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.hud-label {
    font-family: 'Jost', sans-serif;
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--hud-border);
    transition: color 0.6s ease;
}

.hud-panel.active .hud-label {
    color: var(--lichen-green);
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--hud-border);
    transition: background 0.6s ease;
}

.status-dot.pulse {
    background: var(--alert-amber);
    animation: dotPulse 2s ease-in-out infinite;
}

.status-dot.active {
    background: var(--lichen-green);
    animation: dotPulse 3s ease-in-out infinite;
}

.status-dot.repair {
    background: var(--repair-teal);
    animation: dotPulse 1s ease-in-out infinite;
}

@keyframes dotPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.panel-mono {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--crack-light);
    opacity: 0.85;
    margin-bottom: 0.75rem;
}

.panel-integrity {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    color: var(--hud-border);
    margin-bottom: 0.25rem;
}

.amber { color: var(--alert-amber); }
.teal { color: var(--repair-teal); }

/* --- Narrative Text --- */
.narrative-text {
    position: fixed;
    z-index: 20;
    max-width: 420px;
    opacity: 0;
    transition: opacity 1s ease;
    pointer-events: none;
}

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

.nt-1 { left: 55%; top: 45%; }
.nt-2 { left: 10%; top: 40%; }
.nt-3 { right: 10%; top: 30%; left: auto; }

.narrative {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.1rem, 1.8vw, 1.4rem);
    line-height: 1.8;
    color: var(--crack-light);
    opacity: 0.9;
}

/* --- Final Enclosure (State 4) --- */
.final-enclosure {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 30;
    opacity: 0;
    transition: opacity 1.2s ease;
    pointer-events: none;
}

body.state-4 .final-enclosure {
    opacity: 1;
}

.final-brackets {
    position: absolute;
    inset: -40px;
}

.fb {
    position: absolute;
    width: 48px;
    height: 48px;
    transition: border-color 0.6s ease;
}

.fb-tl {
    top: 0; left: 0;
    border-top: 1.5px solid var(--crack-light);
    border-left: 1.5px solid var(--crack-light);
}

.fb-tr {
    top: 0; right: 0;
    border-top: 1.5px solid var(--crack-light);
    border-right: 1.5px solid var(--crack-light);
}

.fb-bl {
    bottom: 0; left: 0;
    border-bottom: 1.5px solid var(--crack-light);
    border-left: 1.5px solid var(--crack-light);
}

.fb-br {
    bottom: 0; right: 0;
    border-bottom: 1.5px solid var(--crack-light);
    border-right: 1.5px solid var(--crack-light);
}

.enclosed-title {
    font-family: 'Jost', sans-serif;
    font-weight: 600;
    font-size: clamp(2rem, 4vw, 3.5rem);
    letter-spacing: 0.6em;
    color: var(--crack-light);
    margin-bottom: 1.5rem;
}

.enclosed-sub {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 400;
    font-style: italic;
    font-size: 1.1rem;
    color: var(--lichen-green);
    max-width: 360px;
    line-height: 1.7;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .hud-panel {
        max-width: 85vw;
        padding: 1.5rem;
    }
    .panel-1 { left: 5%; top: 10%; }
    .panel-2 { left: 5%; top: 40%; right: auto; }
    .panel-3 { left: 5%; top: 65%; }
    .panel-4 { left: 5%; top: 15%; }
    .panel-5 { left: 5%; top: 55%; right: auto; }
    .narrative-text { left: 5% !important; right: auto !important; max-width: 90vw; }
    .nt-1 { top: 88%; }
    .nt-2 { top: 80%; }
    .nt-3 { top: 70%; }
}
