:root {
  color-scheme: light;
  --ink: #17201d;
  --muted: #68736e;
  --line: #d9dfdb;
  --paper: #ffffff;
  --page: #f5f7f4;
  --green: #167a59;
  --green-dark: #105d45;
  --green-soft: #e1f0e9;
  --amber: #b9720d;
  --amber-soft: #fff2dc;
  --red: #b74236;
  --blue: #2879c8;
}

* { box-sizing: border-box; }
html { background: var(--page); }
body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .62; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin-top: 0; }

.topbar {
  max-width: 720px;
  min-height: 82px;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}
.brand { grid-column: 2; }
.brand:first-child { grid-column: 1 / 3; }
.eyebrow, .section-label { margin: 0 0 3px; color: var(--muted); font-size: 12px; font-weight: 650; }
h1 { margin-bottom: 0; font-size: 23px; line-height: 1.2; }
h2 { margin-bottom: 8px; font-size: 20px; line-height: 1.3; }
.version { color: var(--green); border: 1px solid #a8d3c3; padding: 5px 8px; font-size: 12px; border-radius: 4px; }
main { max-width: 720px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }
.view { display: none; }
.view.active { display: block; }

.action-band {
  min-height: 176px;
  margin: 0 -16px;
  padding: 28px 24px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  background: #e3ece6;
  border-top: 1px solid #d4ded7;
  border-bottom: 1px solid #d4ded7;
}
.action-band h2 { font-size: 24px; }
.action-band p:not(.section-label) { max-width: 340px; margin: 0; color: #53615a; font-size: 14px; line-height: 1.65; }
.recognition-band { padding: 24px 0 20px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.section-heading.slim h2 { margin-bottom: 0; font-size: 17px; }
.count-chip { padding: 5px 8px; color: #50605a; background: #e8ece9; border-radius: 4px; font-size: 12px; }

.primary-button, .secondary-button {
  min-height: 50px;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 700;
}
.primary-button { color: white; background: var(--green); border: 1px solid var(--green); box-shadow: 0 3px 9px #146f511c; }
.primary-button:active { background: var(--green-dark); }
.primary-button.compact { width: auto; min-width: 104px; }
.secondary-button { color: var(--ink); background: white; border: 1px solid #cbd4ce; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; margin: 12px 0 16px; padding: 3px; background: #e6eae7; border-radius: 6px; }
.segmented label { min-width: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { min-height: 40px; display: grid; place-items: center; color: #5d6963; border-radius: 4px; font-size: 14px; font-weight: 650; }
.segmented input:checked + span { color: var(--ink); background: white; box-shadow: 0 1px 4px #26352d1b; }

.form-field, .field-row label, .select-field, .note-field { display: block; color: var(--muted); font-size: 12px; }
.form-field { margin-bottom: 15px; }
.model-picker { margin-bottom: 10px; }
input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  min-height: 44px;
  margin-top: 6px;
  padding: 10px 11px;
  color: var(--ink);
  background: white;
  border: 1px solid #cbd4ce;
  border-radius: 4px;
  outline: none;
}
textarea { min-height: 68px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 2px #167a5917; }
.selected-model-meta { margin: -2px 0 14px; color: var(--muted); font-size: 12px; }

.model-library { padding: 22px 0 4px; }
.model-list { margin-top: 10px; border-top: 1px solid var(--line); }
.model-row { min-height: 72px; padding: 10px 0; display: grid; grid-template-columns: 52px 1fr auto; gap: 11px; align-items: center; border-bottom: 1px solid var(--line); }
.model-row img { width: 52px; height: 52px; object-fit: cover; background: #d9ddda; border-radius: 4px; }
.model-row div { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.model-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.model-row span { color: var(--muted); font-size: 11px; line-height: 1.4; }
.model-row button { min-width: 54px; height: 34px; color: var(--green); background: white; border: 1px solid #b9cec3; border-radius: 4px; font-size: 12px; font-weight: 700; }

.capture-view.active { display: flex; }
.capture-view {
  position: fixed;
  inset: 0;
  z-index: 50;
  flex-direction: column;
  background: #101513;
  color: white;
  padding-bottom: env(safe-area-inset-bottom);
}
.capture-toolbar {
  min-height: calc(74px + env(safe-area-inset-top));
  padding: max(14px, env(safe-area-inset-top)) 14px 10px;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  align-items: center;
  background: #111715;
}
.capture-toolbar > div { min-width: 0; }
.capture-toolbar strong, .capture-toolbar small { display: block; }
.capture-toolbar strong { font-size: 15px; }
.capture-toolbar small { margin-top: 3px; overflow: hidden; color: #aeb8b3; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.camera-close { width: 38px; height: 38px; color: white; background: transparent; border: 0; font-size: 29px; line-height: 1; }
.coin-selector { color: #aeb8b3; font-size: 10px; text-align: right; }
.coin-selector select { width: 104px; min-height: 34px; margin-top: 3px; padding: 5px 7px; color: white; background: #242d29; border-color: #3c4742; font-size: 11px; }

.camera-frame { position: relative; width: 100%; max-height: calc(100vh - 164px); aspect-ratio: 3 / 4; margin: auto; overflow: hidden; background: #202824; }
.camera-frame video { width: 100%; height: 100%; display: block; object-fit: cover; }
.camera-placeholder { position: absolute; inset: 0; display: grid; place-items: center; padding: 30px; color: #bac3bf; background: #202824; text-align: center; font-size: 13px; line-height: 1.6; }
.coin-target { position: absolute; left: 11%; top: 68%; width: 18%; aspect-ratio: 1; display: grid; place-items: center; border: 2px dashed #f2f4f2d1; border-radius: 50%; box-shadow: 0 0 0 999px #07100a28; }
.coin-target span { color: white; font-size: clamp(11px, 3vw, 16px); font-weight: 750; text-shadow: 0 1px 3px #000; }
.object-target { position: absolute; left: 35%; top: 12%; width: 57%; height: 72%; border: 1px dashed #ffffff77; border-radius: 6px; }
.object-target.single { left: 44%; top: 31%; width: 34%; height: 28%; border-radius: 50%; }
.object-target span { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); color: #ffffffc4; font-size: 12px; text-shadow: 0 1px 3px #000; white-space: nowrap; }
.capture-status { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); max-width: 82%; padding: 8px 11px; color: white; background: #151d1ad9; border-radius: 4px; font-size: 12px; text-align: center; white-space: nowrap; }
.capture-status.ready { background: #0e6549e8; }
.auto-progress { position: absolute; left: 50%; bottom: 54px; transform: translateX(-50%); display: flex; gap: 5px; }
.auto-progress i { width: 7px; height: 7px; background: #ffffff58; border-radius: 50%; }
.auto-progress i.active { background: #55d2a6; }

.camera-actions { min-height: 88px; padding: 11px 25px; display: grid; grid-template-columns: 1fr 74px 1fr; align-items: center; background: #111715; }
.gallery-button, .auto-button { justify-self: center; min-width: 62px; min-height: 38px; display: grid; place-items: center; color: #dbe1de; background: transparent; border: 0; font-size: 13px; }
.auto-button { border: 1px solid #4e5b55; border-radius: 4px; }
.auto-button.active { color: #69ddb4; border-color: #2d8a69; }
.shutter-button { width: 66px; height: 66px; display: grid; place-items: center; background: transparent; border: 3px solid white; border-radius: 50%; }
.shutter-button span { width: 52px; height: 52px; background: white; border-radius: 50%; }

.loading-view, .done-view { text-align: center; padding: 94px 24px; }
.spinner { width: 46px; height: 46px; margin: 0 auto 22px; border: 4px solid #d9e3dd; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-view p, .done-view p, .form-head p:last-child { color: var(--muted); font-size: 14px; line-height: 1.6; }

.result-head { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 10px; margin-bottom: 14px; }
.result-head h2 { margin: 0; font-size: 27px; }
.nav-icon { width: 40px; height: 40px; color: var(--ink); background: transparent; border: 0; font-size: 31px; line-height: 1; }
.nav-icon.boxed, .danger-icon { border: 1px solid var(--line); background: white; border-radius: 5px; }
.confidence-badge { max-width: 104px; padding: 6px 8px; color: #85540f; background: var(--amber-soft); border-radius: 4px; font-size: 12px; font-weight: 700; text-align: center; }
.confidence-badge.stable { color: #126447; background: #dff0e9; }
.warning-box { margin-bottom: 12px; padding: 11px 12px; color: #70470d; background: #fff5e5; border-left: 3px solid var(--amber); font-size: 13px; line-height: 1.5; }
.canvas-shell { position: relative; min-height: 220px; background: #d8ddda; overflow: hidden; border-radius: 6px; touch-action: manipulation; }
.canvas-shell img { width: 100%; height: auto; display: block; }
.canvas-shell canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.canvas-tip { position: absolute; left: 50%; bottom: 9px; transform: translateX(-50%); width: max-content; max-width: 92%; padding: 6px 9px; overflow: hidden; color: white; background: #111b18cf; border-radius: 4px; font-size: 11px; pointer-events: none; text-overflow: ellipsis; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; padding: 11px 2px; color: var(--muted); font-size: 11px; }
.dot { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; }
.dot.certain { background: var(--green); }
.dot.uncertain { background: var(--amber); }
.dot.selected { background: var(--blue); }
.grid-toggle { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.grid-toggle input { accent-color: var(--green); }

.editor { padding: 15px; background: white; border: 1px solid var(--line); border-radius: 6px; }
.editor-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.editor-title h3 { margin: 0; font-size: 18px; }
.danger-icon { width: 40px; height: 40px; color: var(--red); font-size: 24px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.select-field { margin-top: 11px; }
.confirm-row { margin-top: 13px; display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 13px; }
.confirm-row input { width: 19px; height: 19px; accent-color: var(--green); }
.note-field { margin-top: 15px; }
.button-element { margin-top: 14px; }
.text-button { display: block; margin: 15px auto 0; padding: 9px 16px; color: var(--green); background: none; border: 0; }

.reference-actions { margin-top: 15px; padding-top: 15px; border-top: 1px solid var(--line); }
.reference-actions p { margin-bottom: 12px; display: flex; justify-content: space-between; gap: 10px; align-items: center; font-size: 13px; }
.reference-actions p span { color: var(--muted); font-size: 11px; text-align: right; }
.dual-actions { display: grid; grid-template-columns: 1fr 1.35fr; gap: 10px; }

.model-form-view { padding-bottom: 20px; }
.form-head { padding: 4px 0 10px; }
.form-head h2 { margin-bottom: 4px; font-size: 25px; }
.sample-strip { margin: 4px -16px 20px; padding: 0 16px 12px; display: flex; gap: 9px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.sample-strip figure { flex: 0 0 92px; margin: 0; }
.sample-strip img { width: 92px; height: 92px; display: block; object-fit: cover; background: #d9ddda; border-radius: 5px; }
.sample-strip figcaption { margin-top: 5px; color: var(--muted); font-size: 11px; text-align: center; }

.done-mark { width: 58px; height: 58px; margin: 0 auto 20px; display: grid; place-items: center; color: white; background: var(--green); border-radius: 50%; font-size: 28px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 80; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; width: max-content; max-width: 86%; padding: 10px 14px; overflow-wrap: anywhere; color: white; background: #17201ded; border-radius: 5px; font-size: 13px; text-align: center; transition: .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 390px) {
  .action-band { grid-template-columns: 1fr; gap: 16px; }
  .primary-button.compact { width: 100%; }
  .capture-toolbar { grid-template-columns: 36px 1fr 96px; padding-left: 8px; padding-right: 8px; }
  .coin-selector select { width: 94px; }
  .reference-actions p { align-items: flex-start; flex-direction: column; gap: 3px; }
  .reference-actions p span { text-align: left; }
}

@media (min-width: 720px) {
  main { padding-left: 0; padding-right: 0; }
  .action-band { margin-left: 0; margin-right: 0; border: 1px solid #d4ded7; border-radius: 6px; }
  .capture-view { align-items: center; }
  .capture-toolbar, .camera-frame, .camera-actions { width: min(100%, 540px); }
  .camera-frame { max-height: calc(100vh - 170px); }
}
