/* Solisp Book - Premium Reading Experience */
/* Newspaper-style typography with modern UX */

/* ============================================
   FONTS
   ============================================ */
@import url('https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ============================================
   CSS VARIABLES - LIGHT THEME
   ============================================ */
.light, :root {
    --bg: #FAFAF8 !important;
    --fg: #1A1A1A !important;
    --sidebar-bg: #F0F0ED !important;
    --sidebar-fg: #2D2D2D !important;
    --sidebar-active: #000000 !important;
    --links: #1a5f7a !important;
    --inline-code-color: #c7254e !important;
    --inline-code-bg: #f9f2f4 !important;
    --theme-popup-bg: #FAFAF8 !important;
    --theme-popup-border: #D0D0C8 !important;
    --quote-bg: #F5F5F0 !important;
    --quote-border: #1a5f7a !important;
    --table-border-color: #D0D0C8 !important;
    --table-header-bg: #E8E8E3 !important;
    --table-alternate-bg: #F5F5F0 !important;
    --searchbar-border-color: #D0D0C8 !important;
    --searchbar-bg: #FFFFFF !important;
    --icons: #4A4A4A !important;
    --icons-hover: #000000 !important;
    --accent: #1a5f7a;
    --accent-light: #e8f4f8;
    --success: #2d7d46;
    --warning: #b8860b;
    --drop-cap-color: #1a5f7a;
    --sidenote-bg: #f8f8f5;
    --code-bg: #f8f8f5;
    --code-border: #e0e0d8;
    --toc-bg: rgba(250, 250, 248, 0.95);
}

/* ============================================
   CSS VARIABLES - DARK THEME (OLED)
   ============================================ */
.coal, .navy, .ayu {
    --bg: #0A0A0A !important;
    --fg: #E8E8E8 !important;
    --sidebar-bg: #111111 !important;
    --sidebar-fg: #C8C8C8 !important;
    --sidebar-active: #FFFFFF !important;
    --links: #6CB4D4 !important;
    --inline-code-color: #f8b4c4 !important;
    --inline-code-bg: #2a1a1f !important;
    --theme-popup-bg: #111111 !important;
    --theme-popup-border: #333333 !important;
    --quote-bg: #151515 !important;
    --quote-border: #6CB4D4 !important;
    --table-border-color: #333333 !important;
    --table-header-bg: #1A1A1A !important;
    --table-alternate-bg: #0F0F0F !important;
    --searchbar-border-color: #404040 !important;
    --searchbar-bg: #1A1A1A !important;
    --icons: #A0A0A0 !important;
    --icons-hover: #FFFFFF !important;
    --accent: #6CB4D4;
    --accent-light: #1a2a30;
    --success: #4ade80;
    --warning: #fbbf24;
    --drop-cap-color: #6CB4D4;
    --sidenote-bg: #141414;
    --code-bg: #141414;
    --code-border: #2a2a2a;
    --toc-bg: rgba(10, 10, 10, 0.95);
}

/* ============================================
   BASE TYPOGRAPHY - Consistent 12px
   ============================================ */
html {
    font-size: 12px !important;
}

body, .content, p, li, td, th {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
    font-size: 12px !important;
    line-height: 1.35 !important;
}

/* Skip to content - Accessibility */
.skip-to-content {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: white;
    padding: 12px 24px;
    border-radius: 0 0 8px 8px;
    z-index: 10000;
    font-family: "Inter", sans-serif;
    font-size: 0.9rem;
    transition: top 0.3s ease;
}

.skip-to-content:focus {
    top: 0;
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* ============================================
   MAIN CONTENT - Full width utilization
   ============================================ */
.content {
    max-width: none !important;
    padding: 0 !important;
}

.content main {
    max-width: 75% !important;
    margin: 0 auto !important;
    padding: 0.5rem 2rem !important;
}

#content {
    max-width: 100% !important;
    padding: 0 !important;
}

/* Page wrapper */
.page-wrapper .page {
    padding: 0 !important;
}

/* Make content fill available space */
.page {
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* ============================================
   HEADINGS - Consistent sizing
   ============================================ */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600 !important;
    line-height: 1.2 !important;
    margin-top: 8px !important;
    margin-bottom: 4px !important;
}

h1 {
    font-size: 16px !important;
    border-bottom: 1px solid var(--accent) !important;
    padding-bottom: 2px !important;
}

h2 {
    font-size: 14px !important;
    border-bottom: 1px solid var(--table-border-color) !important;
    padding-bottom: 2px !important;
}

h3 {
    font-size: 13px !important;
    color: var(--accent) !important;
}

h4 {
    font-size: 12px !important;
    text-transform: uppercase !important;
}

/* Drop caps disabled - too aggressive on index pages */

/* ============================================
   PARAGRAPHS - Dense
   ============================================ */
p {
    margin-bottom: 0.25rem !important;
}

/* ============================================
   LINKS
   ============================================ */
a {
    color: var(--links) !important;
    text-decoration: none !important;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}

a:hover {
    border-bottom-color: var(--links) !important;
}

a:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 2px;
}

