/* Scrollytelling Styles for Solar + Battery Atlas */

/* Design tokens — dark Ember palette (kept in sync with ../css/style.css) */
:root {
    --bg-page: #0b0d0c;
    --card: #15181a;
    --elevated: #1f2325;
    --text: #ECEFF5;
    --muted: #9aa19f;
    --divider: #2a2f31;
    --input: #0f1213;
    --ember: #f59e0b;
    --ember-hover: #fbbf24;
    --solar: #f59e0b;
    --battery: #a855f7;
    /* SF Pro (Apple system font, à la Substack). Kept in sync with
       ../css/style.css and Tailwind's font-sans. */
    --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'SF Pro', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* ========== Layout ========== */
.scrolly-container {
    display: flex;
    min-height: 100vh;
}

.scrolly-article {
    width: 45%;
    min-width: 400px;
    max-width: 600px;
    background: linear-gradient(to right, var(--bg-page), var(--card));
    z-index: 10;
    position: relative;
}

.scrolly-visual {
    position: fixed;
    top: 0;
    right: 0;
    width: max(55%, calc(100% - 600px));
    height: 100vh;
    z-index: 1;
}

/* Mobile: Stack layout */
@media (max-width: 1024px) {
    .scrolly-container {
        flex-direction: column;
    }

    .scrolly-article {
        width: 100%;
        min-width: unset;
        max-width: unset;
    }

    .scrolly-visual {
        position: sticky;
        width: 100%;
        height: 50vh;
    }
}

/* ========== Hero Section ========== */
.scrolly-hero {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 3rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.scrolly-hero-content {
    text-align: center;
    max-width: 480px;
}

.scrolly-title {
    font-family: var(--font-sans);
    font-size: 3rem;
    font-weight: 700;
    color: white;
    line-height: 1.1;
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, #fff 0%, #f59e0b 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.scrolly-subtitle {
    font-family: var(--font-sans);
    font-size: 1.25rem;
    font-weight: 400;
    font-style: italic;
    color: var(--muted);
    line-height: 1.6;
    margin-bottom: 2rem;
}

.scrolly-byline {
    font-size: 0.875rem;
    color: var(--muted);
    margin-bottom: 3rem;
}

.scroll-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: var(--muted);
    opacity: 0.7;
}

/* ========== Article Summary (collapsible) ========== */
.scrolly-summary {
    padding: 2.5rem 3rem 3rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.scrolly-summary-content {
    max-width: 500px;
    margin: 0 auto;
}

.scrolly-summary-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 0.75rem;
    padding: 0.5rem 0;
    background: none;
    border: none;
    border-bottom: 1px solid rgba(245, 158, 11, 0.35);
    cursor: pointer;
    text-align: left;
}

.scrolly-summary-title {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #f59e0b;
}

.scrolly-summary-icon {
    color: #f59e0b;
    font-size: 1.5rem;
    transition: transform 0.35s ease;
}

.scrolly-summary.is-open .scrolly-summary-icon {
    transform: rotate(180deg);
}

/* Smooth fold via max-height (collapsed by default) */
.scrolly-summary-collapse {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.45s ease;
}

.scrolly-summary.is-open .scrolly-summary-collapse {
    max-height: 1500px;
}

.scrolly-summary-list {
    list-style: none;
    margin: 0;
    padding: 1.5rem 0 0;
}

.scrolly-summary-list li {
    position: relative;
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.7;
    color: #cdd3e0;
    padding-left: 1.25rem;
    margin-bottom: 1.1rem;
}

.scrolly-summary-list li:last-child {
    margin-bottom: 0;
}

.scrolly-summary-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.62rem;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #f59e0b;
}

.scrolly-summary-list strong {
    color: #fff;
    font-weight: 600;
}

/* ========== Article Sections ========== */
.scrolly-section {
    min-height: 120vh;
    padding: 7rem 3rem;
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
}

.scrolly-section::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: transparent;
    transition: background 0.3s ease;
}

