/* ==========================================================================
   CS210 standalone-page design system
   Shared by every hand-written page under
   /academics/computer-science/cs210/ -- the three exam banks and the twelve
   study guides / cheat sheets.

   Theme comes from html[data-theme="light|dark"], which the site's toggle
   sets. The pages used to theme themselves with @media (prefers-color-scheme)
   or a hand-appended html[data-theme='dark'] patch block, so the toggle either
   did nothing or fought a wall of !important overrides. Everything here
   resolves from a token, in both directions, with no !important anywhere.
   ========================================================================== */

:root {
    color-scheme: light;

    --bg: #f4f6fc;
    --bg-tint-a: rgba(59, 111, 232, 0.10);
    --bg-tint-b: rgba(124, 92, 252, 0.07);

    --surface: #ffffff;
    --surface2: #f1f3fa;
    --surface3: #e7eaf5;
    --inset: #f8f9fd;

    --text: #141a29;
    --text2: #4c5570;
    --muted: #656e8a;

    --border: #e2e6f0;
    --border2: #cfd5e6;

    --accent: #3b6fe8;
    --accent2: #7c5cfc;
    --accent-ink: #2b57c4;
    --accent-soft: rgba(59, 111, 232, 0.09);
    --accent-line: rgba(59, 111, 232, 0.28);
    --on-accent: #ffffff;

    --green: #0f9d58;
    --green-ink: #0b7a44;
    --green-soft: rgba(15, 157, 88, 0.10);
    --green-line: rgba(15, 157, 88, 0.32);

    --red: #dc3d4f;
    --red-ink: #bb2536;
    --red-soft: rgba(220, 61, 79, 0.09);
    --red-line: rgba(220, 61, 79, 0.30);

    --yellow: #b5790d;
    --yellow-ink: #91600a;
    --yellow-soft: rgba(214, 148, 32, 0.13);
    --yellow-line: rgba(214, 148, 32, 0.34);

    --violet-ink: #6b3fd4;
    --violet-soft: rgba(124, 92, 252, 0.10);
    --violet-line: rgba(124, 92, 252, 0.28);

    --code-bg: #f6f7fc;
    --code-color: #2b3350;
    --code-keyword: #8250df;
    --code-string: #0a7d55;
    --code-comment: #7a839d;
    --code-type: #b5790d;
    --code-function: #2b57c4;

    --shadow-sm: 0 1px 2px rgba(20, 26, 41, 0.05);
    --shadow: 0 6px 20px -8px rgba(20, 26, 41, 0.16), 0 2px 6px -2px rgba(20, 26, 41, 0.06);
    --shadow-lg: 0 24px 60px -24px rgba(20, 26, 41, 0.28), 0 6px 18px -10px rgba(20, 26, 41, 0.10);
    --shadow-accent: 0 12px 28px -12px rgba(59, 111, 232, 0.5);

    --progress-bg: rgba(244, 246, 252, 0.88);

    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 18px;
    --r-xl: 26px;

    --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
    --dur: 220ms;

    --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    --page-w: 980px;
}

html[data-theme="dark"] {
    color-scheme: dark;

    --bg: #080b12;
    --bg-tint-a: rgba(96, 140, 255, 0.15);
    --bg-tint-b: rgba(150, 120, 255, 0.10);

    --surface: #111725;
    --surface2: #171e2f;
    --surface3: #1f273c;
    --inset: #141a28;

    --text: #e7ecf8;
    --text2: #a3adc6;
    --muted: #7b859e;

    --border: #232c42;
    --border2: #303b56;

    --accent: #7ea6ff;
    --accent2: #b09bff;
    --accent-ink: #a3c0ff;
    --accent-soft: rgba(126, 166, 255, 0.13);
    --accent-line: rgba(126, 166, 255, 0.32);
    --on-accent: #0a1020;

    --green: #3ecf8e;
    --green-ink: #6fe7b2;
    --green-soft: rgba(62, 207, 142, 0.13);
    --green-line: rgba(62, 207, 142, 0.32);

    --red: #ff6b7d;
    --red-ink: #ff97a4;
    --red-soft: rgba(255, 107, 125, 0.13);
    --red-line: rgba(255, 107, 125, 0.30);

    --yellow: #e0a83c;
    --yellow-ink: #f2c76d;
    --yellow-soft: rgba(224, 168, 60, 0.14);
    --yellow-line: rgba(224, 168, 60, 0.32);

    --violet-ink: #c3b0ff;
    --violet-soft: rgba(176, 155, 255, 0.13);
    --violet-line: rgba(176, 155, 255, 0.30);

    --code-bg: #0d1220;
    --code-color: #cfd8ee;
    --code-keyword: #c4a6ff;
    --code-string: #7bdcb0;
    --code-comment: #6f7994;
    --code-type: #f0c46b;
    --code-function: #8fb6ff;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 8px 24px -10px rgba(0, 0, 0, 0.7), 0 2px 6px -2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 30px 70px -30px rgba(0, 0, 0, 0.85), 0 8px 20px -12px rgba(0, 0, 0, 0.6);
    --shadow-accent: 0 12px 30px -14px rgba(126, 166, 255, 0.55);

    --progress-bg: rgba(8, 11, 18, 0.86);
}

