/* ========================================
   daitoua.com — Archival Design System
   ======================================== */

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

/* CSS Variables */
:root {
    --aged-parchment: #f5efe3;
    --walnut-shadow: #2c241c;
    --sumi-ink: #1c1a17;
    --faded-seal: #7a6b55;
    --vermillion: #8b3a2a;
    --brass: #c4a672;
    --candle-amber: #d4a03c;
    --map-blue: #3d5a80;
    --lamp-black: rgba(28, 26, 23, 0.08);
    --sidebar-width: 280px;
    --topbar-height: 64px;
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--aged-parchment);
    color: var(--sumi-ink);
    font-family: 'Source Serif 4', 'Noto Serif JP', serif;
    font-size: 17px;
    line-height: 1.75;
    overflow-x: hidden;
}

/* Paper grain texture */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    opacity: 0.04;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-size: 200px 200px;
}

/* Vignette overlay */
#vignette {
    position: fixed;
    inset: 0;
    z-index: 100;
    pointer-events: none;
    box-shadow: inset 0 0 150px rgba(44, 36, 28, 0.15);
}

/* ========================================
   Cover Page
   ======================================== */
#cover {
    position: relative;
    width: 100%;
    height: 100vh;
    background: var(--walnut-shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    overflow: hidden;
}

#candle-container {
    position: relative;
    opacity: 0;
    animation: fadeIn 0.8s 0.6s ease forwards;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

#candle-flame {
    animation: flicker 2s ease-in-out infinite;
    filter: drop-shadow(0 0 8px rgba(212, 160, 60, 0.6));
}

@keyframes flicker {
    0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.9; }
    25% { transform: scale(0.95) rotate(-1deg); opacity: 0.85; }
    50% { transform: scale(1.02) rotate(0.5deg); opacity: 1; }
    75% { transform: scale(0.92) rotate(-0.5deg); opacity: 0.88; }
}

#candle-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(212, 160, 60, 0.05) 0%, transparent 100%);
    transform: translate(-50%, -50%);
    animation: glowExpand 2.5s 1s ease-out forwards;
    pointer-events: none;
}

@keyframes glowExpand {
    to {
        width: 600px;
        height: 600px;
    }
}

#cover-title {
    display: flex;
    gap: 16px;
    margin-top: 32px;
    opacity: 0;
    animation: fadeIn 1.2s 1.8s ease forwards;
}

.title-kanji {
    opacity: 0;
}

.title-kanji.visible {
    animation: kanjiReveal 0.8s ease forwards;
}

@keyframes kanjiReveal {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

#cover-subtitle {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 18px;
    letter-spacing: 0.3em;
    color: var(--aged-parchment);
    opacity: 0;
    animation: fadeIn 1s 3s ease forwards;
    margin-top: 24px;
}

#cover-subtitle.visible {
    opacity: 0.4;
}

#scroll-arrow {
    position: absolute;
    bottom: 48px;
    opacity: 0;
    animation: fadeIn 0.6s 4.5s ease forwards, pulse 1.5s 5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.8; }
}

/* ========================================
   Timeline Bar
   ======================================== */
#timeline-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--walnut-shadow);
    z-index: 50;
    display: flex;
    align-items: center;
    padding: 0 24px;
    transform: translateY(-100%);
    transition: transform 0.4s ease;
    border-bottom: 1px solid rgba(196, 166, 114, 0.2);
}

#timeline-bar.visible {
    transform: translateY(0);
}

#timeline-inner {
    width: 100%;
    position: relative;
    overflow: visible;
}

#timeline-svg {
    width: 100%;
    height: 40px;
    cursor: pointer;
}

#timeline-svg circle {
    transition: fill 0.3s, r 0.3s;
    cursor: pointer;
}

#timeline-svg circle:hover,
#timeline-svg circle.active {
    fill: var(--candle-amber);
    r: 6;
}

#timeline-tooltip {
    position: absolute;
    top: 42px;
    background: var(--sumi-ink);
    color: var(--aged-parchment);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 3px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

