:root {
    /* Warm paper / editorial theme */
    --bg: #f5f1eb;
    --paper: #fdfcfa;
    --panel: #f0ebe3;
    --panel-strong: #e8e2d9;
    --text: #1c1916;
    --muted: #5c564d;
    --line: #d4cfc4;
    --accent: #c45c26;
    --accent-soft: rgba(196, 92, 38, 0.12);
    --shadow: 0 2px 12px rgba(28, 25, 22, 0.06);
    --shadow-card: 0 4px 24px rgba(28, 25, 22, 0.08);
    --font-display: "DM Serif Display", Georgia, serif;
    --font-body: "DM Sans", system-ui, -apple-system, sans-serif;
}

html, body { height: 100%; }

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.6;
}

.page-scale {
    transform: none;
    transform-origin: top center;
    height: auto;
}

.main-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 20px 48px;
}

.site-header {
    border-bottom: 2px solid var(--accent);
    background: var(--paper);
    padding: 32px 0 0px;
}

.header-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

.kicker {
    margin: 0 0 6px 0;
    font-size: 11px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 600;
}

.title {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 2.25rem;
    letter-spacing: -0.02em;
    color: var(--text);
}

.subtitle {
    margin: 12px 0 0 0;
    color: var(--muted);
    max-width: 42ch;
    font-size: 0.95rem;
}

.viz-section {
    margin: 28px 0;
    padding: 24px 22px 22px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 4px;
    box-shadow: var(--shadow-card);
    text-align: left;
}

/* Dear Data story */
.story-intro {
    max-width: 70ch;
    margin: 0px 0;
    color: var(--muted);
    font-size: 0.90rem;
    line-height: 1.7;
}
.story-outro {
    max-width: 70ch;
    margin: 28px 0;
    color: var(--muted);
    font-size: 0.80rem;
    line-height: 1.7;
}


