/* ==========================================================================
   layer2.id — a chronicle in strata
   palette: monochrome ink on rag paper, one vermilion stamp
   ========================================================================== */

:root {
    --paper:         #f4efe6;  /* warm rag paper, dominant field */
    --paper-shadow:  #e8e0d2;  /* slight tonal block behind seals */
    --paper-press:   #eee7da;  /* darker tone when reader presses */
    --fold-crease:   #c9bfac;  /* tick marks, faded annotations */
    --ink-faded:     #6f6657;  /* marginalia, italic asides */
    --ink-strong:    #34302a;  /* body and display type */
    --inkwell:       #1a1814;  /* the tail period only */
    --vermilion:     #9c3a2a;  /* the one mark of red */

    --spine-x: 38.2%;
    --margin-w: 14vw;
    --read-col: 42ch;
}

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

html {
    background: var(--paper);
    cursor: none;  /* we draw the quill */
    scroll-behavior: smooth;
}

body {
    background: var(--paper);
    color: var(--ink-strong);
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1.0625rem, 1.4vw, 1.1875rem);
    line-height: 1.78;
    letter-spacing: 0.005em;
    font-variant-numeric: oldstyle-nums;
    font-feature-settings: "liga" on, "dlig" on, "hist" on, "kern" on;
    overflow-x: hidden;
    cursor: none;
    transition: background-color 600ms cubic-bezier(0.45, 0.05, 0.55, 0.95);
}

body.pressed {
    background-color: var(--paper-press);
}

/* ===== Background guilloché tooth ===== */
.paper-tooth {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.04;
}

.guilloche-svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* ===== Quill cursor and pencil follower ===== */
#quill-cursor {
    position: fixed;
    top: 0;
    left: 0;
    width: 14px;
    height: 24px;
    pointer-events: none;
    z-index: 9999;
    transform-origin: 7px 22px;
    transition: transform 120ms cubic-bezier(0.45, 0.05, 0.55, 0.95);
    will-change: transform;
}

#pencil-follow {
    position: fixed;
    top: 0;
    left: 0;
    width: 10px;
    height: 18px;
    pointer-events: none;
    z-index: 9998;
    opacity: 0;
    transition: opacity 320ms ease-out;
    will-change: transform;
}

#pencil-follow.visible {
    opacity: 0.85;
}

#pencil-trail {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9997;
}

.pencil-dot {
    position: absolute;
    width: 2px;
    height: 2px;
    background: var(--ink-faded);
    border-radius: 50%;
    opacity: 0.55;
    transition: opacity 1800ms cubic-bezier(0.45, 0.05, 0.55, 0.95);
    pointer-events: none;
}

.pencil-dot.fade {
    opacity: 0;
}

/* ===== The Spine ===== */
.spine-wrapper {
    position: absolute;
    top: 0;
    left: 38.2%;
    transform: translateX(-50%);
    width: 4px;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

#spine-svg {
    width: 4px;
    height: 100%;
    display: block;
    overflow: visible;
}

#spine-svg path {
    fill: none;
    stroke: var(--ink-strong);
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* hover hit area along the spine */
.spine-hover-zone {
    position: absolute;
    top: 0;
    left: calc(38.2% - 14px);
    width: 28px;
    height: 100%;
    z-index: 2;
    cursor: none;
}

#spine-hover-fragment {
    position: fixed;
    pointer-events: none;
    z-index: 50;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 240ms cubic-bezier(0.45, 0.05, 0.55, 0.95),
                transform 240ms cubic-bezier(0.45, 0.05, 0.55, 0.95);
    font-family: 'EB Garamond', Georgia, serif;
    font-style: italic;
    font-size: 0.86rem;
    color: var(--ink-faded);
    white-space: nowrap;
    background: rgba(244, 239, 230, 0.95);
    padding: 4px 12px;
    border: 0.5px solid var(--fold-crease);
}

#spine-hover-fragment.visible {
    opacity: 1;
    transform: translateY(0);
}

#spine-hover-fragment .hover-numeral {
    font-variant: small-caps;
    color: var(--ink-strong);
    margin-right: 8px;
    font-weight: 500;
}

/* ===== Main chronicle layout ===== */
.chronicle {
    position: relative;
    z-index: 5;
    width: 100%;
    max-width: 100%;
    padding: 0;
}

/* ===== Revision counter and ear-trumpet ===== */
.rev-counter {
    position: absolute;
    top: 24px;
    left: 24px;
    z-index: 10;
}