/* --------------------------------------------------------------- base --- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0 0 clamp(48px, 8vw, 96px);
    min-height: 100vh;
    background-color: var(--bg);
    background-image:
        radial-gradient(64rem 42rem at 10% -14%, var(--bg-tint-a), transparent 62%),
        radial-gradient(52rem 36rem at 94% 2%, var(--bg-tint-b), transparent 60%);
    background-attachment: fixed;
    color: var(--text);
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

h1,
h2,
h3,
h4,
h5,
h6 {
    margin: 0 0 0.5em;
    line-height: 1.25;
    letter-spacing: -0.015em;
    font-weight: 650;
    color: var(--text);
}

h2 {
    font-size: 1.35rem;
}

h3 {
    font-size: 1.1rem;
}

h4 {
    font-size: 0.97rem;
}

p {
    margin: 0 0 0.85em;
}

p:last-child {
    margin-bottom: 0;
}

ul,
ol {
    margin: 0 0 0.85em;
    padding-left: 1.35em;
}

li {
    margin-bottom: 0.35em;
}

li:last-child {
    margin-bottom: 0;
}

a {
    color: var(--accent-ink);
    text-decoration-color: var(--accent-line);
    text-underline-offset: 2px;
    transition: color 160ms var(--ease);
}

a:hover {
    color: var(--accent);
}

strong,
b {
    color: var(--text);
    font-weight: 650;
}

hr {
    height: 1px;
    margin: 24px 0;
    border: 0;
    background: var(--border);
}

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

::selection {
    background: var(--accent-soft);
    color: var(--text);
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

::placeholder {
    color: var(--muted);
}

/* --------------------------------------------------------------- shell -- */

.container,
.content,
.main-content {
    max-width: var(--page-w);
    margin: 0 auto;
    padding: 0;
    background: none;
    border-radius: 0;
    box-shadow: none;
}

.container {
    padding: 0 clamp(14px, 4vw, 28px);
}

.content,
.main-content {
    max-width: none;
}

header {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 11px;
    margin: 0 0 clamp(22px, 3vw, 34px);
    padding: clamp(30px, 5vw, 52px) clamp(18px, 4vw, 32px) clamp(26px, 4vw, 40px);
    background:
        linear-gradient(150deg, var(--bg-tint-a), transparent 58%),
        var(--surface);
    border-bottom: 1px solid var(--border);
    text-align: center;
    overflow: hidden;
    animation: cs-rise 520ms var(--ease) both;
}

header::after {
    content: "";
    position: absolute;
    inset: auto 0 0 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), var(--accent2), transparent);
}

/* Guides put their header inside .container; let it run edge to edge the way
   the exam headers (direct body children) already do. */
.container>header {
    width: 100vw;
    margin-inline: calc(50% - 50vw);
}

/* The header is a centred column, so its children hand spacing to the gap. */
header>* {
    margin-block: 0;
}

header h1 {
    max-width: 26ch;
    margin: 0;
    font-size: clamp(1.55rem, 1.05rem + 2.2vw, 2.35rem);
    font-weight: 700;
    letter-spacing: -0.028em;
}

header h1 span {
    color: var(--accent-ink);
}

header p {
    max-width: 62ch;
    margin: 0;
    color: var(--text2);
    font-size: 0.95rem;
}


.subtitle {
    color: var(--text2);
    font-size: 0.95rem;
}

body[data-cs210-page="hash-tables"] .container>h1:first-of-type,
body[data-cs210-page="merge-sort"] .container>h1:first-of-type {
    margin: clamp(30px, 5vw, 52px) 0 0;
    font-size: clamp(1.55rem, 1.05rem + 2.2vw, 2.35rem);
    font-weight: 700;
    letter-spacing: -0.028em;
    text-align: center;
}

