:root {
 color-scheme: light;
 --bg: #f6f7f6;
 --surface: #fff;
 --raised: #fff;
 --ink: #17201b;
 --muted: #5b6a61;
 --line: #dde4df;
 --tile: #e8ece9;
 --accent: #235c48;
 --accent-ink: #fff;
 --accent-soft: #dcebe3;
 --danger: #b3261e;
 --danger-ink: #fff;
 --warn: #8a4b00;
 --bar: #17201b;
 --bar-ink: #f1f5f2;
 --shadow: 0 1px 2px rgb(0 0 0 / .08), 0 8px 24px rgb(0 0 0 / .12);
 --radius: 10px;
 --gap: 6px;
}
@media (prefers-color-scheme: dark) {
 :root {
  color-scheme: dark;
  --bg: #111613;
  --surface: #1a211d;
  --raised: #222b26;
  --ink: #e8eee9;
  --muted: #a1b0a6;
  --line: #2c3731;
  --tile: #1e2622;
  --accent: #8fd0b0;
  --accent-ink: #0d281d;
  --accent-soft: #23392e;
  --danger: #ffb4ab;
  --danger-ink: #5f1410;
  --warn: #f2b45e;
  --bar: #e8eee9;
  --bar-ink: #111613;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 28px rgb(0 0 0 / .5);
 }
}

