/* ============================================================
   CRACKING GOOGLE — SYSTEM DESIGN MASTERY
   Design System & Styles
   ============================================================ */

/* --- Reset & Custom Properties --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Surfaces */
    --bg-primary: #FAF9F7;
    --bg-warm: #F5F4F0;
    --bg-sidebar: #FFFFFF;
    --bg-code: #F3F4F6;
    --bg-code-block: #1B1D22;
    --bg-callout-blue: #EEF4FD;
    --bg-callout-green: #E9F7EF;
    --bg-callout-yellow: #FEF9E7;
    --bg-callout-red: #FDECEA;
    --bg-exercise: #F9FAFB;

    /* Text */
    --text-primary: #18181B;
    --text-body: #27272A;
    --text-secondary: #52525B;
    --text-muted: #A1A1AA;
    --text-on-dark: #E4E4E7;

    /* Accent */
    --blue: #1A73E8;
    --blue-dark: #1557B0;
    --green: #0D904F;
    --yellow: #E37400;
    --red: #C5221F;

    /* Borders & Shadows */
    --border: #E4E4E7;
    --border-light: #F0F0F0;
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);

    /* Layout */
    --sidebar-width: 296px;
    --content-max: 724px;
    --radius: 8px;
    --radius-lg: 12px;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-serif: 'Source Serif 4', 'Georgia', 'Times New Roman', serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

    /* Transitions */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --duration: 200ms;
}

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-serif);
    font-size: 18px;
    line-height: 1.72;
    color: var(--text-body);
    background: var(--bg-primary);
    overflow-x: hidden;
}

::selection {
    background: rgba(26, 115, 232, 0.15);
}

/* --- Progress Bar --- */
.progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--blue), #4285F4);
    z-index: 1000;
    width: 0%;
    transition: width 0.4s var(--ease);
    will-change: width;
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s var(--ease);
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 28px 22px 20px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.logo-mark {
    width: 38px;
    height: 38px;
    background: var(--blue);
    color: white;
    font-family: var(--font-sans);
    font-weight: 800;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(26, 115, 232, 0.3);
}

.book-title {
    font-family: var(--font-sans);
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.4px;
    color: var(--text-primary);
    line-height: 1.2;
}

.book-subtitle {
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    margin-top: 2px;
    letter-spacing: 0.3px;
}

/* Sidebar search */
.sidebar-search {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    font-family: var(--font-sans);
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}

.sidebar-search input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}

.sidebar-search input::placeholder {
    color: var(--text-muted);
}

/* Chapter navigation */
.chapter-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.chapter-nav::-webkit-scrollbar {
    width: 4px;
}

.chapter-nav::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.nav-group {
    margin-bottom: 4px;
}

.nav-group-title {
    font-family: var(--font-sans);
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    padding: 12px 22px 6px;
}

.nav-item {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 7px 22px;
    font-family: var(--font-sans);
    font-size: 13.5px;
    font-weight: 450;
    color: var(--text-secondary);
    text-decoration: none;
    cursor: pointer;
    transition: all var(--duration) var(--ease);
    border-left: 3px solid transparent;
    line-height: 1.35;
}

.nav-item:hover {
    color: var(--text-primary);
    background: rgba(0,0,0,0.025);
}

.nav-item.active {
    color: var(--blue);
    background: rgba(26, 115, 232, 0.05);
    border-left-color: var(--blue);
    font-weight: 550;
}

.nav-item.hidden {
    display: none;
}

.nav-item-number {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 18px;
    font-variant-numeric: tabular-nums;
}

.nav-item.active .nav-item-number {
    color: var(--blue);
}

/* Sidebar footer */
.sidebar-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
}

.progress-text {
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
}

/* Mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 99;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.3s var(--ease);
}

.sidebar-overlay.open {
    display: block;
    opacity: 1;
}

/* Menu button (mobile) */
.menu-btn {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 101;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    flex-direction: column;
    gap: 4px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--duration) var(--ease);
}

.menu-btn:hover {
    box-shadow: var(--shadow-md);
}

.menu-btn span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all var(--duration) var(--ease);
}

/* --- Main Content --- */
.content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 56px 48px 96px;
}

.chapter {
    max-width: var(--content-max);
    width: 100%;
}