/* ============================================
   CODE BLOCKS - Compact
   ============================================ */
pre {
    font-family: "JetBrains Mono", "Fira Code", monospace !important;
    font-size: 0.8rem !important;
    line-height: 1.4 !important;
    border-radius: 4px !important;
    padding: 0.5rem !important;
    margin: 0.5rem 0 !important;
    border: 1px solid var(--code-border) !important;
    background: var(--code-bg) !important;
    position: relative;
    overflow-x: auto;
}

pre::before {
    content: attr(data-lang);
    position: absolute;
    top: 0;
    right: 0;
    padding: 4px 12px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--table-header-bg);
    border-radius: 0 8px 0 8px;
    font-family: "Inter", sans-serif;
    opacity: 0.7;
}

/* Code copy button */
pre .copy-button {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--sidebar-bg);
    border: 1px solid var(--table-border-color);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
    font-family: "Inter", sans-serif;
}

pre:hover .copy-button {
    opacity: 1;
}

pre .copy-button:hover {
    background: var(--accent-light);
}

/* Inline code */
code {
    font-family: "JetBrains Mono", monospace !important;
    font-size: 0.88em !important;
    padding: 0.2em 0.45em !important;
    border-radius: 4px !important;
    background: var(--inline-code-bg) !important;
    color: var(--inline-code-color) !important;
}

pre code {
    background: transparent !important;
    color: inherit !important;
    padding: 0 !important;
}

