@view-transition { navigation: auto; }

:root {
    color-scheme: light dark;
    --bg: light-dark(oklch(98% 0.004 260), oklch(17% 0.012 260));
    --surface: light-dark(oklch(100% 0 260), oklch(22% 0.014 260));
    --text: light-dark(oklch(25% 0.015 260), oklch(93% 0.008 260));
    --muted: light-dark(oklch(52% 0.015 260), oklch(68% 0.015 260));
    --border: light-dark(oklch(91% 0.006 260), oklch(30% 0.014 260));
    --accent: light-dark(oklch(52% 0.18 260), oklch(76% 0.12 260));
    --radius: 0.6rem;
    --mono: ui-monospace, SFMono-Regular, Menlo, monospace;

    /* Page layout, shared by every route so their edges line up: one
       column (side padding included), the space above it, and the gap
       between the blocks stacked inside it. */
    --page-width: 52rem;
    --gutter: 1.5rem;
    --page-top: 2.5rem;
    --stack: 1.5rem;
    /* Pages that open with breadcrumbs treat them as a top bar: less space
       above, and the title tucked under them. */
    --nav-top: 1rem;
    --nav-gap: 1.5rem;
}
* {
    box-sizing: border-box;
}
/* Pages fill the window: the root and body are at least its height, and
   main grows into whatever body has left. (A percentage min-height only
   resolves against a definite height, hence html's height and body's flex
   column.) */
html {
    height: 100%;
    min-height: 100%;
}
body {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}
main {
    flex: 1 0 auto;
    width: 100%;
    min-height: 100%;
    max-width: var(--page-width);
    margin-inline: auto;
    padding: var(--page-top) var(--gutter);
    display: flex;
    flex-direction: column;
    gap: var(--stack);
}
.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
picture {
    display: contents;
}
picture > source {
    display: none;
}
.logo {
    inline-size: 3.5rem;
    block-size: 3.5rem;
}
h1 {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 650;
    letter-spacing: -0.01em;
}
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
}
.summary {
    margin: 0;
    color: var(--muted);
}
.toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--muted);
    font-size: 0.875rem;
    cursor: pointer;
    user-select: none;
}
.toggle input {
    margin: 0;
    accent-color: var(--accent);
}
/* The index's live region, which /events refreshes (see live-updates.ts); its children
   lay out as if they were main's own. */
.listing {
    display: contents;
}
body:has(#hide-obsolete:checked) .row.obsolete {
    display: none;
}
ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* One grid for the whole list; rows and nested file rows use subgrid so
 icons, names and buttons line up in shared columns. The 1px gap over a
 border-coloured background draws the dividers, so hidden rows never
 leave a stray line behind. */