body[data-cs210-page="hash-tables"] .container>.subtitle,
body[data-cs210-page="merge-sort"] .container>.subtitle {
    margin: 0 0 clamp(24px, 4vw, 38px);
    padding-bottom: clamp(20px, 3vw, 30px);
    border-bottom: 1px solid var(--border);
    text-align: center;
}

section,
.section {
    margin: 0 0 clamp(20px, 3vw, 30px);
    padding: clamp(20px, 2.6vw, 30px);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    animation: cs-rise 520ms var(--ease) both;
}

section>h2:first-child,
.section>h2:first-child,
.card>h2:first-child {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 0.7em;
    padding-bottom: 0.55em;
    border-bottom: 1px solid var(--border);
}

.section-anchor {
    display: block;
    height: 0;
    scroll-margin-top: 80px;
}

footer,
.footer {
    max-width: var(--page-w);
    margin: 32px auto 0;
    padding: 20px clamp(14px, 4vw, 28px) 0;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.85rem;
    text-align: center;
}

/* ---------------------------------------------------------- navigation -- */

.nav,
nav,
.toc,
.menu {
    margin: 0 0 clamp(20px, 3vw, 30px);
    padding: clamp(16px, 2.2vw, 22px);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    animation: cs-rise 520ms var(--ease) both;
}

.toc h2,
.toc h3,
.sidebar h2 {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.nav ul,
nav ul,
.toc ul {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.toc li,
.nav li,
nav li {
    margin: 0;
}

.nav a,
nav a,
.toc a,
.menu-item {
    display: block;
    padding: 8px 12px;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    color: var(--text2);
    font-size: 0.88rem;
    font-weight: 550;
    text-decoration: none;
    transition: background-color 160ms var(--ease), border-color 160ms var(--ease),
        color 160ms var(--ease), transform 160ms var(--ease);
}

.nav a:hover,
nav a:hover,
.toc a:hover,
.menu-item:hover {
    border-color: var(--accent-line);
    background: var(--accent-soft);
    color: var(--accent-ink);
    transform: translateX(2px);
}

.menu {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 6px;
}

/* The tabbed cheat sheet keeps its section list in a rail. */
.sidebar {
    padding: 18px 16px;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.nav-item {
    display: block;
    padding: 8px 12px;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    color: var(--text2);
    font-size: 0.86rem;
    font-weight: 550;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 160ms var(--ease), border-color 160ms var(--ease),
        color 160ms var(--ease);
}

.nav-item:hover {
    background: var(--accent-soft);
    color: var(--accent-ink);
}

.nav-item.active {
    border-color: var(--accent-line);
    background: var(--accent-soft);
    color: var(--accent-ink);
    font-weight: 650;
}

[data-cs210-page="cheat-sheet-2"] body,
body[data-cs210-page="cheat-sheet-2"] {
    display: grid;
    grid-template-columns: minmax(190px, 240px) minmax(0, 1fr);
    gap: clamp(16px, 3vw, 30px);
    align-items: start;
    max-width: 1260px;
    margin: 0 auto;
    padding: clamp(56px, 7vw, 76px) clamp(14px, 3vw, 28px) 60px;
}

body[data-cs210-page="cheat-sheet-2"] .sidebar {
    position: sticky;
    top: 14px;
    max-height: calc(100vh - 28px);
    overflow-y: auto;
}

body[data-cs210-page="cheat-sheet-2"] .main-content {
    min-width: 0;
}

.topic-section {
    display: none;
}

.topic-section.active {
    display: block;
    animation: cs-fade 340ms var(--ease) both;
}

#scrollTop {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 60;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border2);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text2);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 160ms var(--ease), border-color 160ms var(--ease);
}

#scrollTop:hover {
    transform: translateY(-2px);
    border-color: var(--accent-line);
    color: var(--accent-ink);
}

/* ------------------------------------------------------------ callouts -- */
/* One primitive: a tinted panel with a coloured spine. The variants below
   only change the accent, so a page can mix any of them and stay coherent. */

.definition,
.definition-box,
.example,
.example-box,
.important,
.important-box,
.note,
.tip,
.tip-box,
.key-point,
.key-concept,
.key-points,
.highlight,
.highlight-box,
.warning-box,
.danger-box,
.critical,
.complexity-warning,
.success,
.success-box,
.info,
.info-box,
.formula,
.algorithm,
.quote,
.hack,
.explanation,
.solution,
.operation-example {
    margin: 16px 0;
    padding: 15px 18px;
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--r-md);
    background: var(--surface2);
    color: var(--text2);
    font-size: 0.93rem;
}