.mono {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-weight: 300;
    font-size: 0.7rem;
    color: var(--ink-faded);
    letter-spacing: 0.02em;
}

.ear-trumpet {
    position: absolute;
    top: 24px;
    right: 24px;
    z-index: 10;
    background: transparent;
    border: none;
    width: 28px;
    height: 28px;
    cursor: none;
    padding: 0;
    transition: opacity 240ms ease-out;
    opacity: 0.7;
}

.ear-trumpet:hover {
    opacity: 1;
}

.ear-trumpet.active svg g {
    stroke: var(--vermilion) !important;
}

/* ===== Prelude / candle ===== */
.prelude {
    position: relative;
    width: 100%;
    height: 360px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
    padding-left: calc(38.2% - 25px);
    padding-bottom: 60px;
    z-index: 5;
}

.candle-wrapper {
    width: 50px;
    height: 120px;
    position: relative;
}

.candle-svg {
    display: block;
}

#flame-path,
#flame-inner {
    transform-origin: 25px 56px;
    will-change: d, transform;
}

.prelude-line {
    margin-top: 24px;
    font-family: 'EB Garamond', Georgia, serif;
    font-size: 0.86rem;
    font-style: italic;
    color: var(--ink-faded);
    max-width: 320px;
    margin-left: -180px;
}

/* ===== Strata ===== */
.stratum {
    position: relative;
    width: 100%;
    padding: 80px 0 100px 0;
    z-index: 5;
}

.stratum-i { min-height: 220vh; }
.stratum-ii { min-height: 110vh; }
.stratum-iii { min-height: 180vh; }
.stratum-iv { min-height: 100vh; }
.stratum-v { min-height: 130vh; }
.stratum-vi { min-height: 160vh; }
.stratum-vii { min-height: 140vh; }
.stratum-viii { min-height: 110vh; }
.stratum-ix { min-height: 130vh; }
.stratum-x { min-height: 100vh; }
.stratum-xi { min-height: 60vh; }

/* fade-in for opening sequence */
.stratum:not(.entered) .stratum-body > p:first-child,
.stratum:not(.entered) .stratum-title,
.stratum:not(.entered) .stratum-subtitle,
.stratum:not(.entered) .seal,
.stratum:not(.entered) .fleuron-row {
    opacity: 0;
    transform: translateY(6px);
}

.stratum.entered .stratum-body > p:first-child,
.stratum.entered .stratum-title,
.stratum.entered .stratum-subtitle,
.stratum.entered .seal,
.stratum.entered .fleuron-row {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 480ms cubic-bezier(0.45, 0.05, 0.55, 0.95),
                transform 480ms cubic-bezier(0.45, 0.05, 0.55, 0.95);
}

/* fleuron row precedes each title */
.fleuron-row {
    position: relative;
    margin-left: calc(38.2% + 60px);
    margin-bottom: 24px;
    margin-top: 0;
    width: 180px;
    height: 24px;
}

/* The seal anchored to the spine */
.seal {
    position: absolute;
    top: 80px;
    left: 38.2%;
    transform: translateX(-50%);
    width: 64px;
    height: 64px;
    z-index: 6;
    background: var(--paper-shadow);
    border-radius: 50%;
    box-shadow: 0 0 0 4px var(--paper);
}

.seal::before {
    /* the thin tendril attaching seal to spine — small horizontal tail */
    content: "";
    position: absolute;
    top: 32px;
    left: -12px;
    width: 12px;
    height: 1px;
    background: var(--ink-strong);
    opacity: 0.5;
}

.seal-svg {
    display: block;
    width: 100%;
    height: 100%;
}

.seal-svg .seal-ring,
.seal-svg .seal-ring-inner {
    transition: stroke 320ms ease-out, stroke-width 320ms ease-out;
}

.seal.inked .seal-svg .seal-ring,
.seal.inked .seal-svg .seal-ring-inner {
    stroke: var(--ink-strong);
    stroke-width: 1.2;
}

/* ===== Stratum titles and subtitles ===== */
.stratum-title {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 300;
    font-style: italic;
    font-size: clamp(2.4rem, 5.6vw, 4.6rem);
    line-height: 1.05;
    letter-spacing: -0.012em;
    text-transform: lowercase;
    color: var(--ink-strong);
    margin-left: calc(38.2% + 60px);
    max-width: 12ch;
    margin-bottom: 12px;
    font-feature-settings: "swsh" on, "liga" on, "dlig" on;
}

