:root {
  --bg: #f3f5f1;
  --surface: #ffffff;
  --ink: #142019;
  --ink-muted: #5a6960;
  --line: #d9ddd4;
  --green: #1f7a4d;
  --green-deep: #123f28;
  --green-tint: #e6f2ea;
  --red: #b3261e;
  --red-tint: #fbe9e8;
  --amber: #a86400;
  --radius: 14px;
  --tap: 48px;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

h1, h2, legend { font-family: var(--sans); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px calc(14px + env(safe-area-inset-top)) 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--green-deep);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar__mark {
  width: 10px; height: 28px;
  background: var(--green);
  border-radius: 2px;
  flex-shrink: 0;
}
.topbar__title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.02em;
  margin: 0;
  flex: 1;
}
.topbar__standard {
  font-family: var(--mono);
  font-size: 11px;
  opacity: 0.75;
  letter-spacing: 0.03em;
}

/* ---------- Layout ---------- */
#app { max-width: 640px; margin: 0 auto; padding: 16px; }
.view[hidden] { display: none; }

/* ---------- Tag number banner ---------- */
.tagnum {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  background: var(--green-deep);
  color: #fff;
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
}
.tagnum__label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.8;
}
.tagnum__value {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
}

/* ---------- Form groups ---------- */
.group {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 16px;
  margin: 0 0 14px;
}
.group legend {
  padding: 0 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}

.field { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.field > span { font-size: 13px; color: var(--ink-muted); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

input[type="text"],
input[type="number"],
input[type="date"],
input[type="search"],
textarea {
  font-family: var(--sans);
  font-size: 16px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  width: 100%;
  min-height: var(--tap);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus, button:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 1px;
}

/* ---------- Segmented controls ---------- */
.segmented {
  display: flex;
  gap: 8px;
}
.segmented__opt {
  flex: 1;
  min-height: var(--tap);
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-muted);
}
.segmented__opt.is-selected {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.segmented--pf .segmented__opt--pass.is-selected { background: var(--green); border-color: var(--green); }
.segmented--pf .segmented__opt--fail.is-selected { background: var(--red); border-color: var(--red); }

/* ---------- Test rows ---------- */
.test-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  margin-top: 12px;
}
.test-row:first-of-type { border-top: none; margin-top: 4px; padding-top: 4px; }
.test-row__label { font-size: 14px; font-weight: 600; }
.test-row__value { font-family: var(--mono); }

/* ---------- Photo input ---------- */
.photo-input {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  border: 2px dashed var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink-muted);
  font-size: 14px;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}
.photo-input input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer;
}
.photo-input img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 8px;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 700;
  border-radius: 10px;
  border: none;
  min-height: var(--tap);
  padding: 0 18px;
  cursor: pointer;
}
.btn--primary { background: var(--green); color: #fff; }
.btn--primary:active { background: var(--green-deep); }
.btn--block { width: 100%; }
.btn--ghost { background: transparent; color: var(--green-deep); padding-left: 4px; }

.form-error {
  background: var(--red-tint);
  color: var(--red);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  margin: 0 0 12px;
}

/* ---------- Tag guide (signature element) ---------- */
.guide-intro { color: var(--ink-muted); font-size: 14px; margin-bottom: 14px; }
.tag-guide {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  border-left: 10px solid var(--green);
  padding: 18px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.tag-guide__pair { display: flex; gap: 14px; }
.tag-guide__pair .tag-guide__field { flex: 1; }
.tag-guide__field { display: flex; flex-direction: column; gap: 4px; }
.tag-guide__label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}
.tag-guide__value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
}
.guide-result {
  margin: 16px 0;
  font-weight: 700;
  text-align: center;
  border-radius: 10px;
  padding: 10px;
}
.guide-result.is-pass { background: var(--green-tint); color: var(--green-deep); }
.guide-result.is-fail { background: var(--red-tint); color: var(--red); }

/* ---------- History ---------- */
.search-bar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.entry-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.entry-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 8px solid var(--green);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
}
.entry-card.is-fail { border-left-color: var(--red); }
.entry-card__id { font-family: var(--mono); font-weight: 700; font-size: 13px; color: var(--ink-muted); min-width: 34px; }
.entry-card__body { flex: 1; min-width: 0; }
.entry-card__desc { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-card__meta { font-size: 12px; color: var(--ink-muted); font-family: var(--mono); }
.entry-card__thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex-shrink: 0; background: var(--bg); }
.empty-state { color: var(--ink-muted); text-align: center; padding: 40px 0; }

/* ---------- Detail ---------- */
#detail-content .tag-guide { margin-top: 14px; }
.detail-photo { width: 100%; border-radius: 12px; margin-top: 14px; }
.detail-notes { margin-top: 14px; font-size: 14px; line-height: 1.5; }

/* ---------- Settings ---------- */
.save-confirm { color: var(--green-deep); font-size: 13px; margin-top: 8px; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tabbar__btn {
  flex: 1;
  min-height: 56px;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-muted);
}
.tabbar__btn.is-active { color: var(--green-deep); }

@media (prefers-reduced-motion: no-preference) {
  .view { animation: fade 0.15s ease-out; }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