/* Solisp syntax highlighting */
.hljs-keyword, .hljs-built_in { color: #8959a8; }
.hljs-string { color: #718c00; }
.hljs-number { color: #f5871f; }
.hljs-comment { color: #8e908c; font-style: italic; }
.hljs-function { color: #4271ae; }
.hljs-variable { color: #c82829; }

.coal .hljs-keyword, .coal .hljs-built_in { color: #c792ea; }
.coal .hljs-string { color: #c3e88d; }
.coal .hljs-number { color: #f78c6c; }
.coal .hljs-comment { color: #676e95; }
.coal .hljs-function { color: #82aaff; }
.coal .hljs-variable { color: #f07178; }

/* ============================================
   BLOCKQUOTES
   ============================================ */
blockquote {
    background: var(--quote-bg) !important;
    border-left: 4px solid var(--quote-border) !important;
    margin: 1.5rem 0 !important;
    padding: 1.25rem 1.5rem !important;
    font-style: italic !important;
    border-radius: 0 8px 8px 0 !important;
    position: relative;
}

blockquote::before {
    content: '"';
    position: absolute;
    top: -10px;
    left: 15px;
    font-size: 4rem;
    color: var(--quote-border);
    opacity: 0.3;
    font-family: Georgia, serif;
    line-height: 1;
}

blockquote p:last-child {
    margin-bottom: 0 !important;
}

/* ============================================
   SIDENOTES / MARGIN NOTES
   ============================================ */
.sidenote {
    float: right;
    clear: right;
    width: 200px;
    margin-right: -220px;
    margin-bottom: 1rem;
    padding: 0.75rem;
    font-size: 0.85rem;
    background: var(--sidenote-bg);
    border-left: 2px solid var(--accent);
    border-radius: 0 4px 4px 0;
}

@media (max-width: 1200px) {
    .sidenote {
        float: none;
        width: 100%;
        margin: 1rem 0;
        margin-right: 0;
    }
}

/* ============================================
   TABLES
   ============================================ */
table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 1.5rem 0 !important;
    font-size: 0.95rem !important;
    border-radius: 8px;
    overflow: hidden;
}

th, td {
    border: 1px solid var(--table-border-color) !important;
    padding: 0.8rem 1rem !important;
    text-align: left !important;
}

th {
    background: var(--table-header-bg) !important;
    font-family: "Inter", sans-serif !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    font-size: 0.75rem !important;
    letter-spacing: 0.08em !important;
}

tr:nth-child(even) {
    background: var(--table-alternate-bg) !important;
}

tr:hover {
    background: var(--accent-light) !important;
}

/* ============================================
   MATH FORMULAS
   ============================================ */
.math, .katex, .MathJax {
    font-size: 1.1em;
    overflow-x: auto;
    padding: 0.5rem 0;
}

.math-block {
    display: block;
    text-align: center;
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--quote-bg);
    border-radius: 8px;
}

/* ============================================
   FIGURE CAPTIONS
   ============================================ */
figure {
    margin: 2rem 0;
    text-align: center;
}

figcaption {
    font-family: "Inter", sans-serif;
    font-size: 0.85rem;
    color: var(--sidebar-fg);
    margin-top: 0.75rem;
    font-style: italic;
}

figcaption::before {
    content: "Figure: ";
    font-weight: 600;
    font-style: normal;
}

/* ============================================
   SIDEBAR - Compact readable
   ============================================ */
.sidebar {
    font-family: -apple-system, BlinkMacSystemFont, sans-serif !important;
    font-size: 11px !important;
    line-height: 1.3 !important;
}

.sidebar .sidebar-scrollbox {
    padding: 4px 2px !important;
}

.sidebar ol, .sidebar ul {
    padding: 0 0 0 8px !important;
    margin: 0 !important;
}

.sidebar ol.chapter > li {
    margin: 0 !important;
}

.sidebar ol.chapter li a {
    padding: 1px 4px !important;
    display: block !important;
    line-height: 1.35 !important;
}

.sidebar ol.chapter li a:hover {
    background: var(--bg) !important;
}

.sidebar ol.chapter li a.active {
    font-weight: 600 !important;
    color: var(--accent) !important;
}

.sidebar .part-title {
    font-size: 9px !important;
    text-transform: uppercase !important;
    letter-spacing: 0.04em !important;
    opacity: 0.6 !important;
    margin: 4px 0 2px 0 !important;
    padding: 0 4px !important;
}

/* ============================================
   READING PROGRESS BAR
   ============================================ */
#reading-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), var(--links));
    z-index: 9999;
    transition: width 0.1s ease-out;
}

/* Chapter info - minimal */
.chapter-info {
    display: none !important;
}

/* Mini TOC - DISABLED (redundant with sidebar) */
.mini-toc {
    display: none !important;
}

/* ============================================
   BACK TO TOP BUTTON
   ============================================ */
.back-to-top {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 44px;
    height: 44px;
    background: var(--sidebar-bg);
    border: 1px solid var(--table-border-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    z-index: 100;
    font-size: 1.2rem;
}

.back-to-top.visible {
    opacity: 1;
    transform: translateY(0);
}

.back-to-top:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ============================================
   CONTINUE READING BANNER
   ============================================ */
.continue-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--sidebar-bg);
    border-top: 1px solid var(--table-border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: "Inter", sans-serif;
    font-size: 0.9rem;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 1000;
}

.continue-banner.visible {
    transform: translateY(0);
}

.continue-banner-text {
    display: flex;
    align-items: center;
    gap: 12px;
}

.continue-banner-actions {
    display: flex;
    gap: 12px;
}

.continue-banner button {
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid var(--table-border-color);
    background: var(--bg);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    transition: all 0.15s ease;
}

.continue-banner button.primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.continue-banner button:hover {
    transform: translateY(-1px);
}

/* ============================================
   FONT SIZE CONTROLS
   ============================================ */
.font-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: "Inter", sans-serif;
}

.font-controls button {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: 1px solid var(--table-border-color);
    background: var(--bg);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.font-controls button:hover {
    background: var(--accent-light);
}

/* ============================================
   KEYBOARD SHORTCUTS HINT
   ============================================ */
.keyboard-hints {
    position: fixed;
    bottom: 80px;
    right: 24px;
    background: var(--sidebar-bg);
    border: 1px solid var(--table-border-color);
    border-radius: 8px;
    padding: 1rem;
    font-family: "Inter", sans-serif;
    font-size: 0.8rem;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    z-index: 100;
    pointer-events: none;
}

.keyboard-hints.visible {
    opacity: 1;
    transform: translateY(0);
}

.keyboard-hints kbd {
    display: inline-block;
    padding: 2px 6px;
    background: var(--table-header-bg);
    border: 1px solid var(--table-border-color);
    border-radius: 3px;
    font-family: "Inter", sans-serif;
    font-size: 0.75rem;
    margin: 0 2px;
}

/* ============================================
   BOOKMARK TOAST
   ============================================ */
.bookmark-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--accent);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-family: "Inter", sans-serif;
    font-size: 0.9rem;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 8px;
}

.bookmark-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================
   BREADCRUMBS
   ============================================ */
.breadcrumbs {
    font-family: "Inter", sans-serif;
    font-size: 0.8rem;
    margin-bottom: 1rem;
    color: var(--sidebar-fg);
}

.breadcrumbs a {
    color: var(--sidebar-fg) !important;
    opacity: 0.8;
}

.breadcrumbs a:hover {
    opacity: 1;
    color: var(--accent) !important;
}

.breadcrumbs span {
    margin: 0 8px;
    opacity: 0.5;
}

/* ============================================
   LISTS - Dense
   ============================================ */
ul, ol {
    margin: 0.1rem 0 0.25rem !important;
    padding-left: 1rem !important;
}

li {
    margin-bottom: 0.05rem !important;
}

li > ul, li > ol {
    margin-top: 0.05rem !important;
    margin-bottom: 0.05rem !important;
}

/* Checklist style */
ul.checklist {
    list-style: none;
    padding-left: 0;
}

ul.checklist li::before {
    content: "☐ ";
    color: var(--accent);
}

ul.checklist li.checked::before {
    content: "☑ ";
}

/* ============================================
   NAVIGATION
   ============================================ */
.nav-chapters {
    font-size: 2rem !important;
    opacity: 0.5;
    transition: all 0.2s ease;
}

.nav-chapters:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* ============================================
   MENU BAR
   ============================================ */
.menu-bar {
    border-bottom: 1px solid var(--table-border-color) !important;
}

#searchbar {
    font-family: "Inter", sans-serif !important;
    border-radius: 6px !important;
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .sidebar, .menu-bar, .nav-chapters, #reading-progress-bar,
    .mini-toc, .back-to-top, .continue-banner, .keyboard-hints {
        display: none !important;
    }

    .content main {
        max-width: 100% !important;
    }

    body {
        font-size: 11pt !important;
    }

    h1, h2, h3 {
        page-break-after: avoid;
    }

    pre, blockquote, table, figure {
        page-break-inside: avoid;
    }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    html {
        font-size: 16px !important;
    }

    .content main {
        padding: 1rem !important;
    }

    h1 {
        font-size: 1.8rem !important;
    }

    h2 {
        font-size: 1.4rem !important;
    }

    .content main > p:first-of-type::first-letter,
    h1 + p::first-letter,
    h2 + p::first-letter {
        font-size: 3rem;
        padding-right: 8px;
    }

    .back-to-top {
        bottom: 16px;
        right: 16px;
    }
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    html {
        scroll-behavior: auto;
    }
}

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */
@media (prefers-contrast: high) {
    .light {
        --bg: #FFFFFF !important;
        --fg: #000000 !important;
        --links: #0000EE !important;
    }

    .coal, .navy, .ayu {
        --bg: #000000 !important;
        --fg: #FFFFFF !important;
        --links: #99CCFF !important;
    }
}

/* ============================================
   FOCUS INDICATORS - Accessibility
   ============================================ */
*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

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

/* ============================================
   SMOOTH TRANSITIONS
   ============================================ */
body, .sidebar, .menu-bar, .content, pre, code, blockquote, table, th, td {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}
