html, body {
    height: 100%;
}

h1:focus {
    outline: none;
}

/* Introductions and running text keep a readable measure (docs/lab-design-standards.md, section 3). */
.intro {
    max-width: 760px;
}

/* Theory pages and lessons: the standard theory pattern, with callouts for the one thing to remember. */
.lesson {
    max-width: 860px;
}

.lesson p, .lesson li {
    line-height: 1.65;
    margin-bottom: 0.75rem;
}

.lesson ul {
    padding-left: 1.25rem;
}

.lesson .callout {
    border-left: 4px solid var(--mud-palette-primary);
    background: var(--mud-palette-background);
    padding: 0.75rem 1rem;
    margin: 1rem 0;
    border-radius: 4px;
}

/* Diagrams are drawn on their own dark card, so they read the same in both themes. */
.model-figure {
    margin: 0;
    max-width: 1000px;
}

.model-figure img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 16px;
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: #222;
}

    #blazor-error-ui .dismiss {
        cursor: pointer;
        position: absolute;
        right: 0.75rem;
        top: 0.5rem;
    }

/* Reconnect overlay. Blazor toggles the components-reconnect-* classes on #components-reconnect-modal. */
#components-reconnect-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    align-items: center;
    justify-content: center;
    background: rgba(14, 30, 36, 0.75);
    backdrop-filter: blur(2px);
    font-family: Roboto, "Segoe UI", sans-serif;
}

#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected {
    display: flex;
}

.reconnect-card {
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    border-radius: 12px;
    padding: 2rem 2.25rem;
    max-width: 26rem;
    margin: 1rem;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

.reconnect-title {
    font-size: 1.35rem;
    font-weight: 500;
    margin: 0.75rem 0 0.5rem;
}

.reconnect-text, .reconnect-failed-text {
    line-height: 1.55;
    margin: 0 0 1rem;
    color: var(--mud-palette-text-secondary);
}

.reconnect-spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto;
    border: 4px solid var(--mud-palette-lines-default);
    border-top-color: var(--mud-palette-primary);
    border-radius: 50%;
    animation: reconnect-spin 0.9s linear infinite;
}

@keyframes reconnect-spin {
    to { transform: rotate(360deg); }
}

.reconnect-button {
    display: none;
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    border: 0;
    border-radius: 6px;
    padding: 0.6rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
}

.reconnect-failed-text { display: none; }

#components-reconnect-modal.components-reconnect-failed .reconnect-text,
#components-reconnect-modal.components-reconnect-rejected .reconnect-text,
#components-reconnect-modal.components-reconnect-failed .reconnect-spinner,
#components-reconnect-modal.components-reconnect-rejected .reconnect-spinner {
    display: none;
}

#components-reconnect-modal.components-reconnect-failed .reconnect-failed-text,
#components-reconnect-modal.components-reconnect-rejected .reconnect-failed-text,
#components-reconnect-modal.components-reconnect-failed .reconnect-button,
#components-reconnect-modal.components-reconnect-rejected .reconnect-button {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

/* Accessibility helpers. */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: 8px;
    top: -60px;
    z-index: 3000;
    padding: 8px 14px;
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    border-radius: 6px;
    font-weight: 500;
    text-decoration: none;
    transition: top 0.15s;
}

.skip-link:focus {
    top: 8px;
}

:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

#main-content:focus {
    outline: none;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print: drop the chrome, widen the content, open collapsed panels. */
@media print {
    .mud-appbar, .mud-drawer, .mud-overlay, .no-print, #components-reconnect-modal,
    .mud-snackbar, .mud-popover, .skip-link, #blazor-error-ui {
        display: none !important;
    }

    .mud-main-content {
        padding-left: 0 !important;
        padding-top: 0 !important;
        margin-left: 0 !important;
    }

    .mud-container {
        max-width: none !important;
        padding: 0 !important;
    }

    .mud-paper {
        box-shadow: none !important;
        border: 1px solid #ccc;
        break-inside: avoid;
    }

    .mud-expand-panel .mud-collapse-container {
        height: auto !important;
        visibility: visible !important;
        overflow: visible !important;
    }

    html, body {
        background: #fff !important;
        color: #000 !important;
    }
}

/* Small screens: keep everything reachable on a phone without horizontal scrolling. */
.mud-table-container, .mud-simple-table {
    overflow-x: auto;
}