.types {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.row,
.files {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: subgrid;
    align-items: center;
}
.row {
    --row-pad: 0.6rem;
    column-gap: 0.75rem;
    row-gap: 0.25rem;
    padding: var(--row-pad);
    background: var(--surface);
}
.row:has(> .name:hover) {
    background: color-mix(in oklch, var(--accent) 6%, var(--surface));
}
.files {
    margin-top: 0.2rem;
}
/* File rows sit inside their parent row's padding. Pull each one out over
   that padding and pad it back in, so its background (e.g. on hover) runs
   to the list's edges while its icon, name and buttons stay on the shared
   columns: a subgrid's margin and padding cancel out for its tracks. */
.row.file {
    margin-inline: calc(-1 * var(--row-pad));
    padding: 0.3rem var(--row-pad);
    background: transparent;
}
.icon {
    --h: 260;
    display: grid;
    place-items: center;
    inline-size: 2rem;
    block-size: 2rem;
    border-radius: 0.5rem;
    color: light-dark(oklch(50% 0.15 var(--h)), oklch(80% 0.11 var(--h)));
    background: light-dark(oklch(95% 0.03 var(--h)), oklch(30% 0.05 var(--h)));
}
/* Smaller file icons share the icon column; pin them to its right edge. */
.row.file > .icon {
    justify-self: end;
    inline-size: 1.6rem;
    block-size: 1.6rem;
    border-radius: 0.4rem;
}
.icon[data-kind="text"]     {
    --h: 260;
}
.icon[data-kind="document"] {
    --h: 25;
}
.icon[data-kind="code"]     {
    --h: 300;
}
.icon[data-kind="image"]    {
    --h: 150;
}
.icon[data-kind="audio"]    {
    --h: 350;
}
.icon[data-kind="link"]     {
    --h: 220;
}
.icon[data-kind="file"]     {
    --h: 80;
}
.icon[data-kind="data"]     {
    --h: 260;
    color: var(--muted);
    background: color-mix(in oklch, var(--muted) 14%, transparent);
}
.icon svg,
.glyph {
    inline-size: 1.1rem;
    block-size: 1.1rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.row.file > .icon svg {
    inline-size: 0.95rem;
    block-size: 0.95rem;
}
a {
    color: var(--accent);
    text-decoration: none;
}
a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 0.25rem;
}
.name {
    font-family: var(--mono);
    font-size: 0.875rem;
    overflow-wrap: anywhere;
}
.row-actions {
    display: flex;
    align-items: center;
    justify-content: end;
    gap: 0.35rem;
}
.button {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 0.45rem;
    color: var(--text);
    background: var(--surface);
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background-color 120ms, border-color 120ms, color 120ms;
}
.button .glyph {
    inline-size: 0.95rem;
    block-size: 0.95rem;
    color: var(--muted);
}
.button:hover {
    color: var(--accent);
    border-color: color-mix(in oklch, var(--accent) 45%, var(--border));
    background: color-mix(in oklch, var(--accent) 8%, var(--surface));
}
.button:hover .glyph {
    color: var(--accent);
}
.tag {
    justify-self: end;
    padding: 0.05rem 0.45rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 0.7rem;
}
@media (max-width: 30rem) {
    .button span {
        display: none;
    }
    .button {
        padding: 0.4rem;
    }
}

/* Preview pages (/preview/…) */
main.preview-page {
    max-width: none;
    padding-inline: 0;
    /* The preview band runs to the bottom of the window. */
    padding-bottom: 0;
    /* Exactly the window's height, never the content's: the band below
       takes what's left and scrolls its own contents. */
    flex: 1 1 0;
}
main.preview-page,
main.error-page {
    padding-top: var(--nav-top);
}
/* The head and the preview's contents use the same column as every other
   page, padding included, so titles, buttons and content line up with the
   index. Content inside .preview-body adds no side padding of its own. */
.preview-head,
.preview-body {
    max-width: var(--page-width);
    margin-inline: auto;
    padding-inline: var(--gutter);
    width: 100%;
}
.preview-head {
    display: flex;
    flex-direction: column;
    gap: var(--nav-gap);
}
.crumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.15rem 0.45rem;
    font-size: 0.875rem;
    color: var(--muted);
}
.crumbs a {
    font-weight: 500;
    font-family: var(--mono);
}
.crumbs .home {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.crumbs picture {
    display: contents;
}
.crumb-logo {
    inline-size: 1.25rem;
    block-size: 1.25rem;
}
.crumbs .sep {
    opacity: 0.6;
}
.crumbs .current {
    font-family: var(--mono);
    overflow-wrap: anywhere;
}
.preview-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.75rem;
}
.preview-header .icon {
    inline-size: 2.5rem;
    block-size: 2.5rem;
    border-radius: 0.6rem;
}
.preview-header .icon svg {
    inline-size: 1.35rem;
    block-size: 1.35rem;
}
.preview-header h1 {
    font-family: var(--mono);
    font-size: 1.15rem;
    font-weight: 600;
    view-transition-name: brand-name;
    overflow-wrap: anywhere;
}
.file-info {
    display: flex;
    flex-direction: column;
    line-height: 110%;
}
.meta {
    margin: 0.1rem 0 0;
    color: var(--muted);
    font-size: 0.85rem;
}
.actions {
    display: flex;
    gap: 0.4rem;
}
/* A full-width band that takes all the height the page has left; its
   contents (.preview-body) keep the page's column and fill it too. */
