/* Design Tokens */
:root {
    --bg-paper: #F5F0E8;
    --grid-line: #D6E4EE;
    --ink-dark: #1A1A1A;
    --ink-hand: #2C2C2C;
    --green-active: #1B4332;
    --amber-warn: #C97D10;
    --red-warn: #8B1A1A;
    --stamp-ink: #8B6B4A;

    --font-caveat: 'Caveat', cursive;
    --font-mono: 'IBM Plex Mono', monospace;
}

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

html, body {
    width: 100%;
    height: 100%;
    background: var(--bg-paper);
    font-family: var(--font-mono);
    color: var(--ink-dark);
    overflow: hidden;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Grid Texture Background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(0deg, transparent 24%, var(--grid-line) 25%, var(--grid-line) 26%, transparent 27%, transparent 74%, var(--grid-line) 75%, var(--grid-line) 76%, transparent 77%, transparent),
        linear-gradient(90deg, transparent 24%, var(--grid-line) 25%, var(--grid-line) 26%, transparent 27%, transparent 74%, var(--grid-line) 75%, var(--grid-line) 76%, transparent 77%, transparent);
    background-size: 20px 20px;
    opacity: 0.3;
    pointer-events: none;
    z-index: 0;
}

/* Intro Overlay */
.intro-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.intro-container {
    text-align: center;
    font-family: var(--font-mono);
}

#intro-text {
    min-height: 3rem;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 1.5rem;
    line-height: 1.5;
}

.intro-overlay.fade-out {
    animation: fadeOut 400ms ease-out forwards;
}

@keyframes fadeOut {
    to {
        opacity: 0;
        pointer-events: none;
    }
}

/* Logbook */
#logbook {
    position: relative;
    width: 1280px;
    height: 720px;
    background: var(--bg-paper);
    z-index: 1;
}

#logbook.hidden {
    display: none;
}

.logbook-spread {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 40px;
    gap: 0;
}

/* Header */
.logbook-header {
    display: flex;
    justify-content: flex-end;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.1em;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--ink-dark);
}

.header-title {
    text-transform: uppercase;
}

/* Pages Container */
.logbook-spread > .left-page,
.logbook-spread > .right-page {
    flex: 1;
    position: relative;
}

.left-page {
    display: flex;
    align-items: center;
    justify-content: center;
}

.right-page {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    overflow-y: auto;
    padding: 0 40px;
}

.right-page::-webkit-scrollbar {
    width: 4px;
}

.right-page::-webkit-scrollbar-track {
    background: transparent;
}

.right-page::-webkit-scrollbar-thumb {
    background: var(--ink-dark);
    border-radius: 2px;
}

/* Binding */
.binding {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--ink-dark);
    transform: translateX(-50%);
    box-shadow: -2px 0 3px rgba(0,0,0,0.05), 2px 0 3px rgba(0,0,0,0.05);
}

/* Map Container */
.map-container {
    width: 100%;
    height: 100%;
    max-width: 400px;
    max-height: 300px;
    position: relative;
}

.map-svg {
    width: 100%;
    height: 100%;
    cursor: none;
}