.scrolly-section.active::before {
    background: linear-gradient(to bottom, transparent, #f59e0b, transparent);
}

.scrolly-section-content {
    max-width: 500px;
    margin: 0 auto;
}

/* ========== Typography ========== */
.scrolly-heading {
    font-family: var(--font-sans);
    font-size: 2rem;
    font-weight: 700;
    color: white;
    margin-bottom: 2rem;
    line-height: 1.2;
}

.scrolly-section p {
    font-family: var(--font-sans);
    font-size: 1.125rem;
    line-height: 1.9;
    color: #cdd3e0;
    margin-bottom: 1.5rem;
}

.scrolly-section p:last-of-type {
    margin-bottom: 0;
}

/* Drop cap */
.scrolly-drop-cap::first-letter {
    float: left;
    font-size: 4.5rem;
    line-height: 0.8;
    padding-right: 0.75rem;
    padding-top: 0.25rem;
    color: #f59e0b;
    font-weight: 700;
}

/* Emphasis */
.scrolly-section strong {
    color: #f59e0b;
    font-weight: 600;
}

.scrolly-section em {
    font-style: italic;
    color: var(--text);
}

/* Final paragraph */
.scrolly-final {
    font-size: 1.25rem;
    color: var(--text);
    font-style: italic;
    border-left: 3px solid #f59e0b;
    padding-left: 1.5rem;
    margin-top: 2rem;
}

/* ========== Callout Box ========== */
.scrolly-callout {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 0.75rem;
    padding: 1.25rem;
    margin: 2rem 0;
}

.scrolly-callout .material-symbols-outlined {
    font-size: 1.5rem;
    flex-shrink: 0;
    margin-top: 0.125rem;
}

.scrolly-callout p {
    font-family: var(--font-sans);
    font-size: 0.875rem;
    margin: 0;
    color: var(--text);
    line-height: 1.5;
}

/* ========== CTA Button ========== */
.scrolly-cta {
    margin-top: 3rem;
    text-align: center;
}

.scrolly-button {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: black;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 1rem;
    padding: 1rem 2rem;
    border-radius: 9999px;
    text-decoration: none;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(245, 158, 11, 0.3);
}

.scrolly-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 30px rgba(245, 158, 11, 0.4);
}

.scrolly-button .material-symbols-outlined {
    font-size: 1.25rem;
}

/* ========== Footer ========== */
.scrolly-footer {
    padding: 4rem 3rem;
    background: var(--card);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.scrolly-footer-content {
    max-width: 500px;
    margin: 0 auto;
}

/* ========== Visual Panel Elements ========== */
.section-indicator {
    position: absolute;
    right: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 20;
}

.section-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    transition: all 0.3s ease;
}

.section-dot:hover {
    background: rgba(255, 255, 255, 0.4);
}

.section-dot.active {
    background: #f59e0b;
    border-color: #f59e0b;
    transform: scale(1.2);
}

/* The floating title/subtitle box is hidden globally — the legend (and, on chart
   sections, the chart title + article prose) already says what is on screen. */
.visual-label {
    display: none;
}

.visual-label-title {
    font-weight: 600;
    font-size: 1rem;
    color: white;
    margin-bottom: 0.25rem;
}

.visual-label-subtitle {
    font-size: 0.75rem;
    color: var(--muted);
}

.potential-toggle {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;
    left: auto;
    z-index: 20;
    background: rgb(21, 24, 26);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.625rem;
    padding: 0.5rem 0.625rem;
    width: 188px;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.visual-legend {
    position: absolute;
    bottom: 1.5rem;
    right: 1.25rem;
    background: rgb(21, 24, 26);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.625rem;
    padding: 0.5rem 0.625rem;
    width: 156px;
    z-index: 20;
}

#lcoe-outlook-panel {
    z-index: 25;
}

/* Section 4: Demand & Supply by Latitude chart. Covers the map area (above the map,
   below the bottom chart-container which occupies the lower 280px). */
#latitude-chart-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: calc(100% - 280px);
    z-index: 15;
    background: #0a0a0a;
    display: flex;
    flex-direction: column;
    padding: 2.5rem 1rem 0.5rem;
}

#latitude-chart-container.hidden {
    display: none;
}

.latitude-chart-canvas-wrap {
    flex: 1;
    position: relative;
    min-height: 0;
}

@media (max-width: 1024px) {
    #latitude-chart-container {
        height: calc(100% - 200px);
        padding: 2.25rem 0.5rem 0.5rem;
    }
}

/* Chart view (Section 4): reserve a clean top control bar so the Map/Chart toggle
   and the cost-basis control sit ABOVE the chart instead of on top of it, and add
   right padding so the chart axis clears the section-indicator dots. */
#latitude-chart-container.cp-chart-mode {
    padding: 3.5rem 2.75rem 0.5rem 1rem;
}

@media (max-width: 1024px) {
    #latitude-chart-container.cp-chart-mode {
        padding: 3.25rem 1.75rem 0.5rem 0.5rem;
    }

    /* Narrow screens: dock the Map/Chart toggle top-left so it clears the
       top-right cost-basis control instead of colliding with it at centre. */
    #latitude-view-toggle {
        left: 0.5rem;
        transform: none;
    }
}

/* The shared "Cost Assumptions" overlay (every LCOE map section) and the Section 4
   chart-mode pill both collapse to the same single-row Cost Basis control. */
