@layer components {
    /* --- File tree --- */
    .file-tree {
        width: 100%;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        border-collapse: separate;
        border-spacing: 0;
        overflow: hidden;
        margin-bottom: var(--space-6);
        table-layout: auto;
    }
    .file-tree-row + .file-tree-row td {
        border-top: 1px solid var(--color-border-muted);
    }
    .file-tree-row:hover {
        background: var(--color-bg-subtle);
    }
    .file-icon,
    .file-name,
    .file-size {
        padding: var(--space-2) var(--space-3);
        font-size: var(--text-sm);
        vertical-align: middle;
    }
    .file-icon {
        width: 2.25rem;
        padding-right: var(--space-1);
        text-align: center;
        line-height: 0;
    }
    .file-name {
        width: 100%;
        overflow-wrap: anywhere;
    }
    .file-name a {
        color: var(--color-link);
        text-decoration: none;
    }
    .file-name a:hover {
        text-decoration: underline;
    }
    .file-name a.file-name-dir {
        font-weight: 500;
    }
    .file-size {
        text-align: right;
        color: var(--color-text-muted);
        font-size: var(--text-xs);
        white-space: nowrap;
        padding-right: var(--space-4);
    }
    .file-icon-dir {
        color: var(--color-link);
    }
    .file-icon-file {
        color: var(--color-text-muted);
    }
    .tree-icon {
        display: inline-block;
        vertical-align: text-bottom;
    }
    .file-tree-row-up .file-name a {
        color: var(--color-text-muted);
    }
    .file-tree-row-up .file-name a:hover {
        color: var(--color-link);
    }

    /* --- File blob --- */
    .file-blob-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: var(--space-2) var(--space-3);
        padding: var(--space-2) var(--space-4);
        background: var(--color-bg-subtle);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }
    .file-blob-name {
        font-size: var(--text-sm);
        font-weight: 500;
        flex: 1 1 8rem;
        min-width: 0;
        overflow-wrap: anywhere;
    }
    .file-blob-actions {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: var(--space-2);
        margin-left: auto;
    }
    /* Anchor the delete popup to the whole header, so it never runs off the
       left edge when the button sits far from the right edge. */
    .file-blob-header {
        position: relative;
    }
    .file-blob-header .confirm-details {
        position: static;
    }
    .file-blob-header .confirm-popup {
        max-width: 100%;
    }
    .file-blob-body {
        border: 1px solid var(--color-border);
        border-top: none;
        border-radius: 0 0 var(--radius-lg) var(--radius-lg);
        overflow: auto;
        min-width: 0;
    }
    .file-edit-textarea {
        display: block;
        width: 100%;
        font-family: var(--font-mono);
        font-size: var(--text-sm);
        line-height: 1.6;
        padding: var(--space-4);
        background: var(--color-bg);
        color: var(--color-text);
        border: none;
        resize: vertical;
        min-height: 20rem;
        tab-size: 4;
    }
    .file-edit-textarea:focus {
        outline: 2px solid var(--color-accent);
        outline-offset: -2px;
    }

    /* Blob line-number table */
    .blob-table {
        min-width: 100%;
        border-collapse: collapse;
        font-family: var(--font-mono);
        font-size: var(--text-sm);
        line-height: 1.6;
        background-color: var(--code-bg);
        color: var(--code-fg);
    }
    .blob-ln {
        width: 1%;
        min-width: 3rem;
        text-align: right;
        padding: 0 var(--space-3);
        color: var(--color-text-muted);
        border-right: 1px solid var(--color-border-muted);
        user-select: none;
        white-space: nowrap;
        vertical-align: top;
    }
    .blob-ln a {
        color: inherit;
        text-decoration: none;
    }
    .blob-ln a:hover {
        color: var(--color-link);
    }
    .blob-code {
        padding: 0 var(--space-4);
        white-space: pre;
        vertical-align: top;
        tab-size: 4;
    }
    .blob-table tr:target {
        background: color-mix(in srgb, var(--color-link) 12%, transparent);
    }
    .blob-table tr:target .blob-ln {
        background: color-mix(in srgb, var(--color-link) 20%, transparent);
    }
    .file-download-notice {
        padding: clamp(var(--space-6), 6vw, var(--space-8)) var(--space-4);
        text-align: center;
        color: var(--color-text-muted);
    }
    .file-download-notice p {
        margin-bottom: var(--space-4);
    }
    .file-media {
        padding: var(--space-4);
        display: flex;
        justify-content: center;
        background: var(--color-bg-subtle);
    }
    .file-media-img {
        max-width: 100%;
        height: auto;
        display: block;
    }
    .file-media-audio {
        width: 100%;
        max-width: 600px;
    }
    .file-media-video {
        max-width: 100%;
        max-height: 80vh;
    }

    /* --- Commit list --- */
    .commit-list {
        display: flex;
        flex-direction: column;
    }
    .commit-item {
        display: flex;
        flex-direction: column;
        padding: var(--space-3) 0;
        border-bottom: 1px solid var(--color-border-muted);
        gap: var(--space-1);
    }
    .commit-item:last-child {
        border-bottom: none;
    }
    .commit-subject {
        color: var(--color-text);
        text-decoration: none;
        font-size: var(--text-sm);
        font-weight: 500;
        overflow-wrap: anywhere;
    }
    .commit-subject:hover {
        color: var(--color-link);
    }
    .commit-meta {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: var(--space-1) var(--space-3);
        font-size: var(--text-xs);
        color: var(--color-text-muted);
    }
    .commit-meta-right {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: var(--space-2);
        margin-left: auto;
    }
    .commit-date {
        white-space: nowrap;
    }

    /* --- Commit detail --- */
    .commit-page-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: var(--space-2);
        margin-bottom: var(--space-4);
    }
    .commit-card {
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        margin-bottom: var(--space-4);
        overflow: hidden;
        min-width: 0;
    }
    .commit-card-subject {
        font-size: var(--text-xl);
        font-weight: 600;
        padding: var(--space-4) clamp(var(--space-4), 3vw, var(--space-6));
        border-bottom: 1px solid var(--color-border);
        line-height: 1.3;
        overflow-wrap: anywhere;
    }
    .commit-card-subject-empty {
        color: var(--color-text-muted);
        font-style: italic;
        font-weight: 400;
        font-size: var(--text-sm);
    }
    .commit-card-body {
        padding: var(--space-4) clamp(var(--space-4), 3vw, var(--space-6));
        font-family: inherit;
        font-size: var(--text-sm);
        color: var(--color-text-muted);
        border-bottom: 1px solid var(--color-border);
        white-space: pre-wrap;
        overflow-wrap: anywhere;
    }
    .commit-card-meta {
        padding: var(--space-3) clamp(var(--space-4), 3vw, var(--space-6));
        display: flex;
        flex-direction: column;
        gap: var(--space-1);
        background: var(--color-bg-subtle);
    }
    .commit-card-meta-row {
        display: flex;
        align-items: baseline;
        gap: var(--space-1) var(--space-3);
        font-size: var(--text-sm);
        flex-wrap: wrap;
    }
    .commit-meta-label {
        font-weight: 600;
        color: var(--color-text-muted);
        min-width: 6rem;
        font-size: var(--text-xs);
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }
    .commit-meta-value {
        min-width: 0;
        overflow-wrap: anywhere;
    }
    .commit-sha-full {
        font-size: var(--text-xs);
        background: var(--color-bg-inset);
        padding: 2px var(--space-2);
        border-radius: var(--radius-sm);
    }
    .commit-stats-bar {
        font-size: var(--text-sm);
        color: var(--color-text-muted);
        margin-bottom: var(--space-3);
    }

    /* --- Commit layout (file nav + diffs) ---
       Flex wrap with two bases: the nav wants 14rem, the diffs want at least
       34rem and take all spare space. When both do not fit on one row, the
       diffs wrap below the nav and both stretch to full width. */
    .commit-layout {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-4);
        align-items: flex-start;
        container-type: inline-size;
    }
    .commit-file-nav {
        flex: 1 1 14rem;
        min-width: 0;
        max-width: 100%;
    }
    .commit-layout:has(.file-nav-details:not([open])) .commit-file-nav {
        flex: 0 1 auto;
    }
    .commit-diffs {
        flex: 999 1 min(100%, 34rem);
        min-width: 0;
    }
    /* The one width query: the file nav only sticks when it sits beside the
       diffs. Stacked on top it would cover the diff while scrolling. */
    @container (min-width: 50rem) {
        .commit-file-nav {
            position: sticky;
            top: calc(3.5rem + var(--space-3));
            max-height: calc(100vh - 3.5rem - var(--space-6));
            overflow-y: auto;
        }
    }

    /* --- File nav sidebar --- */
    .file-nav-details {
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        background: var(--color-bg-subtle);
        overflow: hidden;
    }
    .file-nav-toggle {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        padding: var(--space-2) var(--space-3);
        font-size: var(--text-sm);
        font-weight: 500;
        cursor: pointer;
        list-style: none;
        user-select: none;
        border-bottom: 1px solid var(--color-border);
    }
    .file-nav-toggle::-webkit-details-marker {
        display: none;
    }
    .file-nav-details:not([open]) .file-nav-toggle {
        border-bottom: none;
    }
    .file-nav-toggle-icon {
        font-size: 0.8em;
        color: var(--color-text-muted);
        transition: transform 0.15s;
    }
    .file-nav-details:not([open]) > .file-nav-toggle .file-nav-toggle-icon {
        transform: rotate(-90deg);
    }
    .file-nav-list {
        padding: var(--space-1) 0;
        list-style: none;
    }
    .file-nav-item {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        padding: var(--space-1) var(--space-3);
        font-size: var(--text-xs);
        text-decoration: none;
        color: var(--color-text);
        overflow: hidden;
    }
    .file-nav-item:hover {
        background: var(--color-bg-inset);
    }
    .file-nav-status,
    .diff-status-badge {
        flex-shrink: 0;
        width: 1.125rem;
        height: 1.125rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: var(--radius-sm);
        font-size: 10px;
        font-weight: 700;
        font-family: var(--font-mono);
    }
    .file-nav-status {
        width: 1rem;
        height: 1rem;
        font-size: 9px;
    }
    .file-status-added,
    .diff-status-added {
        background: var(--color-success-bg);
        color: var(--color-success);
    }
    .file-status-deleted,
    .diff-status-deleted {
        background: var(--color-danger-bg);
        color: var(--color-danger);
    }
    .file-status-modified,
    .diff-status-modified {
        background: var(--color-accent-bg);
        color: var(--color-accent);
    }
    .file-status-renamed,
    .file-status-copied,
    .diff-status-renamed,
    .diff-status-copied {
        background: var(--color-merged-bg);
        color: var(--color-merged);
    }
    .file-nav-name {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-family: var(--font-mono);
    }
    .file-nav-stat {
        flex-shrink: 0;
        display: flex;
        gap: var(--space-1);
        font-size: var(--text-xs);
        font-family: var(--font-mono);
    }
    .nav-add {
        color: var(--color-success);
    }
    .nav-del {
        color: var(--color-danger);
    }
    .nav-binary {
        color: var(--color-text-muted);
        font-size: var(--text-xs);
    }
    .file-nav-dir > details > .file-nav-list {
        padding-left: var(--space-4);
    }
    .file-nav-dir-toggle {
        display: flex;
        align-items: center;
        gap: var(--space-1);
        padding: var(--space-1) var(--space-3);
        font-size: var(--text-xs);
        font-family: var(--font-mono);
        color: var(--color-text-muted);
        cursor: pointer;
        list-style: none;
        user-select: none;
    }
    .file-nav-dir-toggle::-webkit-details-marker {
        display: none;
    }
    .file-nav-dir > details:not([open]) > .file-nav-dir-toggle .file-nav-toggle-icon {
        transform: rotate(-90deg);
    }

    /* --- Diff file cards --- */
    .diff-file {
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        margin-bottom: var(--space-4);
        overflow: hidden;
        min-width: 0;
    }
    .diff-file-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-2) var(--space-3);
        padding: var(--space-2) var(--space-3);
        background: var(--color-bg-subtle);
        cursor: pointer;
        list-style: none;
        user-select: none;
        flex-wrap: wrap;
    }
    .diff-file-header::-webkit-details-marker {
        display: none;
    }
    .diff-file-header-left {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        min-width: 0;
        flex: 1 1 12rem;
    }
    .diff-file-header-right {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        flex-shrink: 0;
        flex-wrap: wrap;
        margin-left: auto;
    }
    .diff-file-toggle-icon {
        font-size: 0.7em;
        color: var(--color-text-muted);
        flex-shrink: 0;
        transition: transform 0.15s;
    }
    .diff-file:not([open]) .diff-file-toggle-icon {
        transform: rotate(-90deg);
    }
    .diff-file-path {
        font-size: var(--text-sm);
        font-weight: 500;
        min-width: 0;
        overflow-wrap: anywhere;
    }
    .diff-rename-arrow {
        font-size: var(--text-xs);
        color: var(--color-text-muted);
        min-width: 0;
        overflow-wrap: anywhere;
    }
    .diff-stat-add,
    .diff-stat-del,
    .diff-stat-binary {
        font-size: var(--text-sm);
        font-family: var(--font-mono);
        font-weight: 600;
        white-space: nowrap;
    }
    .diff-stat-add {
        color: var(--color-success);
    }
    .diff-stat-del {
        color: var(--color-danger);
    }
    .diff-stat-binary {
        color: var(--color-text-muted);
        font-weight: 400;
    }
    .diff-file-header .btn-xs {
        font-family: var(--font-mono);
    }

    /* --- Diff file body --- */
    .diff-binary-notice {
        padding: var(--space-4);
        font-size: var(--text-sm);
        color: var(--color-text-muted);
        font-style: italic;
    }
    .diff-hunk {
        border-top: 1px solid var(--color-border-muted);
        overflow-x: auto;
    }
    .diff-file-body {
        border-top: 1px solid var(--color-border);
    }
    .diff-hunk:first-child {
        border-top: none;
    }
    .diff-hunk-header {
        padding: var(--space-1) var(--space-3);
        font-family: var(--font-mono);
        font-size: var(--text-xs);
        font-weight: normal;
        text-align: left;
        background: color-mix(in srgb, var(--color-merged-bg) 50%, var(--color-bg));
        color: var(--color-merged);
        border-bottom: 1px solid var(--color-border-muted);
        white-space: pre;
    }

    /* --- Diff table --- */
    .diff-table {
        min-width: 100%;
        border-collapse: collapse;
        font-family: var(--font-mono);
        font-size: var(--text-xs);
        line-height: 1.5;
        tab-size: 4;
    }
    .diff-ln {
        width: 2.75rem;
        min-width: 2.75rem;
        text-align: right;
        padding: 0 var(--space-2);
        color: var(--color-text-muted);
        border-right: 1px solid var(--color-border-muted);
        user-select: none;
        vertical-align: top;
        white-space: nowrap;
    }
    .diff-sign {
        width: 1.125rem;
        min-width: 1.125rem;
        text-align: center;
        padding: 0 var(--space-1);
        user-select: none;
        vertical-align: top;
    }
    .diff-code {
        padding: 0 var(--space-3);
        white-space: pre;
        vertical-align: top;
    }
    .diff-row-add {
        background: color-mix(in srgb, var(--color-success-bg) 70%, transparent);
    }
    .diff-row-del {
        background: color-mix(in srgb, var(--color-danger-bg) 70%, transparent);
    }
    .diff-row-add .diff-ln,
    .diff-row-add .diff-sign {
        background: color-mix(in srgb, var(--color-success-bg) 90%, transparent);
    }
    .diff-row-del .diff-ln,
    .diff-row-del .diff-sign {
        background: color-mix(in srgb, var(--color-danger-bg) 90%, transparent);
    }
    .diff-row-add .diff-sign {
        color: var(--color-success);
        font-weight: 700;
    }
    .diff-row-del .diff-sign {
        color: var(--color-danger);
        font-weight: 700;
    }
    .diff-ctrl {
        color: #f0f0f0;
        background: #c0392b;
        border-radius: 2px;
        font-weight: bold;
        padding: 0 1px;
    }
    /* Token colors and --code-bg/--code-fg come from /assets/code-theme.css,
       generated from the chroma themes at runtime. */
}
