/* ============================================
   parallel.day — Coastal Observatory
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --coastal-mist: #e2e7e4;
    --frosted-glass: #f4f6f5;
    --observatory-ink: #2c3e4a;
    --tide-mark: #3a7d6e;
    --instrument-label: #6b828b;
    --shoreline: #c9b99a;
    --lighthouse-beam: #d4776c;
    --abyssal: #1a2f38;
    --fog-light: #d4dde0;
    --fog-warm: #f7f4ef;
    --panel-border: rgba(107, 130, 139, 0.25);
    --grid-line: rgba(107, 130, 139, 0.08);
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Source Sans 3', 'Source Sans Pro', sans-serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.4vw, 1.15rem);
    line-height: 1.72;
    letter-spacing: 0.005em;
    color: var(--observatory-ink);
    background: linear-gradient(175deg, #e8ece9 0%, #d4dde0 50%, #c8cfd4 100%);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* --- SVG Grain Filter (hidden) --- */
.grain-svg {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- Grain Overlay --- */
.grain-overlay {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.3;
    filter: url(#grain);
    background: transparent;
}

/* --- Observatory Grid --- */
.observatory-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(4, minmax(20vh, auto));
    gap: clamp(12px, 2vw, 28px);
    padding: clamp(12px, 2vw, 28px);
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

/* --- Panel Base --- */
.panel {
    position: relative;
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    background: var(--frosted-glass);
    overflow: hidden;
}

.panel-inner {
    position: relative;
    width: 100%;
    height: 100%;
    padding: clamp(16px, 2.5vw, 32px);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Crosshair Registration Marks --- */
.crosshair {
    position: absolute;
    width: 12px;
    height: 12px;
    opacity: 0.4;
    z-index: 2;
}

.crosshair::before,
.crosshair::after {
    content: '';
    position: absolute;
    background: var(--instrument-label);
}

.crosshair::before {
    top: 50%;
    left: 0;
    width: 100%;
    height: 1px;
    transform: translateY(-50%);
}

.crosshair::after {
    left: 50%;
    top: 0;
    width: 1px;
    height: 100%;
    transform: translateX(-50%);
}

.crosshair-tl { top: 8px; left: 8px; }
.crosshair-tr { top: 8px; right: 8px; }
.crosshair-bl { bottom: 8px; left: 8px; }
.crosshair-br { bottom: 8px; right: 8px; }

/* --- Panel A: The Horizon --- */
.panel-a {
    grid-column: 1 / 4;
    grid-row: 1 / 2;
    overflow: hidden;
}

.panel-a-gradient {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, #e2e7e4 0%, #d4dde0 40%, #c9b99a 85%, #c9b99a 100%);
    opacity: 0.5;
    z-index: 0;
}

.panel-a-content {
    position: relative;
    z-index: 1;
    text-align: left;
    width: 100%;
}

.panel-a .panel-inner {
    align-items: flex-end;
    justify-content: flex-start;
    padding: clamp(24px, 4vw, 48px);
}

.headline {
    font-family: 'Libre Baskerville', 'Georgia', serif;
    font-weight: 700;
    font-size: clamp(2.5rem, 5vw, 4.5rem);
    color: var(--observatory-ink);
    letter-spacing: -0.02em;
    line-height: 1.15;
    text-shadow: 0 1px 2px rgba(44, 62, 74, 0.08);
    margin-bottom: 0.5rem;
}

.subtitle {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.7rem, 0.95vw, 0.85rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--instrument-label);
}

/* --- Panel B: The Tide Table --- */
.panel-b {
    grid-column: 4 / 7;
    grid-row: 1 / 3;
}

.panel-b .panel-inner {
    align-items: flex-start;
    justify-content: center;
    flex-direction: column;
}

.tide-table {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 2vh, 24px);
}

.tide-entry {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-bottom: clamp(8px, 1.5vh, 16px);
    border-bottom: 1px solid var(--grid-line);
}

.tide-entry:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.tide-time {
    font-family: 'Libre Baskerville', 'Georgia', serif;
    font-style: italic;
    font-weight: 400;
    font-size: clamp(1.5rem, 3vw, 2.8rem);
    color: var(--tide-mark);
    line-height: 1.2;
}

.tide-label {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.6rem, 0.8vw, 0.75rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--instrument-label);
}

/* --- Panel C: Isometric Process Cluster --- */
.panel-c {
    grid-column: 1 / 3;
    grid-row: 2 / 4;
}

.icon-cluster {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: clamp(8px, 1.5vw, 20px);
    width: 100%;
    max-width: 240px;
}

.iso-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.iso-icon svg {
    width: 100%;
    height: auto;
    max-width: 96px;
}

/* Floating animations */
.iso-icon-1 { animation: float 3.2s ease-in-out infinite; }
.iso-icon-2 { animation: float 3.8s ease-in-out infinite; animation-delay: -1s; }
.iso-icon-3 { animation: float 4.1s ease-in-out infinite; animation-delay: -2s; }
.iso-icon-4 { animation: float 3.5s ease-in-out infinite; animation-delay: -0.5s; }

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

