:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --ink: #14161a;
  --muted: #6b6f76;
  --line: #dedcd6;
  --accent: #1f5f4a;
  --accent-ink: #ffffff;
  --warn-bg: #fff4d6;
  --warn-line: #e0a526;
  --warn-ink: #7a5300;
  --error: #b42318;
  --ok: #1f7a4d;
  --radius: 14px;
  --gutter: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --surface: #1b1d21;
    --ink: #f1f0ec;
    --muted: #9a9ea6;
    --line: #2e3138;
    --accent: #4fb38c;
    --accent-ink: #0d1411;
    --warn-bg: #3a2f12;
    --warn-line: #c99320;
    --warn-ink: #f3d48a;
    --error: #f97066;
    --ok: #4fb38c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 var(--gutter) 32px;
}

[hidden] { display: none !important; }

h1, h2 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.35rem; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) var(--gutter) 10px;
  background: var(--ink);
  color: var(--bg);
}

.brand {
  font-weight: 700;
  letter-spacing: -0.01em;
}

.event-pill {
  min-width: 0;
  max-width: 65%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid color-mix(in srgb, var(--bg) 35%, transparent);
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-size: 0.875rem;
}

/* --- screens ----------------------------------------------------------- */

.screen { padding-top: 20px; }

.screen.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  padding-top: 15vh;
}

.screen.center .btn { width: 100%; }

.stack { display: flex; flex-direction: column; gap: 14px; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.row > .field-narrow { flex: 0 0 34%; }

/* --- login ------------------------------------------------------------- */

.login-card { padding-top: 18vh; }
.brand-large { font-size: 2rem; letter-spacing: -0.02em; }
.login-card .muted { margin: 4px 0 28px; }

/* --- form controls ----------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 0.875rem; font-weight: 600; }

input, textarea, select {
  width: 100%;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

textarea { resize: vertical; }

fieldset {
  border: 0;
  margin: 0;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

legend {
  float: left;
  width: 100%;
  padding: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

fieldset input, fieldset textarea, fieldset select { background: var(--bg); }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  min-height: 44px;
}
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

.list { display: flex; flex-direction: column; gap: 8px; }
.list-row { display: flex; gap: 8px; align-items: center; }
.list-row input { flex: 1; min-width: 0; }
.list-row select { flex: 0 0 96px; width: 96px; }
.list-row .remove {
  flex: 0 0 40px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
}

.field-note { margin: -4px 0 0; font-size: 0.8125rem; color: var(--warn-ink); }

/* low-confidence highlighting */
.uncertain input, .uncertain textarea, .uncertain select {
  background: var(--warn-bg);
  border-color: var(--warn-line);
}
.uncertain > span::after, fieldset.uncertain > legend::after, .tag {
  content: "check";
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--warn-line);
  color: #1d1600;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  vertical-align: 1px;
}
.tag { margin-left: 0; }
.hint-uncertain { margin: 0 0 14px; font-size: 0.875rem; color: var(--muted); }

/* --- buttons ----------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
}
.btn:disabled { opacity: 0.45; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-big { min-height: 58px; font-size: 1.0625rem; }

.link {
  border: 0;
  background: none;
  padding: 6px 0;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  align-self: flex-start;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
}
.sticky-actions .btn { width: 100%; }

/* --- capture ----------------------------------------------------------- */

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 0.875rem;
}
.banner .link { color: inherit; text-decoration: underline; }

.photo-tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}
.photo-front { aspect-ratio: 1.75; }
.photo-back { min-height: 76px; }
.photo-back:has(img) { aspect-ratio: 1.75; }

.photo-tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
}
.photo-hint small { color: var(--muted); }
.photo-tile:has(img) { border-style: solid; }
.photo-tile:has(img) .photo-hint {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.8125rem;
}
.photo-tile:has(img) .photo-hint small { display: none; }

/* --- working ----------------------------------------------------------- */

.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.5s; } }

.working-text { font-weight: 600; margin: 0; }

/* --- review ------------------------------------------------------------ */

.review-images {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  margin-bottom: 14px;
}
.review-images img {
  height: 120px;
  width: auto;
  border-radius: 10px;
  background: var(--surface);
}

/* --- done -------------------------------------------------------------- */

.done-mark {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--ok);
  position: relative;
}
.done-mark::after {
  content: "";
  position: absolute;
  left: 23px;
  top: 14px;
  width: 14px;
  height: 26px;
  border: solid #fff;
  border-width: 0 5px 5px 0;
  transform: rotate(45deg);
}
.done-mark.failed { background: var(--error); }
.done-mark.failed::after {
  content: "!";
  inset: 0;
  width: auto;
  height: auto;
  border: 0;
  transform: none;
  color: #fff;
  font-size: 40px;
  font-weight: 800;
  line-height: 64px;
  text-align: center;
}

.status-list {
  list-style: none;
  margin: 4px 0 8px;
  padding: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}
.status-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 12px;
  font-size: 0.9375rem;
}
.status-list .ok { color: var(--ok); font-weight: 600; }
.status-list .failed { color: var(--error); font-weight: 600; }
.status-list .skipped, .status-list .pending { color: var(--muted); }
.status-list .detail { display: block; color: var(--error); font-size: 0.8125rem; margin-top: 4px; }

.error { color: var(--error); margin: 0; font-size: 0.9375rem; }

/* --- event dialog ------------------------------------------------------ */

dialog {
  width: min(92vw, 420px);
  border: 0;
  border-radius: 18px;
  padding: 20px;
  background: var(--surface);
  color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog input { background: var(--bg); }
