/* ============================================================
   talegrapher.com - Steampunk Typewriter Design
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
    --ink-black: #1B1710;
    --parchment-cream: #F5ECDA;
    --ribbon-blue: #2C4A6E;
    --desk-mahogany: #3B1F12;
    --brass-accent: #B8860B;
    --red-ink: #8B2500;
    --aged-gold: #C9A84C;
    --shadow-umber: #2A1F14;
    --key-pressed: #EDE3CC;
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    background-color: var(--desk-mahogany);
    background-image:
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 40px,
            rgba(27, 23, 16, 0.03) 40px,
            rgba(27, 23, 16, 0.03) 41px
        ),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 8px,
            rgba(27, 23, 16, 0.02) 8px,
            rgba(27, 23, 16, 0.02) 9px
        );
    color: var(--ink-black);
    font-family: 'Courier Prime', 'Courier New', monospace;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.75;
    overflow-x: hidden;
    padding-bottom: 80px;
}

/* --- Paper Container (centered paper area) --- */
.paper-container {
    position: relative;
    max-width: 680px;
    margin: 0 auto;
    background-color: var(--parchment-cream);
    box-shadow:
        -4px 0 12px rgba(27, 23, 16, 0.3),
        4px 0 12px rgba(27, 23, 16, 0.3),
        0 0 40px rgba(27, 23, 16, 0.15);
    min-height: 100vh;
}

/* --- Torn Edge Borders (SVG-like effect via box-shadow/pseudo-elements) --- */
.paper-container::before,
.paper-container::after {
    content: '';
    position: fixed;
    top: 0;
    bottom: 0;
    width: 6px;
    z-index: 5;
    pointer-events: none;
}

.paper-container::before {
    left: calc(50% - 343px);
    background: repeating-linear-gradient(
        to bottom,
        var(--parchment-cream) 0px,
        var(--desk-mahogany) 3px,
        var(--parchment-cream) 6px,
        var(--desk-mahogany) 9px,
        var(--parchment-cream) 12px
    );
    opacity: 0.4;
}

.paper-container::after {
    right: calc(50% - 343px);
    background: repeating-linear-gradient(
        to bottom,
        var(--parchment-cream) 0px,
        var(--desk-mahogany) 3px,
        var(--parchment-cream) 6px,
        var(--desk-mahogany) 9px,
        var(--parchment-cream) 12px
    );
    opacity: 0.4;
}

/* --- Tractor Feed Holes --- */
.tractor-feed {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 20px;
    z-index: 6;
    pointer-events: none;
}

.tractor-feed-left {
    left: calc(50% - 355px);
}

.tractor-feed-right {
    right: calc(50% - 355px);
}

/* Tractor holes generated by JS */
.tractor-hole {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--desk-mahogany);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
    margin: 0 auto 24px auto;
}

/* --- Carriage Return Lever --- */
.carriage-lever {
    position: fixed;
    top: 20px;
    right: calc(50% - 380px);
    z-index: 10;
    opacity: 0.7;
    transition: transform 0.3s ease-out;
    pointer-events: none;
}

/* --- Platen Header (Full-Screen Opening) --- */
.platen-header {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: clamp(2rem, 5vw, 4rem);
    position: relative;
}

.platen-content {
    text-align: center;
}

.domain-title {
    font-family: 'Special Elite', cursive;
    font-weight: 400;
    font-size: clamp(2rem, 5vw, 3.5rem);
    letter-spacing: 0.04em;
    color: var(--ink-black);
    text-shadow: 0 0 1px rgba(27, 23, 16, 0.3);
    min-height: 1.2em;
    position: relative;
}

/* Typing cursor */
.domain-title::after {
    content: '';
    display: inline-block;
    width: 0.6em;
    height: 0.08em;
    background-color: var(--ink-black);
    vertical-align: baseline;
    margin-left: 2px;
    animation: cursorBlink 0.8s step-end infinite;
}

