:root {
  --bg: #fbf7f1; --card: #ffffff; --text: #2b2420; --muted: #756a60; --border: #e6dccf;
  --accent: #b4532a; --accent-text: #ffffff; --danger: #b3261e; --focus: #e0a384;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1c1713; --card: #271f1a; --text: #f3ebe2; --muted: #b3a597; --border: #3b312a; --accent: #d9714a; --accent-text: #1c1713; --danger: #ff8a80; --focus: #8a4a2f; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; line-height: 1.5;
  display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
main { width: 100%; max-width: 440px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 24px 22px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.logo { width: 56px; height: 56px; border-radius: 13px; display: block; margin: 0 0 14px; }
h1 { font-size: 24px; margin: 0 0 6px; }
h2 { font-size: 16px; margin: 22px 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 14px; }
ol.steps { padding-left: 22px; margin: 0 0 14px; }
ol.steps li { margin-bottom: 10px; }
.note { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
label { display: block; font-weight: 600; margin-bottom: 6px; }
input[type=text] {
  width: 100%; font: inherit; font-size: 22px; letter-spacing: .12em; text-transform: uppercase; text-align: center;
  padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text);
}
input[type=text]:focus { outline: 3px solid var(--focus); border-color: var(--accent); }
button.primary {
  width: 100%; margin-top: 12px; font: inherit; font-weight: 600; padding: 13px; border: 0; border-radius: 10px;
  background: var(--accent); color: var(--accent-text); cursor: pointer;
}
button.primary:disabled { opacity: .6; cursor: default; }
.error { color: var(--danger); font-size: 14px; margin: 10px 0 0; min-height: 1.4em; }
/* On an iPhone's Safari tab only the install steps show; the code box belongs in the installed app. With scripts off, both show. */
html.needs-install #code-section { display: none; }
html.ready #install-steps { display: none; }
.pill { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }

/* ── Gallery ── */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.center { text-align: center; }
button.plain { font: inherit; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer; }
button.plain.danger { color: var(--danger); }
button.primary.small { width: auto; margin: 0; padding: 8px 14px; font-size: 14px; }
select {
  font: inherit; font-size: 14px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); max-width: 100%;
}
body.gallery { display: block; padding: 0; min-height: 100vh; }
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.bar-title { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.bar-title img { border-radius: 7px; }
.bar-right { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 14px; }
.filters { display: flex; gap: 8px; padding: 10px max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left)); }
.filters[hidden] { display: none; }
.wrap { padding: 10px max(14px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); max-width: 1100px; margin: 0 auto; }
.empty { text-align: center; padding: 50px 10px; }
.empty[hidden] { display: none; }
.day h2 { font-size: 15px; margin: 18px 0 8px; color: var(--muted); font-weight: 600; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 4px; }
.tile { position: relative; padding: 0; border: 0; border-radius: 6px; overflow: hidden; aspect-ratio: 1; background: var(--border); cursor: pointer; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sheet-wrap { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; background: rgba(0,0,0,.45); }
.sheet-wrap[hidden] { display: none; }
.sheet { width: 100%; max-width: 480px; background: var(--card); border-radius: 18px 18px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); }
.sheet h2 { margin: 0 0 4px; font-size: 18px; }
.sheet input[type=text] { font-size: 16px; letter-spacing: 0; text-transform: none; text-align: left; margin-bottom: 14px; }
.sheet label { font-weight: 600; font-size: 14px; }
.row { display: flex; gap: 10px; justify-content: flex-end; }
.row .primary { width: auto; margin: 0; padding: 10px 20px; }
.bar-track { height: 8px; border-radius: 99px; background: var(--border); overflow: hidden; margin: 10px 0 8px; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.errors { margin: 0 0 12px; padding-left: 18px; color: var(--danger); font-size: 14px; }
.viewer { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 30; background: #000; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.viewer[hidden] { display: none; }
.viewer img { max-width: 100%; max-height: calc(100vh - 150px); max-height: calc(100dvh - 150px); object-fit: contain; }
.v-info { text-align: center; padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); min-height: 90px; }
.v-info p { margin: 0 0 4px; }
.v-info .muted { color: #c7bdb2; }
.v-close, .v-nav { position: absolute; background: rgba(255,255,255,.14); color: #fff; border: 0; border-radius: 50%; width: 44px; height: 44px; font-size: 28px; line-height: 1; cursor: pointer; }
.v-close { top: calc(10px + env(safe-area-inset-top)); right: 12px; }
.v-nav { top: 50%; transform: translateY(-50%); }
.v-prev { left: 8px; } .v-next { right: 8px; }
.v-nav[disabled] { opacity: .25; cursor: default; }

/* ── Tags and editing ── */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer; padding: 0; }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; display: block; }
a.plain { text-decoration: none; display: inline-block; }
a.plain.small { padding: 8px 12px; font-size: 14px; }
.sheet-wrap.top { z-index: 40; }
.day h2 .sel-all { margin-left: 10px; font: inherit; font-size: 13px; font-weight: 600; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 0; }
.tile .pick {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.35);
  display: none; align-items: center; justify-content: center; color: #fff; font-size: 15px; line-height: 1; box-shadow: 0 0 0 1px rgba(0,0,0,.3);
}
body.editing .tile.mine .pick { display: flex; }
body.editing .tile.mine.selected .pick { background: var(--accent); border-color: #fff; }
body.editing .tile:not(.mine) { opacity: .35; cursor: default; }
body.editing .tile.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
body.editing .wrap { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
.edit-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 12px max(14px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: var(--card); border-top: 1px solid var(--border); font-size: 14px;
}
.edit-bar[hidden] { display: none; }
.edit-bar .row .primary { padding: 10px 18px; }
.edit-bar .row button:disabled { opacity: .45; cursor: default; }

/* ── Top bar, sticky sub-bar, headings that stay put, and details that appear on hover or press-and-hold ── */
:root { --stick: 112px; }
.bar { z-index: 12; }
.bar-name { display: flex; flex-direction: column; line-height: 1.15; }
.bar-name .who { font-size: 12px; font-weight: 400; color: var(--muted); }
.icon-btn { text-decoration: none; }
button.with-icon { display: inline-flex; align-items: center; gap: 6px; }
button.with-icon .ic { width: 18px; height: 18px; }
@media (max-width: 480px) { button.with-icon .lbl { display: none; } button.with-icon { padding: 0; width: 38px; height: 38px; justify-content: center; border-radius: 10px; } }

.subbar {
  position: sticky; top: var(--bar-h, 56px); z-index: 11; background: var(--bg); border-bottom: 1px solid var(--border);
  padding: 8px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
}
.subbar[hidden], .chips[hidden], .filter-panel[hidden], .badge[hidden] { display: none; }
.subbar-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--card); }
.seg button { font: inherit; font-size: 14px; padding: 7px 18px; border: 0; background: transparent; color: var(--text); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--accent); color: var(--accent-text); font-size: 12px; line-height: 18px; text-align: center; }
.chips { display: flex; gap: 8px; margin-top: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; font: inherit; font-size: 14px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.chip .n { opacity: .65; margin-left: 4px; font-size: 12px; }
.filter-panel { display: grid; gap: 4px; padding-top: 10px; max-width: 420px; }
.filter-panel label { font-size: 13px; font-weight: 600; margin-top: 6px; }
.filter-panel select { width: 100%; font-size: 16px; }

/* Section headings (the date, or the tag) stay under the bars while you scroll that section. */
.day h2 { position: sticky; top: var(--stick); z-index: 5; margin: 0; padding: 12px 0 8px; background: var(--bg); font-size: 15px; font-weight: 700; color: var(--text); }
.day h2 .count { font-weight: 400; color: var(--muted); margin-left: 6px; font-size: 13px; }

.tile { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.tile .info {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 8px 6px; text-align: left; font-size: 12px; line-height: 1.3; color: #fff;
  background: linear-gradient(to top, rgba(0,0,0,.78), rgba(0,0,0,0)); opacity: 0; transition: opacity .15s; pointer-events: none;
}
.tile .info b { display: block; font-size: 13px; }
.tile .info span { display: block; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile:hover .info, .tile:focus-visible .info, .tile.show-info .info { opacity: 1; }
body.editing .tile .info { opacity: 0; }
.v-info .v-by { font-size: 13px; }

/* ── The "Tag your photos" menu ── */
.sheet.tall { max-width: 600px; max-height: 92vh; max-height: 92dvh; overflow-y: auto; display: flex; flex-direction: column; }
.sheet-wrap.top { align-items: flex-end; }
@media (min-width: 700px) { .sheet-wrap.top { align-items: center; } .sheet.tall { border-radius: 18px; } }
button.link { font: inherit; font-size: 14px; font-weight: 600; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 4px 6px; }
.tg-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 2px 0 8px; font-size: 14px; }
.tg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 6px; overflow-y: auto; max-height: 38vh; padding: 2px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.tg-item { position: relative; padding: 0; border: 0; border-radius: 8px; overflow: hidden; aspect-ratio: 1; background: var(--border); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.tg-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tg-item .nm { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: flex; align-items: center; justify-content: center; padding: 6px; font-size: 11px; color: var(--muted); word-break: break-all; text-align: center; }
.tg-item .tg-check { position: absolute; top: 5px; right: 5px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.35); color: #fff; font-size: 14px; line-height: 18px; text-align: center; box-shadow: 0 0 0 1px rgba(0,0,0,.3); }
.tg-item.ticked { outline: 3px solid var(--accent); outline-offset: -3px; }
.tg-item.ticked .tg-check { background: var(--accent); }
.tg-item .tg-label { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 5px 4px; font-size: 11px; line-height: 1.2; color: #fff; text-align: left; overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; background: linear-gradient(to top, rgba(0,0,0,.8), rgba(0,0,0,0)); }
.tg-item .tg-label.none { color: rgba(255,255,255,.7); font-style: italic; }
.tg-item.changed .tg-label { color: #ffd9a8; font-weight: 600; font-style: normal; }
.tg-box { margin: 12px 0 6px; }
.tg-box label { font-weight: 600; font-size: 14px; display: block; margin-bottom: 6px; }
.tg-inputrow { display: flex; gap: 8px; }
.tg-inputrow input[type=text] { flex: 1 1 auto; min-width: 0; margin: 0; font-size: 16px; letter-spacing: 0; text-transform: none; text-align: left; }
.tg-inputrow .primary { width: auto; margin: 0; padding: 10px 18px; }
.tg-chips { margin-top: 10px; flex-wrap: wrap; overflow: visible; }
.tg-chips[hidden], .tg-suggest[hidden] { display: none; }
.tg-suggest { margin-top: 12px; font-size: 14px; }
.tg-suggest .plain.small { margin-top: 8px; padding: 6px 12px; font-size: 13px; }
#tg-msg { min-height: 1.3em; margin: 8px 0 0; }


/* ── The tag menu, second version: tickboxes, one Apply button, and an "are you sure?" box ── */
.sheet.tall { position: relative; }
.tg-label-text { margin: 0 0 8px; font-weight: 600; font-size: 14px; }
.tg-sub { margin: 6px 0; font-size: 13px; }
.tg-sending { margin: 8px 0 0; font-size: 13px; }
.tg-tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; max-height: 24vh; overflow-y: auto; }
.tg-tag { display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px 7px 9px; border: 1px solid var(--border); border-radius: 999px; background: var(--card); font-size: 14px; cursor: pointer; user-select: none; -webkit-user-select: none; }
.tg-tag input { width: 17px; height: 17px; margin: 0; flex: 0 0 auto; accent-color: var(--accent); }
.tg-tag.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--card)); font-weight: 600; }
.tg-tag.sug { border-style: dashed; border-color: var(--accent); }
.tg-inputrow { margin-top: 2px; }
.tg-inputrow .plain { white-space: nowrap; padding: 10px 14px; }
.tg-item .tg-state { position: absolute; top: 5px; left: 5px; min-width: 22px; padding: 1px 6px; border-radius: 999px; font-size: 11px; line-height: 18px; background: rgba(0,0,0,.6); color: #fff; text-align: center; }
.tg-item .tg-state.ready { background: #1f7a3d; }
.tg-item .tg-state.failed { background: #b3261e; }

/* Tags on some (not all) of the selected photos: highlighted too, with a dash in the box. */
.tg-tag.some { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--card)); }
.errors.good { color: #1f7a3d; }
@media (prefers-color-scheme: dark) { .errors.good { color: #6fd08c; } }

/* ── Tag menu, third version: an X in the corner, a + at the end of the tags, and a page that stays put behind it ── */
html.no-scroll, body.no-scroll { overflow: hidden; }
body.no-scroll { position: fixed; left: 0; right: 0; width: 100%; }
.sheet.tall, .tg-grid, .tg-tags { overscroll-behavior: contain; }
.tg-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 2px; }
.tg-top h2 { margin: 0; }
.tg-x { border: 0; background: transparent; color: var(--accent, #b4532a); font: inherit; font-weight: 600; font-size: 17px; line-height: 1; padding: 10px 12px; margin: -8px -12px -8px 0; cursor: pointer; touch-action: manipulation; }
.tg-x:hover { text-decoration: underline; }
.tg-pills { display: contents; }
.tg-tags { align-items: center; }
.tg-plus { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border: 1px dashed var(--accent); border-radius: 999px; background: var(--card); color: var(--accent); cursor: pointer; }
.tg-plus[hidden], .tg-editor[hidden] { display: none; }
.tg-plus .ic { width: 18px; height: 18px; }
.tg-editor { display: inline-flex; align-items: center; gap: 6px; }
.tg-editor input { width: 150px; max-width: 46vw; margin: 0; padding: 7px 12px; border: 1px solid var(--accent); border-radius: 999px; background: var(--bg); color: var(--text); font: inherit; font-size: 16px; letter-spacing: 0; text-transform: none; text-align: left; }
.tg-editor input:focus { outline: 3px solid var(--focus); }
.tg-donebtn { font: inherit; font-size: 14px; font-weight: 600; padding: 7px 14px; border: 0; border-radius: 999px; background: var(--accent); color: var(--accent-text); cursor: pointer; }

/* Narrow phones: nothing in the top bar or the tag window is allowed to push past the edge of the screen. */
.bar-title { min-width: 0; }
.bar-name { min-width: 0; }
.bar-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-right { flex: 0 0 auto; }
.tg-top h2 { min-width: 0; overflow-wrap: anywhere; }
.tg-x { flex: 0 0 auto; }
.tg-head > span { min-width: 0; }
.tg-box, .tg-tag { max-width: 100%; }
.tg-tag { overflow-wrap: anywhere; }

/* The line under the title: how many photos and how many are selected, then Select all / Clear as two tidy buttons beneath it. */
.tg-head { flex-direction: column; align-items: stretch; gap: 8px; margin: 6px 0 10px; }
.tg-head > #tg-count { font-size: 14px; line-height: 1.3; }
.tg-links { display: flex; gap: 8px; }
.tg-links button.link { padding: 6px 14px; border: 1px solid var(--border); border-radius: 999px; background: var(--card); font-size: 14px; }
.tg-links button.link:active { background: var(--bg); }

/* Apply spans the bottom of the tag window, and is greyed out until there is something to apply. */
#tg-apply { width: 100%; margin: 0; padding: 13px 20px; font-size: 16px; }
#tg-apply:disabled { opacity: .4; cursor: default; }
