@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Space+Grotesk:wght@400;500;700&display=block');

/* ================================================================
   DESIGN TOKENS
   ================================================================ */
:root {
    /* Surfaces */
    --bg: #F8F6F2;
    --card: #FFFFFF;
    --grid-line: rgba(14, 14, 14, 0.08);

    /* Ink */
    --ink: #0E0E0E;
    --ink-muted: #3D3D3D;
    --border: #0E0E0E;

    /* Brand */
    --brand-red: #EE4E4E;
    --brand-orange: #FA641E;
    --brand-orange-text: #C44E00; /* darkened for 4.5:1+ on white */
    --brand-yellow: #FFC400;
    --brand-gradient: linear-gradient(135deg, var(--brand-red), var(--brand-orange), var(--brand-yellow));

    /* Technical Diagram stark color-blocking (Light Mode: Dark diagram) */
    --diagram-bg: #0E0E0E;
    --diagram-fg: #F8F6F2;
    --diagram-border: #F8F6F2;
    --diagram-grid: rgba(248, 246, 242, 0.15);

    /* Elevation */
    --shadow: 4px 4px 0px var(--border);
    --shadow-hover: 2px 2px 0px var(--border);

    /* Motion */
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
    --speed: 0.2s;
    --speed-reveal: 0.7s;
}

html.dark {
    --bg: #0E0E0E;
    --card: #161616;
    --grid-line: rgba(248, 246, 242, 0.06);
    --ink: #F0EDE7;
    --ink-muted: #A8A8A8;
    --border: #F0EDE7;
    --brand-orange-text: #FA641E;
    
    /* Technical Diagram stark color-blocking (Always dark diagram) */
    --diagram-bg: #0E0E0E;
    --diagram-fg: #F0EDE7;
    --diagram-border: #F0EDE7;
    --diagram-grid: rgba(248, 246, 242, 0.15);

    --shadow: 4px 4px 0px var(--border);
    --shadow-hover: 2px 2px 0px var(--border);
}

/* ================================================================
   RESET & BASE
   ================================================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    background-color: var(--bg);
    color: var(--ink);
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    line-height: 1.7;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
    transition: background-color var(--speed), color var(--speed);
}

/* ================================================================
   BACKGROUND GRID
   ================================================================ */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        radial-gradient(circle at 1px 1px, var(--grid-line) 1px, transparent 1px),
        radial-gradient(circle at 1px 1px, var(--grid-line) 1px, transparent 1px);
    background-size: 48px 8px, 8px 48px;
    pointer-events: none;
    z-index: 0;
}

/* ================================================================
   TYPOGRAPHY
   ================================================================ */
h1, h2, h3, h4 {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    line-height: 1.15;
    text-wrap: balance;
}

h1 {
    font-size: clamp(1.75rem, 4vw + 0.5rem, 3rem);
    letter-spacing: -0.025em;
}

h2 {
    font-size: clamp(1.35rem, 2vw + 0.5rem, 1.75rem);
    letter-spacing: -0.015em;
}

h3 {
    font-size: 1rem;
    font-weight: 700;
}

strong {
    font-weight: 600;
}

a {
    color: var(--brand-orange-text);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1.5px;
    transition: color var(--speed);
}

a:hover {
    color: var(--brand-red);
}

a:focus-visible {
    outline: 2px solid var(--brand-orange);
    outline-offset: 2px;
}

/* Screen-reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ================================================================
   LAYOUT
   ================================================================ */
.page {
    width: 100%;
    margin: 0;
    padding: 0;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-height: 100vh;
}

main {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex-grow: 1;
}

/* ================================================================
   HEADER
   ================================================================ */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--border);
    background-color: var(--card);
    padding: 24px clamp(20px, 6vw, 80px);
    margin-bottom: 0;
    box-shadow: none;
    transition: background-color var(--speed), border-color var(--speed);
}

