/* ================================================================
   OpenBook — Unified Design System
   Scientific-practical book UX · Russian & English editions
   ================================================================ */

/* ----------------------------------------------------------
   1. FONT LOADING
   ---------------------------------------------------------- */
@font-face {
    font-family: 'Panton';
    src: url('fonts/Panton-Regular.woff2') format('woff2'),
         url('fonts/Panton-Regular.woff') format('woff');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Panton';
    src: url('fonts/Panton-Bold.woff') format('woff');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Panton';
    src: url('fonts/Panton-Light.woff') format('woff');
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}

/* ----------------------------------------------------------
   2. CSS CUSTOM PROPERTIES (Design Tokens)
   ---------------------------------------------------------- */
:root {
    /* Color palette */
    --color-bg:          #fafbfc;
    --color-surface:     #ffffff;
    --color-text:        #1a1a2e;
    --color-text-muted:  #5a5a72;
    --color-sidebar:     #0a1628;
    --color-sidebar-hover: #162240;
    --color-sidebar-active: #1e3050;
    --color-accent:      #0d9488;
    --color-accent-hover:#0f766e;
    --color-amber:       #d97706;
    --color-amber-light: #fef3c7;
    --color-border:      #e2e8f0;
    --color-border-light:#f1f5f9;
    --color-code-bg:     #f8fafc;
    
    /* Typography */
    --font-body:         'Panton', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono:         'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    --fs-body:           17px;
    --fs-small:          15px;
    --fs-h1:             2rem;
    --fs-h2:             1.5rem;
    --fs-h3:             1.25rem;
    --fs-h4:             1.1rem;
    --lh-body:           1.75;
    --lh-heading:        1.3;
    
    /* Spacing */
    --content-max-width: 800px;
    --content-padding:   2.5rem;
    
    /* Shadows */
    --shadow-sm:         0 1px 2px rgba(0,0,0,.04);
    --shadow-md:         0 4px 12px rgba(0,0,0,.06);
    --shadow-lg:         0 8px 24px rgba(0,0,0,.08);
    
    /* Radii */
    --radius-sm:         4px;
    --radius-md:         8px;
    --radius-lg:         12px;
}

/* ----------------------------------------------------------
   3. BASE RESET & TYPOGRAPHY
   ---------------------------------------------------------- */
body, .book, .book .book-summary, .book .book-body {
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body, .book .book-body .page-wrapper .page-inner {
    color: var(--color-text);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    background: transparent !important;
}

/* Content container */
.book .book-body .page-wrapper .page-inner section.normal {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: 1.5rem var(--content-padding) 4rem;
}

/* ----------------------------------------------------------
   4. HEADINGS
   ---------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-body);
    color: var(--color-text);
    line-height: var(--lh-heading);
    margin-top: 2em;
    margin-bottom: 0.6em;
    font-weight: 700;
    letter-spacing: -0.01em;
}

h1 {
    font-size: var(--fs-h1);
    font-weight: 700;
    padding-bottom: 0.4em;
    border-bottom: 2px solid var(--color-accent);
    margin-top: 0.5em;
}

h2 { font-size: var(--fs-h2); font-weight: 700; }
h3 { font-size: var(--fs-h3); font-weight: 700; }
h4 { font-size: var(--fs-h4); font-weight: 700; color: var(--color-text-muted); }
h5 { font-size: 1.05rem; font-weight: 700; color: var(--color-text-muted); }
h6 { font-size: 1rem; font-weight: 700; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* ----------------------------------------------------------
   5. PARAGRAPHS & LISTS
   ---------------------------------------------------------- */
p {
    font-family: var(--font-body);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    margin: 0 0 1.1em;
    color: var(--color-text);
    background: transparent !important;
    background-color: transparent !important;
}

ul, ol {
    font-family: var(--font-body);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    margin: 0 0 1.1em;
    padding-left: 1.5em;
}

li {
    margin-bottom: 0.25em;
}

li > p {
    margin-bottom: 0.3em;
}

/* ----------------------------------------------------------
   6. LINKS
   ---------------------------------------------------------- */
a {
    color: var(--color-accent);
    text-decoration: none;
    transition: color 0.2s ease, border-color 0.2s ease;
    border-bottom: 1px solid transparent;
}

a:hover {
    color: var(--color-amber);
    border-bottom-color: var(--color-amber);
    text-decoration: none;
}

/* ----------------------------------------------------------
   7. BACKGROUND & OVERLAY
   ---------------------------------------------------------- */
body,
.book,
.book .book-body * {
    background-image: url("images/background.png") !important;
    background-size: cover !important;
    background-repeat: no-repeat !important;
    background-position: center center !important;
    background-attachment: fixed !important;
    background-color: rgba(255,255,255,0.88) !important;
    box-shadow: none !important;
}

.book .book-body .page-wrapper {
    background: transparent !important;
}

/* Remove background from content elements so overlay works */
p, h1, h2, h3, h4, h5, h6, li, blockquote, pre, code, section, article,
.book .book-body .page-wrapper .page-inner section.normal {
    background: transparent !important;
    background-color: transparent !important;
}

/* Content area gets a subtle white card */
.book .book-body .page-wrapper .page-inner section.normal {
    background-color: rgba(255,255,255,0.92) !important;
    border-radius: var(--radius-lg);
    margin: 1.5rem auto 3rem;
    padding: 2.5rem var(--content-padding) 4rem;
    box-shadow: var(--shadow-md);
}

/* ----------------------------------------------------------
   8. SIDEBAR
   ---------------------------------------------------------- */
.book .book-summary {
    width: 300px;
    background: var(--color-sidebar) !important;
    color: #cbd5e1;
    font-family: var(--font-body);
    border-right: none;
    box-shadow: 2px 0 12px rgba(0,0,0,.15);
}

.book .book-summary .summary {
    margin-top: 0 !important;
}

/* Sidebar scrollbar */
.book .book-summary::-webkit-scrollbar { width: 6px; }
.book .book-summary::-webkit-scrollbar-track { background: transparent; }
.book .book-summary::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }

/* Sidebar links */
.book .book-summary .summary li a,
.book .book-summary .summary li span {
    color: #94a3b8 !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    padding: 6px 20px !important;
    transition: color 0.2s ease, background 0.2s ease;
    border-bottom: none !important;
}

.book .book-summary .summary li a:hover {
    color: #e2e8f0 !important;
    background: var(--color-sidebar-hover) !important;
    text-decoration: none;
    border-bottom: none !important;
}

/* Active chapter */
.book .book-summary .summary li.active > a,
.book .book-summary .summary li.active > a span {
    color: var(--color-amber) !important;
    background: var(--color-sidebar-active) !important;
    font-weight: 700;
    border-left: 3px solid var(--color-amber);
    padding-left: 17px !important;
}

/* Chapter numbers */
.book .book-summary .summary li a b {
    font-weight: 600;
    color: var(--color-accent);
    margin-right: 4px;
}

/* Divider */
.book .book-summary .summary li.divider {
    height: 1px;
    margin: 8px 0;
    background: #1e3050;
}

/* ----------------------------------------------------------
   9. LOGO
   ---------------------------------------------------------- */
/* Sidebar logo */
.book .book-summary .logo-container {
    position: relative;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
    background: #060f1e;
    z-index: 1000;
    padding: 24px 20px 16px 20px !important;
    margin-bottom: 0 !important;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid #1e3050;
}

.book .book-summary .logo-container img {
    width: 100%;
    max-width: 240px;
    height: auto;
    display: block;
    margin: 0;
    padding: 0;
    object-fit: contain;
    box-shadow: none !important;
    border-radius: 0 !important;
}

/* Top-right logo on content pages */
.book .book-body .top-page-logo {
    position: absolute;
    top: 12px;
    right: 24px;
    z-index: 10;
    height: 36px;
    width: auto;
    opacity: 0.85;
}

.book .book-body .top-page-logo img {
    height: 36px;
    width: auto;
    box-shadow: none !important;
}

/* ----------------------------------------------------------
   10. CALLOUT BOXES (Notes, Warnings, Tips)
   ---------------------------------------------------------- */
/* Base callout */
.callout,
.note, .warning, .tip, .important, .caution {
    margin: 1.5em 0;
    padding: 1em 1.25em;
    border-left: 4px solid;
    border-radius: var(--radius-sm);
    background: var(--color-surface) !important;
    box-shadow: var(--shadow-sm);
    font-size: var(--fs-small);
}

