/* ==========================================================================
   logical.day  --  Bauhaus oceanographic almanac
   Cormorant Garamond serif body + DM Serif Display numerals + JetBrains Mono ticks.
   Palette: ocean-deep + Bauhaus primaries, every hue muted by 6-12% to simulate
   looking at primaries through ten metres of seawater.
   ========================================================================== */

:root {
    /* Zone backgrounds */
    --photic-bg: #E5EEF2;     /* pale glaucous-blue, the page's daytime ground */
    --twilight-bg: #71909E;   /* slate-bluegrey mid */
    --abyssal-bg: #0B4F6C;    /* ocean-deep */
    --abyssal-deep: #02141B;  /* true abyssal water */

    /* Inks */
    --bauhaus-red: #C8311C;
    --bauhaus-yellow: #E8C547;
    --bauhaus-blue: #0B4F6C;

    /* Text */
    --foam-white: #F4EDE0;    /* warm bone */
    --pencil-grey: #3A3F44;   /* never pure black */

    /* Live (interpolated) values driven by JS */
    --page-bg: var(--photic-bg);
    --text-color: var(--pencil-grey);
    --grid-opacity: 0.06;
    --depth-progress: 0;

    /* Layout */
    --rule-x: 38.2%;
    --row-gap: 13.7vh;        /* easter egg: avg vh-equivalent of a 1m bubble rise */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    overflow-x: hidden;
}

body {
    background: var(--page-bg);
    color: var(--text-color);
    font-family: 'Cormorant Garamond', 'Lora', Georgia, serif;
    font-size: 18px;
    line-height: 1.65;
    font-feature-settings: "onum", "kern", "liga";
    transition: background-color 0.8s ease, color 0.8s ease;
    position: relative;
    min-height: 100vh;
    cursor: default;
}

/* ============================ pencil-graph paper ============================ */
.graph-paper {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    background-image:
        linear-gradient(to right, rgba(113, 144, 158, 0.45) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(113, 144, 158, 0.45) 1px, transparent 1px),
        linear-gradient(to right, rgba(113, 144, 158, 0.18) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(113, 144, 158, 0.18) 1px, transparent 1px);
    background-size: 64px 64px, 64px 64px, 8px 8px, 8px 8px;
    opacity: var(--grid-opacity);
    transition: opacity 0.8s ease;
}

/* ============================ the wordmark ============================ */
.wordmark {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 50;
    transform: rotate(-3deg);
    transform-origin: 0 50%;
    pointer-events: none;
}

.wordmark-text {
    display: inline-block;
    font-family: 'DM Serif Display', 'Cormorant Garamond', serif;
    font-size: 22px;
    font-weight: 400;
    letter-spacing: 0.02em;
    color: var(--bauhaus-red);
    background: rgba(200, 49, 28, 0.06);
    padding: 4px 10px;
    border: 1.2px solid var(--bauhaus-red);
    box-shadow: 1px 1px 0 rgba(200, 49, 28, 0.3);
    clip-path: inset(0 100% 0 0);
    animation: wordmark-ink 1.6s 0.4s cubic-bezier(0.6, 0, 0.4, 1) forwards;
}

@keyframes wordmark-ink {
    from { clip-path: inset(0 100% 0 0); }
    to   { clip-path: inset(0 0 0 0); }
}

/* ============================ bubble field ============================ */
.bubble-field {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 2;
    overflow: hidden;
}

.bubble {
    position: absolute;
    bottom: -40px;
    border-radius: 50%;
    border: 1px solid var(--bauhaus-blue);
    background: radial-gradient(
        circle at 35% 30%,
        rgba(244, 237, 224, 0.18) 0%,
        rgba(11, 79, 108, 0.10) 38%,
        rgba(11, 79, 108, 0.05) 100%
    );
    opacity: 0;
    will-change: transform, opacity;
    animation-name: bubble-rise;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
    animation-fill-mode: both;
}

.bubble::before {
    content: "";
    position: absolute;
    top: 18%;
    left: 28%;
    width: 22%;
    height: 22%;
    background: rgba(244, 237, 224, 0.32);
    border-radius: 50%;
    filter: blur(0.6px);
}

@keyframes bubble-rise {
    0%   { transform: translate3d(0, 0, 0)    scale(0.92); opacity: 0; }
    7%   { opacity: var(--bubble-opacity, 0.12); }
    25%  { transform: translate3d(8px, -25vh, 0)  scale(1); }
    50%  { transform: translate3d(-6px, -50vh, 0) scale(1.02); }
    75%  { transform: translate3d(10px, -75vh, 0) scale(1); }
    93%  { opacity: var(--bubble-opacity, 0.12); }
    100% { transform: translate3d(0, -110vh, 0) scale(0.92); opacity: 0; }
}

/* The pause-by-the-rule variant: every 11th bubble pauses 0.3s mid-rise */
.bubble.bubble-attracted {
    animation-name: bubble-rise-attracted;
}