.header__brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header__logo {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.header__wordmark {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.header__controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ================================================================
   BADGE
   ================================================================ */
.badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.badge--status {
    background: var(--brand-gradient);
    color: #FFFFFF;
    border: 2px solid #000;
    box-shadow: 2px 2px 0px #000;
}

.badge--label {
    background: var(--brand-gradient);
    color: #FFFFFF;
    border: 2px solid #000;
    box-shadow: 2px 2px 0px #000;
    font-size: 12px;
    padding: 2px 8px;
}

/* ================================================================
   BUTTONS
   ================================================================ */
.btn-toggle {
    background-color: var(--card);
    color: var(--ink);
    border: 2px solid var(--border);
    padding: 5px 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform var(--speed) var(--ease-out-quart),
                box-shadow var(--speed) var(--ease-out-quart),
                background-color var(--speed),
                border-color var(--speed),
                color var(--speed);
}

.btn-toggle:hover {
    transform: translate(2px, 2px);
    box-shadow: var(--shadow-hover);
}

.btn-toggle:active {
    transform: translate(4px, 4px);
    box-shadow: none;
}

.btn-toggle:focus-visible {
    outline: 2px solid var(--brand-orange);
    outline-offset: 2px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 15px;
    padding: 12px 28px;
    border: 2px solid #000;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    transition: transform var(--speed) var(--ease-out-quart),
                box-shadow var(--speed) var(--ease-out-quart);
}

.btn--primary {
    background: var(--brand-gradient);
    color: #FFFFFF;
    box-shadow: 4px 4px 0px #000;
}

.btn--primary:hover {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0px #000;
}

.btn--primary:active {
    transform: translate(4px, 4px);
    box-shadow: none;
}

.btn--primary:focus-visible {
    outline: 2px solid var(--brand-orange);
    outline-offset: 3px;
}

.btn--full {
    width: 100%;
}

/* ================================================================
   HERO SECTION
   ================================================================ */
.hero {
    display: grid;
    grid-template-columns: 1fr;
    border-bottom: 2px solid var(--border);
    background-color: var(--card);
    box-shadow: none;
    transition: background-color var(--speed), border-color var(--speed);
}

.hero__content {
    padding: clamp(40px, 8vw, 80px) clamp(20px, 6vw, 80px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 24px;
    border-bottom: 2px solid var(--border);
}

.hero__tag {
    font-size: 11px;
    font-weight: 600;
    color: var(--brand-orange);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.hero__title {
    font-size: clamp(2.2rem, 5.5vw, 4.5rem);
    line-height: 1.05;
    letter-spacing: -0.03em;
    font-weight: 700;
    max-width: 18ch;
}

.hero__subtitle {
    font-size: 15px;
    line-height: 1.8;
    color: var(--ink-muted);
    max-width: 60ch;
}

.hero__actions {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.hero__diagram {
    padding: clamp(48px, 8vw, 96px) clamp(20px, 6vw, 80px);
    background-color: var(--diagram-bg);
    background-image: radial-gradient(var(--diagram-grid) 1px, transparent 1.5px);
    background-size: 24px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    min-height: 320px;
    transition: background-color var(--speed);
}

/* SVG Schematic */
.schematic {
    width: 100%;
    max-width: 280px;
    height: auto;
}

.schematic__line {
    stroke: var(--diagram-fg);
    fill: none;
    opacity: 0.45;
}

.schematic__orbit {
    stroke: var(--diagram-fg);
    fill: none;
    opacity: 0.25;
}

.schematic__orbit--outer {
    animation: orbit-spin 80s linear infinite;
    transform-origin: center;
}

.schematic__core {
    stroke: var(--diagram-fg);
    stroke-width: 1.5;
    fill: none;
}

.schematic__node {
    stroke: var(--diagram-border);
    stroke-width: 1.5;
}

.schematic__node--red { fill: var(--brand-red); }
.schematic__node--orange { fill: var(--brand-orange); }
.schematic__node--yellow { fill: var(--brand-yellow); }
.schematic__node--core {
    fill: var(--brand-orange);
    filter: drop-shadow(0 0 6px var(--brand-orange));
}

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

/* ================================================================
   OPERATIONAL CONSOLE
   ================================================================ */
.console-section {
    border-bottom: none;
    background-color: var(--card);
    transition: background-color var(--speed), border-color var(--speed);
}

.console {
    display: grid;
    grid-template-columns: 1fr;
    border-top: none;
}

/* Tab Navigation */
.console__nav {
    display: flex;
    flex-direction: column;
    border-bottom: 2px solid var(--border);
}

.console__tab {
    background: transparent;
    color: var(--ink);
    border: none;
    border-bottom: 2px solid var(--border);
    padding: 24px clamp(20px, 4vw, 40px);
    text-align: left;
    font-family: inherit;
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    transition: background-color var(--speed), color var(--speed);
}

.console__tab:last-child {
    border-bottom: none;
}

.console__tab-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.console__tab-id {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 12px;
    font-weight: 700;
    color: var(--brand-orange);
    letter-spacing: 0.05em;
}

.console__tab-indicator {
    width: 8px;
    height: 8px;
    border: 1px solid var(--border);
    background-color: transparent;
    transition: background-color var(--speed), border-color var(--speed);
}

.console__tab-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: clamp(1.1rem, 1.5vw + 0.2rem, 1.25rem);
    font-weight: 700;
    letter-spacing: -0.015em;
}

.console__tab-summary {
    font-size: 12px;
    line-height: 1.6;
    color: var(--ink-muted);
    max-width: 50ch;
}

/* Active tab styling */
.console__tab--active {
    background-color: var(--bg);
}

.console__tab--active .console__tab-indicator {
    background-color: var(--brand-orange);
    border-color: var(--brand-orange);
}

.console__tab:focus-visible {
    outline: 2px solid var(--brand-orange);
    outline-offset: -2px;
    z-index: 2;
}

/* Details Display Area */
.console__display {
    background-color: var(--bg);
    display: flex;
    flex-direction: column;
    transition: background-color var(--speed);
}

.console__panel {
    display: none;
    flex-direction: column;
    height: 100%;
}

/* HTML fallback: If no JS is enabled, show all panels */
html:not(.js) .console__panel {
    display: flex !important;
    border-bottom: 2px solid var(--border);
}
html:not(.js) .console__panel:last-child {
    border-bottom: none;
}

.console__panel--active {
    display: flex;
}

/* Telemetry row */
.console__telemetry {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    border-bottom: 2px solid var(--border);
    background-color: var(--card);
    padding: 12px clamp(20px, 4vw, 40px);
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--ink-muted);
    transition: background-color var(--speed), border-color var(--speed), color var(--speed);
}

.console__status-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    letter-spacing: 0.05em;
}

.console__status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.console__status-dot--green {
    background-color: #10B981;
    box-shadow: 0 0 6px #10B981;
}

/* Panel Layout Grid */
.console__panel-grid {
    display: grid;
    grid-template-columns: 1fr;
    flex-grow: 1;
}

.console__text {
    padding: clamp(32px, 5vw, 48px) clamp(20px, 4vw, 40px);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.console__panel-title {
    font-size: clamp(1.25rem, 2vw + 0.5rem, 1.6rem);
    letter-spacing: -0.015em;
}

.console__panel-body {
    font-size: 14px;
    line-height: 1.75;
    color: var(--ink-muted);
    max-width: 65ch;
}

/* Sub-items (for SYS_02 welfare / health) */
.console__sub-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-top: 8px;
}

.console__sub-box {
    border: 1px dashed var(--border);
    padding: 20px;
    background-color: var(--card);
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: background-color var(--speed), border-color var(--speed);
}

.console__sub-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.console__sub-title::before {
    content: '▸';
    color: var(--brand-red);
    font-size: 13px;
    flex-shrink: 0;
}

.console__sub-body {
    font-size: 12px;
    line-height: 1.7;
    color: var(--ink-muted);
}

/* Schematic Diagram Container */
.console__diagram {
    background-color: var(--diagram-bg);
    background-image: radial-gradient(var(--diagram-grid) 1px, transparent 1.5px);
    background-size: 16px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(32px, 5vw, 48px);
    border-top: 2px solid var(--border);
    position: relative;
    overflow: hidden;
    min-height: 240px;
    transition: background-color var(--speed), border-color var(--speed);
}

.console__diagram .schematic {
    width: 100%;
    max-width: 350px;
    height: auto;
}

.console__diagram .schematic text {
    text-anchor: middle;
    font-family: 'JetBrains Mono', monospace !important;
}

.console__diagram .schematic text.text-start {
    text-anchor: start;
    font-family: 'JetBrains Mono', monospace !important;
}

/* ================================================================
   CTA SECTION
   ================================================================ */
.cta {
    border-bottom: 2px solid var(--border);
    background-color: var(--card);
    padding: clamp(64px, 10vw, 120px) clamp(20px, 6vw, 80px);
    box-shadow: none;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    transition: background-color var(--speed), border-color var(--speed);
}

.cta__body {
    max-width: 60ch;
    font-size: 14px;
    line-height: 1.75;
    color: var(--ink-muted);
}

/* ================================================================
   FOOTER
   ================================================================ */
.footer {
    margin-top: auto;
    padding: 32px clamp(20px, 6vw, 80px) 40px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    border-top: none;
    font-size: 12px;
    line-height: 1.6;
    color: var(--ink-muted);
}

.footer__trust {
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex-wrap: wrap;
}

/* ================================================================
   MODAL
   ================================================================ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--speed) var(--ease-out-quart);
}

.modal[aria-hidden="false"] {
    opacity: 1;
    pointer-events: all;
}

.modal__backdrop {
    position: absolute;
    inset: 0;
    background-color: rgba(14, 14, 14, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.modal__card {
    position: relative;
    border: 2px solid var(--border);
    background-color: var(--card);
    width: min(92vw, 480px);
    box-shadow: var(--shadow);
    transform: scale(0.94) translateY(8px);
    transition: transform 0.3s var(--ease-out-expo),
                background-color var(--speed),
                border-color var(--speed);
}

.modal[aria-hidden="false"] .modal__card {
    transform: scale(1) translateY(0);
}

.modal__header {
    border-bottom: 2px solid var(--border);
    padding: 18px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal__title {
    font-size: 18px;
}

.modal__close {
    background: none;
    border: 2px solid var(--border);
    color: var(--ink);
    width: 32px;
    height: 32px;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color var(--speed), color var(--speed);
}

.modal__close:hover {
    background-color: var(--border);
    color: var(--card);
}

.modal__close:focus-visible {
    outline: 2px solid var(--brand-orange);
    outline-offset: 2px;
}

.modal__body {
    padding: 24px;
}

/* ================================================================
   FORM
   ================================================================ */
.form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form__field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form__label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink);
}

