/* ============================================
   paragram.dev - Typographic Alchemy
   ============================================ */

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

html {
    scroll-snap-type: y mandatory;
    overflow-y: scroll;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

body {
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-size: clamp(1rem, 1.6vw, 1.25rem);
    line-height: 1.65;
    color: #1A1A2E;
    background-color: #F7F5F0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Page Container --- */
#page-container {
    width: 100%;
    height: 100vh;
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
}

/* --- Spreads --- */
.spread {
    position: relative;
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    scroll-snap-align: start;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spread-hero {
    background-color: #F7F5F0;
}

.spread-etymology {
    background-color: #E8E6F0;
}

.spread-theater {
    background-color: #F7F5F0;
}

.spread-code {
    background-color: #1A1A2E;
    color: #F7F5F0;
}

.spread-resolution {
    background-color: #F7F5F0;
}

/* --- Pivot Line --- */
.pivot-line {
    position: absolute;
    top: 0;
    left: 61.8%;
    width: 1px;
    height: 100%;
    background-color: #B8B8CC;
    z-index: 1;
    pointer-events: none;
}

.pivot-line-dark {
    background-color: #4A4A5C;
}

/* --- Letter Tiles --- */
.letter-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    width: clamp(3rem, 10vw, 7rem);
    border: 1px solid #4A4A5C;
    box-shadow: 0 2px 8px rgba(26, 26, 46, 0.08);
    background: #F7F5F0;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(2rem, 7vw, 5rem);
    letter-spacing: 0.04em;
    color: #1A1A2E;
    cursor: pointer;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1),
                color 0.3s ease,
                border-color 0.3s ease,
                box-shadow 0.3s ease;
    user-select: none;
    position: relative;
}

.letter-tile:hover {
    border-color: #6E5CFF;
    box-shadow: 0 4px 16px rgba(110, 92, 255, 0.15);
}

.letter-tile.swapping-out {
    color: #E8475F;
}

.letter-tile.swapping-in {
    color: #6E5CFF;
}

.letter-tile.resolved {
    color: #2B9E8F;
    border-color: #2B9E8F;
}

/* --- Hero Section --- */
.hero-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2.5rem;
    z-index: 2;
}

.hero-tiles {
    display: flex;
    gap: clamp(0.25rem, 0.8vw, 0.5rem);
    position: relative;
}

.hero-subtitle {
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-size: clamp(0.9rem, 1.6vw, 1.25rem);
    color: #4A4A5C;
    letter-spacing: 0.05em;
    min-height: 1.65em;
}

.hero-subtitle .char {
    opacity: 0;
    display: inline-block;
}

.hero-subtitle .char.visible {
    opacity: 1;
}

/* --- Spread Navigation --- */
.spread-nav {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 1rem;
    z-index: 10;
}

.nav-glyph {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 400;
    font-size: 1rem;
    color: #B8B8CC;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    transition: color 0.3s ease, transform 0.2s ease;
    letter-spacing: 0.02em;
}

.nav-glyph:hover {
    color: #6E5CFF;
    transform: scale(1.15);
}

.nav-glyph.active {
    color: #D4A843;
    font-weight: 700;
}

/* --- Spread Headings --- */
.spread-heading {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 4.5rem);
    letter-spacing: 0.04em;
    color: #1A1A2E;
    position: relative;
    display: inline-block;
    margin-bottom: 0.5rem;
}

.heading-underline {
    display: block;
    width: 100%;
    height: 4px;
    margin-top: 0.2em;
}

.heading-underline line {
    transition: stroke-dashoffset 1s ease-out;
}

.heading-underline.drawn line {
    stroke-dashoffset: 0;
}

.heading-gold .heading-underline line {
    stroke: #D4A843;
}

.heading-violet .heading-underline line {
    stroke: #6E5CFF;
}

.heading-teal .heading-underline line {
    stroke: #2B9E8F;
}

/* --- Etymology Spread (Spread 2) --- */
.spread-grid {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    gap: 1.25rem;
    width: 90%;
    max-width: 1200px;
    height: 80vh;
    padding: 2rem;
    z-index: 2;
}

.z-top-left {
    grid-column: 1 / 7;
    grid-row: 1;
    align-self: start;
    padding-top: 4vh;
}

.z-top-right {
    grid-column: 10 / 17;
    grid-row: 1;
    align-self: start;
    text-align: right;
    padding-top: 4vh;
}

.etymology-note {
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-style: italic;
    color: #4A4A5C;
    font-size: clamp(0.9rem, 1.4vw, 1.15rem);
    margin-top: 0.5rem;
}

.z-body {
    grid-column: 2 / 10;
    grid-row: 2;
    align-self: center;
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    line-height: 1.75;
    color: #1A1A2E;
    max-width: 580px;
}

.z-widget {
    grid-column: 10 / 16;
    grid-row: 2;
    align-self: center;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.widget-label {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.875rem, 1.2vw, 1.1rem);
    color: #6E5CFF;
}

.transpose-input {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    letter-spacing: 0.04em;
    color: #1A1A2E;
    background: transparent;
    border: none;
    border-bottom: 2px solid #4A4A5C;
    padding: 0.5rem 0;
    outline: none;
    width: 100%;
    transition: border-color 0.3s ease;
}

.transpose-input::placeholder {
    color: #B8B8CC;
}

.transpose-input:focus {
    border-color: #6E5CFF;
}