.definition h3,
.definition h4,
.example h3,
.example h4,
.key-point h4,
.key-points h3,
.important h4,
.note strong,
.tip h4,
.solution h4,
.explanation h4,
.comparison-card h4,
.mini-card h4,
.rotation-card h4,
.complexity-card h4,
.pros h4,
.cons h4 {
    margin: 0 0 0.5em;
    color: var(--text);
    font-size: 0.88rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.definition,
.definition-box,
.key-point,
.key-concept,
.key-points,
.explanation {
    border-left-color: var(--accent);
    background: var(--accent-soft);
}

.example,
.example-box,
.solution,
.operation-example,
.algorithm {
    border-left-color: var(--violet-ink);
    background: var(--violet-soft);
}

.note,
.info,
.info-box,
.quote,
.formula {
    border-left-color: var(--accent2);
    background: var(--surface2);
}

.tip,
.tip-box,
.success,
.success-box,
.hack {
    border-left-color: var(--green);
    background: var(--green-soft);
}

.important,
.important-box,
.highlight,
.highlight-box,
.warning-box,
.complexity-warning {
    border-left-color: var(--yellow);
    background: var(--yellow-soft);
}

.critical,
.danger-box {
    border-left-color: var(--red);
    background: var(--red-soft);
}

.formula {
    font-family: var(--mono);
    font-size: 0.88rem;
    color: var(--text);
}

.quote {
    font-style: italic;
}

.key-points ul,
.operations-list {
    margin: 0;
    padding-left: 1.15em;
}

.key-points li,
.operations-list li {
    margin-bottom: 0.4em;
}

.operations-list li strong {
    color: var(--text);
}

.algorithm-steps,
.operation-steps {
    counter-reset: step;
    margin: 12px 0 0;
    padding: 0;
    list-style: none;
}

.algorithm-steps li,
.operation-steps li {
    position: relative;
    margin-bottom: 8px;
    padding-left: 34px;
    color: var(--text2);
    font-size: 0.92rem;
}

.algorithm-steps li::before,
.operation-steps li::before {
    counter-increment: step;
    content: counter(step);
    position: absolute;
    left: 0;
    top: 1px;
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border: 1px solid var(--accent-line);
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-ink);
    font-size: 0.7rem;
    font-weight: 700;
}

.algorithm-step {
    margin-bottom: 8px;
    padding: 10px 13px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--inset);
    font-size: 0.9rem;
}

.algorithm-step strong,
.solution-step strong {
    color: var(--accent-ink);
}

.solution-step {
    margin-bottom: 6px;
    padding-left: 12px;
    border-left: 2px solid var(--accent-line);
    font-size: 0.9rem;
}

.example-label {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    margin-bottom: 10px;
    border: 1px solid var(--violet-line);
    border-radius: 999px;
    background: var(--violet-soft);
    color: var(--violet-ink);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.example-label.example-generated {
    border-color: var(--accent-line);
    background: var(--accent-soft);
    color: var(--accent-ink);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border: 1px solid var(--yellow-line);
    border-radius: 999px;
    background: var(--yellow-soft);
    color: var(--yellow-ink);
    font-size: 0.64rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    vertical-align: middle;
}

/* ------------------------------------------------------- cards & grids -- */

.card,
.mini-card,
.comparison-card,
.comparison-item,
.rotation-card,
.complexity-card,
.pros,
.cons,
.complexity-box {
    padding: clamp(16px, 2.2vw, 22px);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
        transform var(--dur) var(--ease);
}

.card {
    margin-bottom: 18px;
}

.card:hover,
.mini-card:hover,
.comparison-card:hover,
.rotation-card:hover,
.complexity-card:hover {
    border-color: var(--border2);
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.mini-grid,
.rotation-types,
.comparison,
.comparison-table,
.pros-cons,
.complexity {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 14px;
    margin: 16px 0;
}

.comparison>div,
.comparison .left,
.comparison .right {
    min-width: 0;
}

.pros,
.comparison-item.good,
.array-card {
    border-color: var(--green-line);
    background: var(--green-soft);
}

.cons,
.comparison-item.bad,
.list-card {
    border-color: var(--red-line);
    background: var(--red-soft);
}

.pros h4 {
    color: var(--green-ink);
}

.cons h4 {
    color: var(--red-ink);
}

.comparison-item.good h4 {
    color: var(--green-ink);
}

.comparison-item.bad h4 {
    color: var(--red-ink);
}

.complexity-card {
    text-align: center;
}

.complexity-card .value,
.complexity-card h4+.value {
    margin: 4px 0 6px;
    color: var(--accent-ink);
    font-family: var(--mono);
    font-size: 1.3rem;
    font-weight: 700;
}

.complexity-card p {
    color: var(--muted);
    font-size: 0.82rem;
}

/* --------------------------------------------------- complexity badges -- */

.complexity,
.complexity-badge,
.complexity-good,
.complexity-bad,
.o-1,
.o-n,
.o-n2 {
    font-family: var(--mono);
}

.complexity-badge,
.complexity-good,
.complexity-bad,
.o-1,
.o-n,
.o-n2 {
    display: inline-block;
    padding: 2px 9px;
    border: 1px solid var(--border2);
    border-radius: 999px;
    background: var(--surface2);
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}

.complexity-good,
.o-1,
.complexity.fast,
.complexity.good {
    border-color: var(--green-line);
    background: var(--green-soft);
    color: var(--green-ink);
}

.o-n,
.complexity.medium,
.complexity.average {
    border-color: var(--yellow-line);
    background: var(--yellow-soft);
    color: var(--yellow-ink);
}

.complexity-bad,
.o-n2,
.complexity.slow,
.complexity.bad {
    border-color: var(--red-line);
    background: var(--red-soft);
    color: var(--red-ink);
}

/* `.complexity` doubles as a grid wrapper on some pages and an inline badge
   on others -- only give it badge chrome when it carries a state class. */
.complexity.fast,
.complexity.good,
.complexity.medium,
.complexity.average,
.complexity.slow,
.complexity.bad {
    display: inline-block;
    padding: 2px 9px;
    border-width: 1px;
    border-style: solid;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
}

/* ----------------------------------------------------------------code --- */

code {
    padding: 0.15em 0.4em;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--code-bg);
    color: var(--code-color);
    font-family: var(--mono);
    font-size: 0.86em;
}

pre {
    margin: 14px 0;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--code-bg);
    color: var(--code-color);
    font-family: var(--mono);
    font-size: 0.83rem;
    line-height: 1.6;
    overflow-x: auto;
}

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

