/* ═══════════════════════════════════════════════════════════
   PHB GROUP - Rube Goldberg Machine
   ═══════════════════════════════════════════════════════════ */

:root {
    --color-bg: #f8f7f4;
    --color-text: #1a1a1a;
    --color-text-muted: #666;
    --color-accent: #c44;
    --font-mono: 'IBM Plex Mono', monospace;
    --font-serif: 'Instrument Serif', Georgia, serif;
    --cycle: 12s; /* Full machine cycle */
}

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

html {
    font-size: 16px;
}

body {
    font-family: var(--font-body);
    background-color: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    position: relative;
    overflow-x: hidden;
}

/* ═══════════════════════════════════════════════════════════
   RUBE GOLDBERG MACHINE
   ═══════════════════════════════════════════════════════════ */

.rube-goldberg {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    opacity: 0.12;
}

/* === STAGE 1: Drop ball and first ramp (top-left) === */
.drop-ball {
    position: absolute;
    top: 5%;
    left: 8%;
    width: 20px;
    height: 20px;
    background: var(--color-text);
    border-radius: 50%;
    animation: dropAndRoll var(--cycle) ease-in-out infinite;
}

@keyframes dropAndRoll {
    0% { top: 5%; left: 8%; }
    5% { top: 15%; left: 8%; }
    15% { top: 25%; left: 20%; }
    100% { top: 25%; left: 20%; opacity: 0; }
}

.ramp-1 {
    position: absolute;
    top: 18%;
    left: 5%;
    width: 20%;
    height: 3px;
    background: var(--color-text);
    transform: rotate(25deg);
    transform-origin: left;
}

/* === STAGE 2: Lever === */
.lever-1 {
    position: absolute;
    top: 28%;
    left: 18%;
}

.lever-arm {
    width: 80px;
    height: 4px;
    background: var(--color-text);
    transform-origin: center;
    animation: leverTip var(--cycle) ease-out infinite;
}

@keyframes leverTip {
    0%, 14% { transform: rotate(0deg); }
    16% { transform: rotate(-20deg); }
    20%, 100% { transform: rotate(0deg); }
}

.lever-pivot {
    position: absolute;
    bottom: -8px;
    left: 50%;
    width: 12px;
    height: 12px;
    background: var(--color-text);
    transform: translateX(-50%) rotate(45deg);
}

/* === STAGE 3: Launched ball === */
.launch-ball {
    position: absolute;
    top: 28%;
    left: 22%;
    width: 14px;
    height: 14px;
    background: var(--color-text);
    border-radius: 50%;
    animation: launchArc var(--cycle) ease-out infinite;
}

@keyframes launchArc {
    0%, 15% { top: 28%; left: 22%; opacity: 0; }
    16% { opacity: 1; }
    25% { top: 8%; left: 35%; }
    35% { top: 20%; left: 48%; }
    100% { top: 20%; left: 48%; opacity: 0; }
}

.arc-track {
    position: absolute;
    top: 5%;
    left: 25%;
    width: 30%;
    height: 20%;
    border: 2px dashed var(--color-text);
    border-radius: 0 0 50% 50%;
    border-top: none;
    opacity: 0.3;
}

/* === STAGE 4: Funnel and spiral === */
.funnel {
    position: absolute;
    top: 18%;
    left: 45%;
    width: 0;
    height: 0;
    border-left: 30px solid transparent;
    border-right: 30px solid transparent;
    border-top: 40px solid var(--color-text);
    opacity: 0.5;
}

.spiral-ball {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--color-text);
    border-radius: 50%;
    animation: spiralDown var(--cycle) ease-in infinite;
}

@keyframes spiralDown {
    0%, 34% { top: 22%; left: 48%; opacity: 0; }
    35% { opacity: 1; }
    45% { top: 35%; left: 52%; }
    55% { top: 45%; left: 46%; }
    100% { top: 45%; left: 46%; opacity: 0; }
}

/* === STAGE 5: Dominos === */
.domino {
    position: absolute;
    width: 6px;
    height: 24px;
    background: var(--color-text);
    transform-origin: bottom center;
}

