:root {
  --bg: #14121f;
  --panel: #1f1c30;
  --line: #34304d;
  --text: #ecebf5;
  --muted: #a19dbb;
  --accent: #f2b632;
  --accent-ink: #1b1400;
  --good: #5bd69a;
  --bad: #ff7a7a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

header, main, footer { max-width: 560px; margin: 0 auto; }

header { text-align: center; padding: 20px 0 8px; }
header h1 { margin: 0; font-size: 2rem; letter-spacing: .02em; }
header h1 span { color: var(--accent); }
header p { margin: 4px 0 0; color: var(--muted); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin: 14px 0;
}

/* Scanner */
.viewfinder {
  position: relative;
  aspect-ratio: 3 / 4;
  max-height: 70vh;
  margin: 0 auto;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}
.viewfinder video, .viewfinder img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.viewfinder img { object-fit: contain; background: #000; }

/* Card-shaped guide; zone percentages mirror REGIONS in app.js */
.guide {
  position: absolute;
  top: 50%; left: 50%;
  height: 90%;
  aspect-ratio: 59 / 86;
  max-width: 94%;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 255, 255, .85);
  border-radius: 4%;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
}
.guide { transition: border-color .2s; }
.guide.reading .zone { border-color: #fff; }
.guide.found { border-color: var(--good); }
.guide.found .zone { border-color: var(--good); }
.zone { position: absolute; border: 2px dashed var(--accent); border-radius: 4px; }
.zone-name { left: 5%; width: 78%; top: 4.5%; height: 8%; }
.zone-code { left: 48%; width: 48%; top: 69%; height: 8%; }

.live-result {
  position: absolute; left: 10px; right: 10px; bottom: 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: rgba(20, 18, 31, .92);
  border: 1px solid var(--good);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: left;
  font-weight: 500;
}
.live-result span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-result strong { color: var(--good); font-size: 1.3rem; }

.placeholder {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  text-align: center; color: var(--muted);
  padding: 20px;
}

.actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.actions > * { flex: 1 1 140px; }

button, .button {
  appearance: none;
  border: 1px solid var(--line);
  background: #2a2640;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:disabled { opacity: .6; cursor: progress; }
button.link { background: none; border: none; color: var(--muted); padding: 4px; font-weight: 500; }

.status { min-height: 1.4em; margin: 10px 0 0; color: var(--muted); font-size: .95rem; }
.status.error { color: var(--bad); }

/* Lookup form */
.lookup { display: grid; gap: 12px; }
.lookup label { display: grid; gap: 4px; font-weight: 600; }
.lookup small { font-weight: 400; color: var(--muted); }
input, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: #15131f;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Result */
.result-top { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: start; }
.result-top img { width: 100%; border-radius: 6px; }
.result h2 { margin: 0 0 4px; font-size: 1.2rem; }
.meta { color: var(--muted); font-size: .9rem; margin: 0; }
.price-big { font-size: 2.2rem; font-weight: 800; color: var(--good); margin: 8px 0 0; line-height: 1.1; }
.price-label { color: var(--muted); font-size: .85rem; }
.printing { margin-top: 12px; display: grid; gap: 4px; }
.printing label { font-size: .85rem; color: var(--muted); }

table { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: .95rem; }
th, td { text-align: left; padding: 7px 4px; border-bottom: 1px solid var(--line); }
td:last-child, th:last-child { text-align: right; font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-weight: 500; }

details { margin-top: 12px; }
summary { cursor: pointer; color: var(--muted); }
.sets { max-height: 280px; overflow: auto; }
.sets tr.match td { color: var(--accent); }

.links { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.links a, .result .add {
  flex: 1 1 120px;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: .9rem;
}
.result .add { width: 100%; margin-top: 12px; background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.choices { display: grid; gap: 8px; margin-top: 10px; }
.choices button { text-align: left; font-weight: 500; }

/* List */
.list-head { display: flex; justify-content: space-between; align-items: center; }
.list-head h2 { margin: 0; font-size: 1.1rem; }
#list { list-style: none; padding: 0; margin: 8px 0 0; }
#list li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
#list li span:first-child { flex: 1; min-width: 0; }
#list li small { display: block; color: var(--muted); }
#list li .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.total { text-align: right; margin: 10px 0 0; font-size: 1.1rem; }

footer { color: var(--muted); font-size: .8rem; text-align: center; padding: 8px 0 28px; }
footer a { color: var(--muted); }