#lcoe-outlook-panel.compact,
#lcoe-outlook-panel.cp-chart-cost {
    width: auto;
    max-width: none;
    padding: 0.3rem 0.6rem;
}

#lcoe-outlook-panel.compact > div:first-child,
#lcoe-outlook-panel.cp-chart-cost > div:first-child,
#lcoe-outlook-panel.compact #lcoe-outlook-timeline,
#lcoe-outlook-panel.cp-chart-cost #lcoe-outlook-timeline {
    /* hide the title / play row and the year slider */
    display: none;
}

#lcoe-outlook-panel.compact > div:last-child,
#lcoe-outlook-panel.cp-chart-cost > div:last-child {
    /* lay the cost-basis label + Global/Local toggle out horizontally */
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0;
}

#lcoe-outlook-panel.compact #lcoe-outlook-cost-toggle,
#lcoe-outlook-panel.cp-chart-cost #lcoe-outlook-cost-toggle {
    margin-top: 0;
}

/* While the latitude chart is showing, dock the pill into the top control bar
   (clear of the chart) instead of the default top-right card position. */
#lcoe-outlook-panel.cp-chart-cost {
    top: 0.5rem;
    right: 1.25rem;
}


/* Legend Gradients */
.legend-gradient {
    background: linear-gradient(to right,
            #0049ff 0%,
            #00c853 40%,
            #facc15 70%,
            #f97316 90%,
            #d32f2f 100%);
}

.legend-gradient-cost {
    background: linear-gradient(to right,
            #0b1d3a 0%,
            #1d4ed8 15%,
            #16a34a 45%,
            #eab308 65%,
            #f59e0b 82.5%,
            #dc2626 100%);
    background-size: 100% 100%;
}

.legend-gradient-pop {
    background: linear-gradient(to right,
            rgba(59, 130, 246, 0.1) 0%,
            rgba(59, 130, 246, 0.4) 33%,
            #3b82f6 66%,
            #1e40af 100%);
}

/* ========== Animations ========== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Voronoi ripple wave effect for hero state */
@keyframes cell-hop {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-6px);
    }
}

.voronoi-hop {
    animation: cell-hop 0.6s ease-in-out forwards;
}

.voronoi-hover {
    stroke: #ffffff !important;
    stroke-width: 1.2 !important;
    stroke-opacity: 1 !important;
}

@keyframes dot-hop {
    0%,
    100% {
        transform: translateY(0) scale(1);
    }

    50% {
        transform: translateY(-4px) scale(1.4);
    }
}

.intro-dot-hop {
    transform-box: fill-box;
    transform-origin: center;
    animation: dot-hop 0.8s ease-in-out both;
}

@keyframes intro-breathe {
    0%,
    100% {
        opacity: 0.9;
    }

    50% {
        opacity: 1;
    }
}

.intro-breathe {
    animation: intro-breathe 6s ease-in-out infinite;
}

@keyframes intro-group-fade {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.intro-group-fade {
    opacity: 0;
    animation-name: intro-group-fade;
    animation-timing-function: ease-out;
    animation-fill-mode: forwards;
}

@keyframes voronoi-fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.voronoi-fade-in {
    animation-name: voronoi-fade-in;
    animation-timing-function: ease-out;
    animation-fill-mode: forwards;
}

.dot-fade-in {
    animation-name: voronoi-fade-in;
    animation-timing-function: ease-out;
    animation-fill-mode: forwards;
}

.scrolly-section-content {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.scrolly-section.visible .scrolly-section-content {
    opacity: 1;
    transform: translateY(0);
}

/* ========== Smooth Scrolling ========== */
html {
    scroll-behavior: smooth;
}

/* ========== Custom Scrollbar ========== */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--card);
}

::-webkit-scrollbar-thumb {
    background: var(--elevated);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

/* ========== Mobile Adjustments ========== */
@media (max-width: 768px) {
    .scrolly-hero {
        padding: 3rem 1.5rem;
    }

    .scrolly-title {
        font-size: 2.25rem;
    }

    .scrolly-subtitle {
        font-size: 1rem;
    }

    .scrolly-section {
        padding: 4rem 1.5rem;
        min-height: auto;
    }

    .scrolly-heading {
        font-size: 1.5rem;
    }

    .scrolly-section p {
        font-size: 1rem;
    }

    .scrolly-drop-cap::first-letter {
        font-size: 3.5rem;
    }

    .section-indicator {
        right: 0.75rem;
    }

    .visual-label {
        top: 0.75rem;
        left: 0.75rem;
        padding: 0.75rem 1rem;
    }

    .potential-toggle {
        top: 0.75rem;
        right: 0.75rem;
        left: auto;
        width: 200px;
    }

    .visual-legend {
        bottom: 1rem;
        right: 0.75rem;
        width: 160px;
        padding: 0.75rem;
    }

    #lcoe-outlook-panel {
        top: 0.75rem;
        right: 0.75rem;
        width: 200px;
        padding: 0.75rem;
    }
}

/* ========== Transition Effects ========== */
.transition-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-color: var(--bg-page);
    opacity: 0;
    transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 50;
}