.code-block {
    margin: 14px 0;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--code-bg);
    color: var(--code-color);
    font-family: var(--mono);
    font-size: 0.83rem;
    line-height: 1.65;
    white-space: pre-wrap;
    overflow-x: auto;
}

.code-block .keyword,
.keyword {
    color: var(--code-keyword);
    font-weight: 600;
}

.code-block .string,
.string {
    color: var(--code-string);
}

.code-block .comment,
.comment {
    color: var(--code-comment);
    font-style: italic;
}

.code-block .type,
.type {
    color: var(--code-type);
}

.code-block .function,
.function {
    color: var(--code-function);
}

/* ------------------------------------------------------------- tables --- */

.table-container,
.complexity-chart,
.comparison-table.has-table {
    margin: 16px 0;
    overflow-x: auto;
}

table {
    width: 100%;
    margin: 16px 0;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
    font-size: 0.89rem;
}

th,
td {
    padding: 10px 13px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

th {
    background: var(--surface3);
    color: var(--text);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}

td {
    color: var(--text2);
}

tr:last-child td {
    border-bottom: 0;
}

tbody tr:nth-child(even) td,
table tr:nth-child(even) td {
    background: var(--inset);
}

tr:hover td {
    background: var(--accent-soft);
}

/* ------------------------------------------------ data-structure visuals - */

.visual,
.visual-example,
.visual-diagram,
.visualization,
.diagram,
.tree-diagram,
.tree-visual,
.array-visual,
.stack-visual,
.queue-visual,
.complexity-box {
    margin: 16px 0;
}

.visual,
.visual-example,
.visual-diagram,
.visualization,
.diagram,
.tree-diagram,
.tree-visual {
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--inset);
    text-align: center;
}

.tree-diagram,
.tree-visual,
.diagram {
    font-family: var(--mono);
    font-size: 0.84rem;
    line-height: 1.75;
    color: var(--text);
    overflow-x: auto;
}

.diagram,
body[data-cs210-page="bst"] .tree-diagram {
    white-space: pre;
    text-align: left;
}

.visual-title {
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.array-visual,
.stack-visual,
.queue-visual {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--inset);
}

.array-cell,
.array-box,
.array-item,
.stack-item,
.queue-item {
    display: inline-grid;
    margin: 3px 2px;
    place-items: center;
    min-width: 46px;
    min-height: 42px;
    padding: 8px 12px;
    border: 1px solid var(--accent-line);
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.88rem;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    transition: transform 160ms var(--ease), border-color 160ms var(--ease);
}

.array-cell:hover,
.stack-item:hover,
.queue-item:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.array-index,
.array-cell .index {
    margin-top: 4px;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 0.7rem;
    text-align: center;
}