.preview {
    flex: 1;
    overflow: auto;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.preview-body {
    flex: 1;
    /* Flex items won't shrink below their content by default; this lets a
       big image fit the band instead of propping it open. */
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.preview[data-kind="image"] {
    background: repeating-conic-gradient(color-mix(in oklch, var(--border) 60%, transparent) 0 25%, transparent 0 50%) 0 0 / 1rem 1rem, var(--surface);
}
/* One cell the size of the band (minmax(0, 1fr) keeps a big image from
   growing it), with the image centred inside. */
.preview[data-kind="image"] .preview-body {
    display: grid;
    grid-template: minmax(0, 1fr) / minmax(0, 1fr);
    place-items: center;
    padding-block: 1.5rem;
}
/* Images shrink to fit but are never stretched past their natural size. */
.preview img {
    display: block;
    max-inline-size: 100%;
    max-block-size: 100%;
    object-fit: contain;
}
/* Framed previews (PDF, HTML, rich text) use the window's full width rather than the
   page column: documents need the room. */
.preview[data-kind="pdf"] .preview-body,
.preview[data-kind="html"] .preview-body,
.preview[data-kind="rtf"] .preview-body {
    max-width: none;
    padding-inline: 0;
}
/* Frames (PDF, HTML, rich text) and video fill the band. */
.preview iframe {
    flex: 1;
    min-block-size: 16rem;
    inline-size: 100%;
    border: 0;
    background: white;
}
.preview video {
    flex: 1;
    min-block-size: 0;
    inline-size: 100%;
    object-fit: contain;
    background: black;
}
.preview .player {
    padding-block: 1rem;
}
.preview audio {
    display: block;
    inline-size: 100%;
}
.preview pre.text {
    margin: 0;
    padding-block: 1rem;
    font: 0.85rem/1.55 var(--mono);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    tab-size: 4;
}
.notice {
    margin: 0;
    padding-block: 0.6rem;
    color: var(--muted);
    font-size: 0.8rem;
}
.notice + pre,
pre + .notice {
    border-top: 1px solid var(--border);
}
/* The hex dump's offset column starts at the column's edge like any text. */
.preview hex-dump {
    --hex-inset: 0;
}
@media (max-width: 30rem) {
    .preview-header {
        grid-template-columns: auto minmax(0, 1fr);
    }
    .actions {
        grid-column: 1 / -1;
    }
}

/* Error pages (any 4xx/5xx a browser asks for; see ErrorPage.swift). Same
   column, breadcrumbs and spacing as the other pages. */
.error-page > .crumbs + * {
    margin-top: calc(var(--nav-gap) - var(--stack));
}
.error-header {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.error-page .status {
    margin: 0;
    color: var(--accent);
    font: 600 3.5rem/1 var(--mono);
    letter-spacing: -0.03em;
}
.error-page h1 {
    font-size: 1.4rem;
}
.error-page .message {
    margin: 0;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 0.85rem;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}
/* The page's only action: its own width, and its label even on phones. */
.error-page > .button {
    align-self: flex-start;
    padding: 0.3rem 0.65rem;
}
.error-page .button span {
    display: inline;
}

/* A URL type's preview lists its files exactly like the index: no band. */
.preview[data-kind="listing"] {
    border: 0;
    background: none;
}

/* Cross-page view transitions. Items carry inline view-transition-names
   (see IndexPage.transitionName): a row's icon and name move into the
   preview's header, and a title shrinks into its breadcrumb. The logo
   morphs between the index header and the breadcrumbs. Everything else
   cross-fades. */
@view-transition {
    navigation: auto;
}
.logo,
.crumb-logo {
    view-transition-name: app-logo;
}
::view-transition-group(*) {
    animation-duration: 220ms;
    animation-timing-function: cubic-bezier(0.2, 0, 0, 1);
}
/* Titles are text, scaled as an image mid-flight; pinning both snapshots
   at their own size and fading across keeps them from looking stretched
   while they change size. Icons and the logo scale normally. */
::view-transition-old(*.title),
::view-transition-new(*.title) {
    height: 100%;
    object-fit: none;
    object-position: left center;
}
@media (prefers-reduced-motion: reduce) {
    @view-transition {
        navigation: none;
    }
}

/* A file's own Finder icon inside its coloured badge (see badgeMarkup). */
.icon img {
    display: block;
    inline-size: 1.35rem;
    block-size: 1.35rem;
    object-fit: contain;
}
.row.file > .icon img {
    inline-size: 1.15rem;
    block-size: 1.15rem;
}
.preview-header .icon img {
    inline-size: 1.75rem;
    block-size: 1.75rem;
}
