:root {
    --unit: 8px;
    --gutter: calc(var(--unit) * 4);
    --bg: #FFFFFF;
    --text: #111111;
    --text-secondary: #666666;
    --text-tertiary: #AAAAAA;
    --accent: #0055FF;
    --accent-hover: #003FCC;
    --grid-line: #E8E8E8;
    --code-bg: #F5F5F5;
}

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

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-weight: 400;
    font-size: 16px;
    line-height: 2.0;
    overflow-x: hidden;
    padding-left: 48px;
}

/* Baseline grid */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    background-image: repeating-linear-gradient(
        to bottom,
        var(--grid-line) 0px,
        var(--grid-line) 1px,
        transparent 1px,
        transparent 8px
    );
    opacity: 0.03;
    transition: opacity 0.3s ease;
}

body.grid-visible::before {
    opacity: 0.06;
}

/* Column grid overlay */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 48px;
    width: calc(100% - 48px);
    height: 100%;
    pointer-events: none;
    z-index: 0;
    background-image: repeating-linear-gradient(
        to right,
        transparent 0px,
        transparent 239px,
        var(--grid-line) 239px,
        var(--grid-line) 240px
    );
    opacity: 0;
    transition: opacity 0.3s ease;
}

body.grid-visible::after {
    opacity: 0.04;
}

/* Left rail */
.left-rail {
    position: fixed;
    top: 0;
    left: 0;
    width: 48px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 32px;
    z-index: 10;
    background-color: var(--bg);
}

.rail-section-num {
    font-family: 'DM Mono', monospace;
    font-weight: 400;
    font-size: 10px;
    color: var(--accent);
    margin-bottom: 16px;
}

.rail-progress {
    flex: 1;
    display: flex;
    align-items: stretch;
    padding-bottom: 32px;
}

.rail-track {
    width: 1px;
    background-color: var(--grid-line);
    position: relative;
}

.rail-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--accent);
    position: absolute;
    left: -3.5px;
    top: 0;
    transition: top 0.3s ease;
}

/* Grid toggle */
.grid-toggle {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 32px;
    height: 32px;
    border: 1px solid var(--grid-line);
    background: var(--bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    padding: 6px;
    transition: border-color 0.2s ease;
}

.grid-toggle:hover {
    border-color: var(--accent);
}

.grid-toggle svg {
    width: 16px;
    height: 16px;
}

/* Sections */
.section {
    position: relative;
    z-index: 2;
}

.content-area {
    max-width: 720px;
    padding: 0 var(--gutter);
}

/* Section 1: The Unit */
.section-unit {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    padding-top: 120px;
}

.main-heading {
    font-family: 'DM Sans', sans-serif;
    font-weight: 700;
    font-size: clamp(2rem, 3.5vw, 3rem);
    letter-spacing: -0.02em;
    color: var(--text);
    margin-bottom: var(--gutter);
    line-height: 1.2;
}

.main-sub {
    font-family: 'DM Sans', sans-serif;
    font-weight: 400;
    font-size: 16px;
    color: var(--text-secondary);
    line-height: 2.0;
}

/* Section equations */
.section-equation {
    padding: 48px var(--gutter);
    padding-left: calc(var(--gutter) + 0px);
}

.equation-text {
    font-family: 'DM Mono', monospace;
    font-weight: 400;
    font-size: 10px;
    color: var(--text);
    opacity: 0.15;
    letter-spacing: 0.05em;
}

/* Section 2: The Scale */
.section-scale {
    min-height: 140vh;
    padding-top: 64px;
}

.type-specimen {
    margin-bottom: 64px;
}

.specimen-row {
    display: flex;
    align-items: baseline;
    gap: 24px;
    margin-bottom: 16px;
    border-bottom: 1px solid rgba(232,232,232,0.3);
    padding-bottom: 8px;
}

.specimen-label {
    font-family: 'DM Mono', monospace;
    font-weight: 400;
    font-size: 10px;
    color: var(--text-tertiary);
    min-width: 120px;
    flex-shrink: 0;
}

.specimen-text {
    font-family: 'DM Sans', sans-serif;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

/* Geometric constructions */
.geometric-construction {
    margin-bottom: 48px;
}

.golden-spiral {
    width: 120px;
    height: 120px;
}

.ruler-svg {
    width: 100%;
    max-width: 480px;
    height: auto;
}

.ruler-label {
    font-family: 'DM Mono', monospace;
    font-size: 8px;
    fill: var(--accent);
    opacity: 0.6;
}

.scale-svg {
    width: 200px;
    height: 120px;
}

.scale-label {
    font-family: 'DM Mono', monospace;
    fill: var(--text-secondary);
}

/* Text blocks */
.text-block {
    margin-bottom: var(--gutter);
}

.body-text {
    font-family: 'DM Sans', sans-serif;
    font-weight: 400;
    font-size: 16px;
    line-height: 2.0;
    color: var(--text);
}

.block-240 { max-width: 240px; }
.block-480 { max-width: 480px; }
.block-720 { max-width: 720px; }

/* Code */
.code-inline {
    font-family: 'DM Mono', monospace;
    font-weight: 400;
    font-size: 14px;
    color: var(--accent);
    background-color: var(--code-bg);
    padding: 2px 6px;
}

.code-container {
    margin-bottom: 48px;
}

.code-block {
    background-color: var(--code-bg);
    padding: 24px;
    font-family: 'DM Mono', monospace;
    font-weight: 400;
    font-size: 14px;
    line-height: 1.71;
    color: var(--text);
    overflow-x: auto;
    max-width: 480px;
}

.code-block code {
    white-space: pre;
}

.kw { color: var(--accent); }
.fn { color: var(--text); }
.num { color: var(--accent-hover); }

/* Section 3: The Grid */
.section-grid {
    min-height: 140vh;
    padding-top: 64px;
}

.module-demo {
    display: flex;
    flex-direction: column;
    gap: var(--gutter);
    margin-bottom: 48px;
}

.demo-block {
    padding: 24px;
    border: 1px solid var(--grid-line);
}

/* Section 4: The Application */
.section-application {
    min-height: 140vh;
    padding-top: 64px;
}

/* Section 5: The Principle */
.section-principle {
    min-height: 80vh;
    padding-top: 64px;
    padding-bottom: 96px;
}

.principle-heading {
    font-family: 'DM Sans', sans-serif;
    font-weight: 700;
    font-size: clamp(1.5rem, 2.5vw, 2rem);
    letter-spacing: -0.02em;
    color: var(--text);
    max-width: 600px;
    margin-bottom: 64px;
    line-height: 1.3;
}

.principle-columns {
    display: flex;
    gap: var(--gutter);
    flex-wrap: wrap;
}

.principle-block {
    width: 240px;
    flex-shrink: 0;
}

.principle-title {
    font-family: 'DM Sans', sans-serif;
    font-weight: 700;
    font-size: 16px;
    color: var(--accent);
    margin-bottom: 8px;
}

/* Fade-in */
[data-fade] {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

[data-fade].visible {
    opacity: 1;
    transform: translateY(0);
}

/* Mobile */
@media (max-width: 768px) {
    body {
        padding-left: 0;
    }

    .left-rail {
        display: none;
    }

    .content-area {
        padding: 0 24px;
    }

    .section-equation {
        padding-left: 24px;
    }

    .principle-columns {
        flex-direction: column;
    }

    .principle-block {
        width: 100%;
    }

    .specimen-row {
        flex-direction: column;
        gap: 4px;
    }

    .specimen-label {
        min-width: auto;
    }
}