.arrow {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 1rem;
}

.pivot {
    border-color: var(--yellow-line);
    background: var(--yellow-soft);
    color: var(--yellow-ink);
}

.sorted,
.greater-than {
    border-color: var(--green-line);
    background: var(--green-soft);
    color: var(--green-ink);
}

.unsorted,
.less-than {
    border-color: var(--border2);
    background: var(--surface2);
    color: var(--text2);
}

.merging {
    border-color: var(--accent-line);
    background: var(--accent-soft);
    color: var(--accent-ink);
}

ul.styled-list {
    list-style: none;
    padding-left: 0;
}

ul.styled-list li {
    position: relative;
    padding-left: 20px;
}

ul.styled-list li::before {
    content: "";
    position: absolute;
    left: 4px;
    top: 0.65em;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
}

/* ==========================================================================
   Exam question banks (midterm-1, quiz-1, quiz-2)
   ========================================================================== */

body[data-cs210="exam"] .container {
    max-width: 900px;
    padding-top: 8px;
}

.header-tag {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border: 1px solid var(--accent-line);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-ink);
    font-family: var(--mono);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

/* ---------------------------------------------------------- progress --- */

.progress-wrap {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 11px clamp(14px, 4vw, 28px);
    border-bottom: 1px solid var(--border);
    background: var(--progress-bg);
    backdrop-filter: blur(12px) saturate(1.3);
    -webkit-backdrop-filter: blur(12px) saturate(1.3);
}

.progress-bar-outer {
    flex: 1;
    height: 5px;
    border-radius: 999px;
    background: var(--surface3);
    overflow: hidden;
}

.progress-bar-inner {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    transition: width 480ms var(--ease);
}

.progress-label {
    flex: 0 0 auto;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

/* ---------------------------------------------------- section headers --- */

.section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 30px 0 16px;
}

.section-line {
    flex: 1;
    height: 1px;
    background: var(--border);
}

.section-title {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    white-space: nowrap;
}

.section-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border: 1px solid var(--accent-line);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-ink);
    font-family: var(--mono);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    white-space: nowrap;
}

.badge-written,
.badge-rec {
    border-color: var(--violet-line);
    background: var(--violet-soft);
    color: var(--violet-ink);
}

.badge-bigo,
.badge-bigoh,
.badge-sort {
    border-color: var(--yellow-line);
    background: var(--yellow-soft);
    color: var(--yellow-ink);
}

.badge-ll {
    border-color: var(--green-line);
    background: var(--green-soft);
    color: var(--green-ink);
}

/* ------------------------------------------------------ question card --- */

.question-card {
    position: relative;
    margin-bottom: 14px;
    padding: clamp(17px, 2.3vw, 24px);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
        transform var(--dur) var(--ease);
    animation: cs-rise 520ms var(--ease) both;
}

.question-card:hover {
    border-color: var(--border2);
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.question-card.correct {
    border-color: var(--green-line);
}

.question-card.incorrect {
    border-color: var(--red-line);
}

.question-card.partial {
    border-color: var(--yellow-line);
}

.card-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
}

.card-head>div:first-child {
    flex: 0 0 auto;
}

.q-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    padding: 4px 10px;
    border: 1px solid var(--accent-line);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-ink);
    font-family: var(--mono);
    font-size: 0.72rem;
    font-weight: 700;
}

.q-text {
    flex: 1;
    min-width: 0;
    color: var(--text);
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.55;
}

.q-pts,
.q-era,
.q-source,
.diagram-note {
    flex: 0 0 auto;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.q-era,
.q-source {
    display: block;
    margin-top: 4px;
    white-space: normal;
}

.diagram-note {
    display: block;
    margin: -6px 0 12px;
    white-space: normal;
}

/* ------------------------------------------------------------ options --- */

.options-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.option-label {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--inset);
    color: var(--text);
    font-size: 0.94rem;
    line-height: 1.5;
    cursor: pointer;
    transition: border-color 160ms var(--ease), background-color 160ms var(--ease),
        transform 160ms var(--ease);
}

.option-label:hover {
    border-color: var(--accent-line);
    background: var(--accent-soft);
    transform: translateX(2px);
}

.option-label input[type="radio"] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.option-circle {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    border: 1px solid var(--border2);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text2);
    font-family: var(--mono);
    font-size: 0.75rem;
    font-weight: 700;
    transition: background-color 160ms var(--ease), border-color 160ms var(--ease),
        color 160ms var(--ease);
}

