:root {
    --color-bg: #f3f7f6;
    --color-bg-deep: #e8efed;
    --color-surface: rgba(255, 255, 255, 0.70);
    --color-surface-strong: rgba(255, 255, 255, 0.92);
    --color-text: #172422;
    --color-text-soft: #61706d;
    --color-border: rgba(23, 36, 34, 0.10);

    --color-primary: #3e6df5;
    --color-secondary: #6b8cff;
    --color-accent: #19b3a6;
    --color-accent-soft: rgba(25, 179, 166, 0.12);
    --color-glow: rgba(62, 109, 245, 0.14);

    --color-fact-article: #333;

    --shadow-sm: 0 10px 24px rgba(18, 28, 27, 0.06);
    --shadow-md: 0 20px 50px rgba(18, 28, 27, 0.10);
    --shadow-lg: 0 30px 80px rgba(18, 28, 27, 0.14);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 18px;

    --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-serif: "Crimson Text", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #08111a;
        --color-bg-deep: #0c1722;
        --color-surface: rgba(16, 26, 38, 0.74);
        --color-surface-strong: rgba(19, 31, 45, 0.94);
        --color-text: #edf6ff;
        --color-text-soft: #9bb0c5;
        --color-border: rgba(255, 255, 255, 0.08);

        --color-primary: #7ba8ff;
        --color-secondary: #90b7ff;
        --color-accent: #31d7c6;
        --color-accent-soft: rgba(49, 215, 198, 0.10);
        --color-glow: rgba(123, 168, 255, 0.16);

        --color-fact-article: #555;

        --shadow-sm: 0 12px 28px rgba(0, 0, 0, 0.24);
        --shadow-md: 0 22px 58px rgba(0, 0, 0, 0.34);
        --shadow-lg: 0 34px 88px rgba(0, 0, 0, 0.45);
    }
}

body.dark-mode {
    --color-bg: #08111a;
    --color-bg-deep: #0c1722;
    --color-surface: rgba(16, 26, 38, 0.74);
    --color-surface-strong: rgba(19, 31, 45, 0.94);
    --color-text: #edf6ff;
    --color-text-soft: #9bb0c5;
    --color-border: rgba(255, 255, 255, 0.08);

    --color-primary: #7ba8ff;
    --color-secondary: #90b7ff;
    --color-accent: #31d7c6;
    --color-accent-soft: rgba(49, 215, 198, 0.10);
    --color-glow: rgba(123, 168, 255, 0.16);

    --color-fact-article: #555;
}


body.light-mode {
    --color-bg: #f3f7f6;
    --color-bg-deep: #e8efed;
    --color-surface: rgba(255, 255, 255, 0.70);
    --color-surface-strong: rgba(255, 255, 255, 0.92);
    --color-text: #172422;
    --color-text-soft: #61706d;
    --color-border: rgba(23, 36, 34, 0.10);

    --color-primary: #3e6df5;
    --color-secondary: #6b8cff;
    --color-accent: #19b3a6;
    --color-accent-soft: rgba(25, 179, 166, 0.12);
    --color-glow: rgba(62, 109, 245, 0.14);

    --color-fact-article: #333;
}

@keyframes pulse {
    0%, 100% { transform: scale(.96); opacity: .70; }
    50% { transform: scale(1.08); opacity: .95; }
}

@keyframes pulse2 {
    0%, 100% { transform: scale(1); opacity: .36; }
    50% { transform: scale(1.16); opacity: .68; }
}

@keyframes drift1 {
    0%,100% { transform: translate3d(0,0,0); }
    50% { transform: translate3d(14px,-12px,0); }
}

@keyframes drift2 {
    0%,100% { transform: translate3d(0,0,0); }
    50% { transform: translate3d(-16px,10px,0); }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

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

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

html, body {
    min-height: 100%;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    transition: background-color .35s ease, color .35s ease;
}

body {
    overflow-x: hidden;
    position: relative;
}

/* Background: more creative but still usable */
.animated-background {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    background:
        radial-gradient(circle at 15% 18%, rgba(62,109,245,.12), transparent 20%),
        radial-gradient(circle at 82% 12%, rgba(25,179,166,.10), transparent 18%),
        radial-gradient(circle at 70% 82%, rgba(62,109,245,.08), transparent 22%),
        linear-gradient(180deg, var(--color-bg), var(--color-bg-deep));
}

.blur-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: .26;
}

