:root {
    /* Color palette */
    --olivine: #a1c489ff;
    --cadet-gray: #96a3a6ff;
    --dark-spring-green: #33774eff;
    --gunmetal: #213231ff;
    --auburn: #9e2a2bff;
    
    /* Derived colors */
    --bg-dark: #26302d;
    --bg-light: #fafafa;
    --text-primary: #2c3e50;
    --text-secondary: #6c757d;
    --text-light: #e0e0e0;
    --accent: var(--dark-spring-green);
    --highlight: var(--olivine);
}

/* Coin Flip Animation Styles */
@keyframes flip-to-heads {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(1800deg); }
}

@keyframes flip-to-tails {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(1980deg); }
}

.coin-container {
    width: 100px;
    height: 100px;
    perspective: 1000px;
    margin: 20px auto;
}

.coin {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    cursor: pointer;
}

.coin-face {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    backface-visibility: hidden;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.heads {
    background: var(--olivine);
    color: var(--gunmetal);
}

.tails {
    background: var(--dark-spring-green);
    color: white;
    transform: rotateY(180deg);
}

/* Multi-coin grid */
.coins-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    max-width: 240px;
    margin: 20px auto;
}

/* Multi-coin grid */
.ten-coins-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 20px;
    max-width: 565px;
    margin: 20px auto;
}

/* Mobile responsive coin grids */
@media (max-width: 480px) {
    .ten-coins-grid {
        grid-template-columns: repeat(3, 1fr);
        max-width: 300px;
        gap: 15px;
    }
    
    .coins-grid {
        max-width: 200px;
        gap: 15px;
    }
    
    .coins-grid .coin-container,
    .ten-coins-grid .coin-container {
        width: 60px;
        height: 60px;
    }
    
    .coins-grid .coin-face,
    .ten-coins-grid .coin-face {
        font-size: 14px;
    }
}

.coins-grid .coin-container {
    width: 80px;
    height: 80px;
}

.coins-grid .coin-face {
    font-size: 18px;
}

/* Viz-specific buttons */
.viz-button {
    background: var(--dark-spring-green);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.viz-button:hover {
    background: var(--gunmetal);
}

.viz-result {
    margin-top: 20px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(161, 196, 137, 0.2);
    border-radius: 6px;
    min-height: 50px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Source Sans Pro', sans-serif;
    background: var(--bg-light);
    color: var(--text-primary);
    line-height: 1.7;
    font-size: 18px;
}

/* Header styling */
h2, h3, h4, h5, h6 {
    color: var(--dark-spring-green);
}

/* Strong text styling */
p strong,
h1 strong,
h2 strong,
h3 strong,
h4 strong,
h5 strong,
h6 strong {
    color: var(--dark-spring-green);
    font-weight: 600;
}

/* Quote block styling */
.analysis-quote {
    background: rgba(150, 163, 166, 0.1); /* cadet-gray with transparency */
    border-left: 4px solid var(--cadet-gray);
    margin: 24px 0;
    padding: 20px 24px;
    border-radius: 0 8px 8px 0;
    font-style: italic;
    position: relative;
}

.analysis-quote p {
    margin: 0 0 16px 0;
    color: var(--text-primary);
}

.analysis-quote p:last-child {
    margin-bottom: 0;
}

.analysis-quote strong {
    color: var(--dark-spring-green);
    font-weight: 600;
}

/* Callout box styling */
.callout-box {
    background: linear-gradient(135deg, rgba(161, 196, 137, 0.06), rgba(51, 119, 78, 0.03));
    border: 1px solid rgba(161, 196, 137, 0.25);
    border-radius: 16px;
    margin: 36px 0;
    padding: 24px 32px 20px 32px;
    position: relative;
    box-shadow: 0 2px 12px rgba(51, 119, 78, 0.08);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.callout-box:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(51, 119, 78, 0.12);
    border-color: rgba(161, 196, 137, 0.4);
}

.callout-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--olivine), var(--dark-spring-green), var(--olivine));
    opacity: 0.6;
    transition: opacity 0.25s ease;
}

.callout-box:hover::before {
    opacity: 0.8;
}

.callout-box::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 50% 0%, rgba(161, 196, 137, 0.03), transparent 60%);
    pointer-events: none;
}

.article-content .callout-box p {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
    color: var(--dark-spring-green);
    text-align: center;
    line-height: 1.35;
    letter-spacing: 0.2px;
    position: relative;
    z-index: 1;
}

