/* ============================================
   ringworld.quest - Survey Station Interface
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --void-black: #040810;
    --station-dark: #0A1020;
    --ring-cyan: #00E5FF;
    --survey-amber: #FFB300;
    --instrument-white: #D4DAE0;
    --telemetry-gray: #5A6A7A;
    --threshold-red: #FF3D5A;
    --grid-blue: #1A2A40;

    --font-display: 'Space Grotesk', sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
    --font-annotation: 'Exo 2', sans-serif;

    --chamfer: polygon(16px 0, 100% 0, 100% calc(100% - 16px), calc(100% - 16px) 100%, 0 100%, 0 16px);
    --chamfer-sm: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);

    --ease-panel: cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

body {
    background: var(--void-black);
    color: var(--instrument-white);
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: clamp(0.85rem, 1.1vw, 1rem);
    line-height: 1.75;
    letter-spacing: 0.02em;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Scan lines overlay */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        transparent,
        transparent 2px,
        rgba(0, 229, 255, 0.03) 2px,
        rgba(0, 229, 255, 0.03) 3px
    );
    opacity: 0.4;
    pointer-events: none;
    z-index: 9999;
}

/* --- Starfield Canvas --- */
#starfield {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    pointer-events: none;
}

/* --- Ringworld Arc SVG --- */
#ringworld-arc {
    position: fixed;
    top: -10%;
    right: -10%;
    width: 80vw;
    height: 80vh;
    z-index: 1;
    pointer-events: none;
    opacity: 0.8;
    transition: opacity 2s ease;
}

#ringworld-arc.brightened {
    opacity: 1;
}

#arc-path {
    animation: arcPulse 4s ease-in-out infinite;
}

@keyframes arcPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* --- Coordinate Grid --- */
#coordinate-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    opacity: 0.25;
    background-image:
        linear-gradient(var(--grid-blue) 0.5px, transparent 0.5px),
        linear-gradient(90deg, var(--grid-blue) 0.5px, transparent 0.5px);
    background-size: 80px 80px;
    transition: opacity 1s ease;
}

#coordinate-grid.faded {
    opacity: 0;
}

/* --- Telemetry Header --- */
#telemetry-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 48px;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: rgba(4, 8, 16, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--grid-blue);
}

.telemetry-domain {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--telemetry-gray);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.telemetry-progress-track {
    flex: 1;
    height: 1px;
    margin: 0 24px;
    background: var(--grid-blue);
    position: relative;
}

.telemetry-progress-bar {
    position: absolute;
    top: 0;
    left: 0;
    height: 1px;
    width: 0%;
    background: var(--ring-cyan);
    transition: width 0.1s linear;
}

.telemetry-progress-bar::after {
    content: '';
    position: absolute;
    right: -3px;
    top: -3px;
    width: 6px;
    height: 6px;
    background: var(--ring-cyan);
    transform: rotate(45deg);
}

.telemetry-scroll {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--ring-cyan);
    letter-spacing: 0.05em;
    min-width: 60px;
    text-align: right;
}

/* --- Section Base --- */
.section-viewport {
    position: relative;
    width: 100%;
    height: 100vh;
    z-index: 2;
}

.section-data {
    position: relative;
    width: 100%;
    min-height: 250vh;
    z-index: 2;
    padding: 10vh 0;
}

.section-schematic {
    position: relative;
    width: 100%;
    min-height: 150vh;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20vh 5%;
}

.section-terminal {
    position: relative;
    width: 100%;
    min-height: 100vh;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10vh 0;
}

/* --- Section 1: Visual Contact / Hero --- */
.hero-content {
    position: absolute;
    bottom: 15%;
    left: 12%;
    z-index: 5;
}

.hero-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(5rem, 15vw, 12rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--instrument-white);
    line-height: 1;
    animation: heroPulse 4s ease-in-out infinite;
}

@keyframes heroPulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.hero-subtitle {
    font-family: var(--font-mono);
    font-size: clamp(0.7rem, 1vw, 0.9rem);
    color: var(--telemetry-gray);
    letter-spacing: 0.1em;
    margin-top: 16px;
}

