:root {
  --bg: #fafafa;
  --fg: #1d1d1f;
  --muted: #6e6e73;
  --panel: #ffffff;
  --line: #e2e2e6;
  --accent: #2e6bd9;
  --cell: 116px;
  --gap: 3px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --fg: #ececf0;
    --muted: #9a9aa2;
    --panel: #1c1d21;
    --line: #2c2d33;
    --accent: #7aa5f5;
  }
}
@media (min-width: 900px) {
  :root { --cell: 168px; }
}
/* Phones: four columns, almost edge to edge, like the Photos apps. */
@media (max-width: 600px) {
  :root { --cell: 84px; --gap: 2px; }
  main { padding: 4px 2px 48px; }
  section h2, .tools { margin-left: 12px; }
  .albums { padding: 0 12px; }
  .back { margin-left: 12px; }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
/* A scrollbar appearing mustn't change the width the grid was measured at. */
html { scrollbar-gutter: stable; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.noscroll { overflow: hidden; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

/* Header */
#bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; color: var(--fg); text-decoration: none; margin-right: auto; }
nav { display: flex; gap: 4px; }
nav a { color: var(--muted); text-decoration: none; padding: 4px 10px; border-radius: 999px; }
nav a.active { color: var(--fg); background: var(--panel); box-shadow: 0 0 0 1px var(--line); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 4px 12px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.quiet { border: 0; background: none; color: var(--muted); padding: 4px 6px; }

main { padding: 8px 16px 48px; max-width: 1600px; margin: 0 auto; }
.status { color: var(--muted); padding: 48px 0; text-align: center; }

/* Timeline */
section h2 {
  font-size: 17px; font-weight: 650; margin: 24px 0 10px;
  display: flex; align-items: baseline; gap: 8px;
}
section h2 .count { font-size: 13px; font-weight: 400; color: var(--muted); }
.back { display: inline-block; margin-top: 16px; color: var(--accent); text-decoration: none; }

/* Jump to date and the no-date filter */
.tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.pill {
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 999px; padding: 6px 14px;
}
.pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
#jump-fab {
  position: fixed; z-index: 15; right: 16px; bottom: max(16px, env(safe-area-inset-bottom));
  border: 0; border-radius: 999px; padding: 12px 18px;
  background: var(--accent); color: #fff; font-weight: 600;
  box-shadow: 0 4px 14px rgb(0 0 0 / 25%);
}
#jump {
  padding: 0; border: 0; border-radius: 14px;
  width: min(440px, calc(100vw - 32px)); max-width: none; max-height: min(680px, 85vh);
  background: var(--panel); color: var(--fg);
  box-shadow: 0 12px 40px rgb(0 0 0 / 30%);
}
#jump[open] { display: flex; flex-direction: column; }
#jump::backdrop { background: rgb(0 0 0 / 45%); }
#jump .head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 4px 20px; }
#jump .head h2 { margin: 0; font-size: 18px; font-weight: 650; }
#jump .head .close { font-size: 24px; line-height: 1; }
#jump .years { overflow-y: auto; padding: 0 16px 16px; }
.year h3 {
  font-size: 14px; font-weight: 650; margin: 12px 4px 6px;
  display: flex; align-items: baseline; gap: 8px;
}
.year h3 .count { font-size: 12px; font-weight: 400; color: var(--muted); }
.months { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.months button {
  height: 40px; border: 0; border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 14%, var(--panel));
}
.months button:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 26%, var(--panel)); }
.months button:disabled { background: none; color: var(--muted); opacity: .5; cursor: default; }
.months button[aria-current="true"] { background: var(--accent); color: #fff; }
#jump .undated { margin-top: 14px; border: 0; background: none; color: var(--accent); padding: 8px 4px; }
/* Phones: a sheet from the bottom, like the app. */
@media (max-width: 600px) {
  #jump {
    width: 100vw; margin: auto 0 0; border-radius: 14px 14px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

.grid {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fill, minmax(var(--cell), 1fr));
}
.cell {
  position: relative; aspect-ratio: 1; padding: 0; border: 0;
  background: var(--panel); overflow: hidden; border-radius: 2px;
}
.cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cell:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.cell .badge {
  position: absolute; right: 6px; bottom: 6px;
  width: 24px; height: 24px; border-radius: 50%;
  background: rgb(0 0 0 / 55%); color: #fff; font-size: 11px;
  display: grid; place-items: center; pointer-events: none;
}
.cell .label {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
}

/* Albums */
.albums {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(calc(var(--cell) * 1.3), 1fr));
  margin-top: 16px;
}
.album { color: inherit; text-decoration: none; }
.album .cover { aspect-ratio: 1; background: var(--panel); border-radius: 6px; overflow: hidden; }
.album img { width: 100%; height: 100%; object-fit: cover; display: block; }
.album .title { margin-top: 6px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album .meta { color: var(--muted); font-size: 13px; }

/* Sign in */
#login {
  max-width: 360px; margin: 18vh auto 0; padding: 0 16px;
  display: flex; flex-direction: column; gap: 12px;
}
#login h1 { margin: 0; font-size: 26px; }
#login p { margin: 0; color: var(--muted); }
#login input {
  font: inherit; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--fg);
}
#login button {
  padding: 10px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600;
}
.error { color: #d93025; }

/* Full-screen viewer */
#viewer { position: fixed; inset: 0; z-index: 20; background: #000; color: #fff; }
/* Flex, not grid: a grid row sizes to the photo, so max-height: 100% never
   bit and tall photos ran off the screen. Here it's the window-sized stage. */
#viewer .stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#viewer .stage img, #viewer .stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
#viewer .stage p { color: #bbb; padding: 0 24px; text-align: center; }
#viewer button {
  position: absolute; border: 0; background: rgb(0 0 0 / 35%); color: #fff;
  width: 44px; height: 44px; border-radius: 50%; font-size: 28px; line-height: 1;
}
#viewer button:disabled { opacity: 0; pointer-events: none; }
#viewer .close { top: max(12px, env(safe-area-inset-top)); right: 12px; }
#viewer .motion {
  top: max(12px, env(safe-area-inset-top)); left: 12px;
  width: auto; padding: 0 14px; border-radius: 22px; font-size: 14px;
}
#viewer .motion[aria-pressed="true"] { background: #fff; color: #000; }
#viewer .nav { top: 50%; transform: translateY(-50%); }
#viewer .prev { left: 12px; }
#viewer .next { right: 12px; }
#viewer .info {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline;
  padding: 24px 16px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgb(0 0 0 / 70%));
  font-size: 13px; pointer-events: none;
}
#viewer .info .name { color: #bbb; }
#viewer .info a { color: #fff; margin-left: auto; pointer-events: auto; }
#viewer .info .motion-dl:not([hidden]) + .download { margin-left: 0; }
#viewer .info .edit {
  position: static; width: auto; height: auto; border-radius: 0;
  background: none; padding: 0; font-size: 13px; line-height: inherit;
  margin-left: auto; pointer-events: auto; text-decoration: underline;
}
#viewer .info .edit ~ a { margin-left: 0; }
#viewer .info .saved { color: #bbb; }

/* Editing a photo's details */
#details {
  padding: 0; border: 0; border-radius: 14px;
  width: min(400px, calc(100vw - 32px)); max-width: none;
  background: var(--panel); color: var(--fg);
  box-shadow: 0 12px 40px rgb(0 0 0 / 30%);
}
#details::backdrop { background: rgb(0 0 0 / 55%); }
#details form { display: flex; flex-direction: column; gap: 14px; padding: 18px 20px 14px; }
#details h2 { margin: 0; font-size: 18px; font-weight: 650; }
#details label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
#details .when { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#details input {
  font: inherit; font-size: 15px; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
#details input[type="date"] { flex: 1 1 140px; }
#details .name { margin: 0; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
#details .error { margin: 0; font-size: 13px; }
#details .buttons { display: flex; justify-content: flex-end; gap: 8px; }
#details .buttons button { padding: 8px 14px; border-radius: 8px; }
#details .save { border: 0; background: var(--accent); color: #fff; font-weight: 600; }
#details .save:disabled { opacity: .6; }
@media (hover: none) {
  #viewer .nav { display: none; }
}
