/* --- RESET I KONFIGURACJA GLOBALNA --- */
* {
    box-sizing: border-box;
}

:root {
    /* Paleta kolorów - Modern Dark Mode */
    --bg-main: #0f172a;
    --bg-sidebar: #1e293b;
    --bg-card: #1e293b;
    --bg-code: #282c34;
    
    --text-main: #cbd5e1;
    --text-heading: #f8fafc;
    --text-muted: #94a3b8;
    
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-glow: rgba(59, 130, 246, 0.5);
    
    --border: #334155;
    
    /* Layout */
    --sidebar-width: 280px;
    --radius-lg: 12px;
    --radius-md: 8px;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: 40px;
}

body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.7;
    overflow-x: hidden;
}

/* --- ELEMENTY INTERFEJSU --- */

/* Pasek Postępu Scrolla */
.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 4px;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    width: 0%;
    z-index: 9999;
    box-shadow: 0 0 10px var(--accent-glow);
}

.app-container {
    display: flex;
    min-height: 100dvh;
}

/* --- PASEK BOCZNY (SIDEBAR) --- */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-header {
    flex-shrink: 0;
    padding: 25px 25px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    color: var(--text-heading);
    margin: 0;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.sidebar-header p {
    color: var(--accent);
    margin: 5px 0 0;
    font-size: 0.85rem;
    font-weight: 600;
}

/* Nawigacja wewnątrz sidebaru */
.toc-nav {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px 15px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* Customowy scrollbar dla nawigacji */
.toc-nav::-webkit-scrollbar {
    width: 4px;
}
.toc-nav::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

.toc-link {
    color: var(--text-muted);
    text-decoration: none;
    padding: 10px 15px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.toc-link:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-heading);
}

.toc-link.active {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--accent);
    border-left-color: var(--accent);
}

/* Stopka Sidebaru (Licznik) */
.sidebar-footer {
    flex-shrink: 0;
    padding: 15px 20px;
    border-top: 1px solid var(--border);
    background-color: rgba(15, 23, 42, 0.4);
}

.countdown-container {
    font-family: 'Fira Code', monospace;
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
}

.countdown-label {
    display: block;
    font-size: 0.65rem;
    color: var(--accent);
    font-weight: bold;
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

#countdown-timer {
    font-size: 0.95rem;
    color: #fff;
    font-weight: 600;
    text-shadow: 0 0 8px var(--accent-glow);
}

/* --- GŁÓWNA ZAWARTOŚĆ --- */
.content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 40px 60px;
    max-width: 1000px;
}

.page-header {
    margin-bottom: 50px;
}

.page-header h1 {
    font-size: 2.8rem;
    color: var(--text-heading);
    margin: 0 0 10px;
    letter-spacing: -1px;
}

.page-header p {
    font-size: 1.1rem;
    color: var(--text-muted);
}

/* Sekcje i Karty */
.section-title {
    color: var(--text-heading);
    font-size: 1.8rem;
    margin: 60px 0 25px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.section-title span {
    color: var(--accent);
    margin-right: 10px;
}

.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 25px;
    margin-bottom: 25px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.card:hover {
    border-color: #475569;
    transform: translateY(-2px);
}

.card h3 {
    margin: 0 0 15px;
    color: var(--text-heading);
    font-size: 1.2rem;
}

/* Kod w tekście */
code:not(.hljs) {
    background-color: rgba(255,255,255,0.1);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 0.9em;
    color: #e2e8f0;
}

/* Bloki Kodu */
.code-wrapper {
    position: relative;
    margin-top: 15px;
}

pre {
    margin: 0;
    border-radius: var(--radius-md);
    background-color: #282c34 !important;
    border: 1px solid #3e4451;
    overflow-x: auto;
}

pre code {
    display: block;
    padding: 20px !important;
    font-family: 'Fira Code', 'Consolas', 'Monaco', monospace !important;
    font-size: 0.875rem !important;
    line-height: 1.6 !important;
    background: transparent !important;
    color: #abb2bf !important;
}

pre code.hljs {
    background: transparent !important;
}

.copy-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: #3f4a5c;
    color: #fff;
    border: none;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 10;
}