.form__input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border);
    background-color: var(--bg);
    color: var(--ink);
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    transition: border-color var(--speed), background-color var(--speed), color var(--speed);
}

.form__input::placeholder {
    color: var(--ink-muted);
    opacity: 0.6;
}

.form__input:focus {
    outline: none;
    border-color: var(--brand-orange);
}

.form__input:focus-visible {
    outline: 2px solid var(--brand-orange);
    outline-offset: -2px;
    border-color: var(--brand-orange);
}

/* Success state */
.form-success[hidden] {
    display: none !important;
}

.form-success {
    text-align: center;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.form-success__icon {
    width: 48px;
    height: 48px;
    background: var(--brand-gradient);
    border-radius: 50%;
    border: 2px solid #000;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFFFFF;
    font-size: 20px;
    font-weight: bold;
}

.form-success__title {
    font-size: 18px;
}

.form-success__body {
    font-size: 13px;
    color: var(--ink-muted);
    max-width: 36ch;
    line-height: 1.6;
}

/* ================================================================
   REVEAL ANIMATIONS
   Only active when JS is running. Without JS, all content visible.
   ================================================================ */
html.js .reveal {
    opacity: 0;
    transform: translateY(20px);
    transition:
        opacity var(--speed-reveal) var(--ease-out-expo),
        transform var(--speed-reveal) var(--ease-out-expo);
}

html.js .reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger children */
html.js .reveal-delay-1 { transition-delay: 0.08s; }
html.js .reveal-delay-2 { transition-delay: 0.16s; }
html.js .reveal-delay-3 { transition-delay: 0.24s; }

/* ================================================================
   RESPONSIVE
   ================================================================ */

/* Tablet and up */
@media (min-width: 768px) {
    .hero {
        grid-template-columns: 1fr 1.25fr;
    }

    .hero__diagram {
        order: -1;
        border-right: 2px solid var(--border);
    }

    .hero__content {
        border-bottom: none;
        border-right: none;
    }

    .footer {
        flex-direction: row;
        justify-content: space-between;
        align-items: baseline;
    }
}

/* Desktop */
@media (min-width: 992px) {
    .console {
        grid-template-columns: 360px 1fr;
    }

    .console__nav {
        border-bottom: none;
        border-right: 2px solid var(--border);
    }

    .console__tab {
        flex-grow: 1;
    }

    .console__tab:last-child {
        border-bottom: none;
    }
}

/* Wide screen desktop */
@media (min-width: 1200px) {
    .console {
        grid-template-columns: 400px 1fr;
    }

    .console__panel-grid {
        grid-template-columns: 1.15fr 0.85fr;
    }

    .console__diagram {
        border-top: none;
        border-left: 2px solid var(--border);
        min-height: auto;
    }

    .console__sub-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* Small screens: tighten header */
@media (max-width: 480px) {
    .header {
        flex-direction: column;
        gap: 12px;
        text-align: center;
        padding: 16px;
    }

    .header__controls {
        width: 100%;
        justify-content: center;
    }

    .badge--status {
        font-size: 10px;
    }

    .btn-toggle {
        font-size: 10px;
    }
}

/* ================================================================
   REDUCED MOTION
   ================================================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    html.js .reveal {
        opacity: 1;
        transform: none;
    }

    .schematic__orbit--outer {
        animation: none;
    }
}
