/* ==========================================================================
   COMPLETENGINE.COM - Styles
   Palette: Deep graphite, burnished copper, forged metal aesthetic
   Mechanical easing, diagonal sections, full-bleed immersive layout
   ========================================================================== */

/* --- CSS Custom Properties --- */
:root {
    --bg-primary: #1a1a1e;
    --bg-secondary: #2a2a2f;
    --accent-copper: #b87333;
    --accent-brass: #d4a96a;
    --text-primary: #e8e6e3;
    --text-secondary: #9a9a9f;
    --highlight-orange: #e07830;
    --diagram-slate: #4a6278;
    --white: #ffffff;

    --font-display: 'Bebas Neue', sans-serif;
    --font-heading: 'DM Sans', sans-serif;
    --font-body: 'IBM Plex Mono', monospace;

    --easing-piston: cubic-bezier(0.7, 0, 0.3, 1);
}

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.875rem, 1.1vw, 1.05rem);
    line-height: 1.75;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Grain Overlay --- */
#grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    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)' opacity='0.5'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

/* --- Navigation Monogram --- */
#nav-monogram {
    position: fixed;
    top: 2rem;
    left: 2rem;
    z-index: 1000;
}

#nav-monogram .monogram {
    font-family: var(--font-display);
    font-size: 1.5rem;
    color: var(--accent-copper);
    letter-spacing: 0.08em;
    cursor: pointer;
    display: block;
    position: relative;
}

#nav-monogram .monogram::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--accent-copper);
    transition: width 0.4s var(--easing-piston);
}

#nav-monogram:hover .monogram::after {
    width: 100%;
}

#nav-monogram .nav-links {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

#nav-monogram:hover .nav-links {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

#nav-monogram .nav-links a {
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 300;
    color: var(--text-secondary);
    text-decoration: none;
    letter-spacing: 0.05em;
    transition: color 0.3s ease;
}

#nav-monogram .nav-links a:hover {
    color: var(--accent-copper);
}

/* --- Phase Sections --- */
.phase {
    position: relative;
    width: 100%;
}

/* --- PHASE 1: ASSEMBLY --- */
.phase-assembly {
    background: var(--bg-primary);
}