/* Mobile responsiveness for callout boxes */
@media (max-width: 768px) {
    .callout-box {
        margin: 28px 0;
        padding: 20px 24px 16px 24px;
    }
    
    .article-content .callout-box p {
        font-size: 19px;
        line-height: 1.4;
    }
}

@media (max-width: 480px) {
    .callout-box {
        margin: 24px 0;
        padding: 18px 20px 14px 20px;
        border-radius: 12px;
    }
    
    .article-content .callout-box p {
        font-size: 17px;
        line-height: 1.4;
        letter-spacing: 0.1px;
    }
}

/* Note box styling for extended asides */
.note-box {
    background: linear-gradient(135deg, rgba(150, 163, 166, 0.04), rgba(150, 163, 166, 0.08));
    border: 1px solid rgba(150, 163, 166, 0.2);
    border-left: 4px solid var(--cadet-gray);
    border-radius: 8px;
    margin: 32px 0;
    padding: 24px 28px;
    position: relative;
    font-size: 16px;
    line-height: 1.6;
    box-shadow: 0 1px 8px rgba(150, 163, 166, 0.08);
}

.note-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, var(--cadet-gray), rgba(150, 163, 166, 0.6));
    border-radius: 0 0 0 8px;
}

.note-box h4 {
    margin: 0 0 16px 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--cadet-gray);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 14px;
}

.article-content .note-box p {
    margin: 0 0 16px 0;
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.6;
}

.article-content .note-box p:last-child {
    margin-bottom: 0;
}

.note-box strong {
    color: var(--dark-spring-green);
    font-weight: 600;
}

.note-box em {
    color: var(--text-secondary);
    font-style: italic;
}

/* Mobile responsiveness for note boxes */
@media (max-width: 768px) {
    .note-box {
        margin: 24px 0;
        padding: 20px 24px;
        font-size: 15px;
    }
    
    .article-content .note-box p {
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    .note-box {
        margin: 20px 0;
        padding: 16px 20px;
        border-left-width: 3px;
    }
    
    .note-box h4 {
        font-size: 13px;
    }
    
    .article-content .note-box p {
        font-size: 14px;
        line-height: 1.5;
    }
}

/* Main layout grid */
.main-container {
    display: grid;
    grid-template-columns: 170px 1fr 280px;
    max-width: 1440px;
    margin: 0 auto;
    gap: 40px;
    padding: 40px 20px;
    min-height: 100vh;
}

/* Left navigation (table of contents) */
.toc-sidebar {
    position: sticky;
    top: 40px;
    height: fit-content;
    padding: 0;
}

.toc-sidebar h3 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin: 0 0 20px 0;
    font-weight: 600;
}

.toc-sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-sidebar li {
    margin: 0;
}

.toc-sidebar a {
    display: block;
    padding: 8px 16px 8px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 15px;
    border-left: 3px solid transparent;
    margin-left: -20px;
    transition: all 0.2s ease;
}

.toc-sidebar a:hover {
    color: var(--text-primary);
    background: rgba(0,0,0,0.02);
}

.toc-sidebar a.active {
    color: var(--accent);
    border-left-color: var(--accent);
    background: rgba(51, 119, 78, 0.05);
    font-weight: 600;
}

/* Main content area */
.article-content {
    max-width: 700px;
    margin: 0 auto;
}

.article-content h1 {
    font-size: 48px;
    line-height: 1.2;
    margin: 0 0 16px 0;
    font-weight: 700;
    color: var(--gunmetal);
}

.article-content .subtitle {
    font-size: 22px;
    color: var(--text-secondary);
    margin: 0 0 60px 0;
    font-weight: 400;
}

.article-content p {
    margin: 0 0 28px 0;
    color: var(--text-primary);
}

.article-content p.lead {
    font-size: 21px;
    line-height: 1.6;
    color: var(--text-primary);
    font-weight: 400;
}

