:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --frame: #e6e1d8;
  --text: #24211d;
  --muted: #6b655c;
  --line: #d9d3c8;
  --accent: #365f52;
  --accent-text: #ffffff;
  --open-bg: #e3efe6;
  --open-text: #23533f;
  --taken-bg: #f3e3cf;
  --taken-text: #7a4a12;
  --danger: #a3341f;
  --gutter: clamp(10px, 2.5vw, 40px);
  --bar-h: 60px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #22201d;
    --frame: #0f0e0d;
    --text: #ece8e1;
    --muted: #a39c91;
    --line: #3a3732;
    --accent: #8cc3ae;
    --accent-text: #10201a;
    --open-bg: #1f3a30;
    --open-text: #a9dcc6;
    --taken-bg: #45321a;
    --taken-text: #f0c98f;
    --danger: #f08a75;
  }
}

* { box-sizing: border-box; }

/* Without this, any element given a display value below ignores `hidden`. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 {
  margin: 0;
  font: 800 1.4rem/1.2 Nunito, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0.01em;
}

button, input, select, textarea { font: inherit; color: inherit; }

input[type="text"], input[type="password"], select, textarea {
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

button {
  min-height: 42px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.quiet { border-color: transparent; background: none; color: var(--muted); }
button.link {
  min-height: 0;
  padding: 2px 6px;
  border: 0;
  background: none;
  color: var(--accent);
  text-decoration: underline;
  font-size: 0.9rem;
}
button.link.danger { color: var(--danger); }
button:disabled { opacity: 0.55; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.error { margin: 8px 0 0; color: var(--danger); font-size: 0.95rem; }

/* ---------- sign in ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box {
  width: min(380px, 100%);
  display: grid;
  gap: 10px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.login-box p { margin: 0 0 6px; color: var(--muted); }
.login-box label { font-size: 0.9rem; font-weight: 600; }

/* ---------- top bar ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 8px var(--gutter);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; flex: 1; }
.count { color: var(--muted); font-size: 0.9rem; margin-left: auto; }
.badge {
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--taken-bg);
  color: var(--taken-text);
  font: 600 0.72rem/1.6 system-ui, sans-serif;
  vertical-align: middle;
}

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 8px 14px; font-size: 0.95rem; }
.segmented label + label span { border-left: 1px solid var(--line); }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -4px; }

/* ---------- photo list ---------- */

.list { padding: 20px var(--gutter) 80px; display: grid; gap: 36px; }
.empty { padding: 60px var(--gutter); text-align: center; color: var(--muted); }

.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
  scroll-margin-top: calc(var(--bar-h) + 8px);
}
.card[hidden] { display: none; }

/* The photo fills the column; one that would be taller than the window is
   scaled down to fit so it can be seen whole. */
.frame {
  display: block;
  position: relative;
  width: 100%;
  max-height: calc(100vh - var(--bar-h) - 16px);
  background: var(--frame);
}
.frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }

.below { padding: 14px clamp(12px, 2vw, 24px) 18px; display: grid; gap: 14px; }
.meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; color: var(--muted); font-size: 0.9rem; }
.meta .num { color: var(--text); font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.meta .spacer { flex: 1; }

.claim-status { display: grid; gap: 4px; margin-bottom: 8px; }
.claim-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.claim-line.backup { color: var(--muted); font-size: 0.95rem; }
.claim-line time { color: var(--muted); font-size: 0.85rem; }
.pill { padding: 2px 10px; border-radius: 99px; font-size: 0.8rem; font-weight: 600; }
.pill.open { background: var(--open-bg); color: var(--open-text); }
.pill.taken { background: var(--taken-bg); color: var(--taken-text); }

.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row input[type="text"] { flex: 1 1 200px; min-width: 0; max-width: 340px; }
.row input.wide { flex: 3 1 260px; max-width: none; }

.comments { border-top: 1px solid var(--line); padding-top: 12px; }
.comment-list { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 8px; }
.comment-list:empty { display: none; }
.comment-list li { overflow-wrap: anywhere; }
.comment-list .who { font-weight: 600; }
.comment-list time { color: var(--muted); font-size: 0.85rem; margin-left: 6px; }
.comment-list p { margin: 0; white-space: pre-wrap; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  z-index: 10;
}

#batch { flex: 0 1 auto; min-width: 0; max-width: 100%; }

@media (max-width: 560px) {
  .bar { gap: 6px 10px; }
  .bar h1 { flex: 1; order: 1; font-size: 1.2rem; }
  .controls { display: contents; }
  #signout { order: 2; min-height: 34px; padding: 4px 8px; }
  .segmented { order: 3; }
  .segmented span { padding: 8px 9px; font-size: 0.9rem; }
  #batch { order: 4; flex: 1 1 110px; }
  .count { order: 5; flex-basis: 100%; margin-left: 0; font-size: 0.82rem; }
}
