:root {
  --viewing-grey: #2f3032;   /* neutral backdrop: judges colour better than black */
  --sheet: #3a3b3e;
  --line: #4a4b4f;
  --paper: #ecebe7;
  --muted: #a4a49f;
  --pick: #34a86a;           /* selection green: frame ring, badge, outline */
  --pick-strong: #22804c;    /* button fill; white text stays above 4.5:1 */
  --body: "Noto Sans TC", system-ui, sans-serif;
  --frame: "Barlow Condensed", "Noto Sans TC", sans-serif;
  --gutter: 16px;
  --bar-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--viewing-grey);
  color: var(--paper);
  font: 400 15px/1.6 var(--body);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--paper); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- gate / messages ---------- */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px var(--gutter);
}
.gate-card { width: min(360px, 100%); }
.brand { font: 600 15px/1 var(--frame); letter-spacing: .06em; color: var(--muted); margin: 0 0 28px; }
.gate h1 { font-size: 26px; line-height: 1.3; font-weight: 700; margin: 0 0 8px; overflow-wrap: anywhere; }
.gate p { color: var(--muted); margin: 0 0 24px; }
.field { display: flex; gap: 8px; }
.field input {
  flex: 1; min-width: 0;
  background: var(--sheet); border: 1px solid var(--line); border-radius: 6px;
  padding: 12px 14px; font: 600 20px/1 var(--frame); letter-spacing: .18em; text-transform: uppercase;
}
.field input:focus { border-color: var(--paper); outline: none; }
.err { color: #ff8a80; min-height: 1.6em; margin-top: 10px; font-size: 14px; }

.btn {
  border: 0; border-radius: 6px; padding: 12px 18px; font-weight: 500;
  background: var(--paper); color: #232426;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.quiet { background: transparent; color: var(--paper); border: 1px solid var(--line); }
.btn.primary { background: var(--pick-strong); color: #fff; }

/* ---------- album header ---------- */
.top {
  padding: 28px var(--gutter) 12px;
  max-width: 1600px; margin: 0 auto;
  display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 8px 24px;
}
.top h1 { font-size: clamp(22px, 3.2vw, 32px); line-height: 1.25; margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.top .hint { color: var(--muted); margin: 6px 0 0; font-size: 14px; }
.top .tally { font: 600 15px/1 var(--frame); color: var(--muted); letter-spacing: .04em; }

.notice {
  max-width: 1600px; margin: 4px auto 8px; padding: 0 var(--gutter);
  color: var(--muted); font-size: 14px;
}
.notice b { color: var(--paper); font-weight: 500; }

/* ---------- contact sheet ---------- */
.sheet {
  max-width: 1600px; margin: 0 auto;
  padding: 8px var(--gutter) calc(var(--bar-h) + 40px + env(safe-area-inset-bottom));
}
.row { display: flex; gap: 10px; margin-bottom: 26px; }
.frame { position: relative; flex: 0 0 auto; margin: 0; }
.shot-wrap { position: relative; }
.frame .shot {
  display: block; width: 100%; padding: 0; border: 0; background: var(--sheet);
  border-radius: 2px; overflow: hidden;
}
.frame img { display: block; width: 100%; height: 100%; object-fit: cover; }
.frame figcaption {
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
  margin-top: 6px; font: 500 13px/1 var(--frame); letter-spacing: .05em; color: var(--muted);
}
.frame .note-mark { color: var(--paper); font: 400 12px/1 var(--body); }
.frame.picked figcaption .num { color: var(--pick); }

.pick-toggle {
  position: absolute; right: 6px; bottom: 6px; width: 40px; height: 40px;
  border-radius: 50%; border: 0; display: grid; place-items: center;
  background: rgba(30, 31, 33, .55); color: #fff; backdrop-filter: blur(6px);
}
.pick-toggle svg { width: 18px; height: 18px; }
.frame.picked .pick-toggle { background: var(--pick); }
/* selected: a crisp green ring just inside the photo edge */
.shot-wrap::after {
  content: ""; position: absolute; inset: 0; border-radius: 2px; pointer-events: none;
  box-shadow: inset 0 0 0 3px var(--pick); opacity: 0; transition: opacity .15s;
}
.frame.picked .shot-wrap::after { opacity: 1; }


.empty { max-width: 520px; margin: 18vh auto 0; padding: 0 var(--gutter); text-align: center; color: var(--muted); }
.empty h2 { color: var(--paper); font-size: 20px; margin: 0 0 8px; }

/* ---------- bottom bar ---------- */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
  background: rgba(39, 40, 42, .92); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
}
.bar-inner { max-width: 1600px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.bar .count { font: 600 22px/1 var(--frame); letter-spacing: .02em; }
.bar .count small { font: 400 13px/1 var(--body); color: var(--muted); margin-left: 4px; }
.bar .spacer { flex: 1; }
.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; user-select: none; }
.switch input { accent-color: var(--pick); width: 18px; height: 18px; margin: 0; }

/* ---------- viewer ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 20; background: #252628;
  display: grid; grid-template-rows: auto 1fr auto;
}
.viewer[hidden] { display: none; }
.v-top { display: flex; align-items: center; gap: 12px; padding: 10px var(--gutter); }
.v-top .num { font: 600 17px/1 var(--frame); letter-spacing: .05em; }
.v-top .pos { color: var(--muted); font: 500 14px/1 var(--frame); }
.v-top .spacer { flex: 1; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(255, 255, 255, .06); }
.icon-btn svg { width: 22px; height: 22px; }

.stage { position: relative; min-height: 0; display: grid; place-items: center; padding: 0 56px; touch-action: pan-y; }
.stage figure { position: relative; margin: 0; max-width: 100%; max-height: 100%; display: grid; place-items: center; }
.stage img { max-width: 100%; max-height: calc(100dvh - 210px); object-fit: contain; display: block; user-select: none; -webkit-user-drag: none; }
.stage figure img { outline: 3px solid transparent; outline-offset: 10px; border-radius: 1px; }
.stage figure.picked img { outline-color: var(--pick); transition: outline-color .15s; }
.nav { position: absolute; top: 50%; transform: translateY(-50%); }
.nav.prev { left: 6px; }
.nav.next { right: 6px; }

.v-bottom {
  padding: 12px var(--gutter) calc(14px + env(safe-area-inset-bottom));
  display: flex; gap: 10px; align-items: flex-start; max-width: 900px; width: 100%; margin: 0 auto;
}
.v-bottom textarea {
  flex: 1; min-width: 0; resize: none; height: 46px; padding: 11px 12px;
  background: var(--sheet); border: 1px solid var(--line); border-radius: 6px; line-height: 1.5;
}
.v-bottom textarea:focus { border-color: var(--paper); outline: none; height: 92px; }
.v-bottom .btn { white-space: nowrap; height: 46px; }
.saved { color: var(--muted); font-size: 12px; text-align: center; min-height: 18px; margin-top: -8px; }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 10px; background: var(--sheet); color: var(--paper);
  width: min(440px, calc(100% - 32px)); padding: 24px;
}
dialog::backdrop { background: rgba(20, 20, 22, .6); }
dialog h2 { margin: 0 0 8px; font-size: 20px; }
dialog p { margin: 0 0 20px; color: var(--muted); }
dialog .actions { display: flex; gap: 10px; justify-content: flex-end; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--bar-h) + 24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--paper); color: #232426; padding: 10px 16px; border-radius: 6px; z-index: 30; font-weight: 500;
}

/* ---------- owner dashboard ---------- */
.owner-login { margin-top: 40px; color: var(--muted); position: relative; }
.owner-login summary { cursor: pointer; font-size: 14px; width: fit-content; }
/* the form floats below the toggle so opening it never moves the centred text above */
.owner-login form { position: absolute; top: calc(100% + 14px); left: 0; right: 0; }
.dash { max-width: 1100px; margin: 0 auto; padding: 8px var(--gutter) 64px; }
.top:has(+ .dash) { max-width: 1100px; }
.group { margin-top: 28px; }
.group h2 { font-size: 18px; margin: 0; display: flex; align-items: baseline; gap: 10px; }
.group h2 .n { font: 600 18px/1 var(--frame); color: var(--pick); }
.group-desc, .group-empty { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }
.albums { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.album { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.album-main { flex: 1 1 320px; min-width: 0; }
.album-title { color: var(--paper); font-size: 17px; font-weight: 500; text-decoration: none; overflow-wrap: anywhere; }
.album-title:hover { text-decoration: underline; }
.album-meta { margin: 4px 0 0; color: var(--muted); font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 18px; }
.album-meta b { color: var(--paper); font: 600 16px/1 var(--frame); }
.album-note { margin: 8px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.album-note .pw { font: 600 18px/1 var(--frame); letter-spacing: .14em; color: var(--pick); }
.album-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.album-actions .btn { padding: 8px 12px; font-size: 14px; }
.btn.danger { color: #ff8a80; border-color: rgba(255, 138, 128, .35); }

@media (max-width: 640px) {
  :root { --gutter: 12px; }
  .row { gap: 6px; margin-bottom: 22px; }
  .pick-toggle { width: 34px; height: 34px; right: 4px; bottom: 4px; }
  .stage { padding: 0 10px; }
  .stage figure img { outline-offset: 4px; }
  .nav { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .shot-wrap::after, .stage figure.picked img { transition: none; }
}