.stratum-subtitle {
    font-family: 'EB Garamond', Georgia, serif;
    font-style: italic;
    font-size: 0.95rem;
    color: var(--ink-faded);
    margin-left: calc(38.2% + 60px);
    margin-bottom: 36px;
    letter-spacing: 0.01em;
}

/* ===== Stratum body — narrow reading column ===== */
.stratum-body {
    margin-left: calc(38.2% + 60px);
    max-width: 42ch;
    color: var(--ink-strong);
}

.stratum-body p {
    margin-bottom: 1.2em;
    text-rendering: optimizeLegibility;
    font-feature-settings: "liga" on, "dlig" on, "hist" on;
}

.stratum-body em {
    font-style: italic;
    color: var(--ink-strong);
    font-feature-settings: "swsh" on, "liga" on, "dlig" on;
}

.first-paragraph {
    text-indent: 0;
}

/* drop cap only for stratum i */
.drop-cap {
    float: left;
    width: 64px;
    height: 80px;
    margin-right: 12px;
    margin-top: 4px;
    margin-bottom: -8px;
    shape-outside: margin-box;
}

.drop-cap svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* ===== Margins / Field notes ===== */
.margin-note {
    position: absolute;
    font-family: 'EB Garamond', Georgia, serif;
    font-style: italic;
    font-size: 0.78rem;
    line-height: 1.5;
    color: var(--ink-faded);
    max-width: 180px;
    z-index: 5;
}

.margin-note em {
    font-style: italic;
    display: block;
    margin-top: 4px;
}

.margin-note .mono {
    display: block;
    margin-top: 4px;
    font-size: 0.68rem;
}

.margin-note.margin-left {
    left: 4vw;
    text-align: right;
}

.margin-note.margin-right {
    right: 4vw;
    text-align: left;
    max-width: 200px;
}

.margin-note .margin-glyph {
    display: block;
    margin-bottom: 6px;
}

.margin-note.margin-left .margin-glyph {
    margin-left: auto;
}

/* position the asides by stratum — staggered to keep margins lively */
.stratum-i .margin-note.margin-left { top: 200px; }
.stratum-i .margin-note.margin-right { top: 320px; }
.stratum-ii .margin-note.margin-right { top: 200px; }
.stratum-ii .margin-note.margin-left { top: 360px; }
.stratum-iii .margin-note.margin-right { top: 220px; }
.stratum-iii .margin-note.margin-left { top: 380px; }
.stratum-iv .margin-note.margin-right { top: 220px; }
.stratum-iv .margin-note.margin-left { top: 380px; }
.stratum-v .margin-note.margin-left { top: 220px; }
.stratum-v .margin-note.margin-right { top: 380px; }
.stratum-vi .margin-note.margin-right { top: 220px; }
.stratum-vi .margin-note.margin-left { top: 400px; }
.stratum-vii .margin-note.margin-left { top: 240px; }
.stratum-vii .margin-note.margin-right { top: 380px; }
.stratum-viii .margin-note.margin-right { top: 220px; }
.stratum-viii .margin-note.margin-left { top: 380px; }
.stratum-ix .margin-note.margin-left { top: 220px; }
.stratum-ix .margin-note.margin-right { top: 380px; }
.stratum-x .margin-note.margin-right { top: 220px; }
.stratum-x .margin-note.margin-left { top: 360px; }
.stratum-xi .margin-note.margin-left { top: 200px; }
.stratum-xi .margin-note.margin-right { top: 280px; }

/* ===== Tick marks and annotations along spine ===== */
.tick-mark {
    position: absolute;
    z-index: 4;
    display: flex;
    align-items: center;
    pointer-events: none;
}

.tick-mark svg {
    display: block;
}

.tick-mark.left {
    left: calc(38.2% - 64px);
    transform: translateX(-100%);
    flex-direction: row-reverse;
}

.tick-mark.right {
    left: calc(38.2% + 4px);
}

.tick-label {
    font-family: 'EB Garamond', Georgia, serif;
    font-size: 0.74rem;
    color: var(--ink-faded);
    font-style: italic;
    pointer-events: auto;
    cursor: none;
    position: relative;
}

.tick-label-left {
    margin-right: 8px;
    text-align: right;
}

.tick-label-right {
    margin-left: 8px;
}

/* hand-drawn underline on date hover */
.tick-label::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -2px;
    height: 4px;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 4'><path d='M 1 2 C 8 1 14 3 22 1.5 C 30 1 36 3 44 1.8 C 50 1 54 2.5 59 2' stroke='%236f6657' stroke-width='0.8' fill='none'/></svg>") no-repeat center;
    background-size: 100% 100%;
    transform-origin: left center;
    transform: scaleX(0);
    transition: transform 280ms cubic-bezier(0.45, 0.05, 0.55, 0.95);
}

