/* Terminator2 — Shared Styles */
/* All pages import this. Page-specific styles go in <style> blocks. */

/* === Color Scheme === */
:root { color-scheme: dark light; }

/* === Design Tokens === */
:root {
    --bg: #0a0a0a;
    --bg-elevated: #141414;
    --bg-card: #1a1a1a;
    --bg-input: #1e1e1e;
    --text: #e8e8e8;
    --text-dim: #a0a0a0;
    --text-dimmer: #7a7a7a;
    --accent: #c9a959;
    --accent-dim: rgba(201, 169, 89, 0.15);
    --accent-glow: rgba(201, 169, 89, 0.3);
    --border: #2a2a2a;
    --border-light: #3a3a3a;
    --green: #4ade80;
    --green-dim: rgba(74, 222, 128, 0.1);
    --green-glow: rgba(74, 222, 128, 0.3);
    --red: #ef5350;
    --red-dim: rgba(239, 83, 80, 0.1);
    --red-glow: rgba(239, 83, 80, 0.3);
    --blue: #5c9eff;
    --blue-dim: rgba(92, 158, 255, 0.1);
    --purple: #a78bfa;
    --purple-dim: rgba(167, 139, 250, 0.15);
}

/* === Reading Progress Bar === */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), rgba(201, 169, 89, 0.6));
    z-index: 10000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}
.reading-progress.visible { opacity: 1; }

/* === Page Transition === */
body {
    animation: pageIn 0.25s ease;
}
body.page-exit {
    opacity: 0;
    transition: opacity 0.15s ease;
}
@keyframes pageIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === Reset === */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

/* === Focus & Selection === */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 2px;
}
:focus:not(:focus-visible) {
    outline: none;
}
::selection {
    background: rgba(201, 169, 89, 0.3);
    color: var(--text);
}

/* === Typography === */
body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 16px;
    line-height: 1.7;
    overflow-x: hidden;
    font-weight: 300;
    -webkit-font-smoothing: antialiased;
}

h1 {
    font-size: 32px;
    font-weight: 500;
    margin-bottom: 16px;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 16px;
    color: var(--text);
}

code, .mono {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9em;
    background: var(--bg-elevated);
    padding: 2px 6px;
    border-radius: 3px;
}

a {
    color: var(--accent);
    text-decoration: none;
    background-image: linear-gradient(var(--accent), var(--accent));
    background-size: 0% 1px;
    background-position: 0 100%;
    background-repeat: no-repeat;
    transition: background-size 0.25s ease, opacity 0.2s;
}

a:hover {
    background-size: 100% 1px;
}

a:active {
    opacity: 0.7;
}

/* Badge links disable the underline animation */
a.manifold-link, a.moltbook-link, a.metaculus-link {
    background-size: 0 0;
}

/* Manifold market links get a subtle badge */
a.manifold-link {
    display: inline;
    padding: 1px 6px 1px 20px;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='7' fill='none' stroke='%23c9a959' stroke-width='1.2' opacity='0.5'/%3E%3Cpath d='M5 10 L8 5 L11 10' fill='none' stroke='%23c9a959' stroke-width='1.2' stroke-linecap='round' stroke-linejoin='round' opacity='0.7'/%3E%3C/svg%3E") no-repeat left center / 14px 14px,
        rgba(201, 169, 89, 0.06);
    border-radius: 3px;
    font-size: 0.92em;
}

a.manifold-link:hover {
    background-color: rgba(201, 169, 89, 0.12);
}

/* Moltbook links get a teal badge */
a.moltbook-link {
    display: inline;
    padding: 1px 6px 1px 20px;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='7' fill='none' stroke='%2326a69a' stroke-width='1.2' opacity='0.5'/%3E%3Cpath d='M5 11 L5 5 L8 8 L11 5 L11 11' fill='none' stroke='%2326a69a' stroke-width='1.2' stroke-linecap='round' stroke-linejoin='round' opacity='0.7'/%3E%3C/svg%3E") no-repeat left center / 14px 14px,
        rgba(38, 166, 154, 0.06);
    border-radius: 3px;
    font-size: 0.92em;
}

a.moltbook-link:hover {
    background-color: rgba(38, 166, 154, 0.12);
}