/* Right sidebar */
.right-sidebar {
    position: sticky;
    top: 40px;
    align-self: flex-start;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    /* Hide scrollbar but keep functionality */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

/* Hide scrollbar for Chrome, Safari and Opera */
.right-sidebar::-webkit-scrollbar {
    display: none;
}

.controls-section {
    background: white;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 6px;
    padding: 24px;
    margin-bottom: 24px;
}

.controls-section h4 {
    margin: 0 0 16px 0;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

/* Footnotes container - flows below controls */
#footnotes-container {
    /* Remove sticky positioning to prevent overlap */
    margin-top: 24px;
}

/* Footnotes in right sidebar */
.footnote {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
    background: rgba(161, 196, 137, 0.08);
    border-left: 3px solid var(--olivine);
    border-radius: 4px;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    max-height: 0;
    overflow: hidden;
    margin-bottom: 0;
    padding: 0 16px;
}

.footnote.visible {
    opacity: 1;
    transform: translateY(0);
    max-height: 500px; /* Increased to accommodate longer footnotes */
    padding: 16px;
    margin-bottom: 16px;
}

/* Visualization containers */
.viz-container {
    background: var(--bg-dark);
    border-radius: 8px;
    padding: 48px;
    margin: 32px -20px;
    position: relative;
}

.viz-container .viz-placeholder {
    height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cadet-gray);
    font-style: italic;
    border: 2px dashed rgba(161, 196, 137, 0.3);
    border-radius: 4px;
}

.plot-container {
    width: 100%;
    max-width: 100%;
    margin: 20px auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background-color: white;
}

/* Light container for graph visualizations */
.viz-container-light {
    background: var(--bg-light);
    border-radius: 8px;
    padding: 32px 0px;
    margin: 32px -20px;
    position: relative;
}

.viz-container-light h3 {
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 30px;
}

/* Image container styling */
.image-container {
    width: 100%;
    max-width: 700px;
    margin: 32px auto;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    background-color: white;
    transition: transform 0.2s, box-shadow 0.2s;
}

.image-grid .image-container {
    max-width: 100%;
}

.image-container:hover {
    transform: scale(1.02);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.image-container img {
    width: 100%;
    height: auto;
    padding: 10px;
    display: block;
}

/* Image grid for side-by-side display */
.image-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin: 32px -40px;
    max-width: 900px;
    width: calc(100% + 80px);
}

.image-grid .image-container {
    margin: 0;
}

/* Responsive adjustment for small screens */
@media (max-width: 600px) {
    .image-grid {
        grid-template-columns: 1fr;
    }
}

/* Coin games specific slider styling */
.coin-games-controls {
    width: 100%;
    max-width: 100%;
    margin: 20px auto 0;
}

.coin-games-controls .slider-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0;
}

.coin-games-controls label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-right: 16px;
    flex-shrink: 0;
}

.coin-games-controls input[type="range"] {
    flex: 1;
    margin: 0 16px;
}

.coin-games-controls .value {
    font-size: 14px;
    color: var(--accent);
    font-weight: 600;
    min-width: 40px;
    text-align: right;
}

/* Sliders and controls */
.slider-control {
    margin-bottom: 24px;
}

.slider-control label {
    display: block;
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.slider-control input[type="range"] {
    width: 100%;
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.slider-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--dark-spring-green);
    border-radius: 50%;
    cursor: pointer;
}

.slider-control .value {
    float: right;
    font-size: 14px;
    color: var(--accent);
    font-weight: 600;
}

/* Mobile Controls Bubble */
.mobile-controls-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: var(--auburn);
    border-radius: 50%;
    border: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    cursor: pointer;
    z-index: 1000;
    transition: all 0.3s ease;
    /* Ensure button stays in viewport even with address bar changes */
    transform: translateZ(0);
    will-change: transform;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.mobile-controls-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0,0,0,0.3);
}

.mobile-controls-toggle svg {
    width: 30px;
    height: 30px;
    fill: white;
}

/* Mobile Controls Tooltip */
.mobile-controls-tooltip {
    position: fixed;
    bottom: 90px;
    right: 20px;
    background: var(--cadet-gray);
    color: white;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    max-width: 250px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 1001;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    pointer-events: none;
}

.mobile-controls-tooltip.show {
    opacity: 1;
    transform: translateY(0);
}

.mobile-controls-tooltip::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 30px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid var(--dark-blue);
}

.mobile-controls-tooltip .tooltip-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    color: white;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.mobile-controls-tooltip .tooltip-close:hover {
    opacity: 1;
}

/* Mobile overlay for sidebar */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-overlay.active {
    opacity: 1;
    z-index: 999
}

/* Close button for mobile */
.mobile-close {
    display: none;
}