.code-wrapper:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    background-color: var(--accent);
}

.copy-btn.copied {
    background-color: #10b981;
}

.site-footer {
    margin-top: 80px;
    padding: 30px 0;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* --- RESPONSYWNOŚĆ --- */
@media (max-width: 768px) {
    .app-container { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .content {
        margin-left: 0;
        padding: 20px;
    }
    .sidebar-footer {
        position: relative;
    }
}

/* =============================================
   ALGORYTMY - KAFELKI GRID
   ============================================= */

.section-desc {
    color: var(--text-muted);
    margin-bottom: 30px;
    font-size: 0.95rem;
}

.algo-category {
    margin-bottom: 30px;
}

.category-title {
    color: var(--text-heading);
    font-size: 1.1rem;
    margin: 0 0 15px 0;
    padding: 12px 15px;
    background: rgba(59, 130, 246, 0.1);
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.algo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
}

/* Kafelek algorytmu */
.algo-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 18px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    color: inherit;
}

.algo-tile:hover {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.05);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.algo-tile:active {
    transform: translateY(0);
}

.tile-icon {
    font-size: 1.6rem;
}

.tile-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-heading);
    text-align: center;
    line-height: 1.3;
}

/* =============================================
   MODAL
   ============================================= */

.algo-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

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

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
}

.modal-container {
    position: relative;
    width: 90%;
    max-width: 750px;
    max-height: 85vh;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
}

.algo-modal.active .modal-container {
    transform: scale(1) translateY(0);
}

/* Header modala */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 25px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-icon {
    font-size: 1.5rem;
}

.modal-title h3 {
    margin: 0;
    font-size: 1.3rem;
    color: var(--text-heading);
}

.modal-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
    color: #ef4444;
}

/* Body modala */
.modal-body {
    padding: 25px;
    overflow-y: auto;
    flex: 1;
}

.modal-desc {
    margin: 0 0 20px 0;
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.6;
}

.modal-body .code-wrapper {
    margin: 0;
}

.modal-body pre {
    max-height: 450px;
    overflow: auto;
}

.modal-body pre::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.modal-body pre::-webkit-scrollbar-track {
    background: #21252b;
    border-radius: 4px;
}

.modal-body pre::-webkit-scrollbar-thumb {
    background: #4b5263;
    border-radius: 4px;
}

.modal-body pre::-webkit-scrollbar-thumb:hover {
    background: #5c6370;
}

.modal-body .copy-btn {
    opacity: 1;
}

/* Footer modala - nawigacja */
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 25px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.2);
}

.modal-nav-btn {
    padding: 8px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.modal-nav-btn:hover {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

.modal-nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.modal-counter {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-family: 'Fira Code', monospace;
}

/* Kolory składni - Atom One Dark */
.hljs-keyword,
.hljs-selector-tag,
.hljs-literal {
    color: #c678dd !important;
}

.hljs-string,
.hljs-title,
.hljs-name,
.hljs-type {
    color: #98c379 !important;
}

.hljs-comment {
    color: #5c6370 !important;
    font-style: italic;
}

.hljs-number {
    color: #d19a66 !important;
}

.hljs-function .hljs-title {
    color: #61afef !important;
}

.hljs-built_in {
    color: #e6c07b !important;
}

/* Responsywność */
@media (max-width: 600px) {
    .algo-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .modal-container {
        width: 95%;
        max-height: 90vh;
    }
    
    .modal-header, .modal-body, .modal-footer {
        padding: 15px;
    }
    
    .modal-footer {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .modal-counter {
        order: -1;
        width: 100%;
        text-align: center;
    }
}


/* Linki zewnętrzne w sidebarze */
.external-link {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #64ffda !important;
    transition: all 0.2s ease;
}

.external-link:hover {
    background-color: rgba(100, 255, 218, 0.1) !important;
    transform: translateX(3px);
}

.link-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}