.option-label.selected {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.option-label.selected .option-circle {
    border-color: transparent;
    background: var(--accent);
    color: var(--on-accent);
}

.option-label.show-correct {
    border-color: var(--green-line);
    background: var(--green-soft);
    color: var(--green-ink);
}

.option-label.show-correct .option-circle {
    border-color: transparent;
    background: var(--green);
    color: var(--on-accent);
}

.option-label.show-wrong {
    border-color: var(--red-line);
    background: var(--red-soft);
    color: var(--red-ink);
}

.option-label.show-wrong .option-circle {
    border-color: transparent;
    background: var(--red);
    color: var(--on-accent);
}

/* ------------------------------------------------------ written input --- */

.textarea-wrap {
    margin-top: 4px;
}

textarea.written-answer {
    width: 100%;
    min-height: 118px;
    padding: 12px 14px;
    border: 1px solid var(--border2);
    border-radius: var(--r-md);
    background: var(--inset);
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.86rem;
    line-height: 1.6;
    resize: vertical;
    transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}

textarea.written-answer:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

pre.code-snippet {
    margin: 0 0 14px;
    padding: 15px 17px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--code-bg);
    color: var(--code-color);
    font-family: var(--mono);
    font-size: 0.82rem;
    line-height: 1.6;
    overflow-x: auto;
}

/* -------------------------------------------------------- big-O table --- */

.bigo-table {
    width: 100%;
    margin: 4px 0 0;
}

.bigo-table th {
    white-space: normal;
}

.bigo-input {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--border2);
    border-radius: var(--r-sm);
    background: var(--inset);
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.85rem;
    transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}

.bigo-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.bigo-input.correct-input {
    border-color: var(--green);
    background: var(--green-soft);
    color: var(--green-ink);
}

.bigo-input.wrong-input {
    border-color: var(--red);
    background: var(--red-soft);
    color: var(--red-ink);
}

/* ----------------------------------------------------------- feedback --- */

.feedback-box {
    display: none;
    margin-top: 14px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--r-md);
    background: var(--surface2);
    color: var(--text2);
    font-size: 0.9rem;
}

.feedback-box.show {
    display: block;
    animation: cs-reveal 340ms var(--ease) both;
}

.feedback-box.correct-fb {
    border-left-color: var(--green);
    background: var(--green-soft);
}

.feedback-box.incorrect-fb {
    border-left-color: var(--red);
    background: var(--red-soft);
}

.feedback-box.partial-fb {
    border-left-color: var(--yellow);
    background: var(--yellow-soft);
}