@media (max-width: 600px) {
    .appbar-github {
        display: none;
    }

    .appbar-title {
        font-size: 1rem;
    }

    #main-content {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    .reconnect-card {
        padding: 1.25rem 1rem;
    }
}

/* Radio options stacked one per line, for answers that are full sentences. */
/* MudBlazor lays the group out as a row with a more specific rule, hence !important. */
.radio-stack .mud-radio-group, .mud-radio-group.radio-stack {
    flex-direction: column !important;
    align-items: flex-start !important;
}

/* The footer that ties the lab to the CloudWorrior blog. */
.lab-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 2rem;
    padding: 1.25rem 1rem 1.75rem;
    border-top: 1px solid var(--mud-palette-lines-default);
    font-size: 0.85rem;
    color: var(--mud-palette-text-secondary);
}

.lab-footer a {
    color: var(--mud-palette-text-primary);
    text-decoration: underline;
}

/* The SQL playground: editor, result grid and the tables list. */
.sql-editor {
    min-height: 10rem;
}

.result-scroll {
    max-height: 60vh;
    overflow: auto;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 6px;
}

.result-table {
    border-collapse: collapse;
    width: max-content;
    min-width: 100%;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85rem;
}

.result-table th, .result-table td {
    padding: 0.35rem 0.75rem;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    text-align: left;
    white-space: nowrap;
    max-width: 32rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-table thead th {
    position: sticky;
    top: 0;
    background: var(--mud-palette-surface);
    font-weight: 600;
}

.result-table td.null {
    color: var(--mud-palette-text-secondary);
    font-style: italic;
}

.error-context {
    margin: 0.5rem 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
}

.schema-list, .schema-list ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.schema-list > li {
    border-bottom: 1px solid var(--mud-palette-lines-default);
    padding: 0.4rem 0;
}

.schema-list summary {
    cursor: pointer;
}

.schema-list ul {
    padding: 0.35rem 0 0 1rem;
    font-size: 0.85rem;
    line-height: 1.7;
}

/* The data model page: one card per table, its columns in a table. */
.table-doc code, .columns-table code {
    font-size: 0.9em;
}

.columns-table th[scope="row"] {
    font-weight: 400;
    white-space: nowrap;
}

/* Lessons, theory pages and briefs. */
.theory-paper {
    max-width: 900px;
}

.lesson-heading {
    margin: 1.5rem 0 0.5rem;
}

.lesson .math-block {
    margin: 1rem 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.sql-example {
    margin: 1rem 0 1.25rem;
}

.sql-example pre, .solution pre {
    margin: 0;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    background: var(--mud-palette-background);
    border: 1px solid var(--mud-palette-lines-default);
    overflow-x: auto;
    font-size: 0.9rem;
}

.sql-example figcaption {
    margin-top: 0.35rem;
    font-size: 0.9rem;
    color: var(--mud-palette-text-secondary);
}

.lesson-table {
    overflow-x: auto;
    margin: 1rem 0;
}

.lesson-table table {
    border-collapse: collapse;
    min-width: 60%;
}

.lesson-table caption {
    caption-side: bottom;
    text-align: left;
    padding-top: 0.35rem;
    font-size: 0.85rem;
    color: var(--mud-palette-text-secondary);
}

.lesson-table th, .lesson-table td {
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    text-align: left;
}

.brief-question {
    line-height: 1.6;
    max-width: 860px;
}

.hints {
    padding-left: 1.25rem;
    line-height: 1.6;
}

.solution p {
    margin-top: 0.5rem;
    line-height: 1.6;
}

.quiz-question {
    border: 0;
    margin: 0 0 1rem;
    padding: 0;
}

.quiz-question legend {
    padding: 0;
}

.lesson a, .brief-question a {
    text-decoration: underline;
}

/* Glossary and cheat sheet (M6) */
.glossary-filter {
    max-width: 22rem;
}

.glossary {
    margin: 0;
}

.glossary-entry {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    scroll-margin-top: 5rem;
}

.glossary-entry:target {
    background: color-mix(in srgb, var(--mud-palette-primary) 8%, transparent);
}

.glossary dt {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.glossary-term {
    font-weight: 600;
    font-size: 1.05rem;
}

.glossary dd {
    margin: 0.25rem 0 0;
    max-width: 70ch;
}

.glossary-where {
    display: inline-block;
    margin-left: 0.35rem;
}

.cheat-sheet {
    columns: 2 32rem;
    column-gap: 2rem;
}

.cheat-section {
    break-inside: avoid;
    margin-bottom: 1.5rem;
}

.cheat-section ul {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0;
}

.cheat-section li {
    margin-bottom: 0.6rem;
}

.cheat-section pre {
    margin: 0;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    background: var(--mud-palette-background);
    border: 1px solid var(--mud-palette-lines-default);
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.85rem;
}

.cheat-note {
    font-size: 0.875rem;
    color: var(--mud-palette-text-secondary);
}

@media print {
    .cheat-sheet {
        columns: 2;
        font-size: 0.8rem;
    }
}

/* Language menu: a flag beside each language's name. */
.language-option {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
}

.language-option .flag {
    width: 20px;
    height: 14px;
    object-fit: cover;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}

/* The language button: the current language's flag before its code. */
.language-menu .mud-button-label::before {
    content: "";
    display: inline-block;
    width: 20px;
    height: 14px;
    margin-right: 8px;
    background-size: cover;
    background-position: center;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.language-menu.flag-en .mud-button-label::before { background-image: url("images/flags/en.svg"); }
.language-menu.flag-nl .mud-button-label::before { background-image: url("images/flags/nl.svg"); }
.language-menu.flag-pl .mud-button-label::before { background-image: url("images/flags/pl.svg"); }
.language-menu.flag-de .mud-button-label::before { background-image: url("images/flags/de.svg"); }

/* S3: the kinds of join, drawn beside the lesson. */
.aside-sticky {
    position: sticky;
    top: 80px;
}

.join-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 1rem;
}

.join-list li {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 0.9rem;
    align-items: center;
}

.join-list img {
    width: 120px;
    height: auto;
    border-radius: 8px;
}

.join-list p {
    margin: 0.25rem 0 0;
    font-size: 0.875rem;
}

.join-sql {
    font-size: 0.8rem;
    font-weight: 600;
}

@media print {
    .aside-sticky {
        position: static;
    }
}

/* ---- Animations (docs/build-plan.md, section 13): the shared player in js/animation-player.js, renderers in
   js/join-animation.js and js/group-animation.js. Colours come from the theme, and every state also has a word or a
   mark (the readout, the legend, strike-through), so colour is never the only cue. ---- */

.anim-card {
    margin: 1.5rem 0;
    padding: 1rem 1.25rem 1.25rem;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 10px;
    background: var(--mud-palette-surface);
}

.anim-choice {
    margin-bottom: 0.25rem;
}

.anim-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.anim-speed {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
}

.anim-speed > span {
    margin-right: 4px;
    color: var(--mud-palette-text-secondary);
}

.anim-speed-button {
    min-width: 44px !important;
}

/* The speed in use: filled like a primary button (its colours pass AA in both themes), bold and underlined. */
.anim-speed-button[aria-pressed="true"], .anim-speed-button[aria-pressed="true"]:hover, .anim-speed-button[aria-pressed="true"]:focus {
    background: var(--mud-palette-primary) !important;
    color: var(--mud-palette-primary-text) !important;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.anim-readout {
    margin: 0.75rem 0 0;
    min-height: 3em;
    line-height: 1.55;
}

.join-stage, .group-stage {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    align-items: start;
}

.group-stage {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
}

@media (max-width: 599px) {
    .group-stage {
        grid-template-columns: minmax(0, 1fr);
    }
}

.anim-box {
    min-width: 0;
    overflow-x: auto;
}

.anim-result {
    margin-top: 12px;
}

.anim-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
}

.anim-table caption {
    caption-side: top;
    text-align: left;
    padding-bottom: 0.25rem;
    font-weight: 500;
}

.anim-table th, .anim-table td {
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    text-align: left;
    white-space: nowrap;
}

.anim-table th.is-key, .anim-table td.is-key {
    font-weight: 700;
}

/* NULL keeps the primary text colour: it sits on tinted rows, where the secondary colour is too faint. */
.anim-table td.is-null {
    font-style: italic;
}

.anim-table tr {
    transition: background-color 0.25s, opacity 0.25s;
    box-shadow: inset 4px 0 0 transparent;
}

.anim-table tr.is-current {
    background: color-mix(in srgb, var(--mud-palette-warning) 24%, transparent);
    box-shadow: inset 4px 0 0 var(--mud-palette-warning);
}

.anim-table tr.is-match {
    background: color-mix(in srgb, var(--mud-palette-primary) 22%, transparent);
    box-shadow: inset 4px 0 0 var(--mud-palette-primary);
}

.anim-table tr.is-dropped:not(.is-current) td {
    text-decoration: line-through;
    color: var(--mud-palette-text-secondary);
}

.anim-table tr.is-new {
    background: color-mix(in srgb, var(--mud-palette-success) 20%, transparent);
}

.anim-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    list-style: none;
    padding: 0;
    margin: 10px 0 0;
    font-size: 0.85rem;
    color: var(--mud-palette-text-secondary);
}

.anim-legend li {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.anim-legend .swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border-left: 4px solid;
}

.anim-legend .swatch.is-current {
    background: color-mix(in srgb, var(--mud-palette-warning) 24%, transparent);
    border-color: var(--mud-palette-warning);
}

.anim-legend .swatch.is-match {
    background: color-mix(in srgb, var(--mud-palette-primary) 22%, transparent);
    border-color: var(--mud-palette-primary);
}

.anim-legend .swatch.is-dropped {
    background: linear-gradient(transparent 45%, var(--mud-palette-text-secondary) 45%, var(--mud-palette-text-secondary) 55%, transparent 55%);
    border-color: transparent;
}

.anim-final {
    margin-top: 0.75rem;
}

.anim-final summary {
    cursor: pointer;
    color: var(--mud-palette-primary);
    font-weight: 500;
}

.anim-final .is-null {
    font-style: italic;
    color: var(--mud-palette-text-secondary);
}

/* GROUP BY: one card per group; each group keeps its accent, and its rows in the source table take it too. */
.group-area-title {
    font-weight: 500;
    margin: 0 0 0.25rem;
}

.group-buckets {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
}

.group-bucket {
    --accent: var(--mud-palette-primary);
    border: 1px solid var(--mud-palette-lines-default);
    border-top: 4px solid var(--accent);
    border-radius: 8px;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    transition: opacity 0.25s, background-color 0.25s;
}

[data-accent="0"] { --accent: var(--mud-palette-primary); }
[data-accent="1"] { --accent: var(--mud-palette-warning); }
[data-accent="2"] { --accent: var(--mud-palette-info); }
[data-accent="3"] { --accent: var(--mud-palette-success); }

.group-bucket.is-current {
    background: color-mix(in srgb, var(--accent) 16%, transparent);
    outline: 2px solid var(--accent);
}

.group-bucket.is-dropped {
    border-style: dashed;
    color: var(--mud-palette-text-secondary);
}

.group-bucket.is-dropped .group-title, .group-bucket.is-dropped .group-summary {
    text-decoration: line-through;
}

.group-bucket p {
    margin: 0.15rem 0;
}

.group-rows {
    list-style: none;
    padding: 0;
    margin: 0.2rem 0;
}

.group-rows li {
    font-variant-numeric: tabular-nums;
    transition: opacity 0.25s;
}

.group-bucket.is-collapsed .group-rows {
    display: none;
}

.group-verdict {
    font-weight: 500;
}

.group-bucket.is-dropped .group-verdict {
    color: var(--mud-palette-text-primary);
}

.anim-table tr.is-placed {
    box-shadow: inset 4px 0 0 var(--accent);
    color: var(--mud-palette-text-secondary);
}

.anim-table tr.is-placed.is-current {
    color: inherit;
    background: color-mix(in srgb, var(--accent) 22%, transparent);
}

/* Printing and reduced motion show the final state (the player draws it); the result as a table opens for print. */
@media print {
    .anim-final > :not(summary) {
        display: block !important;
    }
}

/* Legal and privacy: the provider's details and each processing item as term and description, stacked so long
   placeholders and translations wrap on a phone. */
.legal-provider, .privacy-item {
    margin: 0 0 1rem;
    line-height: 1.6;
}
.legal-provider dt, .privacy-item dt {
    font-weight: 600;
    margin-top: 0.5rem;
}
.legal-provider dd, .privacy-item dd {
    margin: 0 0 0 1rem;
    overflow-wrap: anywhere;
}
