/* Base styles and content styles */

:root {
    /* Browser default font-size is 16px, this way 1 rem = 10px */
    font-size: 62.5%;
    color-scheme: var(--color-scheme);
}

html {
    font-family: "Noto Sans", sans-serif;
    color: var(--fg);
    background-color: var(--bg);
    text-size-adjust: none;
    -webkit-text-size-adjust: none;
}

body {
    margin: 0;
    font-size: 1.6rem;
    overflow-x: hidden;
}

code {
    font-family: var(--mono-font) !important;
    font-size: var(--code-font-size);
    direction: ltr !important;
}

/* make long words/inline code not x overflow */
main {
    overflow-wrap: break-word;
}

/* make wide tables scroll if they overflow */
.table-wrapper {
    overflow-x: auto;
}

/* Don't change font size in headers. */
h1 code,
h2 code,
h3 code,
h4 code,
h5 code,
h6 code {
    font-size: unset;
}

.left {
    float: left;
}

.right {
    float: right;
}

.boring {
    opacity: 0.6;
}

.hide-boring .boring {
    display: none;
}

.hidden {
    display: none !important;
}

h2,
h3 {
    margin-block-start: 2.5em;
}

h4,
h5 {
    margin-block-start: 2em;
}

.header+.header h3,
.header+.header h4,
.header+.header h5 {
    margin-block-start: 1em;
}

h1:target::before,
h2:target::before,
h3:target::before,
h4:target::before,
h5:target::before,
h6:target::before {
    display: inline-block;
    content: "»";
    margin-inline-start: -30px;
    width: 30px;
}

/* This is broken on Safari as of version 14, but is fixed
   in Safari Technology Preview 117 which I think will be Safari 14.2.
   https://bugs.webkit.org/show_bug.cgi?id=218076
*/
:target {
    /* Safari does not support logical properties */
    scroll-margin-top: calc(var(--menu-bar-height) + 0.5em);
}

.page {
    outline: 0;
    padding: 0 var(--page-padding);
    margin-block-start: calc(0px - var(--menu-bar-height));
    /* Compensate for the #menu-bar-hover-placeholder */
}

.page-wrapper {
    box-sizing: border-box;
    background-color: var(--bg);
}

.no-js .page-wrapper,
.js:not(.sidebar-resizing) .page-wrapper {
    transition: margin-left 0.3s ease, transform 0.3s ease;
    /* Animation: slide away */
}

[dir=rtl] .js:not(.sidebar-resizing) .page-wrapper {
    transition: margin-right 0.3s ease, transform 0.3s ease;
    /* Animation: slide away */
}

.content {
    overflow-y: auto;
    padding: 0 5px 50px 5px;
}

.content main {
    margin-inline-start: auto;
    margin-inline-end: auto;
    max-width: var(--content-max-width);
}

.content p {
    line-height: 1.45em;
}

.content ol {
    line-height: 1.45em;
}

.content ul {
    line-height: 1.45em;
}

.content a {
    text-decoration: none;
}

.content a:hover {
    text-decoration: underline;
}

.content img,
.content video {
    max-width: 100%;
}

.content .header:link,
.content .header:visited {
    color: var(--fg);
}

.content .header:link,
.content .header:visited:hover {
    text-decoration: none;
}

.sidebar-header {
    flex-shrink: 0;
    padding: 10px;
    border-bottom: 1px solid var(--sidebar-spacer);
    background-color: var(--sidebar-bg);
}

.cover {
    height: auto;
    width: 85%;
    display: block;
    margin: 0 auto;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    object-fit: contain;
}

/* Collapsible Sidebar Styles */
.chapter-toggle {
    background: none;
    border: none;
    color: var(--sidebar-fg);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 3px;
    transition: background-color 0.2s ease, transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
}

.chapter-toggle:hover {
    background-color: var(--theme-hover);
    transform: scale(1.1);
}

.chapter-toggle:focus {
    outline: 2px solid var(--links);
    outline-offset: 2px;
}

.chapter-toggle i {
    font-size: 12px;
    transition: transform 0.2s ease;
}

.chapter-toggle:hover i {
    transform: scale(1.2);
}

/* Smooth animations for collapsing sections */
.sidebar .section {
    transition: all 0.3s ease;
    overflow: hidden;
}

/* Active chapter styling */
.chapter-item.expanded > a {
    font-weight: 600;
}

/* Improved spacing for subsections */
.sidebar .section .chapter-item {
    margin-left: 8px;
}