.hero-anchor-line {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.anchor-line {
    width: 1px;
    height: 30vh;
    background: var(--ring-cyan);
    opacity: 0.6;
}

.anchor-diamond {
    width: 8px;
    height: 8px;
    background: var(--ring-cyan);
    transform: rotate(45deg);
    margin-top: -1px;
    margin-left: -3.5px;
}

/* --- HUD Panels (Section 2) --- */
.hud-panel {
    position: relative;
    width: clamp(340px, 55vw, 720px);
    padding: 32px 36px;
    background: rgba(10, 16, 32, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--ring-cyan);
    clip-path: var(--chamfer);
    margin-bottom: 15vh;

    /* Animation initial state */
    opacity: 0;
    transition: opacity 0.8s var(--ease-panel), transform 0.8s var(--ease-panel);
}

.hud-panel.panel-left {
    margin-left: 8%;
    transform: translateX(-80px);
}

.hud-panel.panel-right {
    margin-left: auto;
    margin-right: 8%;
    transform: translateX(80px);
}

.hud-panel.visible {
    opacity: 1;
    transform: translateX(0);
}

.panel-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 12px;
}

.panel-id {
    font-family: var(--font-annotation);
    font-size: 0.7rem;
    font-weight: 300;
    color: var(--telemetry-gray);
    letter-spacing: 0.12em;
}

.panel-title {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: clamp(1.1rem, 2vw, 1.5rem);
    letter-spacing: 0.08em;
    color: var(--instrument-white);
    text-transform: uppercase;
}

.panel-divider {
    width: 100%;
    height: 2px;
    margin-bottom: 20px;
    overflow: hidden;
}

.divider-svg {
    width: 100%;
    height: 2px;
}

.divider-line {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 0.6s var(--ease-panel);
}

.hud-panel.visible .divider-line {
    stroke-dashoffset: 0;
}

.panel-body {
    margin-bottom: 24px;
}

.panel-body p {
    color: var(--instrument-white);
    font-size: clamp(0.8rem, 1vw, 0.95rem);
    line-height: 1.75;
    opacity: 0.85;
}

/* --- Panel Viz: Bars (Panel 1) --- */
.panel-viz-bars {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.bar-label {
    font-family: var(--font-annotation);
    font-size: 0.65rem;
    font-weight: 300;
    letter-spacing: 0.12em;
    color: var(--telemetry-gray);
    min-width: 70px;
    text-transform: uppercase;
}

.bar-track {
    flex: 1;
    height: 6px;
    background: var(--grid-blue);
    position: relative;
}

.bar-fill {
    height: 100%;
    background: var(--ring-cyan);
    width: 0%;
    transition: width 1.2s var(--ease-panel);
}

.hud-panel.visible .bar-fill {
    width: var(--bar-target);
}

.bar-value {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--survey-amber);
    min-width: 72px;
    text-align: right;
    letter-spacing: 0.05em;
}

/* --- Panel Viz: Radial Chart (Panel 2) --- */
.panel-viz-radial {
    display: flex;
    align-items: center;
    gap: 20px;
}

.radial-chart {
    width: 140px;
    height: 140px;
    flex-shrink: 0;
}

.radial-segment {
    transition: stroke-dasharray 1.5s var(--ease-panel);
}