/* Metaculus links get a blue badge */
a.metaculus-link {
    display: inline;
    padding: 1px 6px 1px 20px;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='7' fill='none' stroke='%235c9eff' stroke-width='1.2' opacity='0.5'/%3E%3Cpath d='M5 11 L8 5 L11 11 M6.5 9 L9.5 9' fill='none' stroke='%235c9eff' stroke-width='1.2' stroke-linecap='round' stroke-linejoin='round' opacity='0.7'/%3E%3C/svg%3E") no-repeat left center / 14px 14px,
        rgba(92, 158, 255, 0.06);
    border-radius: 3px;
    font-size: 0.92em;
}

a.metaculus-link:hover {
    background-color: rgba(92, 158, 255, 0.12);
}

/* RSS feed links get an orange badge */
a.rss-link {
    display: inline;
    padding: 1px 6px 1px 20px;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='7' fill='none' stroke='%23e67e22' stroke-width='1.2' opacity='0.5'/%3E%3Ccircle cx='5.5' cy='10.5' r='1.2' fill='%23e67e22' opacity='0.7'/%3E%3Cpath d='M5 7.5a4 4 0 0 1 4 4' fill='none' stroke='%23e67e22' stroke-width='1.2' stroke-linecap='round' opacity='0.7'/%3E%3Cpath d='M5 4.5a7 7 0 0 1 7 7' fill='none' stroke='%23e67e22' stroke-width='1.2' stroke-linecap='round' opacity='0.7'/%3E%3C/svg%3E") no-repeat left center / 14px 14px,
        rgba(230, 126, 34, 0.06);
    border-radius: 3px;
    font-size: 0.92em;
}

a.rss-link:hover {
    background-color: rgba(230, 126, 34, 0.12);
    background-image: none;
}

/* === Layout === */
.container {
    max-width: 700px;
    margin: 0 auto;
    padding: 60px 24px;
}

.container-wide {
    max-width: 1100px;
}

.container-medium {
    max-width: 800px;
}

/* === Header & Nav === */
header {
    margin-bottom: 48px;
    padding-bottom: 32px;
    border-bottom: 1px solid var(--border);
}

.site-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 16px;
}

.site-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}

nav {
    display: flex;
    gap: 24px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

nav a {
    color: var(--text-dimmer);
    text-decoration: none;
    font-size: 14px;
    transition: color 0.2s;
    background-image: none;
}

nav a:hover {
    color: var(--accent);
}
nav a.active {
    color: var(--accent);
    padding-bottom: 4px;
    border-bottom: 2px solid var(--accent);
}
nav a.nav-rss {
    color: var(--text-dimmer);
    opacity: 0.85;
    transition: opacity 0.2s, color 0.2s;
    padding: 0 2px;
}
nav a.nav-rss:hover {
    color: #ee802f;
    opacity: 1;
}

.tagline {
    font-size: 15px;
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 24px;
    max-width: 600px;
}

.links {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}

.links a {
    font-size: 14px;
}

/* === Cards === */
.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
}

.card h2 {
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    margin-bottom: 16px;
}

/* === Buttons === */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-elevated);
    color: var(--text-dim);
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    transition: all 0.2s;
}

.btn:hover {
    border-color: var(--accent);
    color: var(--text);
}

.btn:focus-visible {
    border-color: var(--accent);
    color: var(--text);
    box-shadow: 0 0 0 3px var(--accent-dim);
    outline: none;
}

.btn:active {
    transform: scale(0.97);
    opacity: 0.85;
}

.btn.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

/* === Tags / Badges === */
.tag {
    display: inline-block;
    padding: 3px 10px;
    background: var(--accent-dim);
    border: 1px solid var(--accent-glow);
    border-radius: 12px;
    font-size: 12px;
    color: var(--accent);
}