.story-outro {
    margin-top: 40px;
    padding-top: 24px;
    border-top: 1px solid var(--line);
    font-style: italic;
}
.postcard-label {
    margin: 0 0 8px 0;
    font-size: 10px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 600;
}
.story-card .viz-desc.story-caption {
    margin-bottom: 18px;
    color: var(--muted);
    line-height: 1.65;
}
.postcard {
    perspective: 1400px;
    overflow: hidden;
    width: 100%;
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
}
.postcard:hover {
    border-color: #c6bfb3;
    box-shadow: 0 10px 30px rgba(28, 25, 22, 0.12);
}
.postcard[open] {
    border-color: var(--accent);
    box-shadow: 0 14px 34px rgba(28, 25, 22, 0.16);
}
.postcard summary {
    list-style: none;
}
.postcard summary::-webkit-details-marker {
    display: none;
}
.postcard-prompt {
    position: relative;
    cursor: pointer;
    background: linear-gradient(180deg, rgba(253, 252, 250, 0.95) 0%, rgba(244, 238, 229, 0.95) 100%);
    background-size: cover;
    background-position: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 18px 18px 16px;
    margin: 0;
    height: 460px;
    min-height: 460px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    transform-origin: center center;
    backface-visibility: hidden;
    transition: transform 0.62s cubic-bezier(0.22, 0.61, 0.36, 1), opacity 0.35s ease, background-color 0.25s ease, border-color 0.25s ease;
}
.postcard:hover .postcard-prompt {
    border-color: #c6bfb3;
}
.postcard-prompt::before {
    content: "";
    position: absolute;
    left: 10px;
    right: 10px;
    top: 10px;
    height: 34px;
    background: linear-gradient(to bottom, #f3ece2 0%, #e6ddcf 100%);
    clip-path: polygon(0 0, 100% 0, 50% 100%);
    transform-origin: top center;
    transform: perspective(700px) rotateX(0deg);
    transition: transform 0.5s ease, opacity 0.5s ease;
    pointer-events: none;
    opacity: 0.95;
}
.postcard-prompt::after {
    content: "Flip postcard";
    position: absolute;
    right: 12px;
    top: 10px;
    border: 1px solid var(--line);
    background: var(--paper);
    border-radius: 999px;
    padding: 4px 10px;
    color: var(--accent);
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    transition: border-color 0.25s ease, background-color 0.25s ease, color 0.25s ease;
}
.postcard[open] .postcard-prompt::after {
    content: "Flip back";
    border-color: var(--accent);
    background: var(--accent-soft);
}
.postcard-prompt h2 {
    margin: 0 0 10px 0;
    position: relative;
    z-index: 1;
    max-width: calc(100% - 130px);
    font-size: 1.35rem;
}
.postcard-prompt .postcard-label {
    position: relative;
    z-index: 1;
}
.postcard-front {
    margin-top: 6px;
    border: 1px solid rgba(28, 25, 22, 0.18);
    border-radius: 6px;
    min-height: 0;
    background: rgba(255, 255, 255, 0.72);
    display: grid;
    grid-template-columns: 1.3fr auto 1fr;
    gap: 12px;
    padding: 12px;
    position: relative;
    z-index: 1;
    flex: 1 1 auto;
}
.postcard-front-message {
    color: #2f2a24;
    font-size: 0.93rem;
    line-height: 1.5;
    padding: 4px 4px 2px;
    display: flex;
    align-items: center;
}
.postcard-front-message p {
    margin: 0;
}
.postcard-front-divider {
    width: 1px;
    background: rgba(28, 25, 22, 0.2);
}
.postcard-front-stamp {
    display: grid;
    grid-template-rows: 1fr auto;
    align-items: center;
    justify-items: center;
    gap: 10px;
    min-width: 140px;
}
.postcard-front-photo {
    width: clamp(170px, 34vw, 230px);
    aspect-ratio: 4 / 3;
    object-fit: cover;
    /* Stamp-like perforated edge */
    clip-path: polygon(
        6% 0%, 10% 2%, 14% 0%, 18% 2%, 22% 0%, 26% 2%, 30% 0%, 34% 2%, 38% 0%, 42% 2%, 46% 0%, 50% 2%,
        54% 0%, 58% 2%, 62% 0%, 66% 2%, 70% 0%, 74% 2%, 78% 0%, 82% 2%, 86% 0%, 90% 2%, 94% 0%, 100% 6%,
        98% 10%, 100% 14%, 98% 18%, 100% 22%, 98% 26%, 100% 30%, 98% 34%, 100% 38%, 98% 42%, 100% 46%,
        98% 50%, 100% 54%, 98% 58%, 100% 62%, 98% 66%, 100% 70%, 98% 74%, 100% 78%, 98% 82%, 100% 86%,
        98% 90%, 100% 94%, 94% 100%, 90% 98%, 86% 100%, 82% 98%, 78% 100%, 74% 98%, 70% 100%, 66% 98%,
        62% 100%, 58% 98%, 54% 100%, 50% 98%, 46% 100%, 42% 98%, 38% 100%, 34% 98%, 30% 100%, 26% 98%,
        22% 100%, 18% 98%, 14% 100%, 10% 98%, 6% 100%, 0% 94%, 2% 90%, 0% 86%, 2% 82%, 0% 78%, 2% 74%,
        0% 70%, 2% 66%, 0% 62%, 2% 58%, 0% 54%, 2% 50%, 0% 46%, 2% 42%, 0% 38%, 2% 34%, 0% 30%, 2% 26%,
        0% 22%, 2% 18%, 0% 14%, 2% 10%, 0% 6%
    );
    border: 2px solid rgba(95, 83, 71, 0.35);
    display: block;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.postcard-front-caption {
    margin: 0;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    color: var(--muted);
    text-transform: uppercase;
}

/* Keep postcard front legible on narrow screens */
@media (max-width: 720px) {
    .postcard-prompt {
        height: 420px;
        min-height: 420px;
    }
    .postcard-prompt h2 {
        max-width: 100%;
        font-size: 1.2rem;
    }
    .postcard-front {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .postcard-front-divider {
        display: none;
    }
    .postcard-front-stamp {
        justify-items: start;
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        row-gap: 8px;
        min-width: 0;
    }
    .postcard-front-photo {
        width: min(210px, 75vw);
    }
    .postcard-front-caption {
        grid-column: 1 / -1;
    }
}
.postcard-body {
    border: 1px solid rgba(28, 25, 22, 0.18);
    border-radius: 6px;
    min-height: 0;
    background: rgba(255, 255, 255, 0.72);
    padding: 8px 12px;
}
.postcard-content {
    position: relative;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transform-origin: center center;
    transform: rotateY(-180deg) scale(0.98);
    backface-visibility: hidden;
    margin-top: 0;
    transition: max-height 0.62s ease, opacity 0.35s ease, transform 0.62s cubic-bezier(0.22, 0.61, 0.36, 1), margin-top 0.3s ease;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 18px 18px 16px;
    background: linear-gradient(180deg, rgba(253, 252, 250, 0.95) 0%, rgba(244, 238, 229, 0.95) 100%);
}
.postcard-content::before {
    content: "";
    position: absolute;
    left: 10px;
    right: 10px;
    top: 10px;
    height: 34px;
    background: linear-gradient(to bottom, #f3ece2 0%, #e6ddcf 100%);
    clip-path: polygon(0 0, 100% 0, 50% 100%);
    transform-origin: top center;
    transform: perspective(700px) rotateX(0deg);
    transition: transform 0.5s ease, opacity 0.5s ease;
    pointer-events: none;
    opacity: 0.95;
}
.postcard[open] .postcard-prompt::before {
    transform: perspective(700px) rotateX(165deg);
    opacity: 0.28;
}
.postcard[open] .postcard-prompt {
    transform: rotateY(180deg) scale(0.96);
    opacity: 0;
    height: 0;
    max-height: 0;
    min-height: 0;
    margin: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
    border-width: 0;
}
.postcard[open] .postcard-content {
    max-height: 3200px;
    opacity: 1;
    transform: rotateY(0deg) scale(1);
    margin-top: 2px;
}
.postcard[open] .postcard-content::before {
    opacity: 1;
}

.postcard-close {
    margin: 2px 0 12px;
    padding: 5px 11px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--paper);
    color: var(--accent);
    font-size: 0.74rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    font-weight: 600;
    cursor: pointer;
}
.postcard-close:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

@media (prefers-reduced-motion: reduce) {
    .postcard,
    .postcard-prompt,
    .postcard-prompt::before,
    .postcard-prompt::after,
    .postcard-content {
        transition: none;
    }
    .postcard[open] .postcard-prompt,
    .postcard[open] .postcard-content {
        transform: none;
    }
}
.viz-section h2 {
    margin: 0 0 10px 0;
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 400;
    letter-spacing: -0.01em;
    color: var(--text);
}

.viz-figure { margin: 0; }

.viz-img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 4px;
    border: 1px solid var(--line);
    background: var(--panel);
}

.viz-block {
    padding: 16px 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.viz-desc {
    margin: 14px 0 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.viz-note {
    margin: 10px 0 0 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.viz-tooltip {
    position: absolute;
    display: none;
    background: var(--text);
    border: 1px solid var(--line);
    color: var(--paper);
    padding: 10px 14px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    pointer-events: none;
    z-index: 9999;
    box-shadow: var(--shadow-card);
}

.viz-tooltip strong {
    color: #e8d5c4;
}

/* ========== Globe visualization (plane crashes heat map) ========== */
.globe-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 25px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    padding: 16px;
    background: var(--panel-strong);
    border-radius: 12px;
    border: 1px solid var(--line);
}
.globe-control-group {
    display: flex;
    align-items: center;
    gap: 12px;
}
.globe-control-group label {
    font-weight: 600;
    font-size: 0.9em;
    color: var(--muted);
}
.globe-viz input[type="range"] {
    width: 200px;
    height: 6px;
    border-radius: 3px;
    background: var(--line);
    -webkit-appearance: none;
    appearance: none;
}
.globe-viz input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--paper);
    box-shadow: var(--shadow);
}
.globe-viz #year-display {
    font-weight: 700;
    min-width: 50px;
    text-align: center;
    background: var(--panel-strong);
    color: var(--text);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 14px;
    border: 1px solid var(--line);
}
.globe-viz .globe-control-group button {
    padding: 10px 20px;
    background: var(--paper);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
}
.globe-viz .globe-control-group button:hover {
    background: var(--panel-strong);
    border-color: var(--accent);
    color: var(--accent);
}
.globe-viz .globe-stats {
    text-align: center;
    margin-bottom: 16px;
    font-size: 1em;
    color: var(--muted);
}
.globe-viz .globe-stats #crash-count {
    color: var(--accent);
    font-weight: 700;
}