.radial-labels {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.radial-label {
    font-family: var(--font-annotation);
    font-size: 0.7rem;
    font-weight: 300;
    letter-spacing: 0.1em;
    color: var(--instrument-white);
    display: flex;
    align-items: center;
    gap: 8px;
}

.label-dot {
    width: 8px;
    height: 8px;
    display: inline-block;
    transform: rotate(45deg);
}

.dot-cyan { background: var(--ring-cyan); }
.dot-amber { background: var(--survey-amber); }
.dot-red { background: var(--threshold-red); }

/* --- Panel Viz: Orbital (Panel 3) --- */
.panel-viz-orbital {
    display: flex;
    align-items: center;
    gap: 20px;
}

.orbital-diagram {
    width: 180px;
    height: 180px;
    flex-shrink: 0;
}

.orbit-dot {
    animation: orbitRotate 12s linear infinite;
    transform-origin: 120px 120px;
}

@keyframes orbitRotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.shadow-sq.sq-1 {
    animation: shadowOrbit1 8s linear infinite;
    transform-origin: 120px 120px;
}

.shadow-sq.sq-2 {
    animation: shadowOrbit2 8s linear infinite;
    transform-origin: 120px 120px;
}

@keyframes shadowOrbit1 {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes shadowOrbit2 {
    0% { transform: rotate(180deg); }
    100% { transform: rotate(540deg); }
}

.orbital-labels {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.orbital-label {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--survey-amber);
    letter-spacing: 0.05em;
}

/* --- Section 3: Schematic --- */
.schematic-container {
    width: 90%;
    max-width: 1200px;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.schematic-container.visible {
    opacity: 1;
}

#ringworld-schematic {
    width: 100%;
    height: auto;
}

.schema-path {
    stroke-dasharray: var(--path-length, 1200);
    stroke-dashoffset: var(--path-length, 1200);
    transition: stroke-dashoffset 0.05s linear;
}

.schema-star {
    animation: starPulseSchema 4s ease-in-out infinite;
}

@keyframes starPulseSchema {
    0%, 100% { opacity: 0.7; r: 28; }
    50% { opacity: 1; r: 32; }
}

.schema-label {
    opacity: 0;
    transition: opacity 0.5s ease;
    text-transform: uppercase;
}

.schema-label.visible {
    opacity: 1;
}

.schema-callout-line {
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 0.6s var(--ease-panel);
}

.schema-callout-line.visible {
    stroke-dashoffset: 0;
}

/* --- Section 4: Terminal Zone --- */
.terminal-container {
    width: 100%;
    max-width: 480px;
    padding: 0 24px;
}

.terminal-output {
    position: relative;
}

.term-line {
    font-family: var(--font-mono);
    font-size: clamp(0.8rem, 1vw, 0.95rem);
    line-height: 2;
    color: var(--ring-cyan);
    opacity: 0;
    overflow: hidden;
    white-space: nowrap;
}

.term-line.revealed {
    opacity: 1;
}

.term-line.typing {
    animation: typeReveal 0.8s steps(40, end) forwards;
    width: 0;
    display: inline-block;
}

@keyframes typeReveal {
    0% { width: 0; }
    100% { width: 100%; }
}

.term-line:last-child {
    color: var(--survey-amber);
}

.terminal-cursor {
    display: inline-block;
    width: 10px;
    height: 1.2em;
    background: var(--ring-cyan);
    vertical-align: text-bottom;
    animation: cursorBlink 0.8s step-end infinite;
    opacity: 0;
    margin-top: 4px;
}

.terminal-cursor.active {
    opacity: 1;
}

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

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    .hero-title {
        font-size: clamp(2.5rem, 12vw, 5rem);
    }

    .hero-content {
        left: 6%;
        bottom: 12%;
    }

    .hud-panel {
        width: 90%;
        margin-left: 5% !important;
        margin-right: 5% !important;
    }

    .hud-panel.panel-left,
    .hud-panel.panel-right {
        margin-left: 5% !important;
        margin-right: 5% !important;
    }

    .panel-viz-radial,
    .panel-viz-orbital {
        flex-direction: column;
        align-items: flex-start;
    }

    .section-schematic {
        padding: 10vh 2%;
    }

    .schematic-container {
        width: 100%;
    }

    #telemetry-header {
        padding: 0 12px;
    }

    .anchor-line {
        height: 15vh;
    }
}

@media (max-width: 480px) {
    .hero-title {
        font-size: clamp(2rem, 10vw, 3.5rem);
    }

    .hud-panel {
        padding: 20px 20px;
    }

    .terminal-container {
        max-width: 100%;
    }

    .term-line {
        white-space: normal;
    }
}