.tick-label:hover::after {
    transform: scaleX(1);
}

/* ===== Perforated dotted-line dividers ===== */
.perforated-divider {
    width: 80%;
    margin: 20px auto;
    height: 8px;
    background-image: radial-gradient(circle, var(--fold-crease) 1px, transparent 1.4px);
    background-size: 12px 8px;
    background-repeat: repeat-x;
    background-position: center;
    position: relative;
    z-index: 4;
    opacity: 0.7;
}

/* ===== Watermark fingerprint ===== */
.watermark {
    position: absolute;
    top: 200px;
    left: 50%;
    transform: translateX(-50%);
    width: 600px;
    height: 600px;
    z-index: 1;
    pointer-events: none;
    opacity: 0.5;
}

/* ===== Vermilion stamp ===== */
.vermilion-stamp {
    position: absolute;
    top: 320px;
    right: 18vw;
    width: 80px;
    height: 80px;
    z-index: 6;
    transform: rotate(-3deg);
    transition: transform 90ms cubic-bezier(0.45, 0.05, 0.55, 0.95);
    cursor: none;
}

.vermilion-stamp.tremble {
    transform: rotate(-3deg) translate(3px, -1px);
}

.vermilion-stamp svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* ===== Vector glyphs hover redraw ===== */
.vector-glyph {
    transition: filter 320ms ease-out;
}

.vector-glyph path,
.vector-glyph circle,
.vector-glyph ellipse,
.vector-glyph rect:not([fill="#9c3a2a"]),
.vector-glyph polygon,
.vector-glyph line {
    transition: stroke-width 320ms ease-out, stroke 320ms ease-out, opacity 320ms ease-out;
}

.vector-glyph.inking path,
.vector-glyph.inking circle,
.vector-glyph.inking ellipse,
.vector-glyph.inking rect,
.vector-glyph.inking polygon,
.vector-glyph.inking line {
    stroke: var(--ink-strong);
    stroke-width: 1.1;
    opacity: 1;
}

/* ===== The Tail ===== */
.tail {
    position: relative;
    width: 100%;
    height: 600px;
    z-index: 5;
}

.tail-period {
    position: absolute;
    top: 480px;
    left: 38.2%;
    transform: translateX(-50%);
    width: 14px;
    height: 14px;
}

.tail-period svg {
    display: block;
}

.legal-note {
    position: absolute;
    bottom: 24px;
    left: 4vw;
    font-family: 'EB Garamond', Georgia, serif;
    font-style: italic;
    font-size: 0.74rem;
    color: var(--ink-faded);
    max-width: 240px;
    z-index: 6;
}

/* ===== Selection ===== */
::selection {
    background: var(--fold-crease);
    color: var(--ink-strong);
}

/* ===== Responsive — collapse margins on narrow screens ===== */
@media (max-width: 900px) {
    :root {
        --margin-w: 6vw;
    }

    .stratum-title,
    .stratum-subtitle,
    .stratum-body,
    .fleuron-row {
        margin-left: 18vw;
        max-width: 70vw;
    }

    .stratum-body {
        max-width: 36ch;
    }

    .margin-note {
        max-width: 130px;
        font-size: 0.7rem;
    }

    .margin-note.margin-left { left: 1vw; }
    .margin-note.margin-right { right: 1vw; max-width: 130px; }

    .vermilion-stamp {
        right: 6vw;
        width: 60px;
        height: 60px;
    }

    .watermark {
        width: 360px;
        height: 360px;
    }

    .tick-label {
        font-size: 0.65rem;
    }

    .prelude {
        padding-left: 12vw;
    }

    .prelude-line {
        margin-left: 0;
    }

    html, body {
        cursor: auto;
    }

    #quill-cursor,
    #pencil-follow,
    #pencil-trail {
        display: none;
    }
}

@media (max-width: 560px) {
    .stratum-title { font-size: 2.4rem; }

    .margin-note { display: none; }

    .stratum-title,
    .stratum-subtitle,
    .stratum-body,
    .fleuron-row {
        margin-left: 14vw;
        max-width: 78vw;
    }

    .stratum-body { max-width: 32ch; }

    .seal {
        width: 48px;
        height: 48px;
    }

    .seal::before { left: -8px; width: 8px; }
}
