/* Reset and Base */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary: #a8c6e0;
    --blue: #3498db;
    --red: #e74c3c;
    --bg: #1a1a2e;
    --card-bg: #16213e;
    --text: #e0e0e0;
    --text-light: #8a8fa8;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

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

body {
    font-family: 'Courier Prime', 'Courier New', monospace;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    height: 100dvh;
}

/* Header */
header {
    background: var(--card-bg);
    color: white;
    padding: 2.5rem 2rem;
    padding-top: 20dvh;
    text-align: center;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    z-index: 100;
    transition: opacity 0.6s ease;
}

/* Exit page */
#exit-page {
    background: rgba(22, 33, 62, 0.75);
    color: white;
    padding: 2.5rem 2rem;
    text-align: center;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.6s ease;
}

header h1 { font-size: 2.5rem; margin-bottom: 0.3rem; }
.subtitle { font-size: 1.1rem; opacity: 0.85; }

.header-text {
    position: relative;
    z-index: 1;
}

#bg-map {
    position: fixed;
    opacity: 0;
    z-index: 101;
    pointer-events: none;
    transition: opacity 0.5s;
}


/* Main */
main { margin: 0; padding: 0; }

section {
    background: var(--card-bg);
    margin: 0;
    padding: 1.5rem 2rem;
    border-radius: 0;
    box-shadow: none;
    scroll-snap-align: start;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

section > * {
    max-width: 1400px;
    width: 100%;
}


section h2 {
    color: var(--primary);
    margin-bottom: 1rem;
    font-size: 1.3rem;
    border-bottom: 2px solid var(--blue);
    padding-bottom: 0.4rem;
}

/* Tooltip */
.tooltip {
    position: absolute;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    border-radius: 6px;
    pointer-events: none;
    font-size: 13px;
    line-height: 1.5;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 100;
}

/* Unified World Map */
#world-visualization {
    position: relative;
}

#world-description {
    color: var(--text-light);
    font-size: 0.95rem;
    text-align: center;
    margin-bottom: 1rem;
}

#world-container {
    display: flex;
    justify-content: center;
}

#world-svg {
    width: 100%;
    max-width: 1200px;
    height: auto;
    aspect-ratio: 960 / 500;
}

.country {
    stroke: rgba(52, 152, 219, 0.3);
    cursor: pointer;
}

.country-hover {
    stroke: #e0e0e0;
    stroke-width: 0.8;
    opacity: 0.85;
}

.country-border {
    fill: none;
    stroke: rgba(52, 152, 219, 0.3);
    pointer-events: none;
}

#slider-wrapper {
    position: relative;
    height: 2.5rem;
    margin-bottom: 0.5rem;
}

#world-year-controls, #world-trend-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.range-slider {
    position: relative;
    width: 400px;
    max-width: 50vw;
    height: 20px;
    display: flex;
    align-items: center;
}

.range-slider input[type="range"] {
    position: absolute;
    left: 0;
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: transparent;
    pointer-events: none;
    outline: none;
    margin: 0;
    padding: 0;
}

.range-slider input[type="range"]:first-child {
    background: rgba(52, 152, 219, 0.3);
    border-radius: 2px;
}

.range-slider input[type="range"]::-moz-range-track {
    height: 4px;
    border-radius: 2px;
}

.range-slider input[type="range"]:first-child::-moz-range-track {
    background: rgba(52, 152, 219, 0.3);
}

.range-slider input[type="range"]:last-child::-moz-range-track {
    background: transparent;
}

.range-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
}

.range-slider input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
}

#world-year-slider {
    width: 400px;
    max-width: 50vw;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: rgba(52, 152, 219, 0.3);
    border-radius: 2px;
    outline: none;
}

#world-year-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

#world-year-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

#world-year-slider::-moz-range-track {
    height: 4px;
    background: rgba(52, 152, 219, 0.3);
    border-radius: 2px;
}

#world-year-label, #trend-range-label {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
    width: 130px;
    text-align: left;
    white-space: nowrap;
}

#world-tooltip {
    z-index: 200;
    max-width: 320px;
}

#world-tooltip .headline-line {
    border-top: 1px solid #3a4565;
    margin: 6px 0;
}