.domain-title.typing-done::after {
    animation: cursorBlink 0.8s step-end infinite;
}

.domain-title.cursor-hidden::after {
    display: none;
}

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

.subtitle {
    font-family: 'Courier Prime', 'Courier New', monospace;
    font-weight: 400;
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    color: var(--ink-black);
    opacity: 0;
    margin-top: 1.5rem;
    letter-spacing: 0.08em;
    transition: opacity 0.8s ease-in;
}

.subtitle.visible {
    opacity: 0.6;
}

/* --- Keystrike flash effect --- */
.keystrike-flash {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ink-black);
    opacity: 0;
    pointer-events: none;
    animation: flashStrike 0.1s ease-out forwards;
}

@keyframes flashStrike {
    0% { opacity: 0.6; transform: scale(1.2); }
    100% { opacity: 0; transform: scale(0.5); }
}

/* --- Character jitter animation --- */
.char-jitter {
    display: inline-block;
    animation: jitter 0.02s ease-out;
}

@keyframes jitter {
    0% { transform: translateX(-2px) scale(1.05); }
    50% { transform: translateX(1px) scale(1.02); }
    100% { transform: translateX(0) scale(1); }
}

/* --- Manuscript Sections --- */
.manuscript-section {
    position: relative;
    padding: clamp(2rem, 5vw, 4rem);
    padding-left: clamp(4rem, 8vw, 6rem);
    min-height: 60vh;
}

.section-content {
    position: relative;
}

.section-heading {
    font-family: 'Special Elite', cursive;
    font-weight: 400;
    font-size: clamp(1.6rem, 4vw, 2.5rem);
    letter-spacing: 0.04em;
    color: var(--ink-black);
    text-shadow: 0 0 1px rgba(27, 23, 16, 0.3);
    margin-bottom: 0.5rem;
}

/* --- Perforation Line --- */
.perforation-line {
    border: none;
    border-top: 2px dashed var(--brass-accent);
    margin: 1rem 0 2rem 0;
    position: relative;
}

.perforation-line::before,
.perforation-line::after {
    content: '';
    position: absolute;
    top: -5px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--desk-mahogany);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
}

.perforation-line::before {
    left: -12px;
}

.perforation-line::after {
    right: -12px;
}

/* --- Body Text --- */
.body-text {
    font-family: 'Courier Prime', 'Courier New', monospace;
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.75;
    color: var(--ink-black);
    text-shadow: 0 0 1px rgba(27, 23, 16, 0.3);
    text-indent: 2em;
    margin-bottom: 1.5em;
}

/* --- Carbon Copy Ghost Text --- */
.carbon-copy {
    position: relative;
}

.carbon-copy::after {
    content: attr(data-text);
    position: absolute;
    top: 2px;
    left: 1px;
    color: var(--ribbon-blue);
    opacity: 0.15;
    pointer-events: none;
    z-index: -1;
    text-indent: 2em;
}

/* --- Correction Tape --- */
.correction-tape {
    position: relative;
    display: inline;
}

.redacted {
    position: relative;
    color: transparent;
}

.redacted::after {
    content: '';
    position: absolute;
    top: 0;
    left: -2px;
    right: -2px;
    bottom: 0;
    background: var(--parchment-cream);
    border: 1px solid rgba(27, 23, 16, 0.1);
}

.corrected {
    position: relative;
    top: -0.15em;
    font-size: 0.9em;
    color: var(--ink-black);
    margin-left: 0.3em;
}

/* --- Margin Annotations --- */
.margin-annotation {
    position: absolute;
    left: 0.5rem;
    top: 3rem;
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--red-ink);
    writing-mode: vertical-lr;
    transform: rotate(-2deg);
    opacity: 0.8;
    max-width: 2rem;
    line-height: 1.2;
}

.margin-annotation[data-rotation="-3"] {
    transform: rotate(-3deg);
}