.domino-1 { top: 43%; left: 50%; animation: dominoFall var(--cycle) ease-out infinite; animation-delay: calc(var(--cycle) * 0.45); }
.domino-2 { top: 43%; left: 53%; animation: dominoFall var(--cycle) ease-out infinite; animation-delay: calc(var(--cycle) * 0.47); }
.domino-3 { top: 43%; left: 56%; animation: dominoFall var(--cycle) ease-out infinite; animation-delay: calc(var(--cycle) * 0.49); }
.domino-4 { top: 43%; left: 59%; animation: dominoFall var(--cycle) ease-out infinite; animation-delay: calc(var(--cycle) * 0.51); }
.domino-5 { top: 43%; left: 62%; animation: dominoFall var(--cycle) ease-out infinite; animation-delay: calc(var(--cycle) * 0.53); }

@keyframes dominoFall {
    0%, 2% { transform: rotate(0deg); }
    5%, 100% { transform: rotate(80deg); }
}

/* === STAGE 6: Pendulum === */
.pendulum {
    position: absolute;
    top: 30%;
    left: 68%;
    transform-origin: top center;
    animation: pendulumSwing var(--cycle) ease-in-out infinite;
}

.pendulum-string {
    width: 2px;
    height: 15vh;
    background: var(--color-text);
    margin: 0 auto;
}

.pendulum-weight {
    width: 25px;
    height: 25px;
    background: var(--color-text);
    border-radius: 50%;
    margin: 0 auto;
}

@keyframes pendulumSwing {
    0%, 52% { transform: rotate(0deg); }
    55% { transform: rotate(-35deg); }
    60% { transform: rotate(25deg); }
    65% { transform: rotate(-15deg); }
    70%, 100% { transform: rotate(0deg); }
}

/* === STAGE 7: Push ball and ramp === */
.push-ball {
    position: absolute;
    width: 16px;
    height: 16px;
    background: var(--color-text);
    border-radius: 50%;
    animation: pushRoll var(--cycle) ease-in infinite;
}

@keyframes pushRoll {
    0%, 58% { top: 52%; left: 72%; opacity: 0; }
    60% { opacity: 1; }
    75% { top: 65%; left: 85%; }
    100% { top: 65%; left: 85%; opacity: 0; }
}

.ramp-2 {
    position: absolute;
    top: 55%;
    left: 70%;
    width: 22%;
    height: 3px;
    background: var(--color-text);
    transform: rotate(15deg);
}

/* === STAGE 8: Gear system (bottom right) === */
.gear-system {
    position: absolute;
    bottom: 15%;
    right: 8%;
}

.gear {
    position: absolute;
    border: 3px solid var(--color-text);
    border-radius: 50%;
}

.gear::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30%;
    height: 30%;
    background: var(--color-text);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.gear::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 80%;
    height: 3px;
    background: var(--color-text);
    transform: translate(-50%, -50%);
}

.gear-big {
    width: 70px;
    height: 70px;
    animation: gearSpin var(--cycle) linear infinite;
    animation-delay: calc(var(--cycle) * 0.6);
}

.gear-med {
    width: 45px;
    height: 45px;
    top: -20px;
    left: 55px;
    animation: gearSpin var(--cycle) linear infinite reverse;
    animation-delay: calc(var(--cycle) * 0.6);
}

.gear-small {
    width: 30px;
    height: 30px;
    top: -45px;
    left: 85px;
    animation: gearSpin var(--cycle) linear infinite;
    animation-delay: calc(var(--cycle) * 0.6);
}

