/* ============================================
   continua.quest - Navigator's Cockpit Styles
   Skeuomorphic Craft Aesthetic
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --hull-dark: #2C1A0E;
    --hull-mid: #4A3222;
    --hull-mid-alt: #3D2918;
    --parchment: #F2E6D0;
    --parchment-dark: #D4C4A8;
    --copper: #B87333;
    --ink: #1C1008;
    --amber: #E8A835;
    --alert-red: #C0392B;
    --verdigris: #2E8B7A;
    --scroll-angle: 0deg;
}

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

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

body {
    font-family: 'Lora', serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.65;
    color: var(--ink);
    background-color: var(--hull-dark);
    overflow-x: hidden;
    min-height: 100vh;
}

/* --- Background Continuum Viewport --- */
#continuum-viewport {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    overflow: hidden;
    background:
        conic-gradient(from 45deg at 30% 40%, var(--hull-dark) 0deg, var(--hull-mid) 90deg, var(--hull-dark) 180deg, var(--hull-mid-alt) 270deg, var(--hull-dark) 360deg),
        radial-gradient(ellipse at 70% 60%, var(--hull-mid) 0%, var(--hull-dark) 70%);
    animation: bg-hue-shift 60s linear infinite;
}

@keyframes bg-hue-shift {
    0% { filter: hue-rotate(0deg); }
    50% { filter: hue-rotate(8deg); }
    100% { filter: hue-rotate(0deg); }
}

.drift-shape {
    position: absolute;
    opacity: 0;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

.shape-1 {
    width: 300px;
    height: 300px;
    top: 10%;
    left: 15%;
    clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%);
    background: var(--hull-mid);
    opacity: 0.15;
    animation: drift-1 45s linear infinite;
}

.shape-2 {
    width: 200px;
    height: 200px;
    top: 50%;
    right: 10%;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    background: var(--copper);
    opacity: 0.08;
    animation: drift-2 60s linear infinite;
}

.shape-3 {
    width: 250px;
    height: 250px;
    bottom: 20%;
    left: 40%;
    clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%);
    background: var(--hull-mid-alt);
    opacity: 0.12;
    animation: drift-3 75s linear infinite;
}

.shape-4 {
    width: 180px;
    height: 180px;
    top: 30%;
    right: 30%;
    clip-path: polygon(50% 0%, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%);
    background: var(--copper);
    opacity: 0.06;
    animation: drift-4 90s linear infinite;
}

.shape-5 {
    width: 350px;
    height: 350px;
    top: 60%;
    left: 5%;
    clip-path: polygon(30% 0%, 70% 0%, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0% 70%, 0% 30%);
    background: var(--hull-mid);
    opacity: 0.1;
    animation: drift-5 55s linear infinite;
}

.shape-6 {
    width: 160px;
    height: 160px;
    top: 5%;
    right: 5%;
    clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
    background: var(--amber);
    opacity: 0.05;
    animation: drift-6 40s linear infinite;
}

.shape-7 {
    width: 220px;
    height: 220px;
    bottom: 10%;
    right: 25%;
    clip-path: polygon(20% 0%, 80% 0%, 100% 60%, 60% 100%, 0% 60%);
    background: var(--hull-mid-alt);
    opacity: 0.09;
    animation: drift-7 85s linear infinite;
}