.callout > :first-child,
.note > :first-child, .warning > :first-child,
.tip > :first-child, .important > :first-child,
.caution > :first-child { margin-top: 0; }

.callout > :last-child,
.note > :last-child, .warning > :last-child,
.tip > :last-child, .important > :last-child,
.caution > :last-child { margin-bottom: 0; }

/* Note — blue */
.note {
    border-left-color: #3b82f6;
    background: #eff6ff !important;
}
.note::before {
    content: "📘 Note";
    display: block;
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #3b82f6;
    margin-bottom: 0.5em;
}

/* Warning — amber */
.warning {
    border-left-color: var(--color-amber);
    background: var(--color-amber-light) !important;
}
.warning::before {
    content: "⚠️ Warning";
    display: block;
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-amber);
    margin-bottom: 0.5em;
}

/* Tip — green */
.tip {
    border-left-color: #10b981;
    background: #ecfdf5 !important;
}
.tip::before {
    content: "💡 Tip";
    display: block;
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #10b981;
    margin-bottom: 0.5em;
}

/* Important — red */
.important {
    border-left-color: #ef4444;
    background: #fef2f2 !important;
}
.important::before {
    content: "❗ Important";
    display: block;
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #ef4444;
    margin-bottom: 0.5em;
}

/* Caution — purple */
.caution {
    border-left-color: #8b5cf6;
    background: #f5f3ff !important;
}
.caution::before {
    content: "🔬 Caution";
    display: block;
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #8b5cf6;
    margin-bottom: 0.5em;
}

/* ----------------------------------------------------------
   11. BLOCKQUOTES
   ---------------------------------------------------------- */
.book .book-body .page-wrapper .page-inner section.normal blockquote {
    border-left: 4px solid var(--color-accent);
    background: #f0fdfa !important;
    padding: 1em 1.25em;
    margin: 1.5em 0;
    color: var(--color-text);
    font-style: italic;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    box-shadow: var(--shadow-sm);
}

.book .book-body .page-wrapper .page-inner section.normal blockquote p {
    margin: 0;
    font-size: var(--fs-body);
}

/* ----------------------------------------------------------
   12. CODE & PRE
   ---------------------------------------------------------- */
code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    background: var(--color-code-bg);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    color: #0f766e;
    border: 1px solid var(--color-border-light);
}

pre {
    background: #0f172a !important;
    color: #e2e8f0;
    padding: 1.25em;
    border-radius: var(--radius-md);
    overflow-x: auto;
    font-size: 14px;
    line-height: 1.6;
    margin: 1.5em 0;
    box-shadow: var(--shadow-md);
    border: 1px solid #1e293b;
}

pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    border: none;
    font-size: inherit;
    border-radius: 0;
}

/* ----------------------------------------------------------
   13. TABLES
   ---------------------------------------------------------- */
table, .table {
    width: 100%;
    margin: 1.5em 0;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--fs-small);
    line-height: 1.5;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
}

table th, .table th {
    background: #f1f5f9;
    color: var(--color-text);
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 10px 14px;
    text-align: left;
    border-bottom: 2px solid var(--color-border);
}

table td, .table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border-light);
    color: var(--color-text);
    background: var(--color-surface);
}

table tr:last-child td, .table tr:last-child td {
    border-bottom: none;
}

table tr:hover td, .table tr:hover td {
    background: #f8fafc;
}

/* ----------------------------------------------------------
   14. IMAGES & FIGURES
   ---------------------------------------------------------- */
img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin: 1.5em auto;
    display: block;
}

/* Figure captions */
.figure, figure {
    margin: 2em 0;
    text-align: center;
}

.figure img, figure img {
    margin-bottom: 0.5em;
}

.caption, figcaption, .figure .caption {
    font-size: var(--fs-small);
    color: var(--color-text-muted);
    font-style: italic;
    margin-top: 0.5em;
}

/* Remove shadows from logos and icons */
.toc-logo img, .logo-container img, .top-page-logo img,
.book .book-summary img {
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
}

/* ----------------------------------------------------------
   15. MATH (KaTeX / MathJax)
   ---------------------------------------------------------- */
.katex, .MathJax {
    font-size: 1.05em;
}

.katex-display, .MathJax_Display {
    margin: 1.5em 0;
    padding: 1em 0;
    overflow-x: auto;
    overflow-y: hidden;
}

