:root {
  --bg: #f4f4f6;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e2e2e6;
  --accent: #e3350d;
  --accent-text: #ffffff;
  --good: #1a7f37;
  --warn-bg: #fff4d6;
  --warn-text: #7a5300;
  --chip: #ececf0;
  --radius: 14px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #111113;
  --surface: #1c1c1f;
  --text: #f2f2f4;
  --muted: #9a9aa2;
  --line: #2e2e33;
  --good: #4ac26b;
  --warn-bg: #3a2f10;
  --warn-text: #f3cf6b;
  --chip: #2a2a2f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.top-right { display: flex; align-items: center; gap: 8px; }
.theme-btn { border: 0; background: var(--chip); color: var(--text); width: 34px; height: 34px; border-radius: 50%; font-size: 1rem; cursor: pointer; }
.top h1 { margin: 0; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.top nav { display: flex; gap: 4px; background: var(--chip); padding: 3px; border-radius: 999px; }
.tab { border: 0; background: none; color: var(--text); font: inherit; font-size: 0.9rem; padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.tab.active { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.15); font-weight: 600; }

main { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 10px 18px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.secondary { background: var(--chip); color: var(--text); }
.btn:disabled { opacity: .5; cursor: default; }

/* Photo */
.capture { display: grid; justify-items: center; gap: 18px; padding: 28px 16px; background: var(--surface); border-radius: var(--radius); cursor: pointer; }
.capture-card {
  width: 128px; aspect-ratio: 63 / 88; border-radius: 10px; border: 3px dashed var(--line);
  background: var(--chip) url("/favicon.svg") center / 44px no-repeat;
}
.capture-btn { background: var(--accent); color: var(--accent-text); font-weight: 700; padding: 14px 24px; border-radius: 999px; font-size: 1.05rem; }
.capture:active .capture-btn { transform: scale(.97); }
.cam-actions { display: flex; justify-content: center; gap: 12px; margin: 14px 0 0; }
.hint { text-align: center; color: var(--muted); font-size: 0.85rem; margin: 12px 0 0; }

/* Result */
.panel { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.loading { text-align: center; padding: 24px 16px; }
.loading img { max-height: 260px; border-radius: 10px; opacity: .8; }
.spinner { width: 28px; height: 28px; margin: 12px auto; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.pair figure { margin: 0; text-align: center; }
.pair img { border-radius: 10px; width: 100%; aspect-ratio: 63 / 88; object-fit: contain; background: var(--chip); }
.pair figcaption { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }

.card-title { margin: 0; font-size: 1.35rem; }
.card-title small { color: var(--muted); font-weight: 400; font-size: 1rem; }
.meta { margin: 4px 0 12px; color: var(--muted); }
.badge { display: inline-block; background: var(--chip); color: var(--text); border-radius: 6px; padding: 1px 7px; font-size: 0.78rem; font-weight: 600; vertical-align: middle; }
.warn { background: var(--warn-bg); color: var(--warn-text); border-radius: 10px; padding: 8px 12px; font-size: 0.9rem; margin: 0 0 12px; }

.price-main { font-size: 2rem; font-weight: 700; margin: 8px 0 2px; }
.price-sub { color: var(--muted); font-size: 0.85rem; margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 0.88rem; cursor: pointer; }
.chip.on { background: var(--text); color: var(--surface); border-color: var(--text); }

table.prices { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-bottom: 12px; }
.prices th, .prices td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; }
.prices th:first-child, .prices td:first-child { text-align: left; }
.prices th { color: var(--muted); font-weight: 500; }

.add-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.stepper { display: inline-flex; align-items: center; background: var(--chip); border-radius: 999px; }
.stepper button { border: 0; background: none; color: var(--text); font: inherit; font-size: 1.1rem; width: 36px; height: 36px; cursor: pointer; }
.stepper span { min-width: 22px; text-align: center; font-weight: 600; }
.added { color: var(--good); font-weight: 600; }

p.reading { margin: 10px 0 0; font-size: 0.8rem; }
details.read { margin-top: 14px; font-size: 0.88rem; }
details.read summary { cursor: pointer; color: var(--muted); }
details.read dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 8px 0 0; }
details.read dt { color: var(--muted); }
details.read dd { margin: 0; }

h3 { font-size: 1rem; margin: 0 0 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.cand { border: 0; background: none; padding: 0; text-align: left; color: var(--text); font: inherit; cursor: pointer; }
.cand img, .cand .noimg { width: 100%; aspect-ratio: 63 / 88; object-fit: contain; border-radius: 8px; background: var(--chip); display: block; }
.cand .noimg { display: grid; place-items: center; font-size: 0.75rem; color: var(--muted); padding: 6px; text-align: center; }
.cand span { display: block; font-size: 0.75rem; line-height: 1.25; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cand.current img { outline: 3px solid var(--accent); }

.search-form { display: grid; grid-template-columns: 1fr 90px; gap: 8px; margin-bottom: 12px; }
.search-form select, .search-form button { grid-column: span 1; }
input, select {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; min-width: 0;
}
.actions-bottom { display: flex; justify-content: center; margin: 8px 0 24px; }

/* Collection */
.coll-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.coll-total { font-size: 1.8rem; font-weight: 700; }
.coll-tools { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 12px; }
.coll-tools select { width: auto; }
.coll-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item { display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; align-items: center; background: var(--surface); border-radius: 12px; padding: 8px 12px 8px 8px; }
.item img, .item .noimg { width: 52px; aspect-ratio: 63 / 88; object-fit: contain; border-radius: 5px; background: var(--chip); }
.item-name { font-weight: 600; line-height: 1.2; }
.item-sub { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.item-right { text-align: right; display: grid; gap: 4px; justify-items: end; }
.item-price { font-weight: 700; }
.item .stepper button { width: 28px; height: 28px; font-size: 1rem; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { background: var(--surface); padding: 28px 24px; border-radius: var(--radius); width: min(340px, 100%); display: grid; gap: 12px; text-align: center; justify-items: center; }
.login h1 { margin: 0 0 6px; font-size: 1.3rem; }
.login .btn { width: 100%; }
.error { color: var(--accent); margin: 0; font-size: 0.9rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 999px; font-size: 0.9rem; z-index: 50;
  max-width: calc(100% - 32px);
}

@media (max-width: 400px) {
  .top h1 span { display: none; }
}
