:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1d2733;
  --muted: #667585;
  --accent: #2f6fb0;
  --accent-text: #ffffff;
  --line: #dbe1e7;
  --tile: #e3e8ed;
  --gap: 3px;
  font-family: "Liberation Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121920; --surface: #1b242d; --text: #e8edf2; --muted: #93a1af; --accent: #5b9bd9; --accent-text: #0c1319; --line: #2a3541; --tile: #222d38; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
button, .btn { font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button:focus-visible, .btn:focus-within, a:focus-visible, .tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
#loginForm { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 24px; display: grid; gap: 14px; }
#loginForm h1 { margin: 0; font-size: 1.5rem; }
#loginForm label { display: grid; gap: 6px; color: var(--muted); font-size: .9rem; }
#loginForm input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
#loginError { margin: 0; min-height: 1.2em; color: #c0392b; font-size: .9rem; }

.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.bar h1 { margin: 0; font-size: 1.25rem; margin-right: auto; }
#status { color: var(--muted); font-size: .85rem; }
.bar { flex-wrap: wrap; }
#tabs { display: flex; gap: 4px; }
#tabs button { border-color: transparent; background: transparent; color: var(--muted); }
#tabs button[aria-pressed="true"] { background: var(--surface); border-color: var(--line); color: var(--text); font-weight: 600; }
button.danger { color: #c0392b; border-color: color-mix(in srgb, #c0392b 45%, var(--line)); }
@media (prefers-color-scheme: dark) { button.danger { color: #ff8a7a; } }
#selBar #selCount { margin-right: auto; font-weight: 600; }
#trashHint { margin: 0; padding: 10px 12px; color: var(--muted); font-size: .9rem; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

#grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: var(--gap); padding: var(--gap); }
@media (min-width: 700px) { #grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); } }
.group { grid-column: 1 / -1; margin: 18px 6px 4px; font-size: 1rem; font-weight: 600; color: var(--muted); }
.tile { padding: 0; border: 0; border-radius: 2px; aspect-ratio: 1; background: var(--tile); overflow: hidden; display: block; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
body.selecting .tile { opacity: .85; }
.tile { position: relative; }
.tile.selected { opacity: 1; outline: 3px solid var(--accent); outline-offset: -3px; }
.tile.selected::after { content: "✓"; position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-size: 15px; font-weight: 700; }
.tile.selected img { transform: scale(.94); border-radius: 4px; }
#toast { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20; display: flex; align-items: center; gap: 14px; background: #1d2733; color: #fff; border-radius: 10px; padding: 10px 14px; box-shadow: 0 6px 24px rgb(0 0 0 / .35); max-width: calc(100vw - 32px); }
#toast button { background: transparent; color: #9cc7ee; border: 0; padding: 4px 6px; font-weight: 600; }
#viewer footer button { position: static; width: auto; height: auto; border-radius: 8px; font-size: .9rem; padding: 6px 12px; background: rgb(255 255 255 / .12); color: #fff; }
#viewer footer button.danger { color: #ff9a8b; }
#empty { text-align: center; color: var(--muted); padding: 48px 16px; }
#sentinel { height: 1px; }

#viewer { position: fixed; inset: 0; z-index: 10; background: #000d; background: rgb(8 12 16 / .96); display: grid; grid-template-rows: 1fr auto; place-items: center; touch-action: pan-y; }
#photo { max-width: 100vw; max-height: calc(100dvh - 56px); object-fit: contain; grid-row: 1; grid-column: 1; }
#viewer button { position: absolute; background: rgb(255 255 255 / .12); color: #fff; border: 0; border-radius: 50%; width: 44px; height: 44px; font-size: 1.6rem; line-height: 1; padding: 0; }
#close { top: max(12px, env(safe-area-inset-top)); right: 12px; font-size: 1.1rem !important; }
#prev { left: 8px; top: 50%; }
#next { right: 8px; top: 50%; }
#viewer footer { display: flex; gap: 16px; align-items: center; justify-content: center; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); color: #cfd8e0; font-size: .9rem; }
#viewer footer a { color: #9cc7ee; }
@media (max-width: 600px) { #prev, #next { display: none; } }