.blur-orb-1 {
    width: 380px;
    height: 380px;
    top: -100px;
    left: -90px;
    background: rgba(62, 109, 245, 0.18);
    animation: drift1 16s ease-in-out infinite;
}

.blur-orb-2 {
    width: 320px;
    height: 320px;
    right: -80px;
    bottom: -70px;
    background: rgba(25, 179, 166, 0.16);
    animation: drift2 18s ease-in-out infinite;
}

.blur-orb-3 {
    width: 240px;
    height: 240px;
    top: 24%;
    right: 18%;
    background: rgba(123, 168, 255, 0.12);
    animation: drift1 20s ease-in-out infinite;
}

.grid-glow {
    position: absolute;
    inset: 0;
    opacity: .34;
    background-image:
        linear-gradient(rgba(62,109,245,.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(62,109,245,.03) 1px, transparent 1px);
    background-size: 42px 42px;
    mask-image: radial-gradient(circle at center, black 34%, transparent 82%);
}

/* Main shell */
.page-shell {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 1180px;
    min-height: 100vh;
    margin: 0 auto;
    padding: 26px 22px 18px;
    display: grid;
    grid-template-rows: 1fr auto;
    gap: 16px;
    animation: fadeIn .55s ease-out;
}

.story-panel {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.story-panel-inner {
    width: 100%;
    max-width: 1040px;
    padding: 24px;
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    background:
        linear-gradient(180deg, rgba(255,255,255,.18), rgba(255,255,255,.03)),
        var(--color-surface);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    box-shadow: var(--shadow-md);
    animation: slideUp .5s ease-out;
}

.story-panel-inner::before {
    content: "";
    position: absolute;
    inset: auto auto -40px -40px;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(25,179,166,.16), transparent 70%);
    pointer-events: none;
}

.story-panel-inner::after {
    content: "";
    position: absolute;
    top: -46px;
    right: -46px;
    width: 190px;
    height: 190px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(62,109,245,.16), transparent 70%);
    pointer-events: none;
}

.story-topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 22px;
}

.story-date-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.story-date-label,
.eyebrow {
    font-size: .74rem;
    font-weight: 800;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--color-primary);
}

.story-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.brand-block-centered {
    text-align: center;
    max-width: 760px;
    margin: 0 auto 24px;
}

.brand-block h1,
.archive-intro h1,
.archive-hero h1 {
    margin: 10px 0 8px;
    font-size: clamp(2.2rem, 5vw, 3.6rem);
    line-height: 1.02;
    letter-spacing: -0.05em;
    font-weight: 800;
    color: var(--color-text);
    text-shadow: 0 2px 20px rgba(62, 109, 245, 0.06);
}

.subtitle,
.archive-subtitle {
    margin: 10px auto 0;
    max-width: 560px;
    color: var(--color-text-soft);
    line-height: 1.55;
    font-size: 1rem;
}

.creative-copy,
.archive-storyline {
    margin: 16px auto 0;
    max-width: 680px;
    font-family: var(--font-serif);
    font-size: clamp(1.08rem, 2vw, 1.3rem);
    line-height: 1.68;
    color: var(--color-text);
    opacity: .92;
}

.date-chip,
.archive-link,
.archive-back-link,
.archive-date-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-surface-strong);
    color: var(--color-text);
    text-decoration: none;
    font-weight: 600;
    font-size: .92rem;
    transition: all .22s ease;
}

.archive-link:hover,
.archive-back-link:hover {
    border-color: rgba(62, 109, 245, .22);
    background: rgba(62, 109, 245, .08);
}

/* Fact */
.fact-shell,
.archive-fact-stage,
.page-content {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.fact-shell {
    align-items: center;
}

.fact-stage,
#fact-container,
.fact-display {
    width: 100%;
    max-width: 920px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
}

#fact-container > *,
.fact-display > * {
    width: 100%;
    max-width: 920px;
    margin: 0 auto !important;
}

.fact-stage.fade-in {
    animation: slideUp .55s ease-out;
}

#fact-container .container {
    width: 100%;
    max-width: 920px;
    margin: 0 auto !important;
    overflow: hidden;
    border-radius: var(--radius-lg) !important;
    border: 1px solid var(--color-border) !important;
    background: var(--color-surface-strong) !important;
    box-shadow: var(--shadow-lg) !important;
}