#world-tooltip .headline-text {
    display: block;
    font-size: 12px;
    color: #c8cdd8;
    font-style: italic;
    line-height: 1.4;
    min-height: 1.4em;
}

/* Connection arcs */
.connection-arc {
    stroke: rgba(224, 224, 224, 0.5);
    stroke-linecap: round;
}

.country-selected {
    stroke: #e0e0e0 !important;
    stroke-width: 2 !important;
}

/* Mode indicator dots */
.mode-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
    position: relative;
    z-index: 160;
    opacity: 0;
    transition: opacity 0.3s;
}

.mode-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2a3555;
    transition: background 0.3s;
}

.mode-dot.active {
    background: var(--blue);
}

/* Connection info panel */
#connection-panel {
    position: absolute;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    padding: 14px 18px;
    max-width: 300px;
    font-size: 14px;
    z-index: 150;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 10px;
    line-height: 1.4;
    color: var(--primary);
}

.panel-header button {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-light);
    padding: 0;
    line-height: 1;
}

.panel-header button:hover {
    color: var(--text);
}

.panel-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.panel-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
    border-bottom: 1px solid #2a3555;
}

.panel-rank {
    color: var(--text);
    min-width: 20px;
}

.panel-name {
    flex: 1;
    color: #fff;
}

.panel-spark {
    flex-shrink: 0;
}

.panel-count {
    color: #5bb8f5;
    font-weight: 700;
    min-width: 45px;
    text-align: right;
}

/* US City Bubble Map (inside map-stack) */
.us-state {
    stroke: rgba(52, 152, 219, 0.3);
}

.us-state-border {
    fill: none;
    stroke: rgba(52, 152, 219, 0.3);
    stroke-width: 0.5;
    pointer-events: none;
}

#precision-toggle {
    position: absolute;
    bottom: 50px;
    right: 10px;
    z-index: 160;
    background: #2a3555;
    color: var(--text-light);
    border: 1px solid rgba(52, 152, 219, 0.3);
    border-radius: 16px;
    padding: 4px 12px;
    font-family: 'Courier Prime', monospace;
    font-size: 11px;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.2s, color 0.2s;
}

#precision-toggle.active {
    background: var(--blue);
    color: white;
    border-color: var(--blue);
}

.city-bubble {
    cursor: pointer;
    transition: opacity 0.15s;
}

#bubble-legend-container {
    display: flex;
    justify-content: center;
    margin-top: 10px;
}

#bubble-tooltip {
    z-index: 200;
    max-width: 300px;
}

/* Word Count by Region Map */
#wordcount-visualization {
    position: relative;
}

#wordcount-description {
    color: var(--text-light);
    font-size: 0.95rem;
    text-align: center;
    margin-bottom: 1rem;
}

#wordcount-container {
    display: flex;
    justify-content: center;
    background: #1e2a45;
    border-radius: var(--radius);
    padding: 0.5rem;
}

#wordcount-svg {
    width: 100%;
    max-width: 1100px;
    height: auto;
    background: #1e2a45;
    border: 1px solid #2a3555;
    border-radius: var(--radius);
}

#wordcount-tooltip {
    z-index: 200;
}

/* Bar Chart Race */
#barrace-description {
    color: var(--text-light);
    font-size: 0.95rem;
    text-align: center;
    margin-bottom: 1rem;
}

#barrace-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-bottom: 1rem;
}

#barrace-slider {
    width: 400px;
    max-width: 60%;
    accent-color: var(--blue);
    cursor: pointer;
}

#barrace-year-label {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
    min-width: 50px;
}

#barrace-container {
    display: flex;
    justify-content: center;
    background: #1e2a45;
    border-radius: var(--radius);
    padding: 0.5rem;
}

#barrace-svg {
    width: 100%;
    max-width: 1100px;
    height: auto;
    background: #1e2a45;
    border: 1px solid #2a3555;
    border-radius: var(--radius);
}

.barrace-year {
    font-size: 72px;
    font-weight: 800;
    fill: #2a3555;
    pointer-events: none;
}

.barrace-x-axis text {
    font-size: 11px;
    fill: var(--text-light);
}

.barrace-x-axis line,
.barrace-x-axis path {
    stroke: #2a3555;
}