@keyframes gearSpin {
    0%, 10% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* === STAGE 9: Pulley and bucket === */
.pulley-rope {
    position: absolute;
    bottom: 35%;
    right: 3%;
    width: 2px;
    height: 20vh;
    background: var(--color-text);
    animation: ropeMove var(--cycle) ease-in-out infinite;
}

@keyframes ropeMove {
    0%, 65% { height: 20vh; }
    80% { height: 12vh; }
    100% { height: 20vh; }
}

.bucket {
    position: absolute;
    bottom: 30%;
    right: 1%;
    width: 30px;
    height: 25px;
    border: 3px solid var(--color-text);
    border-top: none;
    animation: bucketLift var(--cycle) ease-in-out infinite;
}

@keyframes bucketLift {
    0%, 65% { bottom: 30%; transform: rotate(0deg); }
    75% { bottom: 42%; transform: rotate(0deg); }
    85% { bottom: 42%; transform: rotate(-60deg); }
    100% { bottom: 30%; transform: rotate(0deg); }
}

/* === STAGE 10: Pouring balls === */
.pour-ball {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--color-text);
    border-radius: 50%;
}

.pour-1 { animation: pourFall1 var(--cycle) ease-in infinite; }
.pour-2 { animation: pourFall2 var(--cycle) ease-in infinite; }
.pour-3 { animation: pourFall3 var(--cycle) ease-in infinite; }

@keyframes pourFall1 {
    0%, 82% { top: 55%; right: 5%; opacity: 0; }
    83% { opacity: 1; }
    95% { top: 78%; right: 15%; }
    100% { top: 78%; right: 15%; opacity: 0; }
}

@keyframes pourFall2 {
    0%, 84% { top: 55%; right: 4%; opacity: 0; }
    85% { opacity: 1; }
    95% { top: 80%; right: 18%; }
    100% { top: 80%; right: 18%; opacity: 0; }
}

@keyframes pourFall3 {
    0%, 86% { top: 55%; right: 6%; opacity: 0; }
    87% { opacity: 1; }
    95% { top: 82%; right: 12%; }
    100% { top: 82%; right: 12%; opacity: 0; }
}

/* === STAGE 11: See-saw (bottom center) === */
.seesaw {
    position: absolute;
    bottom: 12%;
    right: 20%;
}

.seesaw-plank {
    width: 100px;
    height: 5px;
    background: var(--color-text);
    transform-origin: center;
    animation: seesawTip var(--cycle) ease-out infinite;
}

@keyframes seesawTip {
    0%, 88% { transform: rotate(-5deg); }
    92% { transform: rotate(15deg); }
    100% { transform: rotate(-5deg); }
}

.seesaw-pivot {
    position: absolute;
    bottom: -10px;
    left: 50%;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 15px solid var(--color-text);
    transform: translateX(-50%);
}

/* === STAGE 12: Final ball launch (loops back) === */
.final-ball {
    position: absolute;
    width: 18px;
    height: 18px;
    background: var(--color-text);
    border-radius: 50%;
    animation: finalLaunch var(--cycle) ease-out infinite;
}

@keyframes finalLaunch {
    0%, 91% { bottom: 15%; right: 25%; opacity: 0; }
    92% { opacity: 1; }
    96% { bottom: 40%; right: 40%; }
    100% { bottom: 5%; left: 5%; opacity: 0; }
}

.final-ramp {
    position: absolute;
    bottom: 8%;
    left: 5%;
    width: 15%;
    height: 3px;
    background: var(--color-text);
    transform: rotate(-20deg);
}

/* === Connecting tracks === */
.track {
    position: absolute;
    height: 2px;
    background: var(--color-text);
    opacity: 0.4;
}

.track-1 {
    top: 35%;
    left: 30%;
    width: 15%;
    transform: rotate(10deg);
}

.track-2 {
    top: 50%;
    left: 60%;
    width: 12%;
    transform: rotate(-5deg);
}

.track-3 {
    bottom: 25%;
    right: 25%;
    width: 18%;
    transform: rotate(8deg);
}

/* === Connecting wires === */
.wire {
    position: absolute;
    width: 2px;
    background: var(--color-text);
    opacity: 0.3;
}

.wire-1 {
    top: 25%;
    left: 40%;
    height: 15%;
}

.wire-2 {
    top: 45%;
    right: 30%;
    height: 20%;
}

/* === Background wheels (always spinning) === */
.wheel {
    position: absolute;
    border: 2px solid var(--color-text);
    border-radius: 50%;
    opacity: 0.2;
}

.wheel::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--color-text);
    transform: translateY(-50%);
}