#fact-container .hero-image {
    min-height: 310px !important;
    height: clamp(270px, 40vw, 490px) !important;
    background-size: cover !important;
    background-position: center !important;
    position: relative;
}

#fact-container .hero-image::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(to bottom, transparent 0%, rgba(10, 18, 24, .24) 100%),
        radial-gradient(circle at 18% 18%, rgba(25,179,166,.14), transparent 28%);
}

#fact-container .header {
    padding: 30px 34px 16px !important;
    background: var(--color-surface-strong) !important;
}

#fact-container .headline {
    margin: 0 !important;
    font-family: var(--font-serif);
    font-size: clamp(1.9rem, 4vw, 2.95rem) !important;
    line-height: 1.08 !important;
    letter-spacing: -0.03em;
    color: var(--color-text) !important;
}

#fact-container .article {
    padding: 8px 34px 34px !important;
    background: var(--color-surface-strong) !important;
    color: var(--color-fact-article) !important;
    font-size: 1.04rem !important;
    line-height: 1.82 !important;
}

#fact-container .article p,
#fact-container .article div,
#fact-container .article span,
#fact-container .article li,
#fact-container .article h1,
#fact-container .article h2,
#fact-container .article h3,
#fact-container .article h4,
#fact-container .article h5,
#fact-container .article h6 {
    color: var(--color-fact-article) !important;
}

#fact-container .article a {
    color: var(--color-primary) !important;
}

#fact-container .article p:first-child::first-letter {
    float: left;
    font-family: var(--font-serif);
    font-size: 3.1rem;
    line-height: 1;
    padding-right: 10px;
    padding-top: 4px;
    font-weight: 700;
    color: var(--color-primary);
}

/* Footer */
.page-footer,
.archive-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 1040px;
    margin: 0 auto;
    padding: 16px 18px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow-sm);
    color: var(--color-text-soft);
}

.page-footer-wallet {
    flex-wrap: wrap;
    text-align: center;
}

.wallet-label {
    font-weight: 700;
    color: var(--color-text);
}

.wallet-key,
.btc-wallet {
    display: inline-block;
    padding: 9px 12px;
    border-radius: 999px;
    background: var(--color-surface-strong);
    border: 1px solid var(--color-border);
    color: var(--color-primary);
    font-size: .92rem;
    word-break: break-all;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* States */
.state-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    position: relative;
    z-index: 1;
}

.state-card,
.archive-placeholder,
.archive-error,
.archive-inline-state {
    width: min(100%, 620px);
    margin: 0 auto;
    padding: 34px 26px;
    text-align: center;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow-md);
    color: var(--color-text-soft);
    animation: slideUp .5s ease-out;
}

.state-card h1,
.archive-error h2 {
    margin: 0 0 10px;
    color: var(--color-text);
}

.loading-animation {
    position: relative;
    width: 90px;
    height: 90px;
    margin: 0 auto 26px;
}

.pulse-ring {
    position: absolute;
    width: 72px;
    height: 72px;
    top: 9px;
    left: 9px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--color-primary), transparent 70%);
    animation: pulse 2s infinite;
}

.pulse-ring-2 {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--color-accent), transparent 70%);
    animation: pulse2 2.5s infinite;
}

.error-message {
    color: var(--color-primary);
    word-break: break-word;
    margin: 10px 0;
}

/* Theme toggle restored and obvious */
.theme-toggle-switch {
    position: relative;
    width: 72px;
    height: 40px;
    display: inline-block;
    flex: 0 0 auto;
}

.theme-toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: linear-gradient(135deg, #d8e5ff, #b6fff7);
    box-shadow: inset 0 1px 8px rgba(255,255,255,.35);
    transition: all .25s ease;
}