.opening-viewport {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.center-line-container {
    position: relative;
    width: 60vw;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.center-line {
    width: 0%;
    height: 1px;
    background: var(--accent-copper);
    transition: width 1s var(--easing-piston);
}

.center-line.visible {
    width: 100%;
}

.wordmark-container {
    position: relative;
    margin-top: 0.5rem;
    display: flex;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.wordmark-part {
    font-family: var(--font-display);
    font-size: clamp(3rem, 8vw, 7rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    line-height: 1;
}

.wordmark-complet {
    color: var(--text-primary);
}

.wordmark-engine {
    color: var(--accent-copper);
}

.wordmark-part .letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.wordmark-part .letter.visible {
    opacity: 1;
    transform: translateY(0);
}

.wordmark-engine .letter {
    position: relative;
}

.wordmark-engine .letter::after {
    content: '';
    position: absolute;
    right: -0.1em;
    top: 50%;
    width: 0;
    height: 1px;
    background: var(--accent-copper);
    opacity: 0.4;
    transition: width 0.3s var(--easing-piston);
}

.wordmark-engine .letter.visible::after {
    width: 0.3em;
}

/* --- Manifesto --- */
.manifesto-container {
    min-height: 50vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
}

.manifesto {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.875rem, 1.1vw, 1.05rem);
    line-height: 1.75;
    color: var(--text-secondary);
    max-width: 60vw;
    overflow: hidden;
}

.manifesto .char {
    opacity: 0;
    transition: opacity 0.05s ease;
}

.manifesto .char.typed {
    opacity: 1;
}

/* Cursor after last typed char */
.manifesto .cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background: var(--accent-copper);
    margin-left: 1px;
    vertical-align: text-bottom;
    animation: cursor-blink 0.8s step-end infinite;
}

@keyframes cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.manifesto .cursor.done {
    animation: cursor-blink 0.8s step-end 3;
    animation-fill-mode: forwards;
    opacity: 0;
}

/* --- Diagonal Dividers --- */
.diagonal-divider {
    width: 100%;
    line-height: 0;
    overflow: hidden;
}

.diagonal-divider svg {
    width: 100%;
    height: 60px;
    display: block;
}

/* --- PHASE 2: IGNITION --- */
.phase-ignition {
    background: var(--bg-primary);
}

/* --- Content Sections --- */
.content-section {
    min-height: 80vh;
    display: flex;
    align-items: center;
    padding: 6rem 4rem;
}

.content-grid {
    display: grid;
    grid-template-columns: 7fr 5fr;
    gap: 4rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.content-primary {
    opacity: 0;
    transform: translateX(-30px);
    transition: opacity 0.6s ease 0.1s, transform 0.6s var(--easing-piston) 0.1s;
}

.content-section.in-view .content-primary {
    opacity: 1;
    transform: translateX(0);
}

.section-heading {
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    letter-spacing: 0.01em;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.body-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.875rem, 1.1vw, 1.05rem);
    line-height: 1.75;
    color: var(--text-secondary);
    margin-bottom: 1.25rem;
    max-width: 580px;
}

/* --- Piston Dividers --- */
.piston-divider {
    height: 1px;
    background: var(--accent-copper);
    opacity: 0.6;
    margin: 1.5rem 0;
    transform-origin: left;
    transform: scaleX(0);
    transition: transform 0.8s var(--easing-piston);
}

.piston-short {
    width: 20%;
}

.piston-full {
    width: 100%;
}

.content-section.in-view .piston-divider {
    transform: scaleX(1);
}

/* --- Completion Arcs --- */
.content-secondary {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateX(30px);
    transition: opacity 0.6s ease 0.3s, transform 0.6s var(--easing-piston) 0.3s;
}

.content-section.in-view .content-secondary {
    opacity: 1;
    transform: translateX(0);
}

.completion-arc-container {
    position: relative;
    width: 160px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.completion-arc {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    transform: rotate(-90deg);
}

.arc-track {
    fill: none;
    stroke: var(--bg-secondary);
    stroke-width: 3;
}

.arc-fill {
    fill: none;
    stroke: var(--diagram-slate);
    stroke-width: 3;
    stroke-dasharray: 326.73;
    stroke-dashoffset: 326.73;
    stroke-linecap: round;
    transition: stroke-dashoffset 1.2s var(--easing-piston), stroke 0.8s ease 0.6s;
}

.content-section.in-view .arc-fill {
    stroke: var(--accent-copper);
}

.arc-label {
    font-family: var(--font-display);
    font-size: 2rem;
    color: var(--text-primary);
    letter-spacing: 0.05em;
    z-index: 1;
}

.arc-caption {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 0.7rem;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
    z-index: 1;
}

/* --- Engine Section --- */
.engine-section {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    position: relative;
}

#engine-schematic {
    width: min(80vw, 700px);
    height: auto;
}

.engine-part {
    fill: none;
    stroke: var(--diagram-slate);
    stroke-width: 1.5;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 1s var(--easing-piston);
}

.engine-part.drawn {
    stroke-dashoffset: 0;
}

.engine-part.timing-mark {
    stroke-width: 2;
}

/* Engine running animation */
#engine-schematic.running #engine-flywheel,
#engine-schematic.running #engine-flywheel-inner,
#engine-schematic.running #engine-hub {
    transform-origin: 300px 200px;
    animation: flywheel-spin 50s linear infinite;
}

#engine-schematic.running #engine-gear-1,
#engine-schematic.running #engine-gear-1-inner {
    transform-origin: 520px 140px;
    animation: gear-spin 25s linear infinite reverse;
}

#engine-schematic.running #engine-gear-2,
#engine-schematic.running #engine-gear-2-inner {
    transform-origin: 80px 260px;
    animation: gear-spin 25s linear infinite;
}

#engine-schematic.running #engine-timing-1,
#engine-schematic.running #engine-timing-2,
#engine-schematic.running #engine-timing-3,
#engine-schematic.running #engine-timing-4 {
    transform-origin: 300px 200px;
    animation: flywheel-spin 50s linear infinite;
}

#engine-schematic.running #engine-spoke-1,
#engine-schematic.running #engine-spoke-2,
#engine-schematic.running #engine-spoke-3,
#engine-schematic.running #engine-spoke-4 {
    transform-origin: 300px 200px;
    animation: flywheel-spin 50s linear infinite;
}