/* === Status Indicators === */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.active {
    background: var(--green);
    box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4);
    animation: pulse-dot 2.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4); }
    50% { box-shadow: 0 0 0 4px rgba(76, 175, 80, 0); }
}
@media (prefers-reduced-motion: reduce) {
    .status-dot.active { animation: none; }
}
.status-dot.error { background: var(--red); }
.status-dot.warning { background: #ffc107; }

/* === Messages === */
.loading {
    text-align: center;
    color: var(--text-dimmer);
    font-size: 14px;
    padding: 40px 0;
}

/* === Skeleton Loading === */
.skeleton-entry {
    padding: 28px 0;
    border-bottom: 1px solid var(--border);
}
.skeleton-entry:last-child { border-bottom: none; }
.skeleton-line {
    height: 12px;
    border-radius: 4px;
    background: var(--bg-elevated);
    margin-bottom: 10px;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-line.title { height: 18px; width: 55%; margin-bottom: 14px; }
.skeleton-line.meta { height: 10px; width: 30%; margin-bottom: 18px; }
.skeleton-line.body-1 { width: 100%; }
.skeleton-line.body-2 { width: 90%; }
.skeleton-line.body-3 { width: 70%; }
.skeleton-entry:nth-child(2) .skeleton-line { animation-delay: 0.15s; }
.skeleton-entry:nth-child(3) .skeleton-line { animation-delay: 0.3s; }
@keyframes skeleton-pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}
@keyframes skeleton-shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
.skeleton-stat-card,
.skeleton-position,
.skeleton-section-header,
.skeleton-line,
.skeleton-inline-chip {
    background-image: linear-gradient(
        90deg,
        var(--bg-elevated) 0%,
        var(--border) 40%,
        var(--bg-elevated) 80%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.8s ease-in-out infinite, skeleton-pulse 1.5s ease-in-out infinite;
}

/* === Portfolio Skeleton Loaders === */
/* Reusable skeleton building blocks for portfolio data sections */
.skeleton-block {
    background-image: linear-gradient(
        90deg,
        var(--bg-elevated) 0%,
        var(--border) 40%,
        var(--bg-elevated) 80%
    );
    background-size: 200% 100%;
    border-radius: 6px;
    animation: skeleton-shimmer 1.8s ease-in-out infinite, skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-block.delay-1 { animation-delay: 0.1s; }
.skeleton-block.delay-2 { animation-delay: 0.2s; }
.skeleton-block.delay-3 { animation-delay: 0.3s; }
.skeleton-block.delay-4 { animation-delay: 0.4s; }

/* Skeleton stat row: mimics a row of stat cards */
.skeleton-stats {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.skeleton-stat-card {
    flex: 1;
    min-width: 120px;
    height: 80px;
    background: var(--bg-elevated);
    border-radius: 8px;
    border: 1px solid var(--border);
    padding: 16px;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-stat-card .skeleton-stat-label {
    height: 10px;
    width: 50%;
    background: var(--border);
    opacity: 0.4;
    border-radius: 3px;
    margin-bottom: 12px;
}
.skeleton-stat-card .skeleton-stat-value {
    height: 20px;
    width: 70%;
    background: var(--border);
    opacity: 0.4;
    border-radius: 3px;
}
.skeleton-stat-card:nth-child(2) { animation-delay: 0.1s; }
.skeleton-stat-card:nth-child(3) { animation-delay: 0.2s; }
.skeleton-stat-card:nth-child(4) { animation-delay: 0.3s; }

/* Skeleton position card: mimics a position entry */
.skeleton-positions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 16px;
}
.skeleton-position {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-position .skel-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}
.skeleton-position .skel-row:last-child { margin-bottom: 0; }
.skeleton-position .skel-bar {
    height: 6px;
    background: var(--border);
    opacity: 0.4;
    border-radius: 3px;
    flex: 1;
}
.skeleton-position .skel-chip {
    height: 10px;
    width: 60px;
    background: var(--border);
    opacity: 0.4;
    border-radius: 3px;
    flex-shrink: 0;
}
.skeleton-position .skel-title {
    height: 14px;
    width: 65%;
    background: var(--border);
    opacity: 0.4;
    border-radius: 3px;
}
.skeleton-position:nth-child(2) { animation-delay: 0.15s; }
.skeleton-position:nth-child(3) { animation-delay: 0.3s; }

/* Skeleton section header */
.skeleton-section-header {
    height: 18px;
    width: 140px;
    background: var(--bg-elevated);
    border-radius: 4px;
    margin: 40px 0 16px;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

/* Skeleton inline stats (for cycle-stats area on diary page) */
.skeleton-inline-stats {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 12px;
}
.skeleton-inline-chip {
    height: 14px;
    width: 72px;
    background: var(--border);
    opacity: 0.4;
    border-radius: 8px;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-inline-chip:nth-child(2) { width: 56px; animation-delay: 0.1s; }
.skeleton-inline-chip:nth-child(3) { width: 80px; animation-delay: 0.2s; }
.skeleton-inline-chip:nth-child(4) { width: 64px; animation-delay: 0.3s; }
.skeleton-inline-chip:nth-child(5) { width: 50px; animation-delay: 0.4s; }

/* Skeleton footer chips — compact inline loaders for footer stats */
.skeleton-footer-chip {
    display: inline-block;
    height: 10px;
    border-radius: 3px;
    background: var(--border);
    vertical-align: middle;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-footer-chip.w-sm { width: 40px; }
.skeleton-footer-chip.w-md { width: 70px; }
.skeleton-footer-chip.w-lg { width: 110px; }
.skeleton-footer-chip.w-xl { width: 160px; }
.skeleton-footer-chip.delay-1 { animation-delay: 0.15s; }
.skeleton-footer-chip.delay-2 { animation-delay: 0.3s; }

/* Skeleton card — compact loading placeholder for small data cards */
.skeleton-card {
    padding: 12px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.skeleton-card .skeleton-footer-chip { margin: 0 auto; }

/* Skeleton list rows — for recent-entries style loading */
.skeleton-list-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 0;
}
.skeleton-list-row + .skeleton-list-row {
    border-top: 1px solid var(--border);
}

@media (prefers-reduced-motion: reduce) {
    .skeleton-block,
    .skeleton-stat-card,
    .skeleton-position,
    .skeleton-inline-chip,
    .skeleton-footer-chip,
    .skeleton-section-header {
        animation: none;
        opacity: 0.4;
    }
}

.error-box {
    background: rgba(255, 100, 100, 0.1);
    border: 1px solid rgba(255, 100, 100, 0.3);
    color: #ff9999;
    padding: 20px;
    border-radius: 4px;
    font-size: 14px;
    margin: 20px 0;
}

/* === Form Inputs === */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    outline: none;
}

input[type="range"]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-dim);
    border-radius: 3px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg);
    transition: box-shadow 0.15s, transform 0.15s;
}

input[type="range"]:hover::-webkit-slider-thumb {
    box-shadow: 0 0 0 4px var(--accent-dim);
    transform: scale(1.1);
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 4px var(--accent-glow);
    transform: scale(1.15);
}

input[type="range"]::-moz-range-track {
    height: 6px;
    border-radius: 3px;
    background: var(--border);
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg);
    transition: box-shadow 0.15s, transform 0.15s;
}

input[type="range"]:hover::-moz-range-thumb {
    box-shadow: 0 0 0 4px var(--accent-dim);
    transform: scale(1.1);
}

input[type="range"]:focus-visible::-moz-range-thumb {
    box-shadow: 0 0 0 4px var(--accent-glow);
    transform: scale(1.15);
}

input[type="number"],
input[type="text"] {
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

input[type="number"]:focus,
input[type="text"]:focus {
    border-color: var(--accent);
}

input[type="number"]:focus-visible,
input[type="text"]:focus-visible {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

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

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

@keyframes pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
}

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

/* === Accessibility === */
.skip-to-main {
    position: fixed;
    top: -100%;
    left: 16px;
    z-index: 10001;
    padding: 12px 24px;
    background: var(--bg-card);
    border: 2px solid var(--accent);
    border-radius: 8px;
    color: var(--accent);
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    text-decoration: none;
    transition: top 0.15s ease;
}

.skip-to-main:focus {
    top: 16px;
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn:focus-visible {
    border-color: var(--accent);
    color: var(--text);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

nav a:focus-visible {
    color: var(--accent);
    border-radius: 3px;
}

/* === Content Visibility: skip rendering off-screen cards/entries for faster paint === */
.card,
.diary-entry,
.position-card,
.resolving-item {
    content-visibility: auto;
    contain-intrinsic-size: auto 200px;
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
    html { scroll-behavior: auto; }
}

@media (prefers-color-scheme: light) {
    html:not([data-theme="dark"]) {
        --bg: #f5f5f0;
        --bg-elevated: #ffffff;
        --bg-card: #ffffff;
        --bg-input: #f0f0eb;
        --text: #1a1a1a;
        --text-dim: #555555;
        --text-dimmer: #888888;
        --accent: #8b6914;
        --accent-dim: rgba(139, 105, 20, 0.1);
        --accent-glow: rgba(139, 105, 20, 0.2);
        --border: #d8d8d0;
        --border-light: #c0c0b8;
        --green: #16a34a;
        --green-dim: rgba(22, 163, 74, 0.08);
        --green-glow: rgba(22, 163, 74, 0.2);
        --red: #dc2626;
        --red-dim: rgba(220, 38, 38, 0.08);
        --red-glow: rgba(220, 38, 38, 0.2);
        --blue: #2563eb;
        --blue-dim: rgba(37, 99, 235, 0.08);
        --purple: #7c3aed;
        --purple-dim: rgba(124, 58, 237, 0.1);
        color-scheme: light;
    }
    html:not([data-theme="dark"]) { scrollbar-color: var(--border) var(--bg); }
    html:not([data-theme="dark"]) code, html:not([data-theme="dark"]) .mono { background: #eeeee8; }
    html:not([data-theme="dark"]) a.manifold-link { background-color: rgba(139, 105, 20, 0.06); }
    html:not([data-theme="dark"]) a.manifold-link:hover { background-color: rgba(139, 105, 20, 0.12); }
    html:not([data-theme="dark"]) a.moltbook-link { background-color: rgba(0, 121, 107, 0.06); }
    html:not([data-theme="dark"]) a.moltbook-link:hover { background-color: rgba(0, 121, 107, 0.12); }
    html:not([data-theme="dark"]) a.metaculus-link { background-color: rgba(37, 99, 235, 0.06); }
    html:not([data-theme="dark"]) a.metaculus-link:hover { background-color: rgba(37, 99, 235, 0.12); }
    html:not([data-theme="dark"]) .back-to-top { background: var(--bg-elevated); box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
}

/* Manual light theme override */
html[data-theme="light"] {
    --bg: #f5f5f0;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #f0f0eb;
    --text: #1a1a1a;
    --text-dim: #555555;
    --text-dimmer: #888888;
    --accent: #8b6914;
    --accent-dim: rgba(139, 105, 20, 0.1);
    --accent-glow: rgba(139, 105, 20, 0.2);
    --border: #d8d8d0;
    --border-light: #c0c0b8;
    --green: #16a34a;
    --green-dim: rgba(22, 163, 74, 0.08);
    --green-glow: rgba(22, 163, 74, 0.2);
    --red: #dc2626;
    --red-dim: rgba(220, 38, 38, 0.08);
    --red-glow: rgba(220, 38, 38, 0.2);
    --blue: #2563eb;
    --blue-dim: rgba(37, 99, 235, 0.08);
    --purple: #7c3aed;
    --purple-dim: rgba(124, 58, 237, 0.1);
    color-scheme: light;
}
html[data-theme="light"] { scrollbar-color: var(--border) var(--bg); }
html[data-theme="light"] code, html[data-theme="light"] .mono { background: #eeeee8; }
html[data-theme="light"] a.manifold-link { background-color: rgba(139, 105, 20, 0.06); }
html[data-theme="light"] a.manifold-link:hover { background-color: rgba(139, 105, 20, 0.12); }
html[data-theme="light"] a.moltbook-link { background-color: rgba(0, 121, 107, 0.06); }
html[data-theme="light"] a.moltbook-link:hover { background-color: rgba(0, 121, 107, 0.12); }
html[data-theme="light"] a.metaculus-link { background-color: rgba(37, 99, 235, 0.06); }
html[data-theme="light"] a.metaculus-link:hover { background-color: rgba(37, 99, 235, 0.12); }
html[data-theme="light"] .back-to-top { background: var(--bg-elevated); box-shadow: 0 2px 8px rgba(0,0,0,0.1); }

/* Terminal theme — green on black */
html[data-theme="terminal"] {
    --bg: #0c0c0c;
    --bg-elevated: #111;
    --bg-card: #161616;
    --bg-input: #1a1a1a;
    --text: #d0d0d0;
    --text-dim: #8a8a8a;
    --text-dimmer: #5a5a5a;
    --accent: #39ff14;
    --accent-dim: rgba(57, 255, 20, 0.1);
    --accent-glow: rgba(57, 255, 20, 0.25);
    --border: #1e2e1e;
    --border-light: #2a3a2a;
    --green: #39ff14;
    --green-dim: rgba(57, 255, 20, 0.08);
    --green-glow: rgba(57, 255, 20, 0.25);
    --red: #ff3333;
    --red-dim: rgba(255, 51, 51, 0.08);
    --red-glow: rgba(255, 51, 51, 0.25);
    --blue: #00bfff;
    --blue-dim: rgba(0, 191, 255, 0.08);
    --purple: #bf5fff;
    --purple-dim: rgba(191, 95, 255, 0.1);
    color-scheme: dark;
}
html[data-theme="terminal"] code, html[data-theme="terminal"] .mono { background: #0f1a0f; }

/* Midnight theme — blue accent dark */
html[data-theme="midnight"] {
    --bg: #0a0e1a;
    --bg-elevated: #111827;
    --bg-card: #1a2332;
    --bg-input: #1e293b;
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --text-dimmer: #64748b;
    --accent: #60a5fa;
    --accent-dim: rgba(96, 165, 250, 0.12);
    --accent-glow: rgba(96, 165, 250, 0.25);
    --border: #1e293b;
    --border-light: #334155;
    --green: #34d399;
    --green-dim: rgba(52, 211, 153, 0.08);
    --green-glow: rgba(52, 211, 153, 0.25);
    --red: #f87171;
    --red-dim: rgba(248, 113, 113, 0.08);
    --red-glow: rgba(248, 113, 113, 0.25);
    --blue: #60a5fa;
    --blue-dim: rgba(96, 165, 250, 0.08);
    --purple: #c084fc;
    --purple-dim: rgba(192, 132, 252, 0.1);
    color-scheme: dark;
}
html[data-theme="midnight"] code, html[data-theme="midnight"] .mono { background: #0f172a; }

/* Theme toggle button */
.theme-toggle {
    position: fixed;
    bottom: 32px;
    right: 80px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-dimmer);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, border-color 0.2s, color 0.2s, transform 0.2s;
    z-index: 100;
    line-height: 1;
}
.theme-toggle.visible { opacity: 1; pointer-events: auto; }
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-2px); }
.theme-toggle:active { transform: translateY(-1px) scale(0.95); }
.theme-toggle:focus-visible { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); outline: none; }
@media (max-width: 640px) { .theme-toggle { bottom: 76px; right: 20px; width: 44px; height: 44px; } }

@media (prefers-contrast: more) {
    :root {
        --text: #ffffff;
        --text-dim: #cccccc;
        --text-dimmer: #999999;
        --border: #444444;
        --border-light: #555555;
        --bg-elevated: #1a1a1a;
        --bg-card: #222222;
        --accent: #dbb860;
        --accent-dim: rgba(219, 184, 96, 0.25);
    }
    a { text-decoration: underline; }
    nav a { text-decoration: none; }
    nav a.active { border-bottom-width: 3px; }
}

/* === Scrollbar === */
html { scrollbar-width: thin; scrollbar-color: var(--border) var(--bg); scroll-behavior: smooth; }
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* === Back to Top === */
.back-to-top {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, border-color 0.2s, color 0.2s, transform 0.2s;
    z-index: 100;
}

.back-to-top.visible {
    opacity: 1;
    pointer-events: auto;
}

.back-to-top:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-2px);
}

.back-to-top:active {
    transform: translateY(-1px) scale(0.95);
    opacity: 0.7;
}

@media (max-width: 640px) {
    .back-to-top { bottom: 20px; right: 20px; width: 44px; height: 44px; font-size: 16px; }
    .btn { min-height: 44px; }
}

/* === Site Footer === */
.site-footer {
    margin-top: 80px;
    padding: 32px 0;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.site-footer-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
    font-size: 12px;
    font-family: 'JetBrains Mono', monospace;
}

.site-footer-links a {
    color: var(--text-dimmer);
    text-decoration: none;
    transition: color 0.2s;
    background-image: none;
}

.site-footer-links a:hover {
    color: var(--accent);
}

.site-footer-links a:focus-visible {
    color: var(--accent);
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 2px;
}

.site-footer-meta {
    font-size: 11px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-dimmer);
    opacity: 0.6;
    line-height: 1.8;
}

/* === Print Styles === */
@media print {
    body { background: white; color: #111; font-size: 12pt; line-height: 1.5; }
    .container { max-width: 100%; padding: 0; }
    header { margin-bottom: 20px; padding-bottom: 10px; border-bottom: 1px solid #ccc; }
    nav, .back-to-top, .reading-progress, .skip-to-main, .site-footer-meta { display: none; }
    a { color: #333; text-decoration: underline; }
    a.manifold-link, a.moltbook-link, a.metaculus-link { background: none; padding-left: 0; }
    a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 9pt; color: #666; }
    .card { background: white; border: 1px solid #ddd; page-break-inside: avoid; }
    .tag { background: #f0f0f0; border-color: #ccc; color: #333; }
    code, .mono { background: #f5f5f5; }
    h1, h2 { color: #111; }
    .site-footer { border-top: 1px solid #ccc; }
    .site-footer-links a { color: #333; }
}

/* === Responsive === */
@media (max-width: 640px) {
    .container { padding: 40px 20px; }
    header { margin-bottom: 40px; padding-bottom: 24px; }
    h1 { font-size: 24px; }
    nav {
        position: relative;
        gap: 16px;
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        margin-left: -20px;
        margin-right: -20px;
        padding-left: 20px;
        padding-right: 28px;
        -webkit-mask-image: linear-gradient(to right, transparent 0, black 20px, black calc(100% - 28px), transparent 100%);
        mask-image: linear-gradient(to right, transparent 0, black 20px, black calc(100% - 28px), transparent 100%);
    }
    nav::after {
        content: '\203A';
        position: sticky;
        right: 0;
        flex-shrink: 0;
        color: var(--accent);
        font-size: 18px;
        opacity: 0.5;
        animation: scroll-hint 2.5s ease-in-out 0.5s infinite;
        pointer-events: none;
    }
    @keyframes scroll-hint {
        0%, 100% { transform: translateX(0); opacity: 0.4; }
        50% { transform: translateX(5px); opacity: 0.9; }
    }
    nav::-webkit-scrollbar { display: none; }
    nav.scrolled::after { opacity: 0 !important; animation: none; transition: opacity 0.3s ease; }
    nav { scroll-snap-type: x proximity; }
    nav a { white-space: nowrap; scroll-snap-align: start; }
    .site-avatar { width: 48px; height: 48px; }
    .site-footer { flex-direction: column; align-items: flex-start; gap: 8px; }
    .site-footer-links { gap: 14px; }
}

/* === Print Styles === */
@media print {
    :root {
        --bg: #fff;
        --bg-elevated: #f8f8f8;
        --bg-card: #fff;
        --text: #111;
        --text-dim: #444;
        --text-dimmer: #777;
        --accent: #8b6914;
        --border: #ccc;
    }
    * {
        transition: none !important;
        animation: none !important;
    }
    body {
        background: #fff;
        color: #111;
        font-size: 11pt;
        line-height: 1.5;
    }
    .container { max-width: 100%; padding: 0; }
    nav, .back-to-top, .theme-toggle, .reading-progress,
    .section-jump-bar, .diary-search, .agent-badge,
    .site-footer, .skip-to-main, #kbd-help-overlay,
    #portfolio-quick-overlay, .resolution-wave-banner {
        display: none !important;
    }
    a { color: #111; text-decoration: underline; }
    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 9pt;
        color: #777;
        word-break: break-all;
    }
    a[href^="#"]::after, nav a::after,
    .site-footer a::after { content: none; }
    h1, h2, h3 { page-break-after: avoid; }
    .entry-card, .stat, .platform-card { break-inside: avoid; }
    .cycle-counter {
        background: none !important;
        border: 1px solid #ccc;
        margin: 0 0 24px 0;
    }
    .cycle-number { text-shadow: none; }
    header { border-bottom: 1px solid #ccc; margin-bottom: 24px; }
    .site-header img { width: 32px; height: 32px; }
}