body.dark-mode .toggle-slider {
    background: linear-gradient(135deg, #183555, #103f47);
}



.toggle-slider::before {
    content: "☀";
    position: absolute;
    width: 30px;
    height: 30px;
    top: 4px;
    left: 4px;
    border-radius: 50%;
    background: #fff;
    color: #f4b400;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    box-shadow: 0 2px 10px rgba(0,0,0,.18);
    transition: transform .25s ease, color .25s ease, background .25s ease, content .25s ease;
}

.theme-toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(32px);
    content: "☾";
    color: #7ba8ff;
    background: #eaf1ff;
}

/* Archive compact compatibility */
.archive-wrap {
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    padding: 24px 16px 32px;
}

.archive-card,
.archive-main-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background:
        linear-gradient(180deg, rgba(255,255,255,.18), rgba(255,255,255,.03)),
        var(--color-surface);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.archive-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 22px 28px 0;
}

.archive-hero,
.archive-intro {
    text-align: center;
    padding: 30px 28px 18px;
}

.archive-controls,
.archive-controls-wrap {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: end;
    gap: 12px;
    padding: 0 28px 28px;
}

.archive-controls-wrap {
    display: grid;
    gap: 18px;
}

.archive-field,
.date-picker-field {
    display: grid;
    gap: 8px;
    min-width: 220px;
}

.archive-field label,
.date-picker-field label {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--color-text-soft);
}

.archive-field input,
.date-picker-field input,
.archive-btn,
.archive-load-btn,
.btn-primary,
.calendar-nav button {
    min-height: 44px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface-strong);
    color: var(--color-text);
    font: inherit;
}

.archive-btn,
.archive-load-btn,
.btn-primary {
    cursor: pointer;
    font-weight: 700;
}

.date-picker,
.calendar,
.archive-date-picker,
.archive-calendar {
    background: rgba(255,255,255,.10);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 18px;
    box-shadow: var(--shadow-sm);
}

.date-picker-row,
.calendar-header,
.calendar-nav {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.calendar-header {
    justify-content: space-between;
    margin-bottom: 18px;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
}

.calendar-day-header,
.calendar-day {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    text-align: center;
    border-radius: var(--radius-sm);
}

.calendar-day-header {
    color: var(--color-text-soft);
    background: rgba(255,255,255,.04);
    font-size: .9rem;
    font-weight: 700;
}

.calendar-day {
    border: 1px solid var(--color-border);
    background: var(--color-surface-strong);
    color: var(--color-text);
    cursor: pointer;
}

.calendar-day.other-month {
    opacity: .38;
    cursor: default;
}

.calendar-day.selected {
    background: rgba(62,109,245,.14);
    border-color: rgba(62,109,245,.18);
}

.calendar-day.today {
    box-shadow: inset 0 0 0 1px var(--color-accent);
}

@media (max-width: 900px) {
    .page-shell {
        padding: 18px 14px 14px;
    }

    .story-panel-inner {
        padding: 20px;
    }

    .story-topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .story-actions {
        justify-content: flex-start;
    }

    #fact-container .header,
    #fact-container .article {
        padding-left: 24px !important;
        padding-right: 24px !important;
    }

    #fact-container .hero-image {
        min-height: 240px !important;
        height: 240px !important;
    }

    .archive-topbar,
    .archive-hero,
    .archive-intro,
    .archive-controls,
    .archive-controls-wrap {
        padding-left: 20px;
        padding-right: 20px;
    }
}

@media (max-width: 640px) {
    .page-shell {
        padding: 14px 10px 12px;
    }

    .story-panel-inner {
        padding: 14px;
        border-radius: 16px;
    }

    .brand-block h1,
    .archive-intro h1,
    .archive-hero h1 {
        font-size: 1.92rem;
    }

    .subtitle,
    .archive-subtitle {
        font-size: .9rem;
    }

    .creative-copy,
    .archive-storyline {
        font-size: 1rem;
    }

    #fact-container .header,
    #fact-container .article {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    #fact-container .hero-image {
        min-height: 200px !important;
        height: 200px !important;
    }

    .state-card,
    .archive-placeholder,
    .archive-error {
        padding: 28px 18px;
    }

    .wallet-key,
    .btc-wallet {
        font-size: .82rem;
    }

    .archive-wrap {
        padding: 14px 10px 24px;
    }

    .archive-field,
    .date-picker-field {
        min-width: 100%;
    }

    .archive-btn,
    .archive-load-btn {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}