#engine-schematic.running #engine-piston-right,
#engine-schematic.running #engine-pin-right {
    animation: piston-horizontal 4s var(--easing-piston) infinite;
}

#engine-schematic.running #engine-piston-left,
#engine-schematic.running #engine-pin-left {
    animation: piston-horizontal-reverse 4s var(--easing-piston) infinite;
}

#engine-schematic.running #engine-valve-top {
    animation: piston-vertical-reverse 4s var(--easing-piston) infinite;
    animation-delay: 1s;
}

#engine-schematic.running #engine-valve-bottom {
    animation: piston-vertical 4s var(--easing-piston) infinite;
    animation-delay: 1s;
}

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

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

@keyframes piston-horizontal {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(10px); }
}

@keyframes piston-horizontal-reverse {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(-10px); }
}

@keyframes piston-vertical {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(8px); }
}

@keyframes piston-vertical-reverse {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

/* Engine glow when running */
#engine-schematic.running .engine-part {
    stroke: var(--accent-copper);
    transition: stroke 2s ease;
}

.engine-status {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 0.8rem;
    color: var(--text-secondary);
    letter-spacing: 0.15em;
    margin-top: 2rem;
    opacity: 0;
    transition: opacity 0.6s ease, color 0.6s ease;
}

.engine-status.visible {
    opacity: 1;
}

.engine-status.running {
    color: var(--highlight-orange);
}

/* --- PHASE 3: COMPLETION --- */
.phase-completion {
    background: var(--bg-secondary);
}

/* --- Trust Section --- */
.trust-section {
    min-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6rem 4rem;
}

.trust-quote {
    text-align: center;
    max-width: 800px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s var(--easing-piston);
}

.trust-quote.in-view {
    opacity: 1;
    transform: translateY(0);
}

.quote-text {
    font-family: var(--font-display);
    font-size: clamp(2rem, 5vw, 4rem);
    letter-spacing: 0.06em;
    color: var(--text-primary);
    line-height: 1.2;
    display: block;
}

/* --- Terminal Section --- */
.terminal-section {
    min-height: 80vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6rem 2rem;
}

.terminal-line-container {
    width: 80vw;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.terminal-line {
    width: 0%;
    height: 1px;
    background: var(--accent-copper);
    transition: width 1.5s var(--easing-piston);
}

.terminal-line.visible {
    width: 100%;
}

.terminal-wordmark {
    font-family: var(--font-display);
    font-size: clamp(2.5rem, 6vw, 5rem);
    letter-spacing: 0.08em;
    color: var(--text-primary);
    margin-top: 0.5rem;
    opacity: 0;
    transition: opacity 0.8s ease 0.8s;
}

.terminal-wordmark.visible {
    opacity: 1;
}

.terminal-tagline {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.875rem, 1.1vw, 1.05rem);
    color: var(--text-secondary);
    margin-top: 2rem;
    opacity: 0;
    transition: opacity 0.8s ease 1.2s;
}

.terminal-tagline.visible {
    opacity: 1;
}

.terminal-contact {
    margin-top: 3rem;
    opacity: 0;
    transition: opacity 0.8s ease 1.6s;
}

.terminal-contact.visible {
    opacity: 1;
}

.contact-link {
    position: relative;
    text-decoration: none;
    display: inline-block;
}

.contact-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 1rem;
    color: var(--accent-copper);
    letter-spacing: 0.05em;
    transition: color 0.3s ease;
}

.contact-link:hover .contact-text {
    color: var(--highlight-orange);
}

.contact-stroke {
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--highlight-orange);
    transition: width 0.6s var(--easing-piston);
}

.contact-link:hover .contact-stroke {
    width: 100%;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .content-grid {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .content-section {
        padding: 4rem 2rem;
    }

    .center-line-container {
        width: 85vw;
    }

    .manifesto {
        max-width: 85vw;
    }

    .terminal-line-container {
        width: 90vw;
    }

    .content-secondary {
        justify-content: flex-start;
    }
}

@media (max-width: 480px) {
    #nav-monogram {
        top: 1rem;
        left: 1rem;
    }

    .content-section {
        padding: 3rem 1.25rem;
    }

    .trust-section {
        padding: 4rem 1.5rem;
    }
}