.wheel::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--color-text);
    transform: translateX(-50%);
}

.wheel-1 {
    top: 60%;
    left: 10%;
    width: 60px;
    height: 60px;
    animation: spin 4s linear infinite;
}

.wheel-2 {
    top: 15%;
    right: 15%;
    width: 80px;
    height: 80px;
    animation: spin 6s linear infinite reverse;
}

.wheel-3 {
    bottom: 40%;
    left: 35%;
    width: 45px;
    height: 45px;
    animation: spin 3s linear infinite;
}

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

/* ═══════════════════════════════════════════════════════════
   LAYOUT - Control Panel (Eye of the Storm)
   ═══════════════════════════════════════════════════════════ */

.container {
    position: relative;
    z-index: 10;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.control-panel {
    animation: panelFadeIn 1.5s ease-out 0.5s both;
}

@keyframes panelFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.panel-frame {
    position: relative;
    background: rgba(248, 247, 244, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 3rem 4rem;
    text-align: center;
    border: 1px solid rgba(26, 26, 26, 0.15);
}

/* Corner brackets - technical drawing feel */
.panel-corner {
    position: absolute;
    width: 20px;
    height: 20px;
    border-color: var(--color-text);
    border-style: solid;
    border-width: 0;
}

.panel-corner-tl {
    top: -1px;
    left: -1px;
    border-top-width: 2px;
    border-left-width: 2px;
}

.panel-corner-tr {
    top: -1px;
    right: -1px;
    border-top-width: 2px;
    border-right-width: 2px;
}

.panel-corner-bl {
    bottom: -1px;
    left: -1px;
    border-bottom-width: 2px;
    border-left-width: 2px;
}

.panel-corner-br {
    bottom: -1px;
    right: -1px;
    border-bottom-width: 2px;
    border-right-width: 2px;
}

/* ═══════════════════════════════════════════════════════════
   TYPOGRAPHY - Industrial Precision
   ═══════════════════════════════════════════════════════════ */

.system-label {
    font-family: var(--font-mono);
    font-size: 0.625rem;
    font-weight: 500;
    letter-spacing: 0.2em;
    color: var(--color-accent);
    margin-bottom: 1.5rem;
    animation: blink 2s ease-in-out infinite;
}

@keyframes blink {
    0%, 90%, 100% { opacity: 1; }
    95% { opacity: 0.3; }
}

.logo {
    font-family: var(--font-mono);
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text);
    line-height: 1;
    margin-bottom: 1.25rem;
}

.divider {
    width: 40px;
    height: 1px;
    background: var(--color-text);
    margin: 0 auto 1.25rem;
    opacity: 0.3;
}

.tagline {
    font-family: var(--font-mono);
    font-size: clamp(0.75rem, 2vw, 0.875rem);
    font-weight: 400;
    color: var(--color-text-muted);
    line-height: 1.7;
    letter-spacing: 0.02em;
    margin-bottom: 2rem;
}

/* ═══════════════════════════════════════════════════════════
   CONTACT - Technical Link
   ═══════════════════════════════════════════════════════════ */

.contact-link {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    font-weight: 400;
    color: var(--color-text);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border: 1px solid rgba(26, 26, 26, 0.2);
    transition: all 0.2s ease;
}

.link-indicator {
    width: 6px;
    height: 6px;
    background: var(--color-accent);
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
}

.contact-link:hover {
    background: var(--color-text);
    color: var(--color-bg);
    border-color: var(--color-text);
}

.contact-link:hover .link-indicator {
    background: var(--color-bg);
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .container {
        padding: 1.5rem;
    }

    .panel-frame {
        padding: 2.5rem 2rem;
    }

    .rube-goldberg {
        opacity: 0.1;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 1rem;
    }

    .panel-frame {
        padding: 2rem 1.5rem;
    }

    .tagline {
        margin-bottom: 1.5rem;
    }

    .rube-goldberg {
        opacity: 0.08;
    }

    .panel-corner {
        width: 15px;
        height: 15px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .rube-goldberg * {
        animation: none !important;
    }
}