.bar-label {
    font-size: 13px;
    font-weight: 600;
    fill: var(--text);
}

.bar-value {
    font-size: 12px;
    fill: var(--text-light);
    font-weight: 500;
}

.bar-rect {
    opacity: 0.85;
}

/* Typewriter effect */
.typewriter {
    visibility: hidden;
}

.typewriter.typing {
    visibility: visible;
}

.typewriter-cursor {
    display: inline-block;
    width: 2px;
    background: var(--primary);
    margin-left: 2px;
    animation: blink 0.6s step-end infinite;
    vertical-align: text-bottom;
}

header h1 .typewriter-cursor {
    height: 2.5rem;
}

header .subtitle .typewriter-cursor {
    height: 1.1rem;
}

section h2 .typewriter-cursor {
    height: 1.3rem;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* Touch-action for map SVG */
#world-svg { touch-action: none; }
@media (max-width: 768px) {
    #world-svg { touch-action: pan-x; }
}
.mode-dot { touch-action: manipulation; }
#world-year-slider { touch-action: manipulation; }
.range-slider input[type="range"] { touch-action: manipulation; }

/* Responsive */
@media (max-width: 768px) {
    header h1 { font-size: 1.8rem; }
    header { padding-top: 15dvh; }
    .subtitle { font-size: 0.9rem; }
    main { padding: 0; }
    section { padding: 0.8rem 1rem; }
    section h2 { font-size: 1.1rem; }
    #world-description { font-size: 0.8rem; margin-bottom: 0.5rem; min-height: 4em; }
    #world-visualization h2 { min-height: 3.2em; }

    /* Section: push title to top, dots to bottom */
    section {
        padding: 0;
        justify-content: space-between;
    }
    section h2 {
        padding: 0.8rem 1rem 0.2rem;
        margin-bottom: 0;
        font-size: 1rem;
    }
    #world-description {
        padding: 0.2rem 1rem 0.4rem;
        margin-bottom: 0;
        min-height: 0;
        font-size: 0.8rem;
        line-height: 1.4;
    }
    #slider-wrapper {
        margin: 0.3rem 0;
    }
    .range-slider {
        width: 100%;
        max-width: 60vw;
    }
    #world-visualization h2 { min-height: 0; }

    /* Map: horizontal scroll container */
    #world-container {
        margin: 0;
        overflow-x: scroll;
        overflow-y: hidden;
        flex: 1;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    #world-container::-webkit-scrollbar { display: none; }
    #world-svg {
        width: auto;
        max-width: none;
        height: 72dvh;
        aspect-ratio: 960 / 500;
        flex-shrink: 0;
    }

    /* Dots at bottom edge */
    .mode-dots { margin: 0; padding: 6px 0; }

    /* Mode dots: bigger tap targets */
    .mode-dots { gap: 12px; padding: 8px 0; }
    .mode-dot { width: 16px; height: 16px; }

    /* Sliders: uniform style on mobile */
    #slider-wrapper {
        padding: 0 1rem;
        display: flex;
        justify-content: center;
    }
    #world-year-controls, #world-trend-controls {
        justify-content: center;
    }
    #world-year-slider, .range-slider input[type="range"] {
        height: 3px;
    }
    #world-year-slider { width: 100%; max-width: 65vw; }
    .range-slider { width: 100%; max-width: 65vw; }
    #world-year-slider::-webkit-slider-thumb,
    .range-slider input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
    #world-year-slider::-moz-range-thumb,
    .range-slider input[type="range"]::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }
    #world-year-label, #trend-range-label { font-size: 0.9rem; width: 100px; }

    /* Tooltip: fixed bottom bar, above mode dots */
    .tooltip {
        position: fixed !important;
        bottom: 80px;
        left: 50% !important;
        top: auto !important;
        transform: translateX(-50%);
        width: calc(100vw - 32px);
        max-width: 400px;
        z-index: 155;
    }

    /* Connection panel: bottom sheet */
    #connection-panel {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        top: auto;
        max-width: 100%;
        max-height: 40vh;
        overflow-y: auto;
        border-radius: 12px 12px 0 0;
        padding-bottom: env(safe-area-inset-bottom, 16px);
        z-index: 200;
    }
}
