/* Binder. Phone first: every layout starts at 360px wide and widens from there. */
:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #1c1b19; --muted: #625f58; --line: #e2dfd8;
  --accent: #1f5fbf; --accent-ink: #ffffff; --ok: #1d7a3e; --bad: #b3261e; --warn: #8a5a00;
  --radius: 10px; --gap: 12px; --tap: 44px;
  --tabbar: calc(60px + env(safe-area-inset-bottom));
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211; --panel: #1c1c1a; --ink: #ecebe7; --muted: #a8a59d; --line: #2f2e2b;
    --accent: #7aa9f2; --accent-ink: #0d1420; --ok: #62c486; --bad: #f08a80; --warn: #e2b458;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: var(--tabbar); -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
main { max-width: 900px; margin: 0 auto; padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
  padding-top: calc(12px + env(safe-area-inset-top)); }
h1 { font-size: 24px; line-height: 1.2; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 24px 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Bottom tab bar: thumb reach on phones, stays put on desktop too. */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center;
  background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; max-width: 120px; min-height: 60px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600; }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.on { color: var(--ink); }
.tabbar a.scan { color: var(--accent-ink); }
.tabbar a.scan span.dot { width: 52px; height: 52px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center; margin-top: -18px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18); }
.tabbar a.scan.on span.dot { outline: 3px solid var(--ink); outline-offset: 2px; }
.tabbar a.scan small { color: var(--muted); }

/* Top of page: title with an optional action on the right. */
.pagehead { display: flex; align-items: center; gap: 8px; }
.pagehead h1 { flex: 1; margin: 4px 0; }

/* Controls: 44px tap targets, 16px text so iOS Safari never zooms on focus. */
input, select, textarea, button, .btn { font: inherit; font-size: 16px; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); min-height: var(--tap); padding: 9px 12px; }
textarea { width: 100%; min-height: 160px; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
button, .btn { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600;
  text-decoration: none; }
button.quiet, .btn.quiet { background: transparent; color: var(--ink); border-color: var(--line); }
button.danger, .btn.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button.block, .btn.block { width: 100%; }
.searchbar { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: 8px 0; display: flex; gap: 8px; }
.searchbar input { flex: 1; min-width: 0; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips select { flex: 0 0 auto; min-height: 38px; padding: 6px 10px; border-radius: 999px; font-size: 14px; }
.stats { display: flex; gap: 14px; margin: 2px 0 10px; color: var(--muted); font-size: 14px; flex-wrap: wrap; }
.stats b { color: var(--ink); }

/* Card rows: image, text, trailing value. The main list pattern on every page. */
.list { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; }
.list > li { border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list .rowlink, .list .rowbody { display: flex; align-items: center; gap: 12px; padding: 10px 12px; color: var(--ink);
  min-height: 64px; }
.list .rowlink:active { background: var(--bg); }
.list .thumb { width: 44px; height: 61px; object-fit: cover; border-radius: 4px; flex: 0 0 auto; background: var(--line); }
.list .main { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.list .main > * { max-width: 100%; }
.list .title, .list .sub { display: block; }
.list .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .trail { text-align: right; flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.list .qty { font-weight: 700; font-size: 17px; }
.list input[type=checkbox] { width: 24px; height: 24px; flex: 0 0 auto; }

.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  border: 1px solid currentColor; white-space: nowrap; }
.tag.ok { color: var(--ok); }
.tag.bad { color: var(--bad); }
.tag.plain { color: var(--muted); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.note { padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel);
  margin: 8px 0; }
.note.ok { border-color: var(--ok); }
.note.bad { border-color: var(--bad); }
.note ul { margin: 6px 0 0; padding-left: 20px; }
.err { color: var(--bad); }

/* Forms laid out as stacked fields; two columns where it fits. */
.form { display: grid; gap: 10px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.form input, .form select { width: 100%; }
.seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg label { flex: 1; display: block; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: var(--tap); font-size: 14px;
  font-weight: 600; color: var(--muted); background: var(--panel); border-right: 1px solid var(--line); }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--ink); color: var(--bg); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.stepper { display: flex; align-items: stretch; }
.stepper button { width: var(--tap); padding: 0; border-radius: 0; background: var(--panel); color: var(--ink);
  border-color: var(--line); }
.stepper button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.stepper button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.stepper input { width: 64px; text-align: center; border-radius: 0; border-left: 0; border-right: 0; }

/* Bottom sheet built on <dialog>. */
dialog.sheet { margin: auto auto 0; width: 100%; max-width: 560px; border: 0; padding: 16px 16px
  calc(16px + env(safe-area-inset-bottom)); border-radius: 16px 16px 0 0; background: var(--panel); color: var(--ink); }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); }
dialog.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: -6px auto 12px; }
dialog.sheet h2 { margin-top: 0; }

/* Search results. */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid .item { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px;
  display: flex; flex-direction: column; gap: 6px; }
.grid img { width: 100%; aspect-ratio: 63 / 88; object-fit: cover; border-radius: 6px; display: block;
  background: var(--line); }
.grid .name { font-weight: 600; font-size: 14px; line-height: 1.25; }

/* Card detail. */
.detail { display: grid; gap: 16px; }
.detail img.big { width: auto; max-width: 100%; max-height: 46vh; border-radius: 12px; display: block; margin: 0 auto; }
.facts { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.attack { border-top: 1px solid var(--line); padding: 10px 0; }
.attack .head { display: flex; gap: 8px; align-items: baseline; }
.attack .head b:first-child { flex: 1; }
.actions { position: sticky; bottom: var(--tabbar); display: flex; gap: 8px; margin: 12px -16px; padding: 10px 16px;
  z-index: 5; background: var(--bg); border-top: 1px solid var(--line); }
.actions > * { flex: 1; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; font-size: 14px; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.login { max-width: 360px; margin: 14vh auto; }
.login input { width: 100%; margin: 8px 0 12px; }

@media (min-width: 640px) {
  .detail img.big { max-height: none; }
  .actions { margin: 16px 0; padding: 0; border-top: 0; background: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
  .detail { grid-template-columns: 320px 1fr; align-items: start; }
  .actions { position: static; }
}
@media (prefers-reduced-motion: no-preference) {
  .list .rowlink, button, .btn { transition: background-color .12s ease; }
}