#timeline-tooltip.visible {
    opacity: 1;
}

/* ========================================
   Main Layout
   ======================================== */
#main-layout {
    display: flex;
    min-height: 100vh;
    position: relative;
}

/* Sidebar */
#sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-height);
    width: var(--sidebar-width);
    height: calc(100vh - var(--topbar-height));
    background: var(--walnut-shadow);
    padding: 32px 16px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.4s ease;
    overflow-y: auto;
    border-right: 1px solid rgba(196, 166, 114, 0.15);
}

#sidebar.visible {
    transform: translateX(0);
}

.chapter-link {
    padding: 12px 16px;
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: border-color 0.3s, background 0.3s;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chapter-link:hover {
    background: rgba(196, 166, 114, 0.08);
}

.chapter-link.active {
    border-left-color: var(--vermillion);
}

.chapter-num {
    font-family: 'Noto Serif JP', serif;
    font-size: 28px;
    font-weight: 700;
    color: var(--brass);
    transition: color 0.4s, transform 0.4s;
    display: inline-block;
}

.chapter-link.active .chapter-num {
    color: var(--vermillion);
    transform: scale(1.05);
}

.chapter-title {
    font-family: 'Noto Sans JP', sans-serif;
    font-weight: 500;
    font-size: 14px;
    writing-mode: horizontal-tb;
    color: var(--aged-parchment);
    letter-spacing: 0.15em;
    opacity: 0.8;
}

.chapter-en {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 11px;
    color: var(--faded-seal);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* Mobile hamburger */
#sidebar-toggle {
    display: none;
    position: fixed;
    top: 74px;
    left: 12px;
    z-index: 45;
    background: var(--walnut-shadow);
    border: 1px solid rgba(196, 166, 114, 0.3);
    border-radius: 4px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px;
}

#sidebar-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--brass);
    transition: transform 0.3s;
}

/* Content area */
#content {
    margin-left: var(--sidebar-width);
    padding-top: calc(var(--topbar-height) + 48px);
    padding-left: 48px;
    padding-right: 48px;
    flex: 1;
    position: relative;
    background: radial-gradient(circle at var(--mouse-x) var(--mouse-y), rgba(212, 160, 60, 0.06) 0%, transparent 250px);
}

/* ========================================
   Chapters
   ======================================== */
.chapter {
    position: relative;
    min-height: 80vh;
    padding-bottom: 64px;
    margin-bottom: 48px;
}

.topo-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.topo-bg svg {
    width: 100%;
    height: 100%;
}

.chapter-header {
    position: relative;
    z-index: 1;
    margin-bottom: 40px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(196, 166, 114, 0.3);
}

.chapter-heading {
    font-family: 'Space Grotesk', sans-serif;
    font-size: clamp(2.5rem, 5vw, 4.5rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--sumi-ink);
    line-height: 1.1;
}

.chapter-date {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
    color: var(--faded-seal);
    margin-top: 8px;
    display: block;
}

/* ========================================
   Document Panels
   ======================================== */
.document-panel {
    position: relative;
    z-index: 1;
    background: var(--aged-parchment);
    border: 1px solid var(--brass);
    border-left: 3px solid var(--vermillion);
    padding: 32px 36px;
    margin-bottom: 48px;
    box-shadow: 0 2px 12px var(--lamp-black);
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s cubic-bezier(0.25, 0.1, 0.25, 1.0), transform 0.8s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.document-panel.visible {
    opacity: 1;
    transform: translateY(0);
}

.document-panel h3 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--sumi-ink);
    margin-bottom: 16px;
    letter-spacing: -0.01em;
}

.document-panel p {
    margin-bottom: 16px;
    color: var(--sumi-ink);
}

.document-panel p:last-child {
    margin-bottom: 0;
}

.annotation {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
    color: var(--faded-seal);
    border-top: 1px solid rgba(196, 166, 114, 0.3);
    padding-top: 12px;
    margin-top: 20px;
}