/* CSS Callout System for Tips, Warnings, and Notes */
.callout {
    margin: 16px 0;
    padding: 12px 16px;
    border-left: 4px solid;
    border-radius: 0 4px 4px 0;
    position: relative;
    background-color: var(--quote-bg);
}

.callout::before {
    content: '';
    font-family: 'FontAwesome';
    font-size: 16px;
    position: absolute;
    left: 8px;
    top: 12px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.callout-content {
    margin-left: 32px;
}

.callout-title {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.95em;
}

/* Tip Callout */
.callout.tip {
    border-left-color: #28a745;
    background-color: rgba(40, 167, 69, 0.1);
}

.callout.tip::before {
    content: '\f0eb'; /* lightbulb icon */
    color: #28a745;
}

.callout.tip .callout-title {
    color: #28a745;
}

/* Warning Callout */
.callout.warning {
    border-left-color: #ffc107;
    background-color: rgba(255, 193, 7, 0.1);
}

.callout.warning::before {
    content: '\f071'; /* warning triangle icon */
    color: #ffc107;
}

.callout.warning .callout-title {
    color: #ffc107;
}

/* Error/Danger Callout */
.callout.error {
    border-left-color: #dc3545;
    background-color: rgba(220, 53, 69, 0.1);
}

.callout.error::before {
    content: '\f06a'; /* exclamation circle icon */
    color: #dc3545;
}

.callout.error .callout-title {
    color: #dc3545;
}

/* Info/Note Callout */
.callout.info {
    border-left-color: var(--links);
    background-color: rgba(0, 150, 207, 0.1);
}

.callout.info::before {
    content: '\f05a'; /* info circle icon */
    color: var(--links);
}

.callout.info .callout-title {
    color: var(--links);
}

/* Success Callout */
.callout.success {
    border-left-color: #20c997;
    background-color: rgba(32, 201, 151, 0.1);
}

.callout.success::before {
    content: '\f00c'; /* check icon */
    color: #20c997;
}

.callout.success .callout-title {
    color: #20c997;
}

/* Code Block Callout */
.callout.code {
    border-left-color: var(--inline-code-color);
    background-color: rgba(255, 180, 84, 0.1);
}

.callout.code::before {
    content: '\f121'; /* code icon */
    color: var(--inline-code-color);
}

.callout.code .callout-title {
    color: var(--inline-code-color);
}

/* Dark theme adjustments */
.ayu .callout, .coal .callout, .navy .callout {
    background-color: var(--quote-bg);
}

.ayu .callout.tip, .coal .callout.tip, .navy .callout.tip {
    background-color: rgba(40, 167, 69, 0.15);
}

.ayu .callout.warning, .coal .callout.warning, .navy .callout.warning {
    background-color: rgba(255, 193, 7, 0.15);
}

.ayu .callout.error, .coal .callout.error, .navy .callout.error {
    background-color: rgba(220, 53, 69, 0.15);
}

.ayu .callout.info, .coal .callout.info, .navy .callout.info {
    background-color: rgba(0, 150, 207, 0.15);
}

.ayu .callout.success, .coal .callout.success, .navy .callout.success {
    background-color: rgba(32, 201, 151, 0.15);
}

.ayu .callout.code, .coal .callout.code, .navy .callout.code {
    background-color: rgba(255, 180, 84, 0.15);
}

/* Mobile responsive callouts */
@media (max-width: 768px) {
    .callout {
        margin: 12px 0;
        padding: 10px 12px;
    }
    
    .callout-content {
        margin-left: 28px;
    }
    
    .callout::before {
        font-size: 14px;
        left: 6px;
        top: 10px;
    }
}

/* Enhanced Mobile Drawer Navigation */
@media (max-width: 1080px) {
    /* Mobile overlay backdrop */
    .mobile-drawer-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 100;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        backdrop-filter: blur(2px);
    }
    
    /* Show overlay when sidebar is open */
    #sidebar-toggle-anchor:checked ~ .mobile-drawer-overlay {
        opacity: 1;
        visibility: visible;
    }
    
    /* Enhanced sidebar for mobile */
    .sidebar {
        box-shadow: 4px 0 12px rgba(0, 0, 0, 0.15);
        z-index: 101;
        border-right: 1px solid var(--sidebar-resize-indicator-color);
    }
    
    /* Improve sidebar scrolling on mobile */
    .sidebar .sidebar-scrollbox {
        padding: 12px 8px;
        overscroll-behavior: contain;
    }
    
    /* Better mobile menu bar */
    #menu-bar {
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        backdrop-filter: blur(8px);
        background-color: var(--bg);
    }
    
    /* Enhanced sidebar toggle button for mobile */
    #sidebar-toggle {
        position: relative;
        transition: transform 0.2s ease, background-color 0.2s ease;
        border-radius: 6px;
        margin: 4px;
        padding: 8px;
    }
    
    #sidebar-toggle:hover, #sidebar-toggle:focus {
        background-color: var(--theme-hover);
        transform: scale(1.05);
    }
    
    #sidebar-toggle:active {
        transform: scale(0.95);
    }
    
    /* Animated hamburger icon */
    #sidebar-toggle i {
        transition: transform 0.3s ease;
    }
    
    #sidebar-toggle-anchor:checked ~ * #sidebar-toggle i {
        transform: rotate(90deg);
    }
    
    /* Better spacing for mobile chapter items */
    .sidebar .chapter-item {
        margin: 2px 0;
    }
    
    .sidebar .chapter-item > a {
        padding: 12px 8px;
        border-radius: 6px;
        transition: background-color 0.2s ease, transform 0.1s ease;
        display: block;
        min-height: 44px; /* Better touch target */
        display: flex;
        align-items: center;
    }
    
    .sidebar .chapter-item > a:hover {
        background-color: var(--theme-hover);
        transform: translateX(4px);
    }
    
    .sidebar .chapter-item > a:active {
        transform: translateX(4px) scale(0.98);
    }
    
    /* Enhanced cover image for mobile */
    .cover {
        width: 70%;
        margin: 8px auto 16px auto;
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    
    /* Improved chapter toggle buttons for mobile */
    .chapter-toggle {
        min-width: 32px;
        height: 32px;
        margin-left: 8px;
        border-radius: 6px;
        background-color: var(--theme-popup-bg);
        border: 1px solid var(--theme-popup-border);
    }
    
    .chapter-toggle:hover {
        background-color: var(--theme-hover);
        border-color: var(--links);
    }
    
    .chapter-toggle:active {
        transform: scale(0.9);
    }
}