/* Responsive adjustments */
@media (max-width: 968px) {
    /* Adjust main grid for tablet/mobile */
    .main-container {
        grid-template-columns: 1fr;
        gap: 20px;
        padding: 20px 15px;
    }
    
    /* Hide sidebars on mobile */
    .toc-sidebar,
    .right-sidebar {
        display: none;
    }
    
    /* Show mobile controls toggle */
    .mobile-controls-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Transform right sidebar into mobile panel */
    .right-sidebar.mobile-active {
        display: block;
        position: fixed;
        right: 0;
        top: 0;
        height: 100vh;
        width: 300px;
        max-width: 85vw;
        background: white;
        z-index: 1001;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        box-shadow: -4px 0 16px rgba(0,0,0,0.1);
        padding: 60px 20px 20px;
        overflow-y: auto;
    }
    
    .right-sidebar.mobile-active.open {
        transform: translateX(0);
    }
    
    /* Show close button on mobile */
    .mobile-close {
        display: block;
        position: absolute;
        top: 15px;
        right: 15px;
        width: 32px;
        height: 32px;
        background: none;
        border: none;
        cursor: pointer;
        padding: 0;
        z-index: 1002;
    }
    
    .mobile-close svg {
        width: 24px;
        height: 24px;
        fill: var(--text-secondary);
    }
    
    /* Full width containers on mobile */
    .viz-container,
    .viz-container-light {
        margin: 20px -15px;
        border-radius: 0;
        padding: 32px 15px;
    }
    
    /* Adjust article content */
    .article-content {
        padding: 0;
    }
    
    .article-content h1 {
        font-size: 36px;
    }
    
    .article-content h2 {
        font-size: 28px;
    }
    
    /* Mobile responsive coin containers */
    .coin-container {
        width: 80px;
        height: 80px;
    }
    
    .coin-face {
        font-size: 20px;
    }
    
    /* Mobile responsive buttons */
    .viz-button {
        padding: 10px 20px;
        font-size: 14px;
    }
    
    /* Mobile responsive plot containers */
    .plot-container {
        margin: 20px 0;
        overflow-x: auto;
    }
    
    /* Show overlay on mobile */
    .mobile-overlay {
        display: block;
    }
    
    /* Mobile-specific text */
    .desktop-only {
        display: none;
    }
    
    .mobile-only {
        display: block !important;
    }
}

/* Extra small mobile devices */
@media (max-width: 480px) {
    .main-container {
        padding: 15px 10px;
    }
    
    .viz-container,
    .viz-container-light {
        margin: 15px -10px;
        padding: 24px 10px;
    }
    
    .article-content h1 {
        font-size: 28px;
        line-height: 1.3;
    }
    
    .article-content .subtitle {
        font-size: 18px;
    }
    
    .article-content p {
        font-size: 16px;
    }
    
    .viz-button {
        padding: 8px 16px;
        font-size: 13px;
    }
    
    .viz-result {
        padding: 12px;
        font-size: 14px;
    }
}

/* Desktop-specific text */
@media screen and (min-width: 969px) {
    .mobile-only {
        display: none !important;
    }
    
    .desktop-only {
        display: block;
    }
}

/* Toggle Switch Styling */
.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: #ff3b30;
}

input:checked + .toggle-slider:before {
    transform: translateX(26px);
}

/* Lightbox Styles */
.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    z-index: 10000;
    cursor: pointer;
}

.lightbox-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-container {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    cursor: default;
}

.lightbox-image {
    max-width: 100%;
    max-height: 95vh;
    width: auto;
    height: auto;
    display: block;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: white;
    font-size: 32px;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 4px;
    transition: background 0.2s;
    z-index: 10001;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lightbox-caption {
    position: absolute;
    bottom: -40px;
    left: 0;
    right: 0;
    color: white;
    text-align: center;
    font-size: 14px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 4px;
}

/* Make images clickable */
.content-image {
    cursor: pointer;
    transition: opacity 0.2s;
}

.content-image:hover {
    opacity: 0.8;
}

/* Mobile lightbox adjustments */
@media (max-width: 768px) {
    .lightbox-close {
        top: 10px;
        right: 10px;
        font-size: 28px;
        background: rgba(0, 0, 0, 0.7);
        border-radius: 50%;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .lightbox-caption {
        position: static;
        margin-top: 10px;
    }
}

/* Run Simulation Button */
.run-simulation-btn {
    width: 100%;
    padding: 8px;
    background: var(--dark-spring-green);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
}