@keyframes bubble-rise-attracted {
    0%   { transform: translate3d(0, 0, 0)    scale(0.92); opacity: 0; }
    7%   { opacity: var(--bubble-opacity, 0.12); }
    48%  { transform: translate3d(0, -48vh, 0) scale(1.02); }
    50%  { transform: translate3d(0, -50vh, 0) scale(1.02); }   /* pause */
    52%  { transform: translate3d(0, -52vh, 0) scale(1.02); }
    93%  { opacity: var(--bubble-opacity, 0.12); }
    100% { transform: translate3d(0, -110vh, 0) scale(0.92); opacity: 0; }
}

/* ============================ timeline rule ============================ */
.timeline-rule {
    position: absolute;
    top: 0;
    left: var(--rule-x);
    width: 4px;
    height: 100%;
    z-index: 5;
    pointer-events: none;
    transform: translateX(-50%);
    overflow: visible;
}

.timeline-rule line {
    stroke-dasharray: 12000;
    stroke-dashoffset: 12000;
    animation: rule-draw 4s 0.2s ease-out forwards;
}

.timeline-rule circle {
    opacity: 0;
    animation: cap-fade 1s 4s ease-out forwards;
}

@keyframes rule-draw {
    to { stroke-dashoffset: 0; }
}

@keyframes cap-fade {
    to { opacity: 1; }
}

/* ============================ depth gauge ============================ */
.depth-gauge {
    position: fixed;
    top: 0;
    right: 24px;
    bottom: 0;
    width: 60px;
    z-index: 40;
    pointer-events: none;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 60px 0;
}

.depth-gauge-svg {
    position: absolute;
    top: 60px;
    bottom: 60px;
    left: 0;
    width: 60px;
    height: calc(100% - 120px);
    overflow: visible;
}

.depth-gauge-svg .gauge-rule {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    animation: gauge-draw 4s 0.2s ease-out forwards;
}

@keyframes gauge-draw {
    to { stroke-dashoffset: 0; }
}

.gauge-ticks line {
    opacity: 0;
    animation: tick-fade 0.6s ease-out forwards;
}

@keyframes tick-fade {
    to { opacity: 1; }
}

.gauge-labels {
    position: absolute;
    top: 60px;
    bottom: 60px;
    right: 36px;
    width: 64px;
    pointer-events: none;
}

.gauge-label {
    position: absolute;
    right: 0;
    transform: translateY(-50%);
    font-family: 'JetBrains Mono', 'Menlo', monospace;
    font-size: 10px;
    font-weight: 400;
    letter-spacing: 0.04em;
    color: var(--text-color);
    opacity: 0;
    animation: tick-fade 0.6s ease-out forwards;
    white-space: nowrap;
}

.gauge-cursor {
    position: absolute;
    top: 60px;
    left: 18px;
    transform: translate3d(0, 0, 0);
    transition: transform 0.18s cubic-bezier(0.18, 0.89, 0.32, 1.18);
    display: flex;
    align-items: center;
    gap: 6px;
    will-change: transform;
}

.gauge-cursor-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--bauhaus-yellow);
    background: rgba(2, 20, 27, 0.4);
    padding: 1px 5px;
    border: 0.5px solid var(--bauhaus-yellow);
    letter-spacing: 0.04em;
    transform: translateX(-78px);
    white-space: nowrap;
}

/* ============================ timeline / entries ============================ */
.timeline {
    position: relative;
    z-index: 10;
    padding-top: 22vh;
    padding-bottom: 18vh;
    width: 100%;
    max-width: 100%;
}

.entry {
    position: relative;
    width: 100%;
    margin-bottom: var(--row-gap);
    opacity: 0;
    transform: translateY(0);
    transition: opacity 1.2s ease;
}

.entry.entry-visible {
    opacity: 1;
}

/* The header (date small-caps + depth) hangs in the left margin */
.entry-header {
    position: absolute;
    top: 0;
    width: 28%;
    padding-right: 28px;
    text-align: right;
    line-height: 1.25;
    font-family: 'Cormorant Garamond', Georgia, serif;
}

.entry-date {
    display: block;
    font-size: 14px;
    font-weight: 500;
    font-variant: small-caps;
    letter-spacing: 0.06em;
    color: var(--text-color);
    opacity: 0.85;
}

.entry-depth {
    display: block;
    font-family: 'JetBrains Mono', 'Menlo', monospace;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.04em;
    color: var(--text-color);
    opacity: 0.55;
    margin-top: 8px;
}

/* The body (primitives + paragraph) sits to the right of the rule.
   For entry-left, we instead position the body at the left of the rule. */
.entry-row {
    position: relative;
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 32px;
    padding-top: 4px;
    transition: filter 1.6s ease;
    filter: blur(8px);
}

.entry-visible .entry-row {
    filter: blur(2.6px);
}

.entry-focused .entry-row {
    filter: blur(0);
}

/* RIGHT-side entries: header on left, body to the right of the rule */
.entry-right .entry-header {
    left: 0;
}

.entry-right .entry-row {
    margin-left: calc(var(--rule-x) + 32px);
    width: calc(100% - var(--rule-x) - 80px);
    flex-direction: row;
    text-align: left;
}