/* Chapter header */
.chapter-number {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2.5px;
    color: var(--blue);
    margin-bottom: 10px;
}

.chapter-title {
    font-family: var(--font-sans);
    font-size: 42px;
    font-weight: 900;
    letter-spacing: -1.5px;
    line-height: 1.1;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.chapter-subtitle {
    font-family: var(--font-serif);
    font-size: 20px;
    color: var(--text-secondary);
    line-height: 1.55;
    margin-bottom: 48px;
    font-style: italic;
    font-weight: 400;
}

/* --- Chapter Typography --- */
.chapter h2 {
    font-family: var(--font-sans);
    font-size: 26px;
    font-weight: 750;
    letter-spacing: -0.5px;
    color: var(--text-primary);
    margin: 52px 0 18px;
    padding-top: 20px;
    line-height: 1.25;
}

.chapter h2:first-of-type {
    margin-top: 0;
    padding-top: 0;
}

.chapter h3 {
    font-family: var(--font-sans);
    font-size: 19px;
    font-weight: 650;
    color: var(--text-primary);
    margin: 36px 0 12px;
    line-height: 1.3;
}

.chapter h4 {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 650;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin: 28px 0 10px;
}

.chapter p {
    margin-bottom: 18px;
}

.chapter ul, .chapter ol {
    margin-bottom: 18px;
    padding-left: 26px;
}

.chapter li {
    margin-bottom: 7px;
}

.chapter li::marker {
    color: var(--text-muted);
}

.chapter strong {
    font-weight: 650;
    color: var(--text-primary);
}

.chapter em {
    font-style: italic;
}

.chapter hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 48px 0;
}

.chapter blockquote {
    border-left: 3px solid var(--border);
    padding-left: 20px;
    margin: 20px 0;
    color: var(--text-secondary);
    font-style: italic;
}

/* Inline code */
.chapter code {
    font-family: var(--font-mono);
    font-size: 0.84em;
    background: var(--bg-code);
    padding: 2px 7px;
    border-radius: 4px;
    color: #C7254E;
    font-weight: 450;
}

/* Code blocks */
.chapter pre {
    background: var(--bg-code-block);
    color: var(--text-on-dark);
    padding: 22px 26px;
    border-radius: var(--radius-lg);
    overflow-x: auto;
    margin: 22px 0;
    font-family: var(--font-mono);
    font-size: 13.5px;
    line-height: 1.65;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(255,255,255,0.04);
}

.chapter pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
    font-weight: 400;
}

/* --- Callout Boxes --- */
.callout {
    padding: 20px 24px;
    border-radius: var(--radius);
    margin: 28px 0;
    border-left: 4px solid;
    font-size: 16px;
    line-height: 1.65;
}

.callout-concept {
    background: var(--bg-callout-blue);
    border-color: var(--blue);
}

.callout-tip {
    background: var(--bg-callout-green);
    border-color: var(--green);
}

.callout-warning {
    background: var(--bg-callout-red);
    border-color: var(--red);
}

.callout-interview {
    background: var(--bg-callout-yellow);
    border-color: var(--yellow);
}

.callout-title {
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.callout-concept .callout-title { color: var(--blue); }
.callout-tip .callout-title { color: var(--green); }
.callout-warning .callout-title { color: var(--red); }
.callout-interview .callout-title { color: var(--yellow); }

.callout p:last-child { margin-bottom: 0; }
.callout ul { margin-bottom: 0; }
.callout li:last-child { margin-bottom: 0; }

/* --- Exercise Blocks --- */
.exercise {
    background: var(--bg-exercise);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin: 28px 0;
    overflow: hidden;
    transition: box-shadow var(--duration) var(--ease);
}

.exercise:hover {
    box-shadow: var(--shadow-sm);
}

.exercise-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 22px;
    cursor: pointer;
    user-select: none;
    transition: background var(--duration) var(--ease);
}

.exercise-header:hover {
    background: rgba(0,0,0,0.02);
}

.exercise-title {
    font-family: var(--font-sans);
    font-size: 14.5px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.exercise-icon {
    font-size: 16px;
    opacity: 0.7;
}

.exercise-toggle {
    font-size: 12px;
    color: var(--text-muted);
    transition: transform 0.3s var(--ease);
    flex-shrink: 0;
}

.exercise-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.5s var(--ease);
}