/* Extra small mobile devices */
@media (max-width: 480px) {
    /* Adjust sidebar width for very small screens */
    :root {
        --sidebar-width: 280px;
    }
    
    .sidebar .sidebar-scrollbox {
        padding: 8px 6px;
    }
    
    .sidebar .chapter-item > a {
        padding: 10px 6px;
        font-size: 0.9em;
    }
    
    .cover {
        width: 60%;
        margin: 6px auto 12px auto;
    }
    
    /* Smaller menu bar for tiny screens */
    #menu-bar {
        padding: 0 8px;
    }
    
    .menu-title {
        font-size: 0.9em;
        line-height: 1.2;
    }
    
}

/* Diagram Zoom Modal System (HTML-only) */
.diagram-zoom-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

.diagram-zoom-modal.active {
    opacity: 1;
    visibility: visible;
}

.diagram-zoom-container {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    overflow: hidden;
    cursor: grab;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.diagram-zoom-container:active {
    cursor: grabbing;
}

.diagram-zoom-image {
    max-width: 100%;
    max-height: 95vh;
    transition: transform 0.2s ease;
    transform-origin: center center;
    display: block;
}

.diagram-zoom-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 12px;
    z-index: 1001;
}

.diagram-zoom-button {
    background-color: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--fg);
    font-size: 18px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.diagram-zoom-button:hover {
    background-color: rgba(255, 255, 255, 1);
    transform: scale(1.1);
}

.diagram-zoom-button:active {
    transform: scale(0.95);
}

.diagram-zoom-close {
    background-color: rgba(255, 0, 0, 0.9);
    color: white;
}

.diagram-zoom-close:hover {
    background-color: rgba(255, 0, 0, 1);
}

.diagram-zoom-info {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9em;
    opacity: 0.8;
    transition: opacity 0.3s ease;
    pointer-events: none;
    white-space: nowrap;
}

.diagram-zoom-info.hidden {
    opacity: 0;
}