/* LEFT-side entries: header on the right of the body, body to the left of the rule */
.entry-left .entry-header {
    right: calc(100% - var(--rule-x) + 32px);
    left: auto;
    text-align: left;
    width: 28%;
    padding-right: 0;
    padding-left: 28px;
}

.entry-left .entry-row {
    margin-left: 4%;
    margin-right: calc(100% - var(--rule-x) + 32px);
    width: calc(var(--rule-x) - 4% - 32px);
    flex-direction: row-reverse;
    text-align: right;
}

/* Re-position left-side header above the entry body for narrower viewports */
@media (max-width: 980px) {
    :root { --rule-x: 30%; }
    .entry-header { position: relative; width: 100%; text-align: left; padding: 0 24px 8px; right: auto !important; left: auto !important; }
    .entry-right .entry-row,
    .entry-left .entry-row {
        margin-left: 24px;
        margin-right: 24px;
        width: calc(100% - 48px);
        flex-direction: column;
        text-align: left;
        align-items: flex-start;
    }
}

/* ============================ Bauhaus primitives ============================ */
.entry-primitives {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: nowrap;
    transition: transform 2.4s cubic-bezier(0.18, 0.89, 0.32, 1.18);
}

.entry-left .entry-primitives {
    flex-direction: row-reverse;
}

.prim {
    transition:
        transform 2.4s cubic-bezier(0.18, 0.89, 0.32, 1.18),
        filter 1.6s ease;
    will-change: transform, filter;
    transform: translateY(28px);
    filter: blur(0.4px);
}

.prim-square    { transform: translateY(28px) rotate(-2deg); }
.prim-circle    { transform: translateY(28px); }
.prim-triangle  { transform: translateY(28px); }

.entry-visible .prim-square {
    transform: translateY(14px) rotate(-2deg);
}
.entry-visible .prim-circle {
    transform: translateY(10px);
}
.entry-visible .prim-triangle {
    transform: translateY(6px);
}

.entry-focused .prim-square {
    transform: translateY(0) rotate(-2deg);
    filter: blur(0);
}
.entry-focused .prim-circle {
    transform: translateY(0);
    filter: blur(0);
}
.entry-focused .prim-triangle {
    transform: translateY(0);
    filter: blur(0);
}

/* the abyssal-zone faint outer-glow on primitives */
.abyssal-entry .prim-square,
.abyssal-entry .prim-circle,
.abyssal-entry .prim-triangle {
    filter: blur(0.4px) drop-shadow(0 0 6px rgba(244, 237, 224, 0.06));
}

.abyssal-entry.entry-focused .prim-square,
.abyssal-entry.entry-focused .prim-circle,
.abyssal-entry.entry-focused .prim-triangle {
    filter: drop-shadow(0 0 6px rgba(244, 237, 224, 0.10));
}

/* ============================ entry body text ============================ */
.entry-body {
    flex: 1 1 auto;
    font-size: 19px;
    line-height: 1.65;
    color: var(--text-color);
    font-weight: 400;
    max-width: 36em;
    transition: color 0.8s ease;
}

.entry-left .entry-body {
    text-align: right;
}

.entry-right .entry-body {
    text-align: left;
}

/* italic must be GENUINE italic; Cormorant Garamond italic is cursive */
em, i {
    font-style: italic;
    font-family: 'Cormorant Garamond', Georgia, serif;
}

/* ============================ closing stamp ============================ */
.closing-stamp {
    margin-top: calc(var(--row-gap) * 1.4);
    padding-bottom: 24vh;
    text-align: center;
    position: relative;
}

.closing-stamp svg {
    display: block;
    margin: 0 auto 26px;
    opacity: 0.7;
}

.closing-line {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-style: italic;
    font-size: 22px;
    color: var(--text-color);
    letter-spacing: 0.02em;
    opacity: 0;
    transition: opacity 4s ease-out;
}

.closing-stamp.closing-revealed .closing-line {
    opacity: 0.85;
}

.closing-attribution {
    margin-top: 28px;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-style: italic;
    font-size: 14px;
    opacity: 0;
    transition: opacity 4s 1.2s ease-out;
}

.closing-stamp.closing-revealed .closing-attribution {
    opacity: 0.45;
}

.closing-attribution a {
    color: var(--text-color);
    text-decoration: underline;
    text-decoration-color: rgba(244, 237, 224, 0.25);
    text-underline-offset: 3px;
}

.closing-attribution a:hover {
    text-decoration-color: var(--bauhaus-yellow);
}

/* ============================ scroll-driven body color ============================ */
body.zone-photic   { --page-bg: var(--photic-bg);    --text-color: var(--pencil-grey); --grid-opacity: 0.06; }
body.zone-twilight { --page-bg: var(--twilight-bg);  --text-color: var(--foam-white);  --grid-opacity: 0.08; }
body.zone-abyssal  { --page-bg: var(--abyssal-bg);   --text-color: var(--foam-white);  --grid-opacity: 0.10; }
body.zone-deep     { --page-bg: var(--abyssal-deep); --text-color: var(--foam-white);  --grid-opacity: 0.12; }

/* numeric labels on the gauge always re-color */
.gauge-label,
.entry-depth {
    color: var(--text-color);
}