.exercise.open .exercise-body {
    max-height: 4000px;
}

.exercise.open .exercise-toggle {
    transform: rotate(180deg);
}

.exercise-content {
    padding: 0 22px 20px;
    border-top: 1px solid var(--border-light);
    font-size: 16px;
    line-height: 1.65;
}

.exercise-content p:first-child {
    margin-top: 18px;
}

/* --- Tables --- */
.chapter table {
    width: 100%;
    border-collapse: collapse;
    margin: 22px 0;
    font-size: 15px;
    line-height: 1.5;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.chapter thead {
    background: var(--bg-code);
}

.chapter th {
    font-family: var(--font-sans);
    font-weight: 650;
    text-align: left;
    padding: 12px 18px;
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
}

.chapter td {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: top;
}

.chapter tbody tr:last-child td {
    border-bottom: none;
}

.chapter tbody tr:hover {
    background: rgba(0,0,0,0.015);
}

/* --- Architecture Diagrams --- */
.architecture {
    background: var(--bg-warm);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 32px;
    margin: 28px 0;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.35;
    white-space: pre;
    overflow-x: auto;
    color: var(--text-secondary);
}

/* --- Comparison Grid --- */
.comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin: 24px 0;
}

.comparison-card {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: box-shadow var(--duration) var(--ease);
}

.comparison-card:hover {
    box-shadow: var(--shadow-sm);
}

.comparison-card h4 {
    margin-top: 0;
    margin-bottom: 8px;
}

.comparison-card p:last-child {
    margin-bottom: 0;
}

/* --- Key Term --- */
.key-term {
    font-weight: 650;
    color: var(--blue-dark);
}

/* --- Chapter Pagination --- */
.chapter-pagination {
    max-width: var(--content-max);
    width: 100%;
    display: flex;
    justify-content: space-between;
    margin-top: 72px;
    padding-top: 36px;
    border-top: 1px solid var(--border);
    gap: 20px;
}

.page-link {
    display: flex;
    flex-direction: column;
    padding: 18px 22px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    text-decoration: none;
    cursor: pointer;
    transition: all var(--duration) var(--ease);
    flex: 1;
    max-width: 46%;
    background: var(--bg-sidebar);
}

.page-link:hover {
    border-color: var(--blue);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.page-link-label {
    font-family: var(--font-sans);
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.page-link-title {
    font-family: var(--font-sans);
    font-size: 15px;
    font-weight: 650;
    color: var(--blue);
    line-height: 1.3;
}

.page-link.next {
    text-align: right;
    margin-left: auto;
}

/* --- Responsive --- */
@media (max-width: 960px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .content {
        margin-left: 0;
        padding: 56px 32px 80px;
    }

    .menu-btn {
        display: flex;
    }
}

@media (max-width: 640px) {
    body {
        font-size: 16.5px;
    }

    .content {
        padding: 52px 18px 64px;
    }

    .chapter-title {
        font-size: 32px;
        letter-spacing: -1px;
    }

    .chapter-subtitle {
        font-size: 17px;
        margin-bottom: 36px;
    }

    .chapter h2 {
        font-size: 22px;
        margin: 40px 0 14px;
    }

    .chapter h3 {
        font-size: 17px;
    }

    .chapter pre {
        padding: 16px 18px;
        font-size: 12.5px;
        border-radius: var(--radius);
    }

    .callout {
        padding: 16px 18px;
        font-size: 15px;
    }

    .comparison {
        grid-template-columns: 1fr;
    }

    .chapter-pagination {
        flex-direction: column;
        margin-top: 48px;
    }

    .page-link {
        max-width: 100%;
    }

    .page-link.next {
        text-align: left;
    }

    .architecture {
        padding: 18px 14px;
        font-size: 11.5px;
    }
}

/* --- Print Styles --- */
@media print {
    .sidebar, .menu-btn, .progress-bar, .chapter-pagination, .sidebar-overlay {
        display: none !important;
    }

    .content {
        margin-left: 0;
        padding: 0;
    }

    .chapter {
        max-width: 100%;
    }

    .exercise-body {
        max-height: none !important;
    }
}