.margin-annotation[data-rotation="-1"] {
    transform: rotate(-1deg);
}

/* --- Ink Links --- */
.ink-link {
    color: var(--ribbon-blue);
    text-decoration: none;
    border-bottom: 1px solid var(--ribbon-blue);
    position: relative;
    transition: color 0.2s ease;
    background-size: 0 100%;
    background-repeat: no-repeat;
    background-image: radial-gradient(circle, rgba(27, 23, 16, 0.08) 0%, transparent 70%);
    transition: background-size 0.3s ease, color 0.2s ease;
}

.ink-link:hover {
    color: var(--red-ink);
    border-bottom-color: var(--red-ink);
    background-size: 200% 200%;
}

/* --- Gear Dividers --- */
.gear-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 2rem 0;
    position: relative;
}

.gear-divider::before,
.gear-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--aged-gold), transparent);
}

.gear {
    display: block;
    flex-shrink: 0;
}

.gear-large {
    animation: spinCW 8s linear infinite;
}

.gear-medium {
    animation: spinCCW 12s linear infinite;
}

.gear-small {
    animation: spinCW 6s linear infinite;
}

@keyframes spinCW {
    to { transform: rotate(360deg); }
}

@keyframes spinCCW {
    to { transform: rotate(-360deg); }
}

/* --- Typewriter Key Navigation Bar --- */
.typewriter-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 14px 0;
    background: var(--desk-mahogany);
    border-top: 2px solid var(--brass-accent);
    z-index: 100;
    box-shadow: 0 -4px 12px rgba(27, 23, 16, 0.5);
}

.typewriter-key {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--brass-accent);
    background: var(--parchment-cream);
    color: var(--ink-black);
    font-family: 'Syne Mono', monospace;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: 1px 2px 3px var(--shadow-umber);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.typewriter-key:hover {
    transform: translateY(2px);
    box-shadow: 0 0 1px var(--shadow-umber);
}

.typewriter-key.active {
    transform: translateY(2px);
    box-shadow: inset 0 1px 3px var(--shadow-umber);
    background: var(--key-pressed);
}

/* --- Typewriter Reveal (clip-path animation) --- */
.typewriter-reveal {
    clip-path: inset(0 100% 0 0);
    transition: clip-path 0s;
}

.typewriter-reveal.revealed {
    clip-path: inset(0 0% 0 0);
    transition: clip-path 1.2s cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* --- Ribbon Spool Illustration --- */
.ribbon-spool-illustration {
    display: flex;
    justify-content: center;
    margin-top: 3rem;
    opacity: 0.6;
}

/* --- Ink Intensity Variation (per-paragraph) --- */
.manuscript-section:nth-child(odd) .body-text {
    opacity: 0.95;
}

.manuscript-section:nth-child(even) .body-text {
    opacity: 0.88;
}

/* --- Bottom Spacer --- */
.bottom-spacer {
    height: 4rem;
}

/* --- Responsive --- */
@media (max-width: 760px) {
    .paper-container {
        max-width: 100%;
        margin: 0;
    }

    .paper-container::before,
    .paper-container::after {
        display: none;
    }

    .tractor-feed {
        display: none;
    }

    .carriage-lever {
        right: 10px;
        opacity: 0.4;
    }

    .carriage-lever svg {
        width: 50px;
        height: 75px;
    }

    .manuscript-section {
        padding-left: clamp(2.5rem, 5vw, 4rem);
    }

    .margin-annotation {
        font-size: 0.75rem;
        left: 0.3rem;
    }

    .typewriter-key {
        width: 32px;
        height: 32px;
        font-size: 0.65rem;
    }

    .typewriter-nav {
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .manuscript-section {
        padding: 1.5rem;
        padding-left: 2.5rem;
    }

    .gear-divider svg {
        transform: scale(0.8);
    }

    .ribbon-spool-illustration svg {
        width: 150px;
        height: 60px;
    }
}