.transpose-results {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 40vh;
    overflow-y: auto;
}

.transpose-result-row {
    display: flex;
    gap: 0.2rem;
    opacity: 0;
    transform: translateY(8px);
    animation: fadeUp 0.3s ease forwards;
}

.transpose-result-row .mini-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 1px solid #4A4A5C;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 0.9rem;
    color: #1A1A2E;
    background: #F7F5F0;
}

.transpose-result-row .mini-tile.swapped {
    color: #6E5CFF;
    border-color: #6E5CFF;
}

@keyframes fadeUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Theater Spread (Spread 3) --- */
.theater-content {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 90%;
    max-width: 1200px;
    gap: 2rem;
    z-index: 2;
}

.theater-left,
.theater-right {
    flex: 1;
    display: flex;
    justify-content: center;
}

.theater-left {
    justify-content: flex-end;
}

.theater-right {
    justify-content: flex-start;
}

.theater-word {
    display: flex;
    gap: clamp(0.15rem, 0.5vw, 0.3rem);
}

.theater-word .letter-tile {
    width: clamp(2.5rem, 7vw, 5rem);
    font-size: clamp(1.5rem, 5vw, 3.5rem);
}

.theater-center {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.pivot-glyph {
    animation: pivotRotate 12s linear infinite;
}

@keyframes pivotRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.theater-pair-label {
    position: absolute;
    bottom: 3rem;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.875rem, 1.2vw, 1.1rem);
    color: #6E5CFF;
    z-index: 2;
}

.trail-lines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 3;
}

.trail-line {
    stroke: rgba(110, 92, 255, 0.4);
    stroke-width: 1;
    stroke-dasharray: 2 4;
    fill: none;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.trail-line.visible {
    opacity: 1;
}

/* --- Code Spread (Spread 4) --- */
.code-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    z-index: 2;
    width: 90%;
    max-width: 800px;
}

.code-title {
    color: #F7F5F0;
}

.code-block {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.875rem, 1.2vw, 1.1rem);
    line-height: 1.85;
    color: #F7F5F0;
    width: 100%;
    position: relative;
}

.code-block code {
    display: block;
}

.code-block .line-num {
    color: #D4A843;
    display: inline-block;
    width: 2.5em;
    text-align: right;
    margin-right: 1em;
    user-select: none;
}

.code-block .kw {
    color: #6E5CFF;
}

.code-block .fn {
    color: #E8475F;
}

.code-block .str {
    color: #2B9E8F;
}

.code-block .num {
    color: #D4A843;
}

.code-block .cm {
    color: #B8B8CC;
    font-style: italic;
}

.code-line-wrapper {
    display: block;
    padding: 0.1rem 0;
    border-left: 3px solid transparent;
    padding-left: 0.5rem;
    transition: transform 0.2s ease, border-color 0.15s ease;
    cursor: default;
}

.code-line-wrapper:hover {
    transform: scale(1.05);
    transform-origin: left center;
    border-left-color: #6E5CFF;
}

/* --- Resolution Spread (Spread 5) --- */
.resolution-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    z-index: 2;
}

.resolution-tiles {
    display: flex;
    gap: clamp(0.25rem, 0.8vw, 0.5rem);
}

.resolution-tile {
    opacity: 0;
    transform: translate(0, 0);
}

.resolution-tile.animating {
    transition: opacity 0.8s ease, transform 1s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.5s ease 1s, border-color 0.5s ease 1s;
}

.resolution-tile.arrived {
    opacity: 1;
    transform: translate(0, 0) !important;
}

.resolution-tile.resolved {
    color: #2B9E8F;
    border-color: #2B9E8F;
}

.resolution-dev {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 4rem);
    color: #2B9E8F;
    letter-spacing: 0.04em;
    display: flex;
    gap: 0;
}

.resolution-dev span {
    opacity: 0;
    display: inline-block;
}

.resolution-dev span.visible {
    opacity: 1;
    transition: opacity 0.15s ease;
}

.resolution-rule {
    width: 100%;
    height: 4px;
    position: absolute;
    bottom: 45%;
    left: 0;
}

.resolution-rule line {
    transition: stroke-dashoffset 1.5s ease-out;
}

.resolution-rule.drawn line {
    stroke-dashoffset: 0;
}

/* --- Scrollbar Styling --- */
#page-container::-webkit-scrollbar {
    width: 4px;
}

#page-container::-webkit-scrollbar-track {
    background: #F7F5F0;
}

#page-container::-webkit-scrollbar-thumb {
    background: #B8B8CC;
    border-radius: 2px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .spread-grid {
        display: flex;
        flex-direction: column;
        padding: 1.5rem;
        gap: 1.5rem;
        height: auto;
        min-height: 100vh;
        justify-content: center;
    }

    .z-top-left,
    .z-top-right {
        text-align: left;
        padding-top: 0;
    }

    .z-body {
        max-width: 100%;
    }

    .theater-content {
        flex-direction: column;
        gap: 1.5rem;
    }

    .theater-left,
    .theater-right {
        justify-content: center;
    }

    .pivot-line {
        display: none;
    }

    .letter-tile {
        width: clamp(2.2rem, 10vw, 4rem);
        font-size: clamp(1.4rem, 7vw, 3rem);
    }

    .theater-word .letter-tile {
        width: clamp(2rem, 8vw, 3.5rem);
        font-size: clamp(1.2rem, 5vw, 2.5rem);
    }
}
