/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Dark mode scrollbar */
.dark ::-webkit-scrollbar-thumb {
    background: #4b5563;
}
.dark ::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* Smooth transitions - optimized for Safari */
:root {
    color-scheme: light dark;
}

.dark {
    color-scheme: dark;
}

/* Apply transitions only to specific elements instead of * */
body,
.bg-white,
.dark\:bg-gray-800,
nav,
aside,
article,
.prose {
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    will-change: auto;
}

/* Remove transition from all other elements for better Safari performance */
*, *::before, *::after {
    transition: none;
}

code:not(pre code) {
    background-color: rgba(59, 130, 246, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace !important;
}

.dark code:not(pre code) {
    background-color: rgba(96, 165, 250, 0.2);
    color: #60a5fa;
}

/* Search highlight */
.search-highlight {
    background-color: #fef3c7;
    padding: 2px 4px;
    border-radius: 2px;
}

.md-level-1, .md-level-2 {
    margin-left: 0px;
    font-size: 0.95rem;
}

.md-level-3 {
    margin-left: 8px;
    font-size: 0.85rem;
}

.md-level-4 {
    margin-left: 12px;
    font-size: 0.8rem;
}

.md-level-5 {
    margin-left: 16px;
    font-size: 0.75rem;
}

.md-level-6 {
    margin-left: 20px;
    font-size: 0.7rem;
}

/* Active TOC item */
.toc-active {
    color: #3b82f6 !important;
    background-color: rgba(243, 244, 246, 1) !important;
    border-left-color: #3b82f6 !important;
}

.dark .toc-active {
    color: #60a5fa !important;
    background-color: rgba(55, 65, 81, 0.5) !important;
    border-left-color: #60a5fa !important;
}

/* Responsive prose elements */
article pre {
    max-width: 100%;
    overflow-x: auto;
}

article table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

article img {
    max-width: 100%;
    height: auto;
}

.md-index-active {
    font-weight: 600 !important;
    color: #2563eb !important;
    border-left: 3px solid #3b82f6 !important;
    background-color: rgba(59, 130, 246, 0.1) !important;
    margin-left: -3px !important;
}

/* Prevent layout breaking on small screens */
@media (max-width: 640px) {
    article {
        font-size: 0.875rem;
    }
    
    article h1 {
        font-size: 1.5rem;
    }
    
    article h2 {
        font-size: 1.25rem;
    }
    
    article h3 {
        font-size: 1.125rem;
    }
}

/* Prism.js Code Block Styling */
div.code-toolbar {
    position: relative;
    margin: 1.5em 0;
}

div.code-toolbar > .toolbar {
    position: absolute;
    top: 0.5em;
    right: 0.5em;
    transition: opacity 0.3s ease-in-out;
    opacity: 0;
}

div.code-toolbar:hover > .toolbar {
    opacity: 1;
}

div.code-toolbar > .toolbar .toolbar-item {
    display: inline-block;
}

div.code-toolbar > .toolbar button {
    background: rgba(59, 130, 246, 0.9);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

div.code-toolbar > .toolbar button:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

div.code-toolbar > .toolbar button:active {
    transform: translateY(0);
}

/* Dark mode adjustments for copy button */
.dark div.code-toolbar > .toolbar button {
    background: rgba(96, 165, 250, 0.9);
}

.dark div.code-toolbar > .toolbar button:hover {
    background: #60a5fa;
    box-shadow: 0 2px 8px rgba(96, 165, 250, 0.3);
}

/* Code block container */
pre[class*="language-"] {
    border-radius: 8px;
    margin: 1.5em 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.dark pre[class*="language-"] {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Header Copy Link Button */
.header-copy-link {
    padding: 4px 8px;
    border-radius: 4px;
    background: transparent;
    border: none;
    cursor: pointer;
    vertical-align: middle;
    font-size: 0.875em;
}

.header-copy-link:hover {
    background: rgba(59, 130, 246, 0.1);
}

.dark .header-copy-link:hover {
    background: rgba(96, 165, 250, 0.1);
}

/* Ensure headers can show the button on hover */
.md-header-tag {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.md-header-tag:hover .header-copy-link {
    opacity: 1 !important;
}

/* Search popup blur background */
.search-blur-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    background-color: rgba(0, 0, 0, 0.2);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.search-blur-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.dark .search-blur-backdrop {
    background-color: rgba(0, 0, 0, 0.4);
}

/* Spinner Animation */
.spinner-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem 0;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(59, 130, 246, 0.2);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.dark .spinner {
    border: 4px solid rgba(96, 165, 250, 0.2);
    border-top-color: #60a5fa;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}