/* Tide mercury animation */
.tide-mercury {
    animation: tide-rise 4s ease-in-out infinite alternate;
}

@keyframes tide-rise {
    0% { y: 30; height: 18; }
    100% { y: 10; height: 38; }
}

/* Fog cube opacity animation */
.fog-cube {
    animation: fog-cycle 5s ease-in-out infinite;
}

@keyframes fog-cycle {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.8; }
}

/* --- Panel D: Barometric Gauge --- */
.panel-d {
    grid-column: 3 / 5;
    grid-row: 2 / 3;
}

.gauge-container {
    width: 100%;
    max-width: 240px;
    aspect-ratio: 1;
}

.barometric-gauge {
    width: 100%;
    height: 100%;
}

.gauge-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 6px;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    fill: var(--instrument-label);
}

.gauge-needle-group {
    transform-origin: 100px 100px;
    animation: rotate-needle 8s ease-in-out infinite alternate;
}

@keyframes rotate-needle {
    0% { transform: rotate(-45deg); }
    100% { transform: rotate(45deg); }
}

.needle-pulse {
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { opacity: 0.6; r: 3; }
    50% { opacity: 1; r: 5; }
}

/* --- Panel E: Signal Animation --- */
.panel-e {
    grid-column: 5 / 7;
    grid-row: 3 / 4;
}

.signal-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.signal-svg {
    width: 100%;
    height: auto;
    max-height: 120px;
}

.signal-line {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    animation: draw-signal 4s linear infinite;
}

.signal-line-main {
    animation-delay: 0s;
}

.signal-line-upper {
    animation-delay: 0.8s;
}

.signal-line-lower {
    animation-delay: 0.8s;
}

@keyframes draw-signal {
    0% { stroke-dashoffset: 400; }
    50% { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: -400; }
}

/* --- Panel F: Chart Legend --- */
.panel-f {
    grid-column: 1 / 7;
    grid-row: 4 / 5;
    background: var(--fog-warm);
    border-top: 2px solid var(--shoreline);
}

.panel-f .panel-inner {
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.legend-content {
    width: 100%;
    max-width: 800px;
}

.legend-entries {
    display: flex;
    flex-wrap: wrap;
    gap: clamp(16px, 3vw, 40px);
    justify-content: center;
    margin-bottom: clamp(16px, 2vh, 24px);
}

.legend-entry {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-icon {
    flex-shrink: 0;
}

.legend-text {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.65rem, 0.85vw, 0.8rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--instrument-label);
}

.legend-attribution {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding-top: clamp(12px, 2vh, 20px);
}

.parallax-line {
    display: block;
    width: 120px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--shoreline) 20%, var(--shoreline) 80%, transparent);
}

.attribution-text {
    font-family: 'Libre Baskerville', 'Georgia', serif;
    font-style: italic;
    font-size: 0.8rem;
    color: var(--instrument-label);
}

/* --- Bounce-In Animation --- */
@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.97);
    }
    60% {
        transform: translateY(-4px) scale(1.01);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.animate-bounce-in {
    opacity: 0;
    transform: translateY(20px) scale(0.97);
}

.animate-bounce-in.is-visible {
    animation: bounceIn 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Headline specific entrance */
.headline.animate-bounce-in.is-visible {
    animation-duration: 1.8s;
    animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

/* --- Grid overlay on panels --- */
.panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
    opacity: 0.5;
}

/* --- Responsive: Mobile Stack --- */
@media (max-width: 768px) {
    .observatory-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        gap: 0;
        padding: 0;
    }

    .panel-a,
    .panel-b,
    .panel-c,
    .panel-d,
    .panel-e,
    .panel-f {
        grid-column: 1 / -1;
        grid-row: auto;
        border-radius: 0;
        border-left: none;
        border-right: none;
        margin-bottom: clamp(16px, 3vh, 32px);
    }

    .panel-inner {
        padding: clamp(24px, 5vw, 48px);
    }

    .panel-a {
        min-height: 40vh;
    }

    .panel-b {
        min-height: auto;
    }

    .panel-c {
        min-height: 50vh;
    }

    .panel-d {
        min-height: 50vh;
    }

    .panel-e {
        min-height: 30vh;
    }

    .icon-cluster {
        max-width: 280px;
        margin: 0 auto;
    }

    .gauge-container {
        max-width: 280px;
        margin: 0 auto;
    }

    .legend-entries {
        flex-direction: column;
        align-items: center;
    }
}

/* --- Larger screens fine-tuning --- */
@media (min-width: 769px) {
    .panel-a { min-height: 20vh; }
    .panel-b { min-height: 40vh; }
    .panel-c { min-height: 40vh; }
    .panel-d { min-height: 20vh; }
    .panel-e { min-height: 20vh; }
    .panel-f { min-height: 15vh; }
}

/* --- Panel C specific: row 3 overlap fix --- */
@media (min-width: 769px) {
    .panel-c {
        grid-column: 1 / 3;
        grid-row: 2 / 4;
    }

    .panel-d {
        grid-column: 3 / 5;
        grid-row: 2 / 3;
    }

    .panel-e {
        grid-column: 5 / 7;
        grid-row: 3 / 4;
    }
}