@keyframes drift-1 {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(30px, -20px) rotate(8deg); }
    50% { transform: translate(-15px, 25px) rotate(-3deg); }
    75% { transform: translate(20px, 10px) rotate(5deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

@keyframes drift-2 {
    0% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(-25px, 15px) rotate(-10deg); }
    66% { transform: translate(20px, -30px) rotate(6deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

@keyframes drift-3 {
    0% { transform: translate(0, 0) rotate(0deg); }
    50% { transform: translate(40px, -20px) rotate(12deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

@keyframes drift-4 {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(-20px, 30px) rotate(-7deg); }
    50% { transform: translate(15px, -10px) rotate(4deg); }
    75% { transform: translate(-10px, -25px) rotate(-12deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

@keyframes drift-5 {
    0% { transform: translate(0, 0) rotate(0deg); }
    50% { transform: translate(-30px, 15px) rotate(-8deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

@keyframes drift-6 {
    0% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(15px, 20px) rotate(15deg); }
    66% { transform: translate(-20px, -10px) rotate(-5deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

@keyframes drift-7 {
    0% { transform: translate(0, 0) rotate(0deg); }
    50% { transform: translate(25px, -35px) rotate(10deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

/* --- HUD Overlay --- */
#hud-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 100;
    pointer-events: none;
}

/* Edge tick marks */
.hud-ticks {
    position: absolute;
}

.hud-ticks-top,
.hud-ticks-bottom {
    left: 0;
    width: 100%;
    height: 12px;
    background: repeating-linear-gradient(
        90deg,
        transparent,
        transparent 49px,
        var(--copper) 49px,
        var(--copper) 50px
    );
    opacity: 0.2;
}

.hud-ticks-top { top: 0; }
.hud-ticks-bottom { bottom: 48px; }

.hud-ticks-left,
.hud-ticks-right {
    top: 0;
    height: 100%;
    width: 12px;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 49px,
        var(--copper) 49px,
        var(--copper) 50px
    );
    opacity: 0.2;
}

.hud-ticks-left { left: 0; }
.hud-ticks-right { right: 0; }

/* Crosshair */
#crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    transition: top 0.8s ease-out;
}

.crosshair-h {
    position: absolute;
    top: 50%;
    left: -5px;
    width: 50px;
    height: 1px;
    background: var(--copper);
    opacity: 0.25;
}

.crosshair-v {
    position: absolute;
    left: 50%;
    top: -5px;
    width: 1px;
    height: 50px;
    background: var(--copper);
    opacity: 0.25;
}

.crosshair-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 6px;
    border: 1px solid var(--copper);
    opacity: 0.3;
    transform: translate(-50%, -50%) rotate(45deg);
}

/* --- Compass Rose --- */
#compass-rose {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 80px;
    height: 80px;
    z-index: 200;
    cursor: pointer;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#compass-rose svg {
    width: 100%;
    height: 100%;
    transform: rotate(var(--scroll-angle));
    transition: transform 0.3s ease-out;
}

#compass-rose:hover {
    transform: scale(1.15);
}

.compass-label {
    font-family: 'Caveat', cursive;
    font-size: 9px;
    font-weight: 700;
    fill: var(--parchment);
}

.compass-degree {
    font-family: 'Inconsolata', monospace;
    font-size: 5px;
    fill: var(--copper);
    opacity: 0.6;
}

/* --- Main Navigator Console --- */
#navigator-console {
    position: relative;
    z-index: 10;
    max-width: 1100px;
    margin: 0 auto;
    padding: 60px 20px 100px;
}

/* --- Console Sections --- */
.console-section {
    margin-bottom: 40px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
}

/* --- Section Divider (Chevrons) --- */
.section-divider {
    text-align: center;
    padding: 40px 0;
    position: relative;
    z-index: 10;
}

.chevron-text {
    font-family: 'Inconsolata', monospace;
    font-size: 0.8rem;
    letter-spacing: 0.2em;
    color: var(--copper);
    opacity: 0.5;
    text-transform: uppercase;
}

/* --- Instrument Bezel (core component) --- */
.instrument-bezel {
    position: relative;
    filter: grayscale(0.6);
    opacity: 0.6;
    transition: filter 0.6s ease-out, opacity 0.6s ease-out, box-shadow 0.6s ease-out;
}

.instrument-bezel[data-powered="true"] {
    filter: grayscale(0);
    opacity: 1;
}

.instrument-bezel[data-powered="true"] .bezel-frame {
    box-shadow: 0 0 20px rgba(232, 168, 53, 0.15);
}

/* Power-on glow pulse */
@keyframes power-on-glow {
    0% { box-shadow: 0 0 0 rgba(232, 168, 53, 0); }
    50% { box-shadow: 0 0 30px rgba(232, 168, 53, 0.4); }
    100% { box-shadow: 0 0 20px rgba(232, 168, 53, 0.15); }
}

.instrument-bezel.powering-on .bezel-frame {
    animation: power-on-glow 0.8s ease-out forwards;
}

/* Bezel Frame - chamfered corners (sharp angles) */
.bezel-frame {
    position: relative;
    background: var(--hull-mid);
    padding: 20px;
    clip-path: polygon(
        12px 0%, calc(100% - 12px) 0%,
        100% 12px, 100% calc(100% - 12px),
        calc(100% - 12px) 100%, 12px 100%,
        0% calc(100% - 12px), 0% 12px
    );
    overflow: hidden;
}

/* Wood grain texture overlay */
.bezel-frame::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        repeating-linear-gradient(
            2deg,
            transparent,
            transparent 8px,
            rgba(61, 41, 24, 0.3) 8px,
            rgba(61, 41, 24, 0.3) 9px
        ),
        repeating-linear-gradient(
            -1deg,
            transparent,
            transparent 14px,
            rgba(74, 50, 34, 0.15) 14px,
            rgba(74, 50, 34, 0.15) 15px
        );
    transform: skewY(2deg);
    pointer-events: none;
    z-index: 0;
}

/* Canvas stitching border effect */
.bezel-frame::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    right: 3px;
    bottom: 3px;
    border: 1px dashed var(--copper);
    opacity: 0.25;
    clip-path: polygon(
        12px 0%, calc(100% - 12px) 0%,
        100% 12px, 100% calc(100% - 12px),
        calc(100% - 12px) 100%, 12px 100%,
        0% calc(100% - 12px), 0% 12px
    );
    pointer-events: none;
    z-index: 1;
}

/* Bezel Label */
.bezel-label {
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: 1rem;
    color: var(--copper);
    letter-spacing: 0.05em;
    margin-bottom: 12px;
    position: relative;
    z-index: 2;
}

.alert-label {
    color: var(--alert-red);
}

/* Bezel Content */
.bezel-content {
    position: relative;
    z-index: 2;
}

.bezel-content p {
    color: var(--parchment);
    margin-bottom: 12px;
    font-family: 'Lora', serif;
    font-size: clamp(0.9rem, 1.6vw, 1.05rem);
    line-height: 1.65;
}

.bezel-content p:last-child {
    margin-bottom: 0;
}

/* --- Bezel Variants --- */

/* Title bezel spans full width */
.bezel-title {
    grid-column: 1 / -1;
}

.site-title {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: clamp(2.4rem, 7vw, 5rem);
    color: var(--parchment);
    line-height: 1.1;
    margin-bottom: 8px;
    position: relative;
    z-index: 2;
}

.site-subtitle {
    font-family: 'Lora', serif;
    font-style: italic;
    font-size: clamp(1rem, 2vw, 1.3rem);
    color: var(--parchment-dark);
    position: relative;
    z-index: 2;
    margin-bottom: 16px;
}

.bezel-ornament {
    position: relative;
    z-index: 2;
    margin-top: 8px;
}

.zigzag-border {
    width: 100%;
    max-width: 300px;
    height: auto;
}

/* Dial bezels */
.bezel-dial {
    text-align: center;
}

.bezel-dial .bezel-frame {
    padding: 24px 16px;
}

.readout-value {
    font-family: 'Inconsolata', monospace;
    font-weight: 400;
    font-size: 2rem;
    letter-spacing: 0.1em;
    color: var(--amber);
    text-transform: uppercase;
    position: relative;
    z-index: 2;
    margin: 8px 0;
}

.readout-unit {
    font-family: 'Inconsolata', monospace;
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    color: var(--copper);
    text-transform: uppercase;
    position: relative;
    z-index: 2;
    opacity: 0.7;
}

/* Wide bezels span full width */
.bezel-wide {
    grid-column: 1 / -1;
}

/* Diagram bezels */
.bezel-diagram .bezel-frame {
    padding: 16px;
}

.diagram-svg {
    width: 100%;
    height: auto;
    max-height: 200px;
    position: relative;
    z-index: 2;
}

.diagram-label {
    font-family: 'Caveat', cursive;
    font-size: 8px;
    fill: var(--copper);
}

.diagram-label-alert {
    fill: var(--alert-red);
}

/* SVG draw animation */
.svg-draw {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 1.2s ease-out;
}

.instrument-bezel[data-powered="true"] .svg-draw {
    stroke-dashoffset: 0;
}

/* --- Typewriter Text --- */
.typewriter-text {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.instrument-bezel[data-powered="true"] .typewriter-text {
    opacity: 1;
}

.typewriter-text.revealed {
    opacity: 1;
}

/* --- Shake Animation (instrument malfunction) --- */
@keyframes instrument-shake {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    10% { transform: translate(-3px, 1px) rotate(-0.5deg); }
    20% { transform: translate(4px, -1px) rotate(0.7deg); }
    30% { transform: translate(-2px, 2px) rotate(-0.3deg); }
    40% { transform: translate(3px, -2px) rotate(0.5deg); }
    50% { transform: translate(-1px, 1px) rotate(-0.2deg); }
    60% { transform: translate(2px, 0px) rotate(0.3deg); }
    70% { transform: translate(-1px, -1px) rotate(-0.1deg); }
    80%, 100% { transform: translate(0, 0) rotate(0deg); }
}

.instrument-bezel.shaking {
    animation: instrument-shake 0.8s ease-out;
}

.instrument-bezel.shaking .bezel-frame {
    box-shadow: 0 0 25px rgba(192, 57, 43, 0.5) !important;
    border-color: var(--alert-red);
}

/* Recalibration bar */
.recalibrate-bar {
    position: relative;
    z-index: 2;
    height: 3px;
    width: 100%;
    background: rgba(46, 139, 122, 0.2);
    margin-top: 12px;
    overflow: hidden;
}

.recalibrate-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    background: var(--verdigris);
    transition: width 1s ease-out;
}

.instrument-bezel.recalibrated .recalibrate-bar::after {
    width: 100%;
}

/* --- Waveform Canvas --- */
#waveform-canvas {
    width: 100%;
    height: 100px;
    position: relative;
    z-index: 2;
    display: block;
}

/* --- Manifest Panel --- */
.manifest-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 320px;
    height: 100vh;
    z-index: 300;
    clip-path: polygon(0 0, 0 0, 0 100%, 0 100%);
    transition: clip-path 0.6s cubic-bezier(0.77, 0, 0.175, 1);
    overflow-y: auto;
}

.manifest-panel.open {
    clip-path: polygon(0 0, 100% 0, 85% 100%, 0 100%);
}

.manifest-content {
    background: var(--parchment);
    background-image:
        radial-gradient(ellipse at center, var(--parchment) 0%, var(--parchment-dark) 100%);
    min-height: 100vh;
    padding: 40px 30px;
}

.manifest-title {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: clamp(1.6rem, 4vw, 2.4rem);
    color: var(--ink);
    margin-bottom: 16px;
}

.manifest-ornament {
    margin-bottom: 24px;
}

.manifest-ornament svg {
    width: 100%;
    max-width: 200px;
    height: auto;
}

.manifest-list {
    list-style: none;
    padding: 0;
}

.manifest-entry {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 0;
    border-bottom: 1px dashed var(--copper);
    cursor: pointer;
    transition: background 0.2s;
}

.manifest-entry:hover {
    background: rgba(184, 115, 51, 0.08);
}

.manifest-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--copper);
    opacity: 0.3;
    flex-shrink: 0;
    transition: opacity 0.3s, background 0.3s;
}

.manifest-dot.visited {
    opacity: 1;
    background: var(--amber);
}

.manifest-number {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--hull-mid);
    min-width: 30px;
}

.manifest-name {
    font-family: 'Lora', serif;
    font-style: italic;
    font-size: 1rem;
    color: var(--ink);
}

/* --- Manifest Toggle Switch --- */
#manifest-toggle {
    position: fixed;
    bottom: 60px;
    left: 16px;
    z-index: 250;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.toggle-track {
    width: 36px;
    height: 20px;
    background: var(--hull-mid);
    border: 1px solid var(--copper);
    border-radius: 3px;
    position: relative;
    box-shadow:
        inset 0 2px 4px rgba(0, 0, 0, 0.4),
        0 1px 2px rgba(184, 115, 51, 0.2);
}

.toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: radial-gradient(circle at 40% 35%, #d4a054, var(--copper));
    border-radius: 2px;
    transition: left 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

#manifest-toggle.active .toggle-knob {
    left: 18px;
}

.toggle-label {
    font-family: 'Inconsolata', monospace;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    color: var(--copper);
    text-transform: uppercase;
    opacity: 0.6;
}

/* --- Status Bar --- */
#status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 44px;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    /* Brushed metal texture */
    background:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(184, 115, 51, 0.06) 2px,
            rgba(184, 115, 51, 0.06) 3px
        ),
        linear-gradient(180deg, var(--hull-mid) 0%, var(--hull-dark) 100%);
    border-top: 1px solid var(--copper);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-label {
    font-family: 'Inconsolata', monospace;
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    color: var(--copper);
    text-transform: uppercase;
    opacity: 0.6;
}

.status-value {
    font-family: 'Inconsolata', monospace;
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    color: var(--amber);
    text-transform: uppercase;
}

#status-waveform {
    display: block;
}

/* --- Parchment Surface for Text Panels --- */
.bezel-wide .bezel-frame,
.bezel-title .bezel-frame {
    background: var(--hull-mid);
}

.bezel-wide .bezel-content p,
.bezel-title .bezel-content p {
    color: var(--parchment);
}

/* Parchment interior option for text-heavy bezels */
.bezel-wide .bezel-frame::before {
    background:
        repeating-linear-gradient(
            2deg,
            transparent,
            transparent 11px,
            rgba(61, 41, 24, 0.2) 11px,
            rgba(61, 41, 24, 0.2) 12px
        );
}

/* --- Anomaly Section Overrides --- */
.anomaly-section .instrument-bezel.shaking .bezel-frame::after {
    border-color: var(--alert-red);
    opacity: 0.4;
}

/* --- Responsive: Mobile Cockpit Fold --- */
@media (max-width: 768px) {
    .console-section {
        grid-template-columns: 1fr;
    }

    .bezel-dial {
        grid-column: 1;
    }

    .bezel-wide,
    .bezel-title,
    .bezel-diagram {
        grid-column: 1;
    }

    #compass-rose {
        width: 60px;
        height: 60px;
        top: 10px;
        right: 10px;
    }

    #navigator-console {
        padding: 40px 12px 90px;
    }

    .manifest-panel {
        width: 85vw;
    }

    .bezel-frame {
        padding: 16px 12px;
    }

    .site-title {
        font-size: clamp(2rem, 8vw, 3rem);
    }

    #status-bar {
        padding: 0 10px;
        gap: 4px;
    }

    .status-item {
        gap: 3px;
    }

    .status-label {
        font-size: 0.55rem;
    }

    .status-value {
        font-size: 0.7rem;
    }

    .status-wave {
        display: none;
    }

    .readout-value {
        font-size: 1.5rem;
    }
}

@media (max-width: 480px) {
    .status-depth {
        display: none;
    }

    #manifest-toggle {
        bottom: 52px;
    }
}

/* --- Hover Effects for Bezels --- */
.instrument-bezel[data-powered="true"]:hover .bezel-frame {
    box-shadow: 0 0 25px rgba(232, 168, 53, 0.25);
}

/* --- Selection Color --- */
::selection {
    background: var(--copper);
    color: var(--parchment);
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--hull-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--hull-mid);
    border: 1px solid var(--copper);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--copper);
}