.fb-icon {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.fb-icon.ok {
    color: var(--green-ink);
}

.fb-icon.no {
    color: var(--red-ink);
}

.fb-icon.so {
    color: var(--yellow-ink);
}

.fb-explanation {
    color: var(--text2);
    font-size: 0.9rem;
    line-height: 1.6;
}

.fb-keywords {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.kw-tag {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border: 1px solid var(--border2);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-family: var(--mono);
    font-size: 0.7rem;
    font-weight: 600;
}

.kw-tag.found {
    border-color: var(--green-line);
    background: var(--green-soft);
    color: var(--green-ink);
}

/* ------------------------------------------------------------ actions --- */

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 26px 0 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 auto;
    min-width: 160px;
    padding: 13px 24px;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 650;
    line-height: 1.2;
    cursor: pointer;
    transition: transform 160ms var(--ease), box-shadow 160ms var(--ease),
        background-color 160ms var(--ease), border-color 160ms var(--ease),
        filter 160ms var(--ease);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: var(--on-accent);
    box-shadow: var(--shadow-accent);
}

.btn-primary:hover {
    transform: translateY(-2px);
    filter: saturate(1.06);
}

.btn-outline {
    border-color: var(--border2);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.btn-outline:hover {
    transform: translateY(-2px);
    border-color: var(--accent-line);
    background: var(--accent-soft);
}

.btn:active {
    transform: translateY(0);
}

/* ------------------------------------------------------------- result --- */

.result-section {
    display: none;
    margin-top: 24px;
    padding: clamp(24px, 4vw, 38px);
    border: 1px solid var(--accent-line);
    border-radius: var(--r-xl);
    background:
        linear-gradient(150deg, var(--accent-soft), transparent 60%),
        var(--surface);
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.result-section.show {
    display: block;
    animation: cs-pop 420ms var(--ease) both;
}

.score-big {
    margin: 6px 0 4px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    font-size: clamp(2.4rem, 1.6rem + 3.4vw, 3.4rem);
    font-weight: 750;
    letter-spacing: -0.03em;
    line-height: 1.05;
}

.score-label {
    color: var(--text2);
    font-family: var(--mono);
    font-size: 0.85rem;
}

.score-breakdown {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    max-width: 420px;
    margin: 22px auto 0;
}

.sb-item {
    padding: 13px 10px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface2);
}

.sb-item .sb-val {
    font-family: var(--mono);
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.1;
}

.sb-item .sb-label {
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.sb-correct {
    border-color: var(--green-line);
    background: var(--green-soft);
}

.sb-wrong {
    border-color: var(--red-line);
    background: var(--red-soft);
}

.sb-partial {
    border-color: var(--yellow-line);
    background: var(--yellow-soft);
}

.sb-correct .sb-val {
    color: var(--green-ink);
}

.sb-wrong .sb-val {
    color: var(--red-ink);
}

.sb-partial .sb-val {
    color: var(--yellow-ink);
}

header .sg-page-search.sg-page-search {
    display: inline-flex;
    width: auto;
    padding: 4px 5px;
    border-radius: 999px;
    border-width: 1px;
    border-style: solid;
}

header .sg-page-search.sg-page-search .sg-page-search__input {
    border-radius: 999px;
}

/* --------------------------------------------------------- theme toggle -- */
/* html-theme-sync.js injects its own .sg-theme-toggle rules at runtime, after
   this file. The doubled class outranks them without reaching for !important. */

.sg-theme-toggle.sg-theme-toggle {
    position: fixed;
    inset: 14px 14px auto auto;
    z-index: 99999;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: auto;
    height: 36px;
    padding: 0 14px 0 11px;
    border: 1px solid var(--border2);
    border-radius: 999px;
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    color: var(--text2);
    font-family: var(--sans);
    font-size: 0.78rem;
    font-weight: 650;
    letter-spacing: 0.02em;
    cursor: pointer;
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px) saturate(1.4);
    -webkit-backdrop-filter: blur(12px) saturate(1.4);
    transition: transform 200ms var(--ease), border-color 200ms var(--ease),
        color 200ms var(--ease), background-color 200ms var(--ease);
}

.sg-theme-toggle.sg-theme-toggle:hover,
.sg-theme-toggle.sg-theme-toggle:focus-visible {
    transform: translateY(-1px);
    border-color: var(--accent-line);
    color: var(--text);
}

.sg-theme-toggle svg {
    display: block;
    width: 15px;
    height: 15px;
    transition: transform 320ms var(--ease);
}

.sg-theme-toggle .sg-icon-sun {
    display: none;
}

html[data-theme="dark"] .sg-theme-toggle .sg-icon-sun {
    display: block;
}

html[data-theme="dark"] .sg-theme-toggle .sg-icon-moon {
    display: none;
}

.sg-theme-toggle:hover svg {
    transform: rotate(-18deg);
}

[dir="rtl"] .sg-theme-toggle.sg-theme-toggle,
html[lang="ar"] .sg-theme-toggle.sg-theme-toggle {
    inset: 14px auto auto 14px;
}

/* The exam pages put a sticky progress bar at the top; nudge the toggle down
   so the two never overlap. */
body[data-cs210="exam"] .sg-theme-toggle.sg-theme-toggle {
    inset: auto 14px 14px auto;
}

/* ----------------------------------------------------------- animation -- */

@keyframes cs-rise {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes cs-fade {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes cs-reveal {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes cs-pop {
    from {
        opacity: 0;
        transform: scale(0.96);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

/* --------------------------------------------------------------- small -- */

@media (max-width: 768px) {
    body {
        font-size: 14.5px;
    }

    .nav ul,
    nav ul,
    .toc ul,
    .menu {
        grid-template-columns: 1fr;
    }

    .score-breakdown {
        grid-template-columns: 1fr;
    }

    body[data-cs210-page="cheat-sheet-2"] {
        grid-template-columns: minmax(0, 1fr);
    }

    body[data-cs210-page="cheat-sheet-2"] .sidebar {
        position: static;
        max-height: none;
    }
}

@media (max-width: 600px) {
    .card-head {
        flex-wrap: wrap;
    }

    .btn {
        min-width: 100%;
    }

    .sg-theme-toggle.sg-theme-toggle {
        inset: 10px 10px auto auto;
    }

    body[data-cs210="exam"] .sg-theme-toggle.sg-theme-toggle {
        inset: auto 10px 10px auto;
    }
}

@media print {
    body {
        background: #fff;
        color: #000;
    }

    .sg-theme-toggle,
    .progress-wrap,
    .actions,
    #scrollTop {
        display: none;
    }

    section,
    .section,
    .card,
    .question-card {
        break-inside: avoid;
        box-shadow: none;
    }
}