.map-dot {
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.map-dot.locked {
    opacity: 0.3;
    cursor: default;
}

.map-dot.ready {
    filter: drop-shadow(0 0 8px var(--green-active));
    animation: pulse 2s ease-in-out infinite;
}

.map-dot.connected {
    opacity: 1;
}

@keyframes pulse {
    0%, 100% {
        filter: drop-shadow(0 0 4px var(--green-active));
    }
    50% {
        filter: drop-shadow(0 0 12px var(--green-active));
    }
}

.map-dot:hover.ready {
    filter: drop-shadow(0 0 14px var(--green-active));
}

.map-label {
    font-family: var(--font-caveat);
    font-size: 1rem;
    font-weight: 400;
    fill: var(--ink-hand);
    text-anchor: middle;
    pointer-events: none;
}

.map-label.locked {
    opacity: 0.3;
}

/* Chapter Container */
.chapter-container {
    width: 100%;
    font-size: 0.9rem;
    line-height: 1.6;
    animation: fadeIn 200ms ease-out;
}

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

.chapter-header {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px dashed var(--ink-dark);
}

.chapter-leg {
    display: inline-block;
    margin-right: 20px;
}

.chapter-location {
    display: inline-block;
}

.chapter-date {
    display: block;
    font-size: 0.7rem;
    margin-top: 2px;
}

.chapter-sketch {
    width: 140px;
    height: 140px;
    margin: 20px 0 20px 0;
    border: 1px dashed var(--ink-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: rgba(255,255,255,0.5);
}

.chapter-sketch img,
.chapter-sketch svg {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chapter-sketch-placeholder {
    font-family: var(--font-caveat);
    font-size: 0.9rem;
    color: var(--ink-dark);
    opacity: 0.5;
    text-align: center;
    padding: 10px;
}

.chapter-body {
    font-family: var(--font-caveat);
    font-size: 1rem;
    line-height: 1.8;
    color: var(--ink-hand);
    margin: 20px 0;
    max-width: 400px;
}

.chapter-callout {
    border: 1px solid var(--ink-dark);
    padding: 15px;
    margin: 20px 0;
    font-family: var(--font-caveat);
    font-style: italic;
    font-size: 0.95rem;
    color: var(--ink-hand);
}

.chapter-stamp {
    font-family: var(--font-caveat);
    font-size: 2rem;
    font-weight: 700;
    color: var(--stamp-ink);
    opacity: 0.6;
    transform: rotate(-8deg);
    display: inline-block;
    margin-top: 30px;
    animation: stampBounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes stampBounce {
    0% {
        transform: rotate(-8deg) scale(0.5);
        opacity: 0;
    }
    50% {
        transform: rotate(-8deg) scale(1.1);
    }
    100% {
        transform: rotate(-8deg) scale(1);
        opacity: 0.6;
    }
}

.chapter-status {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    margin-top: 20px;
    margin-bottom: 20px;
}

.chapter-contact {
    font-family: var(--font-caveat);
    font-size: 0.9rem;
    color: var(--ink-hand);
    margin-top: 15px;
    opacity: 0.8;
}

.chapter-contact a {
    color: var(--green-active);
    text-decoration: none;
    border-bottom: 1px solid var(--green-active);
}

.chapter-contact a:hover {
    color: var(--amber-warn);
    border-bottom-color: var(--amber-warn);
}

/* Bottom Bar */
.bottom-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--ink-dark);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    height: 40px;
}

.dot-indicators {
    display: flex;
    gap: 10px;
}

.indicator {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    border: 1px solid var(--ink-dark);
    background: transparent;
    transition: background 0.3s ease;
}

.indicator.connected {
    background: var(--green-active);
    border-color: var(--green-active);
}

.hint-text {
    font-family: var(--font-caveat);
    font-size: 0.9rem;
    color: var(--ink-hand);
    opacity: 0.7;
}

/* Responsive: Tablet */
@media (max-width: 1279px) {
    #logbook {
        width: 100%;
        height: 100vh;
        padding: 20px;
    }

    .logbook-spread {
        padding: 20px;
    }

    .map-container {
        max-width: 300px;
        max-height: 225px;
    }

    .right-page {
        padding: 0 20px;
    }
}

/* Responsive: Mobile */
@media (max-width: 767px) {
    #logbook {
        width: 100%;
        height: 100vh;
    }

    .logbook-spread {
        flex-direction: column;
        padding: 15px;
    }

    .logbook-header {
        margin-bottom: 10px;
        font-size: 0.65rem;
    }

    .left-page,
    .right-page {
        width: 100%;
    }

    .left-page {
        height: 40vh;
        margin-bottom: 20px;
    }

    .right-page {
        height: 50vh;
        padding: 0 15px;
    }

    .binding {
        display: none;
    }

    .map-container {
        max-width: 100%;
        max-height: 100%;
    }

    .bottom-bar {
        margin-top: 10px;
        padding-top: 10px;
        gap: 10px;
        flex-direction: column;
        align-items: flex-start;
        height: auto;
    }

    .dot-indicators {
        width: 100%;
        justify-content: center;
    }

    .hint-text {
        font-size: 0.85rem;
    }
}