/* Panel corner ornaments */
.panel-corner {
    position: absolute;
    width: 16px;
    height: 16px;
    pointer-events: none;
}

.panel-corner::before,
.panel-corner::after {
    content: '';
    position: absolute;
    background: var(--brass);
    opacity: 0.4;
}

.panel-corner.tl { top: 4px; left: 4px; }
.panel-corner.tl::before { width: 12px; height: 1px; top: 0; left: 0; }
.panel-corner.tl::after { width: 1px; height: 12px; top: 0; left: 0; }

.panel-corner.tr { top: 4px; right: 4px; }
.panel-corner.tr::before { width: 12px; height: 1px; top: 0; right: 0; }
.panel-corner.tr::after { width: 1px; height: 12px; top: 0; right: 0; }

.panel-corner.bl { bottom: 4px; left: 4px; }
.panel-corner.bl::before { width: 12px; height: 1px; bottom: 0; left: 0; }
.panel-corner.bl::after { width: 1px; height: 12px; bottom: 0; left: 0; }

.panel-corner.br { bottom: 4px; right: 4px; }
.panel-corner.br::before { width: 12px; height: 1px; bottom: 0; right: 0; }
.panel-corner.br::after { width: 1px; height: 12px; bottom: 0; right: 0; }

/* Bibliography */
.bibliography {
    border-left-color: var(--brass);
}

.bib-entry {
    font-size: 15px;
    line-height: 1.6;
    padding-left: 24px;
    text-indent: -24px;
    color: var(--sumi-ink);
}

.bib-entry em {
    font-style: italic;
}

/* ========================================
   SVG Elements
   ======================================== */
.wave-divider {
    display: block;
    width: 100%;
    max-width: 600px;
    height: 30px;
    margin: 32px auto;
    position: relative;
    z-index: 1;
}

.wave-divider path {
    transition: stroke-dashoffset 1.8s ease-in-out;
}

.map-route {
    display: block;
    width: 100%;
    max-width: 600px;
    height: auto;
    margin: 24px auto;
    position: relative;
    z-index: 1;
}

.map-route polyline {
    transition: stroke-dashoffset 2.5s ease-in-out;
}

/* Seal stamps */
.seal-stamp {
    display: flex;
    justify-content: center;
    margin: 40px auto 24px;
    position: relative;
    z-index: 1;
}

.seal-stamp circle {
    transition: stroke-dashoffset 0.8s ease-in-out;
}

.seal-text {
    opacity: 0;
    transition: opacity 0.6s 0.4s ease;
}

.seal-stamp.visible .seal-text {
    opacity: 1;
}

/* End spacer */
#end-spacer {
    height: 200px;
}

/* Diamond border pattern */
.chapter-header::after {
    content: '◇ ◇ ◇ ◇ ◇';
    display: block;
    font-size: 8px;
    letter-spacing: 8px;
    color: var(--brass);
    opacity: 0.3;
    margin-top: 12px;
    text-align: center;
}

/* ========================================
   Links
   ======================================== */
a {
    color: var(--map-blue);
    text-decoration: none;
    border-bottom: 1px solid rgba(61, 90, 128, 0.3);
    transition: border-color 0.3s;
}

a:hover {
    border-bottom-color: var(--map-blue);
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 260px;
    }

    #sidebar-toggle {
        display: flex;
    }

    #sidebar {
        transform: translateX(-100%);
    }

    #sidebar.open {
        transform: translateX(0);
    }

    #sidebar.visible {
        transform: translateX(-100%);
    }

    #sidebar.visible.open {
        transform: translateX(0);
    }

    #content {
        margin-left: 0;
        padding: calc(var(--topbar-height) + 48px) 16px 0;
    }

    .document-panel {
        padding: 24px 20px;
    }

    .chapter-heading {
        font-size: clamp(1.8rem, 5vw, 3rem);
    }

    #timeline-inner {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    #timeline-svg {
        min-width: 600px;
    }
}
