:root {
  --accent: #1a5fb4;
  --bg: #f6f7f9;
  --card: #fff;
  --text: #1d1f23;
  --muted: #646a73;
  --border: #d9dce1;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #78aeed;
    --bg: #17181b;
    --card: #222428;
    --text: #e8e9eb;
    --muted: #9aa0a8;
    --border: #3a3d43;
  }
}

* { box-sizing: border-box; }

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

header { padding: 1rem; text-align: center; }
header h1 { margin: 0; font-size: 1.4rem; }

main { max-width: 640px; margin: 0 auto; padding: 0 1rem 2rem; }

#search-form { display: flex; gap: .5rem; }
#search-form input { flex: 1; min-width: 0; }

input, button {
  font: inherit;
  padding: .6rem .75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}

button { cursor: pointer; }
button[type="submit"], #scan-btn { background: var(--accent); color: #fff; border-color: var(--accent); }

.hint { color: var(--muted); font-size: .85rem; }
.hint a { color: inherit; }

#scanner { margin: 1rem 0; text-align: center; }
#scanner video { width: 100%; max-height: 50vh; border-radius: 8px; background: #000; object-fit: cover; }

#status { min-height: 1.2em; color: var(--muted); }
#status.error { color: #c01c28; }

#results { list-style: none; padding: 0; margin: 0; }
#results li {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem; margin-bottom: .5rem;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer;
}
#results img, .detail-head img { width: 48px; height: 48px; object-fit: contain; border-radius: 4px; background: #fff; }
#results .info { flex: 1; min-width: 0; }
#results .name { font-weight: 600; }
#results .meta { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  min-width: 3rem; text-align: center; font-weight: 700;
  padding: .3rem .5rem; border-radius: 999px; background: var(--accent); color: #fff;
}
.badge.na { background: var(--border); color: var(--muted); }
.badge small { display: block; font-weight: 400; font-size: .65rem; }

#detail {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 1rem; margin-bottom: 1rem;
}
.detail-head { display: flex; gap: .75rem; align-items: center; }
.detail-head img { width: 72px; height: 72px; }
.detail-head h2 { margin: 0; font-size: 1.15rem; }
.detail-head p { margin: .2rem 0 0; color: var(--muted); font-size: .9rem; }

.points-box { text-align: center; margin: 1rem 0; }
#d-points { display: block; font-size: 3rem; font-weight: 700; color: var(--accent); line-height: 1; }

label { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin: .4rem 0; }
label input { width: 8rem; text-align: right; }
.amount { font-weight: 600; }

.presets { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem; }
.presets button { padding: .3rem .6rem; font-size: .85rem; }

fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0 0 .75rem; }
legend { color: var(--muted); font-size: .9rem; }

.warn { color: #c64600; font-size: .9rem; }

.actions { display: flex; gap: .5rem; justify-content: space-between; flex-wrap: wrap; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }

#full h2 { margin: 1rem 0 .5rem; font-size: 1.25rem; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: .75rem 1rem; margin-bottom: 1rem;
}
.card h3 { margin: 0 0 .5rem; font-size: 1rem; }

.gallery { display: flex; gap: .5rem; overflow-x: auto; margin-bottom: 1rem; }
.gallery a { flex: 0 0 auto; text-align: center; color: var(--muted); font-size: .75rem; text-decoration: none; }
.gallery img { display: block; height: 110px; border-radius: 6px; background: #fff; margin-bottom: .2rem; }

dl.kv { display: grid; grid-template-columns: minmax(7rem, 35%) 1fr; gap: .35rem .75rem; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .9rem; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip { padding: .1rem .5rem; border-radius: 999px; border: 1px solid var(--border); font-size: .85rem; }

#f-nutrition { width: 100%; border-collapse: collapse; font-size: .9rem; }
#f-nutrition th, #f-nutrition td { padding: .3rem .25rem; border-bottom: 1px solid var(--border); }
#f-nutrition th { text-align: left; color: var(--muted); font-weight: 500; }
#f-nutrition td:not(:first-child), #f-nutrition th:not(:first-child) { text-align: right; white-space: nowrap; }

.raw summary { cursor: pointer; color: var(--muted); }
.raw pre { max-height: 60vh; overflow: auto; font-size: .75rem; white-space: pre-wrap; overflow-wrap: anywhere; }
