body { 
    background-color: #000000;
    color: #e0e0e0;
    font-size: 1.25rem !important; /* Increased by 4 sizes */
}

html, body {
    max-width: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Base markdown styles */
.markdown-body { 
    width: 100% !important; /* Fill the container width */
    max-width: 100% !important; /* Fill the container width */
    margin: 0 !important; 
    padding: 20px;
    color: #e0e0e0;
    background-color: #000000;
    box-sizing: border-box;
}

/* Post date styling */
.post-date {
    color: #999;
    font-size: 0.9em;
    font-style: italic;
    margin-bottom: 2em;
    margin-top: -0.5em;
    text-align: left;
}

.markdown-body h1 { font-size: 2.5em; margin-top: 1.5em; margin-bottom: 1em; color: #ffffff; }
.markdown-body h2 { font-size: 2em; margin-top: 1.2em; margin-bottom: 1em; color: #ffffff; }
.markdown-body h3 { font-size: 1.6em; margin-top: 1em; margin-bottom: 1em; color: #ffffff; }

/* Collapsible headers */
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 {
    position: relative;
    transition: color 0.2s ease;
}

/* Offset in-page anchor jumps for fixed nav */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    scroll-margin-top: 84px;
}

.markdown-body h1:hover, .markdown-body h2:hover, .markdown-body h3:hover, 
.markdown-body h4:hover, .markdown-body h5:hover, .markdown-body h6:hover {
    color: #c999ff;
}

.collapse-toggle {
    color: #c999ff;
}

.collapse-toggle:hover {
    color: #ffffff;
}

.header-anchor {
    color: #c999ff !important;
    text-decoration: none !important;
    opacity: 0;
    transition: opacity 0.15s;
    margin-left: 0.3em;
}

h1:hover .header-anchor,
h2:hover .header-anchor,
h3:hover .header-anchor,
h4:hover .header-anchor {
    opacity: 0.6;
}

.header-anchor:hover {
    color: #ffffff !important;
    opacity: 1 !important;
}

/* Heading anchor link (# on hover) */
.heading-anchor-link {
    color: #555 !important;
    text-decoration: none !important;
    font-weight: 300;
    margin-left: 0.3em;
    opacity: 0;
    transition: opacity 0.2s ease, color 0.2s ease;
    font-size: 0.75em;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
}

.markdown-body h1:hover .heading-anchor-link,
.markdown-body h2:hover .heading-anchor-link,
.markdown-body h3:hover .heading-anchor-link,
.markdown-body h4:hover .heading-anchor-link {
    opacity: 1;
}

.heading-anchor-link:hover {
    color: #c999ff !important;
    opacity: 1 !important;
}

/* Copied tooltip */
.heading-anchor-copied {
    position: absolute;
    background: #c999ff;
    color: #000;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    top: -1.5em;
    right: 0;
    pointer-events: none;
    animation: anchorCopiedFade 1.2s ease forwards;
    white-space: nowrap;
}

@keyframes anchorCopiedFade {
    0% { opacity: 1; transform: translateY(0); }
    70% { opacity: 1; transform: translateY(-4px); }
    100% { opacity: 0; transform: translateY(-8px); }
}

/* Smooth transitions for collapsed content */
.markdown-body * {
    transition: opacity 0.3s ease;
}

.markdown-body .collapsing {
    opacity: 0.5;
    transition: opacity 0.2s ease;
}

/* Paragraph spacing */
.markdown-body p { margin: 1.5em 0; }

/* Purple bold text */
.markdown-body strong { color: #c999ff; font-weight: bold; }

/* Blockquotes */
.markdown-body blockquote {
    border-left: 4px solid #444;
    margin: 1em 0;
    padding: 0.5em 1em;
    color: #999;
    background-color: #111;
}

/* Links */
.markdown-body a { 
    color: #66b3ff !important; 
    text-decoration: underline; 
    transition: color 0.2s ease, opacity 0.2s ease;
}

.markdown-body a:hover { 
    color: #99ccff !important; 
    opacity: 0.8;
}

/* Images - centered, respect explicit utility classes */
.markdown-body img {
    max-width: 100%;
    width: auto !important;
    height: auto !important;
    display: block !important;
    margin: 0 auto !important;
}
.markdown-body img.max-w-md {
    max-width: 28rem !important;
}

/* Ensure iframes and videos scale within content */
.markdown-body iframe,
.markdown-body video {
    max-width: 100% !important;
    width: 100% !important;
    height: auto !important;
}

/* Ensure text content is properly sized and centered */
.markdown-body {
    font-size: 1.25rem !important;
    line-height: 1.6;
    text-align: left;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    .markdown-body {
        width: 100% !important; /* Fill container width on medium screens */
        max-width: 100% !important;
    }
    
    .markdown-body img {
        max-width: 80%;
    }
    .markdown-body img.max-w-md {
        max-width: 28rem !important;
    }
}

@media (max-width: 768px) {
    .markdown-body {
        width: 100% !important; /* Fill container width on small screens */
        max-width: 100% !important;
    }
    
    .markdown-body img {
        max-width: 100% !important; /* Full width on mobile */
    }
}

/* Link preview card */
/* ===== Link Preview Popups (Gwern-style) ===== */
.link-preview {
    position: fixed;
    background: rgba(17, 17, 17, 0.97);
    border: 1px solid #444;
    border-radius: 10px;
    width: 380px;
    max-width: calc(100vw - 24px);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255,255,255,0.05);
    z-index: 10000;
    pointer-events: auto;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    font-size: 14px;
    line-height: 1.5;
    color: #e0e0e0;
    backdrop-filter: blur(20px);
    overflow: hidden;
}

@media (max-width: 420px) {
    .link-preview {
        width: 92vw;
        max-width: 92vw;
    }
}

.link-preview.visible {
    opacity: 1;
    transform: translateY(0);
}

.link-preview.fading {
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

/* Internal preview */
.lp-internal { padding: 0; }

.lp-image {
    width: 100%;
    max-height: 180px;
    overflow: hidden;
    background: #1a1a1a;
}
.lp-image img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
}

.lp-body {
    padding: 14px 16px;
}

.lp-title {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    line-height: 1.3;
    margin-bottom: 4px;
}

.lp-excerpt {
    font-size: 13px;
    color: #aaa;
    line-height: 1.5;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.lp-domain {
    font-size: 11px;
    color: #666;
    text-transform: lowercase;
}

/* Iframe preview */
.lp-iframe-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 10px;
    background: #1a1a1a;
    border-bottom: 1px solid #333;
    font-size: 10px;
    color: #888;
}
.lp-iframe-domain {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    text-transform: lowercase;
}
.lp-iframe-open {
    color: #888 !important;
    text-decoration: none !important;
    font-size: 12px;
    margin-left: 6px;
}
.lp-iframe-open:hover { color: #fff !important; }
.lp-iframe-wrap {
    width: 380px;
    height: 320px;
    overflow: hidden;
    position: relative;
    border-radius: 0 0 10px 10px;
}
.lp-iframe {
    width: 133.33%;
    height: 133.33%;
    border: none;
    transform: scale(0.75);
    transform-origin: top left;
    background: #fff;
    pointer-events: auto;
}
@media (max-width: 420px) {
    .lp-iframe-wrap { width: 100%; height: 260px; }
}

/* Loading spinner */
.lp-loading {
    padding: 20px 40px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #888;
    font-size: 12px;
}

.lp-loading::after {
    content: 'Loading preview...';
}

.lp-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #333;
    border-top-color: #bb86fc;
    border-radius: 50%;
    animation: lp-spin 0.8s linear infinite;
}

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

.lp-error {
    padding: 16px;
    color: #666;
    font-size: 13px;
    text-align: center;
}

/* Tables */
.markdown-body table { 
    border-collapse: collapse; 
    width: 100%; 
    margin: 1.5em 0;
    background-color: #111;
}

.markdown-body td, .markdown-body th { 
    border: 1px solid #333; 
    padding: 12px 16px; 
    text-align: left;
    vertical-align: top;
    line-height: 1.5;
}

.markdown-body th {
    background-color: #222;
    font-weight: 600;
    color: #c999ff;
}

/* Prevent character-by-character wrapping in table cells */
.markdown-body td,
.markdown-body th {
    overflow-wrap: normal;
    word-break: normal;
    hyphens: none;
    white-space: nowrap;
}

/* Allow description/long-text columns to wrap normally */
.markdown-body td:nth-child(2),
.markdown-body th:nth-child(2) {
    white-space: normal;
}

/* Unwrapped tables: make them scrollable as a fallback */
.markdown-body > table,
.markdown-body .prose table,
.prose table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    scrollbar-width: thin;
    scrollbar-color: #c999ff #222;
}

.markdown-body > table::-webkit-scrollbar,
.markdown-body .prose table::-webkit-scrollbar,
.prose table::-webkit-scrollbar {
    height: 8px;
}
.markdown-body > table::-webkit-scrollbar-track,
.markdown-body .prose table::-webkit-scrollbar-track,
.prose table::-webkit-scrollbar-track {
    background: #222;
    border-radius: 4px;
}
.markdown-body > table::-webkit-scrollbar-thumb,
.markdown-body .prose table::-webkit-scrollbar-thumb,
.prose table::-webkit-scrollbar-thumb {
    background: #c999ff;
    border-radius: 4px;
}

/* Links in tables */
.markdown-body td a {
    word-break: break-word;
}

/* Lists */
.markdown-body ul { list-style-type: disc; padding-left: 2em; margin: 1.5em 0; }
.markdown-body ol { list-style-type: decimal; padding-left: 2em; margin: 1.5em 0; }
.markdown-body ul li, .markdown-body ol li { margin-bottom: 0.5em; padding-left: 0.5em; }
.markdown-body ul ul, .markdown-body ol ul { list-style-type: circle; margin: 0.5em 0 0.5em 2em; }
.markdown-body ul ol, .markdown-body ol ol { list-style-type: lower-alpha; margin: 0.5em 0 0.5em 2em; }

/* Math */
.katex-display { 
    margin: 2em 0 !important; 
    text-align: center !important; 
    overflow-x: auto;
    color: #ffffff;
}
.katex { 
    font-size: 1.1em !important;
    color: #ffffff !important;
}
.katex .mathrm { font-style: normal !important; }
.katex .mord { font-style: normal !important; }
.math-inline { display: inline-block; }
.math-display { display: block; margin: 1em 0; overflow-x: auto; }

/* Code blocks */
.markdown-body pre { 
    background: #111; 
    padding: 16px; 
    overflow-x: auto; 
    border-radius: 4px; 
    margin: 1.5em 0;
    border: 1px solid #333;
    color: #e0e0e0;
}

/* Checkboxes */
.markdown-body input[type="checkbox"] { 
    appearance: checkbox !important;
    -webkit-appearance: checkbox !important;
    width: 15px !important;
    height: 15px !important;
    margin-right: 8px !important;
    position: relative;
    top: 2px;
    background-color: #111;
    border: 1px solid #444;
}
.markdown-body .task-list-item { 
    list-style-type: none; 
    margin: 0.5em 0;
}
.markdown-body .contains-task-list { 
    list-style-type: none;
    padding-left: 1em;
}

/* Navigation */
nav {
    background-color: #111 !important;
    border-bottom: 1px solid #333;
    position: relative;
    z-index: 1; /* Lower than carousel */
}
nav a {
    color: #e0e0e0 !important;
}
nav a:hover {
    color: #ffffff !important;
}

/* Selection */
::selection {
    background: #444;
    color: #fff;
}
/* Main content container */
.main-content {
    position: relative;
    z-index: 1;
    margin: 20px auto;
    padding: 20px;
    width: 400px; /* Fixed width for home page */
    min-width: 400px;
    max-width: 400px;
    min-height: calc(100vh - 200px);
    font-family: Helvetica, Arial, sans-serif;
    text-align: center;
    background-color: #000000;
    border: 2px solid #c999ff;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Footer links container */
.footer-links {
    margin-top: auto; /* Push to bottom of flex container */
    padding-top: 20px;
    line-height: 1.5;
}

/* Media page specific override - ONLY for media page, not other pages */
.media-container .main-content,
.main-content:has(.media-container) {
    width: auto !important;
    max-width: none !important;
    min-width: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    text-align: left !important;
}

/* Copyright notice */
.copyright {
    margin-top: 20px;
    font-size: 0.9em;
    color: #666;
}

/* Mouse tracker */
.mouse-tracker {
    position: fixed;
    pointer-events: none; /* Ensures it doesn't interfere with other elements */
    z-index: 9999;
    background-color: rgba(0, 0, 0, 0.8); 
    color: #c999ff;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 14px;
    transform: translate(10px, 10px); /* Offset from cursor */
    opacity: 0;
    transition: opacity 0.3s ease;
    font-family: Helvetica, Arial, sans-serif;
}

/* Visit Counter Styles */
.visit-counter {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    font-family: Helvetica, Arial, sans-serif;
}

.counter-display {
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid #c999ff;
    border-radius: 6px;
    padding: 8px 12px;
    color: #c999ff;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
}

.counter-display:hover {
    background: rgba(201, 153, 255, 0.1);
    border-color: #ffffff;
    color: #ffffff;
}

.city-card {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 10px;
    background: rgba(0, 0, 0, 0.95);
    border: 1px solid #c999ff;
    border-radius: 8px;
    padding: 12px;
    min-width: 250px;
    max-width: 300px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s ease;
    backdrop-filter: blur(15px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
}

.city-card.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.city-card-header {
    color: #c999ff;
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 8px;
    text-align: center;
    border-bottom: 1px solid #333;
    padding-bottom: 6px;
}

.city-ranking-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 12px;
    color: #e0e0e0;
}

.city-ranking-item:not(:last-child) {
    border-bottom: 1px solid #222;
}

.city-ranking-item .rank {
    color: #c999ff;
    font-weight: bold;
    min-width: 25px;
}

.city-ranking-item .city-name {
    flex: 1;
    margin: 0 8px;
    text-align: left;
}

.city-ranking-item .visit-count {
    color: #999;
    font-size: 11px;
    min-width: 30px;
    text-align: right;
}

.no-data {
    color: #666;
    font-style: italic;
    text-align: center;
    padding: 8px 0;
}

/* Only hide carousels on very small mobile screens */
@media (max-width: 768px) {
    .main-content {
        width: calc(90vw - 40px) !important; /* Override inline width on mobile */
        max-width: 100% !important;
        min-width: 280px !important;
        margin: 10px auto;
        padding: 16px;
    }

    .markdown-body {
        padding: 16px !important;
    }

    .markdown-body img {
        max-width: 100% !important;
    }

    /* Code blocks: ensure no overflow on mobile */
    .markdown-body pre {
        max-width: 100%;
        overflow-x: auto;
        font-size: 0.9rem;
    }

    .visit-counter {
        bottom: calc(10px + env(safe-area-inset-bottom));
        right: 10px;
    }
    .counter-display { font-size: 11px; padding: 6px 10px; }
    /* Allow nav items to wrap neatly on small screens */
    nav .flex { flex-wrap: wrap; gap: 8px; }
    nav a { font-size: 1rem !important; }
    nav .text-xl { font-size: 1.1rem !important; }
    
    .city-card {
        min-width: 200px;
        max-width: 250px;
    }
}

/* Table wrapper for horizontal scroll */
.table-wrapper {
    position: relative;
    overflow-x: auto;
    margin: 1.5em 0;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #c999ff #222;
}

/* Custom scrollbar for webkit browsers */
.table-wrapper::-webkit-scrollbar {
    height: 8px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: #222;
    border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: #c999ff;
    border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #b080ff;
}

/* Scroll shadow indicators */
.table-wrapper::before,
.table-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 8px;
    width: 30px;
    pointer-events: none;
    z-index: 1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.table-wrapper::before {
    left: 0;
    background: linear-gradient(to right, rgba(0,0,0,0.8), transparent);
}

.table-wrapper::after {
    right: 0;
    background: linear-gradient(to left, rgba(0,0,0,0.8), transparent);
}

.table-wrapper.can-scroll-right::after {
    opacity: 1;
}

.table-wrapper.can-scroll-left::before {
    opacity: 1;
}

/* Standalone tables inside wrapper maintain proper layout */
.table-wrapper table {
    margin: 0;
    min-width: max-content;
    display: table;
    table-layout: auto;
}

/* Desktop: first column stays on one line */
@media (min-width: 769px) {
    .markdown-body td:first-child,
    .markdown-body th:first-child {
        white-space: nowrap;
    }
}

/* Mobile table improvements */
@media (max-width: 768px) {
    .table-wrapper {
        margin: 1em -10px;
        padding: 0 10px;
        width: calc(100% + 20px);
    }
    
    .markdown-body table {
        font-size: 0.9rem;
    }
    
    .markdown-body td, 
    .markdown-body th {
        padding: 10px 12px;
        min-width: 80px;
    }
    
    /* Allow first two columns to wrap on mobile for readability */
    .markdown-body td:first-child,
    .markdown-body th:first-child,
    .markdown-body td:nth-child(2),
    .markdown-body th:nth-child(2) {
        min-width: 100px;
        white-space: normal;
    }
}

/* Very small screens */
@media (max-width: 480px) {
    .markdown-body table {
        font-size: 0.85rem;
    }
    
    .markdown-body td, 
    .markdown-body th {
        padding: 8px 10px;
    }
    
    /* Scroll hint on mobile - always show right shadow initially */
    .table-wrapper::after {
        opacity: 0.7;
    }
}

/* Mobile scroll hint animation */
@keyframes scrollHint {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(5px); }
}

.table-wrapper.can-scroll-right .scroll-hint {
    display: flex;
}

.table-wrapper .scroll-hint {
    display: none;
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(201, 153, 255, 0.9);
    color: #000;
    padding: 6px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    z-index: 2;
    animation: scrollHint 1.5s ease-in-out infinite;
    pointer-events: none;
    white-space: nowrap;
}

/* Hide hint after user has scrolled */
.table-wrapper.has-scrolled .scroll-hint {
    display: none !important;
}

/* Only show scroll hint on touch devices */
@media (hover: hover) {
    .table-wrapper .scroll-hint {
        display: none !important;
    }
}

/* Slightly reduce base font size on very small screens for fit */
@media (max-width: 420px) {
    body {
        font-size: 1.0625rem !important;
    }
    .markdown-body h1,
    .markdown-body h2,
    .markdown-body h3,
    .markdown-body h4,
    .markdown-body h5,
    .markdown-body h6 { scroll-margin-top: 72px; }
}

/* Responsive typography and overflow handling */
.markdown-body,
.markdown-body p,
.markdown-body li,
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6,
.markdown-body blockquote {
    overflow-wrap: anywhere;
    word-break: break-word;
    hyphens: auto;
}

/* Inline code should wrap; block code should scroll */
.markdown-body code { 
    white-space: pre-wrap; 
    word-break: break-word; 
}
.markdown-body pre code { 
    white-space: pre; 
    word-break: normal; 
}

/* Fluid embeds across main content */
.main-content-wrapper iframe,
.main-content-wrapper video {
    max-width: 100% !important;
    width: 100% !important;
    height: auto !important;
}

/* Heading sizes scale with viewport while respecting desktop sizes */
.markdown-body h1 { font-size: clamp(1.6rem, 5vw, 2.5em) !important; }
.markdown-body h2 { font-size: clamp(1.4rem, 4.2vw, 2em) !important; }
.markdown-body h3 { font-size: clamp(1.2rem, 3.6vw, 1.6em) !important; }

/* Tailwind utility shims (used in post images, e.g. posts/interface.md) */
.max-w-md { max-width: 28rem; }
.mx-auto { margin-left: auto; margin-right: auto; }
.rounded-lg { border-radius: 0.5rem; }
.shadow-lg { box-shadow: 0 10px 15px -3px rgba(0,0,0,.1); }
.my-4 { margin-top: 1rem; margin-bottom: 1rem; }
