:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --text: #1d1d24;
  --muted: #6b6b78;
  --line: #e2ddd2;
  --accent: #e3350d;
  --accent-ink: #ffffff;
  --ok: #1f9d55;
  --slot: #ebe6da;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15151b;
    --surface: #1f1f28;
    --text: #ededf2;
    --muted: #9a9aab;
    --line: #2e2e3a;
    --slot: #262631;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 82%, transparent); color: var(--text);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 1.2rem; display: flex; align-items: center; gap: 8px; }
.ball {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid #1d1d24; flex: none;
  background:
    radial-gradient(circle, #fff 0 3px, #1d1d24 3px 5px, transparent 5px),
    linear-gradient(#e3350d 0 45%, #1d1d24 45% 55%, #fff 55%);
  box-shadow: 0 0 0 1.5px #fff;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.version-btn {
  position: relative; border: 0; cursor: pointer; font-size: .72rem; font-weight: 800;
  background: var(--slot); color: var(--muted); padding: 3px 8px; border-radius: 999px;
}
.version-btn.unseen::after { /* "new update" dot */
  content: ""; position: absolute; top: -3px; right: -3px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--bg);
}
.changelog h3 { margin: 0 0 12px; }
.changelog section { border-top: 1px solid var(--line); padding: 12px 0 4px; }
.cl-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.cl-version { background: var(--accent); color: var(--accent-ink); font-size: .72rem; font-weight: 800; padding: 1px 7px; border-radius: 999px; }
.cl-head small { color: var(--muted); margin-left: auto; }
.changelog ul { margin: 6px 0 0; padding-left: 20px; }
.changelog li { margin: 4px 0; font-size: .92rem; line-height: 1.4; }

.account-btn {
  border: 1px solid var(--line); background: transparent; color: var(--text);
  border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: .85rem; cursor: pointer;
}
.account-btn.offline { background: #1d1d24; color: #fff; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.tab { display: none; }
.tab.active { display: block; }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.target { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.target label { font-weight: 700; white-space: nowrap; }
.scan { text-align: center; }
.hint { color: var(--muted); font-size: .9rem; margin: 10px 0 0; }
.preview-wrap { margin-top: 12px; }
#preview { max-width: 180px; max-height: 250px; border-radius: 10px; }
.status { margin-top: 10px; font-size: .95rem; min-height: 1.2em; }
.status.error { color: var(--accent); }

.search { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.field { flex: 1 1 180px; display: flex; flex-direction: column; gap: 4px; }
.field.small { flex: 0 1 150px; }
.field label { font-size: .8rem; color: var(--muted); }
input:not([type=checkbox]):not([type=color]), select {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); min-width: 0; width: 100%;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.big { font-size: 1.15rem; padding: 14px 26px; border-radius: 14px; }
.btn.ghost { background: transparent; }
a.btn { color: inherit; }
.btn.danger { color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.linkish { background: none; border: 0; color: var(--accent); cursor: pointer; font-weight: 600; padding: 0; }

.results-head { margin: 16px 0 8px; color: var(--muted); font-size: .9rem; }

/* ---------- card grid: 3 per row on phones, like a 9-pocket binder page ---------- */
.grid { display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }

.tile {
  position: relative; padding: 0; border: 0; background: var(--slot);
  border-radius: 8px; cursor: pointer; aspect-ratio: 63 / 88; overflow: hidden;
  transition: transform .12s ease;
}
.tile:hover { transform: translateY(-2px); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .noimg {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center;
  padding: 6px; font-size: .8rem; text-align: center; color: var(--text);
  border: 2px dashed var(--line); border-radius: 8px;
}
.tile .noimg small { color: var(--muted); font-size: .65rem; }
.tile .num .jp { font-style: normal; color: #ffb3c1; font-weight: 800; margin-right: 4px; }
.tile .lang-tag {
  position: absolute; bottom: 4px; right: 4px; font-size: .62rem; font-weight: 800;
  background: #fff; color: #bc002d; padding: 1px 5px; border-radius: 5px; box-shadow: 0 1px 2px rgb(0 0 0 / .3);
}
.lang-switch { display: flex; justify-content: center; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tile .badge {
  position: absolute; top: 6px; right: 6px;
  background: var(--ok); color: #fff; font-size: .75rem; font-weight: 700;
  padding: 2px 7px; border-radius: 999px; box-shadow: 0 1px 3px rgb(0 0 0 / .3);
}
.tile .num {
  position: absolute; bottom: 4px; left: 4px; font-size: .7rem; font-weight: 600;
  background: rgb(0 0 0 / .6); color: #fff; padding: 1px 6px; border-radius: 6px;
}
.tile.missing img { filter: grayscale(1); opacity: .45; }
.tile.best { outline: 3px solid var(--ok); outline-offset: 2px; }
.tile.best::after {
  content: "Best match"; position: absolute; left: 50%; top: 6px; transform: translateX(-50%);
  background: var(--ok); color: #fff; font-size: .62rem; font-weight: 800; padding: 1px 7px; border-radius: 999px; white-space: nowrap;
}

/* ---------- binders ---------- */
.segmented { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.seg { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg.active { background: var(--accent); color: var(--accent-ink); }
.filter { margin-bottom: 12px; }
.tabs-row { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 18px; }
.text-tabs { display: flex; gap: 22px; }
.text-tabs .seg {
  flex: none; padding: 6px 0; border-radius: 0; background: none; color: var(--muted);
  font-size: 1.2rem; font-weight: 800; position: relative; transition: color .2s ease;
}
.text-tabs .seg.active { background: none; color: var(--text); }
.text-tabs .seg::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 3px; border-radius: 3px;
  background: var(--accent); transform: scaleX(0); transition: transform .25s cubic-bezier(.3, 1.4, .5, 1);
}
.text-tabs .seg.active::after { transform: scaleX(1); }
.more { position: relative; }
.more summary {
  list-style: none; cursor: pointer; width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 1.3rem; color: var(--muted);
}
.more summary::-webkit-details-marker { display: none; }
.more summary:hover, .more[open] summary { background: var(--slot); }
.more .menu {
  position: absolute; right: 0; top: 42px; z-index: 10; min-width: 180px; padding: 6px;
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 12px 32px rgb(0 0 0 / .25); animation: menu-in .18s ease-out;
}
.more .menu button, .more .menu label {
  text-align: left; padding: 10px 12px; border: 0; background: none; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: .95rem;
}
.more .menu button:hover, .more .menu label:hover { background: var(--slot); }
@keyframes menu-in { from { opacity: 0; transform: translateY(-6px) scale(.97); } }

.shelf { display: grid; gap: 18px 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .shelf { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
.shelf-item { border: 0; background: none; padding: 0; cursor: pointer; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.shelf-item:hover .cover { transform: translateY(-3px) rotate(-.5deg); }
.shelf-count { color: var(--muted); font-size: .85rem; padding-left: 4px; }
.new-binder {
  aspect-ratio: 5 / 6; border: 2px dashed var(--line); border-radius: 6px 14px 14px 6px;
  align-items: center; justify-content: center; color: var(--muted); font-weight: 700;
}
.new-binder .plus { font-size: 2rem; line-height: 1; }

/* A binder cover: spine + rings on the left, pattern, optional art, title plate. */
.cover {
  --cover: #e3350d;
  position: relative; aspect-ratio: 5 / 6; width: 100%; overflow: hidden;
  border-radius: 6px 14px 14px 6px;
  background-color: var(--cover);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / .15), 0 6px 16px rgb(0 0 0 / .18);
  transition: transform .15s ease;
  isolation: isolate;
}
.cover::before { /* spine */
  content: ""; position: absolute; inset: 0 auto 0 0; width: 13%; z-index: 3;
  background:
    radial-gradient(circle at 50% 50%, #d9d9de 0 3.5px, #8a8a92 3.5px 5px, transparent 5px) center 22% / 100% 20px no-repeat,
    radial-gradient(circle at 50% 50%, #d9d9de 0 3.5px, #8a8a92 3.5px 5px, transparent 5px) center 50% / 100% 20px no-repeat,
    radial-gradient(circle at 50% 50%, #d9d9de 0 3.5px, #8a8a92 3.5px 5px, transparent 5px) center 78% / 100% 20px no-repeat,
    linear-gradient(90deg, rgb(0 0 0 / .35), rgb(0 0 0 / .12));
  border-right: 1px solid rgb(0 0 0 / .2);
}
.cover::after { /* pattern layer */ content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.pat-ball::after {
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cg fill='none' stroke='white' stroke-opacity='.22' stroke-width='6'%3E%3Ccircle cx='50' cy='50' r='44'/%3E%3Cpath d='M6 50h30M64 50h30'/%3E%3Ccircle cx='50' cy='50' r='13'/%3E%3C/g%3E%3C/svg%3E") 130% 115% / 85% no-repeat;
}
.pat-stripes::after { background: repeating-linear-gradient(135deg, rgb(255 255 255 / .14) 0 12px, transparent 12px 24px); }
.pat-dots::after { background: radial-gradient(rgb(255 255 255 / .25) 2.5px, transparent 3px) 0 0 / 18px 18px; }
.pat-grid::after {
  background:
    linear-gradient(rgb(255 255 255 / .13) 1px, transparent 1px) 0 0 / 16px 16px,
    linear-gradient(90deg, rgb(255 255 255 / .13) 1px, transparent 1px) 0 0 / 16px 16px;
}
.pat-holo::after {
  background: linear-gradient(125deg, #ff7eb3aa, #ffd76eaa 20%, #7affc1aa 40%, #6ecbffaa 60%, #b58bffaa 80%, #ff7eb3aa);
  background-size: 250% 250%; mix-blend-mode: overlay; animation: holo 6s ease-in-out infinite alternate;
}
@keyframes holo { to { background-position: 100% 100%; } }

.cover-photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.cover.has-photo::after { z-index: 2; opacity: .6; }
.cover-card {
  position: absolute; z-index: 1; left: 50%; top: 10%; width: 44%; transform: translateX(-38%) rotate(4deg);
  border-radius: 6px; box-shadow: 0 4px 12px rgb(0 0 0 / .4); outline: 3px solid rgb(255 255 255 / .85);
}
.cover-plate {
  position: absolute; z-index: 4; left: 16%; right: 5%; bottom: 7%;
  background: rgb(255 255 255 / .92); color: #1d1d24; border-radius: 8px;
  padding: 7px 10px; display: flex; align-items: center; gap: 6px;
  box-shadow: 0 2px 6px rgb(0 0 0 / .2);
}
.cover-title { font-weight: 800; font-size: clamp(.75rem, 3.6vw, .95rem); line-height: 1.15; min-width: 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cover-sticker { font-size: 1.1rem; line-height: 1; flex: none; }
.cover.mini { width: 84px; flex: none; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .15), 0 3px 8px rgb(0 0 0 / .18); }
.cover.mini .cover-plate { padding: 3px 5px; left: 16%; right: 5%; bottom: 6%; border-radius: 5px; }
.cover.mini .cover-title { font-size: .55rem; }
.cover.mini .cover-sticker { font-size: .7rem; }
.cover.mini::before { background-size: 100% 12px; }

.binder-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.binder-head .btn.ghost { border: 0; padding-left: 0; padding-right: 0; color: var(--muted); }
.binder-head .btn.ghost:hover { color: var(--text); }
.binder-hero { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.binder-hero h2 { margin: 0 0 4px; font-size: 1.4rem; word-break: break-word; }
.meta { color: var(--muted); font-size: .9rem; margin: 0; }

.set-group { margin-bottom: 22px; }
.set-group h3 { font-size: 1rem; margin: 0 0 8px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.set-group h3 small { color: var(--muted); font-weight: 500; }

.checklist-opts { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; color: var(--muted); }
.checklist-opts > label:first-child { display: flex; align-items: center; gap: 8px; flex: 1 1 220px; white-space: nowrap; }
.check { display: flex; gap: 8px; align-items: center; }

.progress { background: var(--slot); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.progress .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.progress img { max-height: 40px; max-width: 140px; }
.bar { height: 10px; background: var(--slot); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--ok); }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; grid-column: 1 / -1; }
.backup { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 28px; }

/* ---------- bottom tabs ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbtn {
  flex: 1; border: 0; background: none; padding: 10px 0 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 1.2rem; color: var(--muted);
}
.tabbtn span { font-size: .75rem; font-weight: 600; }
.tabbtn.active { color: var(--accent); }

/* ---------- dialogs ---------- */
dialog {
  border: 0; border-radius: 16px; padding: 20px; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); max-height: calc(100dvh - 32px);
}
dialog::backdrop { background: rgb(0 0 0 / .55); }
.close { position: absolute; top: 8px; right: 8px; border: 0; background: var(--slot); width: 32px; height: 32px; border-radius: 50%; cursor: pointer; z-index: 5; }

.detail { text-align: center; }
.detail-img { width: min(260px, 70vw); border-radius: 12px; }
.detail h3 { margin: 12px 0 2px; }
.detail .price { font-size: .9rem; margin: 6px 0 0; min-height: 1.2em; }
.owned-note { color: var(--ok); font-weight: 700; margin: 12px 0 6px; }
.own-list { text-align: left; }
.own-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); }
.own-name { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.swatch-dot { width: 12px; height: 12px; border-radius: 3px; background: var(--cover); flex: none; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper .btn { width: 40px; padding: 6px 0; }
.stepper b { min-width: 2ch; font-size: 1.1rem; text-align: center; }
.add-row { display: flex; gap: 8px; margin-top: 14px; }
.add-row select { flex: 1; }

.editor h3, .account h3 { margin: 0 0 12px; }
.editor-preview { width: 150px; margin: 0 auto 8px; }
.editor-label { display: block; font-size: .8rem; font-weight: 700; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .04em; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--surface);
  background: var(--cover); cursor: pointer; box-shadow: 0 0 0 1px var(--line);
}
.swatch.on { box-shadow: 0 0 0 3px var(--text); }
.swatch.custom { display: inline-flex; align-items: center; justify-content: center; background: var(--slot); position: relative; font-size: .9rem; }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px;
  padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: .85rem;
}
.chip.sticker { min-width: 40px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.art-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; margin-top: 8px; max-height: 220px; overflow-y: auto; padding: 3px; }
.art-card { padding: 0; border: 0; background: none; cursor: pointer; border-radius: 5px; }
.art-card img { width: 100%; display: block; border-radius: 5px; }
.art-card.on { outline: 3px solid var(--accent); }
.editor-actions { display: flex; justify-content: space-between; margin-top: 20px; gap: 10px; }

.manual h3 { margin: 0 0 6px; }
.manual .chip { display: inline-block; margin-top: 8px; }
.manual-photo { margin-top: 12px; width: 110px; aspect-ratio: 63 / 88; border-radius: 8px; background: var(--slot); overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .8rem; }
.manual-photo img { width: 100%; height: 100%; object-fit: cover; }
.manual-row { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 10px; }
.results-head .linkish { margin-left: 4px; }

.account { display: flex; flex-direction: column; gap: 10px; }
.account p { margin: 0; }
.switch { font-size: .9rem; color: var(--muted); }

/* ---------- checklists ---------- */
.lists { display: flex; flex-direction: column; }
.list-card {
  display: flex; align-items: center; gap: 14px; text-align: left; cursor: pointer; width: 100%;
  background: none; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 14px 6px;
  transition: background-color .15s ease;
}
.list-card:hover { background: var(--slot); }
.list-icon { font-size: 1.6rem; width: 40px; text-align: center; flex: none; }
.list-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.list-body b { font-size: 1rem; overflow-wrap: anywhere; }
.list-body small { color: var(--muted); }
.list-body .bar { height: 6px; margin-top: 2px; }
.list-body .bar > span { width: 0; transition: width .3s ease; }
.list-card.new-list { border-bottom: 0; color: var(--accent); }
.list-card.new-list small { color: var(--muted); }
.segmented.small { margin: 4px 0 6px; }
.segmented.small .seg { padding: 6px; font-size: .9rem; }

.tile .want-tag {
  position: absolute; top: 5px; left: 5px; width: 22px; height: 22px; border-radius: 50%;
  background: #ffcb05; color: #7a5a00; font-size: .8rem; font-weight: 900;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 3px rgb(0 0 0 / .35);
}
.detail-links { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.want-btn.on { background: #ffcb05; color: #3b2c00; border-color: transparent; }

/* ---------- live camera ---------- */
body.camera-open { overflow: hidden; }
.camera { position: fixed; inset: 0; z-index: 30; background: #000; }
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-frame {
  position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%);
  width: min(84vw, calc((100dvh - 190px) * 63 / 88)); aspect-ratio: 63 / 88;
  border: 3px solid #fff; border-radius: 16px;
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / .55);
}
.cam-tip {
  position: absolute; left: 0; right: 0; top: -40px; text-align: center; color: #fff;
  font-weight: 700; text-shadow: 0 1px 3px #000;
}
.cam-corner { /* sits just under the frame, pointing up at where the number is */
  position: absolute; bottom: -34px; left: 4px; padding: 3px 8px; border-radius: 6px;
  border: 2px dashed #ffcb05; color: #ffcb05; font-size: .75rem; font-weight: 700; background: rgb(0 0 0 / .35);
}
.cam-corner.right { left: auto; right: 4px; }
.cam-bar {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 28px calc(22px + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: space-between;
}
.cam-shutter {
  width: 74px; height: 74px; border-radius: 50%; border: 5px solid #fff; background: var(--accent); cursor: pointer;
  box-shadow: 0 0 0 3px rgb(0 0 0 / .3);
}
.cam-shutter:active { transform: scale(.94); }
.cam-side {
  width: 48px; height: 48px; border-radius: 50%; border: 0; background: rgb(255 255 255 / .2); color: #fff;
  font-size: 1.2rem; cursor: pointer;
}
.cam-side[hidden] { display: block !important; visibility: hidden; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 40;
  font-weight: 600; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

/* ---------- quick add, grades & prices ---------- */
.tile .quick-add {
  position: absolute; bottom: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid #fff; background: var(--accent); color: #fff; font-size: 1rem; font-weight: 900; line-height: 1;
  display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0;
  box-shadow: 0 1px 4px rgb(0 0 0 / .4);
  transition: transform .22s cubic-bezier(.3, 1.6, .5, 1), box-shadow .22s ease, background-color .22s ease;
}
@media (hover: hover) {
  .tile:hover .quick-add { transform: scale(1.1); }
  .tile .quick-add:hover {
    transform: scale(1.3) rotate(90deg); background: #ff4a1f;
    box-shadow: 0 0 0 5px rgb(227 53 13 / .3), 0 3px 10px rgb(0 0 0 / .45);
  }
}
.tile .quick-add:active { transform: scale(.85) rotate(90deg); transition-duration: .08s; }

/* "− n +" once the card is in the binder */
.tile .quick-step {
  position: absolute; bottom: 4px; right: 4px; display: flex; align-items: center; gap: 2px;
  background: rgb(20 20 26 / .85); border: 2px solid #fff; border-radius: 999px; padding: 1px;
  box-shadow: 0 1px 4px rgb(0 0 0 / .4); animation: step-in .25s cubic-bezier(.3, 1.6, .5, 1);
}
.tile .quick-step button {
  width: 24px; height: 24px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 900; font-size: .95rem; line-height: 1;
  transition: transform .18s cubic-bezier(.3, 1.6, .5, 1), background-color .18s ease;
}
.tile .quick-step button:first-child { background: #4a4a57; }
@media (hover: hover) { .tile .quick-step button:hover { transform: scale(1.18); } }
.tile .quick-step button:active { transform: scale(.85); transition-duration: .08s; }
.tile .quick-step b { min-width: 18px; text-align: center; color: #fff; font-size: .8rem; }
.tile .quick-step b.bump { animation: bump .35s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes step-in { from { transform: scale(.4); opacity: 0; } }
@keyframes bump { 40% { transform: scale(1.6); color: #ffcb05; } }

.float-count {
  position: fixed; z-index: 50; pointer-events: none; transform: translate(-50%, 0);
  background: var(--ok); color: #fff; font-weight: 900; font-size: .85rem; padding: 2px 9px; border-radius: 999px;
  box-shadow: 0 2px 6px rgb(0 0 0 / .35); animation: float-up .8s ease-out forwards;
}
.float-count.minus { background: #4a4a57; }
@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, 4px) scale(.6); }
  20% { opacity: 1; transform: translate(-50%, -8px) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -46px) scale(1); }
}
.tile .grade-tag {
  position: absolute; top: 30px; right: 6px; background: linear-gradient(135deg, #f7d774, #c9a227);
  color: #3b2c00; font-size: .66rem; font-weight: 900; padding: 1px 6px; border-radius: 4px;
  box-shadow: 0 1px 3px rgb(0 0 0 / .35);
}
.copy-row { display: flex; align-items: center; gap: 8px; padding: 4px 0 4px 20px; font-size: .85rem; }
.copy-grade { font-weight: 700; color: var(--muted); }
.copy-grade.graded { color: #c9a227; }
.copy-info { flex: 1; color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.copy-info a { color: inherit; }
.copy-remove { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: .9rem; padding: 2px 6px; }
.paid-total { margin: 8px 0 0; font-weight: 700; font-size: .9rem; }
.add-box { margin-top: 14px; text-align: left; display: flex; flex-direction: column; gap: 10px;
  border-top: 1px solid var(--line); padding-top: 14px; }
.add-line { display: flex; align-items: center; gap: 10px; }
.add-line label { font-weight: 700; white-space: nowrap; }
.add-label { font-size: .85rem; font-weight: 700; margin-bottom: -4px; }
.add-label small { color: var(--muted); font-weight: 500; }
.chips.grades .chip { min-width: 44px; }
.price-row { display: flex; gap: 8px; align-items: center; }
.price-row input { flex: 1; }
.add-btn { width: 100%; }
.toast { display: flex; align-items: center; gap: 12px; }
.toast-action { border: 0; background: none; color: #ffcb05; font-weight: 800; cursor: pointer; padding: 0; font-size: inherit; }

/* ---------- minimal Add cards ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.searchbar {
  display: flex; align-items: center; gap: 2px; margin: 6px 0 12px; padding: 4px 4px 4px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.searchbar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgb(227 53 13 / .14); }
.sb-icon { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2.2; stroke-linecap: round; }
#search-form input { border: 0; background: transparent; border-radius: 0; padding: 10px 8px; min-width: 0; outline: none; }
#search-form #q-name { flex: 1; }
#search-form .sb-number { flex: 0 0 92px; border-left: 1px solid var(--line); padding-left: 12px; }
.sb-scan {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center;
  transition: transform .22s cubic-bezier(.3, 1.6, .5, 1), box-shadow .22s ease;
}
.sb-scan svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.sb-scan:hover { transform: scale(1.08); box-shadow: 0 0 0 5px rgb(227 53 13 / .2); }
.sb-scan:active { transform: scale(.9); }
.chip-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.chip-row .chip { background: var(--surface); }
.select-chip { display: inline-flex; align-items: center; gap: 2px; padding: 0 6px 0 12px; }
#target { border: 0; background: transparent; padding: 6px 4px; width: auto; max-width: 46vw; font-weight: 600; cursor: pointer; outline: none; }
.lang-toggle { display: inline-flex; padding: 2px; background: var(--slot); border-radius: 999px; }
.chip-row .lang-toggle .chip { border: 0; background: transparent; padding: 5px 12px; transition: background-color .2s ease, color .2s ease; }
.chip-row .lang-toggle .chip.on { background: var(--accent); color: var(--accent-ink); }
.chip-row .chip.ghost { background: transparent; color: var(--muted); }
.scan-row { display: flex; align-items: center; gap: 12px; margin: 0 0 14px; }
.scan-row #preview { width: 52px; max-height: none; border-radius: 6px; box-shadow: var(--shadow); flex: none; }
.scan-row .status { margin: 0; min-height: 0; font-size: .92rem; }
.results-head { margin: 4px 0 10px; }
.results-head:empty { display: none; }
.add-empty { display: none; text-align: center; color: var(--muted); padding: 56px 16px; line-height: 1.6; margin: 0; }
#results-head:empty + #results:empty + .add-empty { display: block; }

/* ---------- card animation: lift, fly to the middle, flip ---------- */
.tile.lifted { visibility: hidden; }
.fly-shade { position: fixed; inset: 0; z-index: 60; background: rgb(0 0 0 / .55); pointer-events: none; }
.fly-card {
  position: fixed; z-index: 61; border-radius: 14px; overflow: hidden; pointer-events: none;
  transform-origin: center; backface-visibility: hidden; will-change: transform; background: var(--slot);
}
.fly-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
dialog { transform-origin: center; }

/* ---------- binder pages ---------- */
.binder-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.pill-toggle { display: inline-flex; padding: 2px; background: var(--slot); border-radius: 999px; }
.pill-toggle .chip { border: 0; background: transparent; padding: 5px 12px; transition: background-color .2s ease, color .2s ease; }
.pill-toggle .chip.on { background: var(--accent); color: var(--accent-ink); }
.arrange-btn { background: var(--surface); }
.arrange-btn.on { background: var(--ok); color: #fff; border-color: transparent; }

.page-nav { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 10px; font-weight: 700; }
.page-nav small { color: var(--muted); font-weight: 500; }
.page-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  font-size: 1.3rem; line-height: 1; cursor: pointer; transition: transform .15s ease;
}
.page-btn:hover:not(:disabled) { transform: scale(1.1); }
.page-btn:disabled { opacity: .3; cursor: default; }
.spread {
  position: relative; display: grid; grid-template-columns: repeat(var(--pages), minmax(0, 1fr)); gap: 26px;
  max-width: calc(var(--pages) * 520px); margin: 0 auto; touch-action: pan-y;
}
.spread[style*="--pages:2"]::before { /* binder rings between the two pages */
  content: ""; position: absolute; left: 50%; top: 8%; bottom: 8%; width: 12px; transform: translateX(-50%);
  background: radial-gradient(circle, #c9c9cf 0 4px, #6f6f78 4px 6px, transparent 6px) center 0 / 12px 25% repeat-y;
}
.page {
  display: grid; grid-template-columns: repeat(var(--size), minmax(0, 1fr)); gap: 6px; padding: 10px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--surface) 92%, #fff), var(--surface));
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgb(0 0 0 / .18);
}
.pocket {
  position: relative; aspect-ratio: 63 / 88; border-radius: 6px; background: var(--slot);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / .08);
}
.pocket::after { /* plastic sleeve shine */
  content: ""; position: absolute; inset: 0; border-radius: 6px; pointer-events: none;
  background: linear-gradient(115deg, rgb(255 255 255 / .16), transparent 35%, transparent 65%, rgb(255 255 255 / .06));
}
.pocket .tile { width: 100%; height: 100%; border-radius: 6px; }
.pocket.vacant { display: flex; align-items: center; justify-content: center; }
.pocket.planned .tile img { filter: grayscale(1); opacity: .5; }
.planned-tag {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 2; pointer-events: none;
  background: rgb(0 0 0 / .65); color: #fff; font-size: .62rem; font-weight: 800; padding: 2px 7px; border-radius: 999px;
}
.page.s4 .tile .num { display: none; }
.page.s4 .tile .quick-add { width: 22px; height: 22px; font-size: .8rem; }
.page.s4 .tile .quick-step { transform: scale(.78); transform-origin: bottom right; }
.page.s4 .planned-tag { font-size: .5rem; padding: 1px 5px; }

/* Arrange mode: cards wiggle gently; the picked one lifts. */
.arranging .pocket { cursor: pointer; }
.arranging .pocket:not(.vacant) .tile { animation: wiggle .9s ease-in-out infinite alternate; }
.arranging .pocket:nth-child(2n) .tile { animation-delay: -.45s; }
@keyframes wiggle { from { transform: rotate(-1.2deg); } to { transform: rotate(1.2deg); } }
.arranging .pocket.vacant { border: 2px dashed var(--line); background: transparent; }
.arranging .pocket.vacant:hover { border-color: var(--accent); }
.plan-plus { font-size: 1.4rem; color: var(--muted); font-weight: 800; transition: transform .2s ease, color .2s ease; }
.arranging .pocket.vacant:hover .plan-plus { color: var(--accent); transform: scale(1.2); }
.pocket.picked { z-index: 3; transform: scale(1.08) translateY(-4px); box-shadow: 0 0 0 3px var(--accent), 0 14px 28px rgb(0 0 0 / .35); transition: transform .2s ease; }
.pocket.picked .tile { animation: none; }
.arranging .pocket.vacant.picked { border-color: var(--accent); }
.unplan {
  position: absolute; top: -6px; right: -6px; z-index: 4; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--surface); background: #4a4a57; color: #fff; font-size: .7rem; cursor: pointer; padding: 0;
}
.arrange-hint { text-align: center; color: var(--muted); font-size: .88rem; margin: 12px 0 0; }

/* plan picker */
.plan-picker h3 { margin: 0 0 4px; }
.plan-picker .searchbar { margin: 12px 0 8px; }
.plan-lang { margin-bottom: 10px; }
.plan-results { max-height: 50dvh; overflow-y: auto; }
.plan-results .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.pick-card {
  display: flex; flex-direction: column; gap: 4px; padding: 0; border: 0; background: none; cursor: pointer;
  border-radius: 6px; transition: transform .15s ease;
}
.pick-card:hover { transform: translateY(-3px); }
.pick-card img { width: 100%; aspect-ratio: 63 / 88; object-fit: cover; border-radius: 6px; background: var(--slot); }
.pick-card small { color: var(--muted); font-size: .7rem; }
.plan-picker .searchbar input { border: 0; background: transparent; border-radius: 0; padding: 10px 8px; min-width: 0; outline: none; }
.plan-picker .searchbar #plan-q { flex: 1; }
.plan-picker .searchbar .sb-number { flex: 0 0 80px; border-left: 1px solid var(--line); padding-left: 12px; }

/* drag & drop */
.arranging .pocket:not(.vacant) { touch-action: none; cursor: grab; }
body.dragging, body.dragging * { cursor: grabbing !important; user-select: none; }
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 70; pointer-events: none; border-radius: 6px;
  box-shadow: 0 18px 40px rgb(0 0 0 / .45); will-change: transform;
}
.drag-ghost .tile { width: 100%; height: 100%; border-radius: 6px; animation: none; }
.pocket.drag-from .tile { opacity: .25; animation: none; }
.pocket.drop-target { outline: 3px dashed var(--accent); outline-offset: 2px; transform: scale(1.05); transition: transform .12s ease; }
.pocket img, .drag-ghost img { -webkit-user-drag: none; user-select: none; }

/* tray: cards in the binder that aren't on a page yet */
.tray { margin-top: 22px; padding: 14px; border-radius: 12px; background: var(--slot); transition: box-shadow .15s ease; }
.tray h4 { margin: 0 0 2px; font-size: 1rem; }
.tray h4 small { color: var(--muted); font-weight: 600; margin-left: 4px; }
.tray .meta { font-size: .85rem; margin-bottom: 10px; }
.tray-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); }
.tray-card { position: relative; aspect-ratio: 63 / 88; border-radius: 6px; }
.tray-card .tile { width: 100%; height: 100%; border-radius: 6px; }
.arranging .tray-card { cursor: grab; touch-action: none; }
.arranging .tray-card .tile { animation: wiggle .9s ease-in-out infinite alternate; }
.tray-card.picked { z-index: 3; transform: scale(1.08) translateY(-4px); box-shadow: 0 0 0 3px var(--accent), 0 14px 28px rgb(0 0 0 / .35); }
.tray-card.picked .tile { animation: none; }
.tray-card.drag-from .tile { opacity: .25; animation: none; }
.tray.drop-target { outline: 3px dashed var(--accent); outline-offset: 3px; }
.tray-done { text-align: center; color: var(--ok); font-weight: 700; margin: 18px 0 0; }
.pocket.vacant { cursor: pointer; }
.pocket.vacant .plan-plus { opacity: .45; }
.pocket.vacant:hover .plan-plus { opacity: 1; color: var(--accent); transform: scale(1.2); }
.picker-h { margin: 16px 0 4px; font-size: .95rem; }
.picker-note { margin-top: 12px; }
.ghost-chip { background: transparent; color: var(--muted); }
.ghost-chip:hover { color: var(--text); border-color: var(--muted); }