/* Diagram hover effects for clickable diagrams */
.content img[src*="diagrams/"] {
    cursor: zoom-in;
    transition: all 0.2s ease;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.content img[src*="diagrams/"]:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

/* Dark theme adjustments */
.ayu .diagram-zoom-button, .coal .diagram-zoom-button, .navy .diagram-zoom-button {
    background-color: rgba(50, 50, 50, 0.9);
    color: var(--fg);
}

.ayu .diagram-zoom-button:hover, .coal .diagram-zoom-button:hover, .navy .diagram-zoom-button:hover {
    background-color: rgba(70, 70, 70, 1);
}

/* Mobile adjustments for diagram zoom */
@media (max-width: 768px) {
    .diagram-zoom-controls {
        top: 15px;
        right: 15px;
        gap: 8px;
    }
    
    .diagram-zoom-button {
        width: 44px;
        height: 44px;
        font-size: 16px;
    }
    
    .diagram-zoom-info {
        bottom: 15px;
        font-size: 0.8em;
        padding: 6px 12px;
    }
    
    .diagram-zoom-container {
        max-width: 98vw;
        max-height: 98vh;
    }
}

table {
    margin: 0 auto;
    border-collapse: collapse;
}

table td {
    padding: 3px 20px;
    border: 1px var(--table-border-color) solid;
}

table thead {
    background: var(--table-header-bg);
}

table thead td {
    font-weight: 700;
    border: none;
}

table thead th {
    padding: 3px 20px;
}

table thead tr {
    border: 1px var(--table-header-bg) solid;
}

/* Alternate background colors for rows */
table tbody tr:nth-child(2n) {
    background: var(--table-alternate-bg);
}


blockquote {
    margin: 20px 0;
    padding: 0 20px;
    color: var(--fg);
    background-color: var(--quote-bg);
    border-block-start: .1em solid var(--quote-border);
    border-block-end: .1em solid var(--quote-border);
}

.warning {
    margin: 20px;
    padding: 0 20px;
    border-inline-start: 2px solid var(--warning-border);
}

.warning:before {
    position: absolute;
    width: 3rem;
    height: 3rem;
    margin-inline-start: calc(-1.5rem - 21px);
    content: "ⓘ";
    text-align: center;
    background-color: var(--bg);
    color: var(--warning-border);
    font-weight: bold;
    font-size: 2rem;
}

blockquote .warning:before {
    background-color: var(--quote-bg);
}

kbd {
    background-color: var(--table-border-color);
    border-radius: 4px;
    border: solid 1px var(--theme-popup-border);
    box-shadow: inset 0 -1px 0 var(--theme-hover);
    display: inline-block;
    font-size: var(--code-font-size);
    font-family: var(--mono-font);
    line-height: 10px;
    padding: 4px 5px;
    vertical-align: middle;
}

sup {
    /* Set the line-height for superscript and footnote references so that there
       isn't an awkward space appearing above lines that contain the footnote.

       See https://github.com/rust-lang/mdBook/pull/2443#discussion_r1813773583
       for an explanation.
    */
    line-height: 0;
}

.footnote-definition {
    font-size: 0.9em;
}

/* The default spacing for a list is a little too large. */
.footnote-definition ul,
.footnote-definition ol {
    padding-left: 20px;
}

.footnote-definition>li {
    /* Required to position the ::before target */
    position: relative;
}

.footnote-definition>li:target {
    scroll-margin-top: 50vh;
}

.footnote-reference:target {
    scroll-margin-top: 50vh;
}

/* Draws a border around the footnote (including the marker) when it is selected.
   TODO: If there are multiple linkbacks, highlight which one you just came
   from so you know which one to click.
*/
.footnote-definition>li:target::before {
    border: 2px solid var(--footnote-highlight);
    border-radius: 6px;
    position: absolute;
    top: -8px;
    right: -8px;
    bottom: -8px;
    left: -32px;
    pointer-events: none;
    content: "";
}

/* Pulses the footnote reference so you can quickly see where you left off reading.
   This could use some improvement.
*/
@media not (prefers-reduced-motion) {
    .footnote-reference:target {
        animation: fn-highlight 0.8s;
        border-radius: 2px;
    }

    @keyframes fn-highlight {
        from {
            background-color: var(--footnote-highlight);
        }
    }
}

.tooltiptext {
    position: absolute;
    visibility: hidden;
    color: #fff;
    background-color: #333;
    transform: translateX(-50%);
    /* Center by moving tooltip 50% of its width left */
    left: -8px;
    /* Half of the width of the icon */
    top: -35px;
    font-size: 0.8em;
    text-align: center;
    border-radius: 6px;
    padding: 5px 8px;
    margin: 5px;
    z-index: 1000;
}

.tooltipped .tooltiptext {
    visibility: visible;
}

.chapter li.part-title {
    color: var(--sidebar-fg);
    margin: 5px 0px;
    font-weight: bold;
}

.result-no-output {
    font-style: italic;
}