/* ----------------------------------------------------------
   16. WELCOME BANNER
   ---------------------------------------------------------- */
.welcome-banner {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    color: var(--color-text);
    padding: 2rem 2rem;
    border-radius: var(--radius-lg);
    margin-bottom: 2rem;
    font-size: 1.1em;
    font-weight: 400;
    line-height: 1.6;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-accent);
}

.welcome-banner p {
    color: var(--color-text);
    margin: 0;
}

/* ----------------------------------------------------------
   17. TOP NAVIGATION BAR
   ---------------------------------------------------------- */
.navbar, .navbar-default {
    background: var(--color-sidebar);
    color: #e2e8f0;
}

/* ----------------------------------------------------------
   18. ALERTS
   ---------------------------------------------------------- */
.alert-info {
    background: #eff6ff;
    border-left: 4px solid #3b82f6;
    color: var(--color-text);
}

.alert-warning {
    background: var(--color-amber-light);
    border-left: 4px solid var(--color-amber);
    color: var(--color-text);
}

/* ----------------------------------------------------------
   19. LIGHTBOX / OVERLAY FIXES
   ---------------------------------------------------------- */
.book .book-body .html-widget *,
.book .book-body .vis-network * {
    background-image: none !important;
    background-color: white !important;
    position: relative;
    z-index: 1000;
}

/* ----------------------------------------------------------
   20. SCROLLBAR (content area)
   ---------------------------------------------------------- */
.book .book-body::-webkit-scrollbar { width: 8px; }
.book .book-body::-webkit-scrollbar-track { background: transparent; }
.book .book-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.book .book-body::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ----------------------------------------------------------
   21. KEYBOARD SHORTCUT HINT
   ---------------------------------------------------------- */
kbd {
    display: inline-block;
    padding: 2px 6px;
    font-family: var(--font-mono);
    font-size: 0.8em;
    background: var(--color-code-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: 0 1px 0 var(--color-border);
}

/* ----------------------------------------------------------
   22. PRINT STYLES
   ---------------------------------------------------------- */
@media print {
    body,
    .book,
    .book .book-body * {
        background-image: none !important;
        background-color: #ffffff !important;
    }
    
    .book .book-body .page-wrapper .page-inner section.normal {
        background: #ffffff !important;
        box-shadow: none !important;
        max-width: 100%;
        padding: 0;
    }
    
    .book .book-summary { display: none !important; }
    .book .book-body { left: 0 !important; }
    
    a { color: var(--color-text); border-bottom: none; }
    
    pre, code { background: #f8fafc !important; color: var(--color-text) !important; }
    
    @page {
        margin: 2cm;
        @bottom-center { content: counter(page); font-family: var(--font-body); }
    }
    
    h1, h2, h3 { page-break-after: avoid; }
    table, figure { page-break-inside: avoid; }
}

/* ----------------------------------------------------------
   23. MOBILE RESPONSIVE
   ---------------------------------------------------------- */
@media screen and (max-width: 768px) {
    :root {
        --fs-body: 16px;
        --fs-h1: 1.6rem;
        --fs-h2: 1.3rem;
        --fs-h3: 1.15rem;
        --content-padding: 1.25rem;
    }
    
    .book .book-summary { width: 280px; }
    
    .book .book-body .page-wrapper .page-inner section.normal {
        padding: 1rem var(--content-padding) 2rem;
        margin: 0.5rem auto 1.5rem;
    }
    
    .book .book-summary .logo-container {
        padding: 16px 12px 12px 12px !important;
    }
    
    .book .book-summary .logo-container img { max-width: 180px; }
    
    .welcome-banner {
        padding: 1.25rem;
        font-size: 1em;
    }
    
    table, .table { font-size: 13px; }
    table th, table td, .table th, .table td { padding: 6px 8px; }
}

/* ----------------------------------------------------------
   24. DARK MODE (System Preference)
   ---------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
    /* Keep light theme for scientific reading — 
       dark mode not recommended for long-form content.
       Uncomment below for dark mode support.
    */
    /*
    :root {
        --color-bg: #0f172a;
        --color-surface: #1e293b;
        --color-text: #e2e8f0;
        --color-text-muted: #94a3b8;
        --color-border: #334155;
        --color-border-light: #1e293b;
        --color-code-bg: #1e293b;
    }
    */
}