.transition-overlay.active {
    opacity: 1;
}

.transition-overlay.scroll-driven {
    transition: none !important;
    pointer-events: none;
}

#map {
    transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* The overlay-driven black hold is the single source of truth for map reveals.
   A per-layer opacity transition here would fight that reveal (the map would
   fade independently after the overlay lifts), so keep the layer opaque/stable. */
.leaflet-zoom-animated {
    transition: none;
}

/* ========== Subtle in-map loader (shown only during an unavoidable wait) ========== */
.map-loader {
    position: absolute;
    inset: 0;
    z-index: 60; /* above the transition overlay (z-index: 50) */
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.35s ease;
}

.map-loader.visible {
    opacity: 1;
}

.map-loader-spinner {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.18);
    border-top-color: rgba(255, 255, 255, 0.7);
    animation: map-loader-spin 0.9s linear infinite;
}

@keyframes map-loader-spin {
    to { transform: rotate(360deg); }
}

/* ========== Chart Container ========== */
#chart-container {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 0;
    background: rgb(11, 13, 12);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 25;
    overflow: hidden;
    transition: height 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

#chart-container.chart-slide-in {
    height: 280px;
}

#chart-container.chart-slide-out {
    height: 0;
}

.chart-wrapper {
    padding: 0.75rem 1.5rem 1.25rem 1.5rem;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.chart-header {
    margin-bottom: 0.5rem;
}

.chart-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: white;
    margin-bottom: 0.25rem;
    min-height: 2.25rem;
    /* Sufficient for 2 lines of text */
    display: flex;
    align-items: flex-start;
}

.chart-subtitle {
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.chart-canvas-wrapper {
    flex: 1;
    position: relative;
    min-height: 0;
}

.chart-canvas-wrapper canvas {
    max-height: 100%;
}

/* ========== Clickable Data Links ========== */
.data-link {
    color: #f59e0b;
    border-bottom: 1px dotted currentColor;
    cursor: pointer;
    transition: all 0.2s ease;
    padding-bottom: 1px;
    text-decoration: none;
}

.data-link:hover {
    background: rgba(245, 158, 11, 0.15);
    border-bottom-style: solid;
}

.data-link:active {
    background: rgba(245, 158, 11, 0.25);
}

/* Data link visual feedback when activated */
.data-link.active {
    background: rgba(245, 158, 11, 0.2);
    border-bottom: 2px solid #f59e0b;
}

/* Tooltip for data links */
.data-tooltip {
    position: fixed;
    background: rgba(21, 24, 26, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    font-size: 0.8125rem;
    color: white;
    max-width: 280px;
    z-index: 100;
    pointer-events: none;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s, transform 0.2s;
}

.data-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ========== Animation Indicator (Battery etc) ========== */


/* ========== Leaflet Popup Overrides ========== */
/* Remove default Leaflet white background and shadow for our custom tooltips */
.leaflet-popup.bg-transparent .leaflet-popup-content-wrapper {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
}

.leaflet-popup.bg-transparent .leaflet-popup-tip-container {
    display: none;
}

.leaflet-popup.bg-transparent .leaflet-popup-content {
    margin: 0;
}

/* ========== Visual Panel Layout for Charts ========== */
.scrolly-visual.with-chart #map {
    height: calc(100% - 280px);
    transition: height 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* When a bottom chart is showing it covers the lower 280px of the panel, where the
   map legend normally sits — so lift the legend above the chart (and nudge it left of
   the section-dot rail) so the colour key stays visible over the map. */
.scrolly-visual.with-chart .visual-legend {
    bottom: calc(280px + 0.75rem);
    right: 2.75rem;
}

/* Mobile chart adjustments */
@media (max-width: 1024px) {
    #chart-container.chart-slide-in {
        height: 200px;
    }

    .scrolly-visual.with-chart #map {
        height: calc(100% - 200px);
    }

    .scrolly-visual.with-chart .visual-legend {
        bottom: calc(200px + 0.5rem);
        right: 2.25rem;
    }

    .chart-wrapper {
        padding: 0.75rem 1rem;
    }
}