/* Globe + timeline side-by-side postcard */
.globe-timeline-card .globe-timeline-row {
    display: flex;
    gap: 20px;
    margin-top: 18px;
    flex-wrap: wrap;
}
.globe-timeline-card .globe-column,
.globe-timeline-card .timeline-column {
    flex: 1 1 280px;
    min-width: 0;
}
.globe-timeline-card .timeline-column {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}
.globe-timeline-card #timeline-viz svg {
    width: 100%;
    height: auto;
}

.globe-timeline-card .timeline-panel {
    background: var(--panel);
    border-radius: 8px;
    border: 1px solid var(--line);
    padding: 16px 18px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
}

/* Shared row for crash detail boxes */
.globe-timeline-card .crash-summary-row {
    display: flex;
    gap: 20px;
    margin-top: 18px;
    flex-wrap: wrap;
}
.globe-timeline-card .crash-summary-column {
    flex: 1 1 280px;
    min-width: 0;
}

/* Timeline info box (most fatal crash per year) */
.globe-viz .crash-info-box,
.timeline-info-box {
    width: 100%;
    max-width: 100%;
    margin-top: 20px;
    padding: 20px 24px;
    background: var(--panel);
    border-radius: 4px;
    border: 1px solid var(--line);
    min-height: 110px;
    box-sizing: border-box;
}
.timeline-info-box {
    box-shadow: var(--shadow);
}
.timeline-info-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.timeline-info-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.timeline-info-toggle {
    padding: 4px 10px;
    font-size: 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--paper);
    color: var(--muted);
    cursor: pointer;
}
.timeline-info-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.timeline-info-box.collapsed .timeline-info-content {
    display: none;
}
.timeline-info-content {
    color: var(--text);
    font-size: 0.9rem;
}
.timeline-info-placeholder {
    margin: 0;
    font-style: italic;
    color: var(--muted);
}
.timeline-crash-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}
.timeline-crash-main {
    grid-column: 1 / -1;
    font-weight: 600;
}
.timeline-crash-meta {
    font-size: 0.9rem;
}
.timeline-crash-label {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.75rem;
    color: var(--muted);
}
.timeline-crash-value {
    font-size: 0.95rem;
}
.timeline-crash-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.timeline-crash-actions button {
    padding: 6px 10px;
    font-size: 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--paper);
    color: var(--muted);
    cursor: pointer;
}
.timeline-crash-actions button:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.globe-viz #legend.globe-legend {
    margin-bottom: 20px;
    padding: 14px 20px;
    background: var(--panel);
    border-radius: 8px;
    border: 1px solid var(--line);
    text-align: center;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
}
.globe-viz .legend-title {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.globe-viz .legend-items {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}
.globe-viz .legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8em;
    color: var(--muted);
}
.globe-viz .legend-color {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid var(--line);
}
.globe-viz .legend-gradient {
    display: inline-block;
    width: 180px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid var(--line);
}
.globe-viz #globe-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--panel);
    border-radius: 8px;
    padding: 24px;
    border: 1px solid var(--line);
    margin: 0 auto;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
}
.globe-viz #globe-container svg,
.globe-viz #globe-container canvas {
    max-width: 100%;
}
.globe-viz #globe-container svg {
    position: relative;
    z-index: 1;
    cursor: grab;
}
.globe-viz #globe-container canvas {
    position: absolute;
    top: 24px;
    left: 24px;
    z-index: 2;
    cursor: grab;
    pointer-events: auto;
}
.globe-viz #auto-rotate-btn {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    padding: 10px 16px;
    background: var(--panel-strong);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
}
.globe-viz #auto-rotate-btn:hover {
    background: var(--panel-strong);
    color: var(--accent);
    border-color: var(--accent);
}
.globe-viz .crash-info-box {
    position: relative;
}
.globe-viz .crash-info-box.active {
    border-color: var(--accent);
    background: var(--panel);
}
.globe-viz .info-box-content { color: var(--text); }
.globe-viz .info-placeholder {
    text-align: center;
    color: var(--muted);
    font-style: italic;
    margin: 0;
}
.globe-viz .crash-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}
.globe-viz .crash-close {
    position: absolute;
    top: 10px;
    right: 12px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 4px;
}
.globe-viz .crash-close:hover {
    color: var(--accent);
}
.globe-viz .crash-detail-item { display: flex; flex-direction: column; }
.globe-viz .crash-detail-label {
    font-size: 0.8em;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
}
.globe-viz .crash-detail-value { font-size: 1em; color: var(--text); }
.globe-viz .crash-detail-value.highlight { color: var(--accent); font-weight: 700; }
.globe-viz .crash-title {
    grid-column: 1 / -1;
    font-size: 1.2em;
    font-weight: 700;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line);
}
.globe-viz .crash-navigation {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.globe-viz .nav-button {
    padding: 8px 16px;
    background: var(--panel-strong);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
}
.globe-viz .nav-button:hover:not(:disabled) {
    background: var(--panel-strong);
    border-color: var(--accent);
    color: var(--accent);
}
.globe-viz .nav-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.globe-viz .nav-info { font-weight: 600; color: var(--muted); font-size: 0.9em; }

.axis-label {
    color: var(--text);
    fill: var(--text);
}

/* ========== Airplane Survivor Heatmap ========== */
#airplane-heatmap {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding-top: 0;
}

/* ========== Timeline Click and Drag ========== */
#timeline-viz {
    user-select: none;
}

#year-display {
    width: 2.5em;
    display: inline-block;
    text-align: right;
}

#play-pause {
    min-width: 4em;
    text-align: center;
}

#reset {
    min-width: 4em;
    text-align: center;
}

#globe-speed-slider {
    min-width: 20em;
}

/* ========== Plane Animation Reset ========== */
#reset-plane {
    position: absolute;
    bottom: 20px;
    right: 20px;

    /* Aesthetics */
    padding: 10px 20px;
    background: #ffffff;
    border: 1.5px solid #333;
    color: #333;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    border-radius: 25px; /* Rounded pill shape looks great on postcards */
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);

    /* Animation state managed by JS */
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s ease;
}

#reset-plane:hover {
    background: #333;
    color: #fff;
    transform: translateY(-2px); /* Subtle lift on hover */
    box-shadow: 0 6px 15px rgba(0,0,0,0.15);
}

#reset-plane:active {
    transform: translateY(0);
}