* { box-sizing: border-box; }
body {
 margin: 0;
 background: var(--bg);
 color: var(--ink);
 font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
 -webkit-font-smoothing: antialiased;
 padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
h1, h2, p { margin: 0; }
button, a, input, label { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

button, .button {
 display: inline-flex;
 align-items: center;
 justify-content: center;
 gap: 8px;
 min-height: 40px;
 padding: 8px 16px;
 border: 1px solid transparent;
 border-radius: 999px;
 font: inherit;
 font-weight: 600;
 color: var(--accent-ink);
 background: var(--accent);
 cursor: pointer;
 text-decoration: none;
}
button:hover:not(:disabled) { filter: brightness(.94); }
button:disabled { opacity: .45; cursor: default; }
button.secondary { background: transparent; border-color: var(--line); color: var(--ink); }
button.quiet { background: transparent; color: var(--accent); padding-inline: 12px; }
button.danger { background: var(--danger); color: var(--danger-ink); }
.icon-button {
 display: inline-flex;
 align-items: center;
 justify-content: center;
 width: 40px;
 min-height: 40px;
 padding: 0;
 border: 0;
 border-radius: 999px;
 background: transparent;
 color: inherit;
 cursor: pointer;
}

/* File intake uses the same surface, buttons and spacing as the gallery. */
.intake { margin: 12px 32px 20px; padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.intake-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
#intake-help, #paste-help { color: var(--muted); font-size: 14px; }
#paste-help { margin-top: 8px; }
.intake [hidden], #drop-hint[hidden] { display: none; }
.login { max-width: 400px; margin: 12vh auto; padding: 24px; }
.login h1 { margin: 12px 0 8px; }
.login form { display: grid; gap: 12px; margin-top: 24px; }
.login input { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); padding: 12px; font: inherit; }
#login-error { color: var(--danger); }
.upload-attempt { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.upload-attempt h2 { font-size: 14px; margin-bottom: 8px; }
.upload-attempt ul { list-style: none; padding: 0; margin: 0; }
.upload-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; margin-top: 8px; }
.upload-row p { overflow-wrap: anywhere; }
.upload-row .upload-state { color: var(--muted); font-size: 13px; }
.upload-row.failed .upload-state { color: var(--danger); }
.upload-row progress { grid-column: 1 / -1; width: 100%; height: 6px; accent-color: var(--accent); }
.upload-row button { grid-column: 2; grid-row: 1 / 3; align-self: center; }
#drop-hint { position: fixed; inset: 12px; z-index: 10; display: grid; place-items: center; border: 3px dashed var(--accent); border-radius: 20px; background: color-mix(in srgb, var(--surface) 92%, transparent); font-size: 24px; font-weight: 600; pointer-events: none; }
@media (max-width: 640px) { .intake { margin-inline: 16px; padding: 12px; } }
.icon-button:hover:not(:disabled) { background: rgb(127 127 127 / .16); filter: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header */
.top {
 display: flex;
 align-items: center;
 gap: 16px;
 max-width: 1528px;
 margin: 0 auto;
 padding: 22px max(48px, env(safe-area-inset-right)) 8px max(48px, env(safe-area-inset-left));
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 7px; }
h1 { font-size: 19px; font-weight: 650; letter-spacing: -.01em; }
.summary { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; margin-right: auto; }
.all-control { display: flex; align-items: center; gap: 8px; min-height: 40px; color: var(--muted); font-size: 14px; cursor: pointer; }
.all-control:hover { color: var(--ink); }
.all-control input { appearance: auto; width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

.banner {
 display: flex;
 align-items: center;
 gap: 12px;
 max-width: 1432px;
 margin: 8px auto 0;
 padding: 6px 6px 6px 16px;
 border-radius: var(--radius);
 background: color-mix(in srgb, var(--danger) 12%, var(--bg));
 color: var(--ink);
}
.banner[hidden] { display: none; }
.banner p { margin-right: auto; font-size: 14px; }
@media (max-width: 1528px) { .banner { margin-inline: 48px; } }

/* Groups */
main { max-width: 1528px; margin: 0 auto; padding: 0 max(48px, env(safe-area-inset-right)) 0 max(48px, env(safe-area-inset-left)); }
.upload-group { margin-top: 22px; }
.group-heading { position: relative; display: flex; align-items: center; gap: 4px; min-height: 48px; padding: 4px 0 8px; }
.group-select { position: absolute; left: -38px; display: flex; align-items: center; justify-content: center; width: 36px; height: 40px; cursor: pointer; }
.group-title { min-width: 0; }
.group-title h2 { font-size: 16px; font-weight: 650; }
.group-title p { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.group-title .soon { color: var(--warn); font-weight: 600; }
.group-download { margin-left: 16px; min-height: 36px; padding: 6px 12px; font-size: 14px; }

/* Desktop rows keep each image's shape. Width follows the measured aspect ratio. */
.file-grid {
 --row: clamp(160px, 19vw, 320px);
 display: flex;
 flex-wrap: wrap;
 gap: var(--gap);
 list-style: none;
 margin: 0;
 padding: 0;
}

/* Tiles */
.file {
 --ratio: 1;
 position: relative;
 flex: none;
 width: calc(var(--ratio) * var(--row));
 height: var(--row);
 min-width: 0;
 overflow: hidden;
 border-radius: var(--radius);
 background: var(--tile);
 cursor: zoom-in;
 user-select: none;
 -webkit-user-select: none;
}
.preview { position: absolute; inset: 0; border-radius: inherit; overflow: hidden; background: var(--tile); }
.preview img { display: block; width: 100%; height: 100%; object-fit: cover; }
.selecting .file { cursor: pointer; }
.file:not(.is-image) { --ratio: .66; }
.file:focus-visible { outline-offset: 3px; }
.file.selected { background: var(--accent-soft); }
.file.selected .preview { inset: 10px; border-radius: 6px; }
.file.selected::after { content: ""; position: absolute; inset: 0; border: 2px solid var(--accent); border-radius: inherit; pointer-events: none; }

.file-placeholder {
 position: absolute;
 inset: 0;
 display: flex;
 flex-direction: column;
 align-items: center;
 justify-content: center;
 gap: 8px;
 padding-bottom: 52px;
 color: var(--muted);
}
.file-placeholder svg { width: 40px; height: 40px; stroke-width: 1.3; }
.file-placeholder span { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.preview-failed { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px 16px 56px; color: var(--muted); font-size: 13px; text-align: center; }

.file-copy { position: absolute; inset: auto 0 0; padding: 10px 12px; min-width: 0; }
.file-name { font-size: 13px; font-weight: 600; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.file:not(.is-image) .file-name { white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow-wrap: anywhere; }
.file.is-image .file-copy {
 color: #fff;
 background: linear-gradient(transparent, rgb(0 0 0 / .62));
 padding-top: 28px;
 opacity: 0;
 transition: opacity .15s;
 pointer-events: none;
}
.file.is-image .file-size { color: rgb(255 255 255 / .82); }
.file.is-image:hover .file-copy, .file.is-image:focus-within .file-copy { opacity: 1; }
.file.selected .file-copy { opacity: 0 !important; }

/* Tile controls appear on hover, while selecting, and always on touch screens. */
.select-control, .file-download { position: absolute; z-index: 1; top: 4px; display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; cursor: pointer; opacity: 0; transition: opacity .15s; }
.select-control { left: 4px; }
.file-download { right: 4px; color: #fff; }
.file-download span { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 999px; background: rgb(0 0 0 / .45); }
.file-download svg { width: 18px; height: 18px; }
.file-download:hover span { background: rgb(0 0 0 / .7); }
.file:not(.is-image) .file-download { color: var(--ink); }
.file:not(.is-image) .file-download span { background: rgb(127 127 127 / .16); }
.file:hover .select-control, .file:hover .file-download, .file:focus-within .select-control, .file:focus-within .file-download, .selecting .select-control, .file.selected .select-control { opacity: 1; }

input[type=checkbox].check, .group-select input {
 appearance: none;
 position: relative;
 width: 22px;
 height: 22px;
 margin: 0;
 border: 2px solid #fff;
 border-radius: 999px;
 background: rgb(0 0 0 / .22);
 box-shadow: 0 0 0 1px rgb(0 0 0 / .12);
 cursor: pointer;
}
.group-select input, .file:not(.is-image) input[type=checkbox].check { border-color: var(--muted); background: transparent; box-shadow: none; }
input[type=checkbox].check:checked, .group-select input:checked, .group-select input:indeterminate { border-color: var(--accent); background: var(--accent); }
input[type=checkbox].check:checked::after, .group-select input:checked::after {
 content: "";
 position: absolute;
 left: 6px;
 top: 2px;
 width: 5px;
 height: 10px;
 border: solid var(--accent-ink);
 border-width: 0 2px 2px 0;
 transform: rotate(45deg);
}
.group-select input:indeterminate::after { content: ""; position: absolute; left: 4px; right: 4px; top: 8px; height: 2px; background: var(--accent-ink); }
.group-select { opacity: 0; transition: opacity .15s; }
.upload-group:hover .group-select, .group-select:focus-within, .selecting .group-select { opacity: 1; }

@media (hover: none) {
 .select-control, .group-select { opacity: 1; }
 .group-select { position: static; margin-left: -8px; }
 .file-download { display: none; }
}

.file.arrived { animation: arrive 1.6s ease-out; }
@keyframes arrive { from { box-shadow: inset 0 0 0 3px var(--accent); } to { box-shadow: inset 0 0 0 3px transparent; } }

.empty { display: grid; justify-items: center; gap: 8px; padding: 18vh 24px 0; text-align: center; color: var(--muted); }
.empty svg { width: 48px; height: 48px; stroke-width: 1.3; margin-bottom: 6px; }
.empty h2 { color: var(--ink); font-size: 18px; font-weight: 650; }
.empty p { max-width: 340px; }

/* Selection bar */
.actions {
 position: fixed;
 z-index: 5;
 left: 50%;
 bottom: calc(20px + env(safe-area-inset-bottom));
 display: flex;
 align-items: center;
 gap: 6px;
 padding: 6px;
 border-radius: 999px;
 background: var(--bar);
 color: var(--bar-ink);
 box-shadow: var(--shadow);
 transform: translate(-50%, 0);
 transition: transform .2s ease, opacity .2s ease, visibility .2s;
}
.actions:not(.open) { transform: translate(-50%, 140%); opacity: 0; visibility: hidden; }
#selection-status { padding: 0 14px 0 2px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.actions button:not(.icon-button) { min-height: 40px; }
#download-selected { background: var(--bar-ink); color: var(--bar); }
.actions .danger { background: transparent; color: color-mix(in srgb, var(--danger) 70%, var(--bar-ink)); }
@media (prefers-color-scheme: dark) { .actions .danger { color: #b3261e; } }

.toast {
 position: fixed;
 z-index: 6;
 left: 50%;
 bottom: calc(84px + env(safe-area-inset-bottom));
 max-width: calc(100% - 32px);
 padding: 10px 16px;
 border-radius: 8px;
 background: var(--raised);
 color: var(--ink);
 box-shadow: var(--shadow);
 transform: translateX(-50%);
 font-size: 14px;
}

/* Dialogs */
dialog { color: var(--ink); }
#delete-dialog {
 width: min(420px, calc(100% - 32px));
 padding: 24px;
 border: 0;
 border-radius: 20px;
 background: var(--raised);
 box-shadow: var(--shadow);
}
#delete-dialog::backdrop { background: rgb(0 0 0 / .45); }
#delete-dialog h2 { font-size: 20px; font-weight: 650; margin-bottom: 8px; }
#delete-dialog p { color: var(--muted); margin-bottom: 20px; }
#delete-error { color: var(--danger) !important; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

#viewer {
 width: 100vw;
 max-width: none;
 height: 100dvh;
 max-height: none;
 margin: 0;
 padding: 0;
 border: 0;
 background: #0b0d0c;
 color: #fff;
 overflow: hidden;
}
#viewer::backdrop { background: transparent; }
#viewer[open] { display: grid; grid-template-rows: auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); }
#viewer button[hidden], .markup-panel[hidden] { display: none; }
.markup-picture { position: relative; width: 100%; height: 100%; min-height: 0; display: grid; place-items: center; }
.markup-picture img { position: absolute; inset: 0; }
.markup-canvas { position: relative; }
.markup-canvas.drawing { touch-action: none; cursor: crosshair; }
.markup-canvas.drawing.typing { cursor: text; }
.viewer-actions, .markup-actions { display: flex; align-items: center; gap: 4px; }
#viewer.marked .viewer-actions, #viewer:not(.marked) .markup-actions { display: none; }
.markup-actions button { min-height: 40px; padding-inline: 14px; }
.markup-actions button.secondary { color: #fff; border-color: #59615c; }
#markup-save { background: #8fd0b0; color: #0d281d; }
.markup-panel { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px; min-width: 0; padding-top: 6px; border-top: 1px solid #39433c; }
.markup-tool { width: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 12px; background: transparent; color: #fff; }
.markup-tool:hover:not(:disabled) { background: rgb(255 255 255 / .12); filter: none; }
.markup-tool[aria-pressed=true], .markup-tool[aria-pressed=true]:hover { background: #8fd0b0; color: #0d281d; }
.markup-divider { width: 1px; height: 24px; margin-inline: 6px; background: #39433c; }
.markup-dot { width: var(--dot, 12px); height: var(--dot, 12px); border-radius: 999px; background: var(--color, #ff453a); box-shadow: 0 0 0 2px #0b0d0c, 0 0 0 3px rgb(255 255 255 / .7); }
.markup-style { position: fixed; inset: auto; width: 264px; margin: 0; padding: 12px; border: 1px solid #39433c; border-radius: 16px; background: #1a211d; color: #fff; box-shadow: 0 8px 28px rgb(0 0 0 / .5); }
.markup-style:popover-open { display: grid; gap: 12px; }
.markup-swatches, .markup-sizes { display: flex; justify-content: space-between; gap: 4px; }
.markup-swatch { width: 34px; min-height: 34px; padding: 0; border: 1px solid rgb(255 255 255 / .3); background: var(--swatch); }
.markup-swatch[aria-pressed=true] { box-shadow: 0 0 0 2px #1a211d, 0 0 0 4px #fff; }
.markup-size { flex: 1; min-height: 40px; padding: 0; border: 1px solid #39433c; border-radius: 10px; background: transparent; }
.markup-size[aria-pressed=true] { border-color: #8fd0b0; background: #23392e; }
.markup-size span { width: var(--dot); height: var(--dot); border-radius: 999px; background: #fff; }
.markup-editor, .markup-editor:focus-visible { position: absolute; z-index: 1; margin: 0; padding: 0; border: 0; background: transparent; font-family: system-ui, sans-serif; font-weight: 600; line-height: 1.2; field-sizing: content; min-inline-size: 1ch; resize: none; overflow: hidden; white-space: pre-wrap; overflow-wrap: normal; caret-color: currentColor; outline: 1.5px dashed currentColor; outline-offset: 5px; text-shadow: 0 0 2px var(--halo), 0 0 2px var(--halo), 0 0 3px var(--halo); }
.markup-editor[hidden] { display: none; }
#markup-status { position: absolute; z-index: 2; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); padding: 8px 16px; border-radius: 999px; background: rgb(26 33 29 / .94); color: #e8eee9; font-size: 14px; text-align: center; transform: translateX(-50%); pointer-events: none; }
#markup-status:empty { display: none; }
#viewer.marking .viewer-nav { display: none; }
.viewer-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); }
.viewer-title { flex: 1; min-width: 0; margin-left: 8px; }
.viewer-title h2 { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-title p { font-size: 13px; color: rgb(255 255 255 / .68); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#viewer .icon-button { color: #fff; }
.viewer-check { width: 22px; height: 22px; border: 2px solid #fff; border-radius: 999px; position: relative; }
#viewer-select[aria-pressed=true] .viewer-check { background: #8fd0b0; border-color: #8fd0b0; }
#viewer-select[aria-pressed=true] .viewer-check::after { content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px; border: solid #0d281d; border-width: 0 2px 2px 0; transform: rotate(45deg); }
#viewer .icon-button:hover:not(:disabled) { background: rgb(255 255 255 / .14); }
.viewer-stage { min-height: 0; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); place-items: center; padding: 0 72px max(24px, env(safe-area-inset-bottom)); outline: none; }
.viewer-stage img { width: 100%; height: 100%; object-fit: contain; }
.viewer-file { display: grid; justify-items: center; gap: 12px; text-align: center; color: rgb(255 255 255 / .8); }
.viewer-file svg { width: 64px; height: 64px; stroke-width: 1.1; }
.viewer-file a { margin-top: 8px; background: #fff; color: #111; }
.viewer-nav { position: absolute; top: 50%; width: 48px; min-height: 48px; transform: translateY(-50%); background: rgb(255 255 255 / .08) !important; }
.viewer-nav.previous { left: 12px; }
.viewer-nav.next { right: 12px; }
.viewer-nav:disabled { visibility: hidden; }

@media (max-width: 640px) {
 .top { flex-wrap: wrap; gap: 4px 12px; padding: 14px 16px 4px; }
 .banner { margin-inline: 16px !important; }
 .summary { order: 3; flex-basis: 100%; }
 .all-control { margin-left: auto; }
 main { padding-inline: 0; }
 .upload-group { margin-top: 14px; }
 .group-heading { padding: 0 8px 6px 16px; }
 .group-select { position: static; margin-left: -8px; opacity: 1; }
 .actions button:not(.icon-button) { width: 44px; padding: 0; }
 .actions button span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
 .file-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; }
 .file { width: auto; height: auto; aspect-ratio: 1; border-radius: 0; }
 .group-download { margin-left: auto; }
 .file.selected .preview { inset: 8px; }
 .file-copy { padding: 6px 8px; }
 .file-placeholder { padding-bottom: 40px; }
 .file-placeholder svg { width: 28px; height: 28px; }
 .banner { margin-inline: 16px; }
 .actions { left: 12px; right: 12px; transform: none; }
 .actions:not(.open) { transform: translateY(140%); }
 #selection-status { margin-right: auto; }
 .viewer-stage { padding: 0 0 env(safe-area-inset-bottom); }
 .viewer-nav { display: none; }
 .markup-tool { width: 40px; }
 .markup-divider { margin-inline: 4px; }
 .markup-actions button { padding-inline: 12px; }
}

@media (prefers-reduced-motion: reduce) {
 *, *::before, *::after { transition-duration: 0s !important; animation: none !important; }
}
