:root {
  --blue: #2b59c3;
  --blue-dark: #1d3f8f;
  --yellow: #ffcb05;
  --red: #ef4b4b;
  --green: #2fb36d;
  --bg: #f3f6ff;
  --card: #ffffff;
  --ink: #1b2340;
  --muted: #6b7393;
  --line: #e2e7f5;
  --radius: 20px;
  --tabbar-h: 74px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
img { -webkit-user-drag: none; }

/* ---------- Top & tabs ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: var(--blue); color: #fff;
  box-shadow: 0 4px 16px rgba(29, 63, 143, .25);
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: .3px; }
.profile-chip {
  display: flex; align-items: center; gap: 10px; border: 0; border-radius: 999px;
  background: rgba(255,255,255,.18); color: #fff; padding: 6px 16px 6px 6px; font-weight: 700; font-size: 17px;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  font-size: 22px; background: var(--yellow); flex: none;
}
main { padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px); max-width: 1100px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around; background: #fff;
  border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--safe-b));
  height: calc(var(--tabbar-h) + var(--safe-b));
}
.tab {
  flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 14px; font-weight: 700; color: var(--muted); border-radius: 16px; padding: 6px 0;
}
.tab .ti { font-size: 28px; line-height: 1; }
.tab.active { color: var(--blue); background: #eaf0ff; }

/* ---------- Generic ---------- */
h1 { font-size: 28px; margin: 4px 0 14px; }
h2 { font-size: 22px; margin: 18px 0 10px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.panel { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 2px 10px rgba(27,35,64,.06); }

.btn {
  border: 0; border-radius: 18px; padding: 16px 22px; font-weight: 800; font-size: 19px;
  background: var(--blue); color: #fff; box-shadow: 0 4px 0 var(--blue-dark);
  transition: transform .06s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--blue-dark); }
.btn.big { width: 100%; font-size: 22px; padding: 20px; }
.btn.green { background: var(--green); box-shadow: 0 4px 0 #1f8650; }
.btn.yellow { background: var(--yellow); color: var(--ink); box-shadow: 0 4px 0 #c99e00; }
.btn.red { background: var(--red); box-shadow: 0 4px 0 #b83232; }
.btn.light { background: #fff; color: var(--blue); box-shadow: 0 3px 0 #c9d4f2; }
.btn.ghost { background: #eaf0ff; color: var(--blue); box-shadow: none; }
.btn.small { padding: 9px 14px; font-size: 16px; border-radius: 14px; }
.btn:disabled { opacity: .5; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 9px 15px;
  font-weight: 700; font-size: 16px; white-space: nowrap; color: var(--ink);
}
.chip.on { border-color: var(--blue); background: var(--blue); color: #fff; }

.input {
  width: 100%; font: inherit; font-size: 19px; padding: 15px 16px; border-radius: 16px;
  border: 2px solid var(--line); background: #fff; color: var(--ink); -webkit-user-select: text; user-select: text;
}
.input:focus { outline: none; border-color: var(--blue); }
select.input { appearance: none; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); font-size: 18px; }
.empty .big-emoji { font-size: 64px; display: block; margin-bottom: 10px; }

/* ---------- Profiles ---------- */
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.profile-tile {
  border: 0; border-radius: 26px; padding: 22px 10px; background: #fff; display: flex; flex-direction: column;
  align-items: center; gap: 10px; box-shadow: 0 4px 0 var(--line); font-weight: 800; font-size: 21px;
}
.profile-tile .avatar { width: 84px; height: 84px; font-size: 46px; }
.profile-tile small { font-weight: 600; font-size: 14px; color: var(--muted); }
.profile-tile.add { border: 3px dashed #c3cdea; background: transparent; box-shadow: none; color: var(--blue); }
.emoji-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.emoji-pick button, .color-pick button {
  border: 3px solid transparent; border-radius: 16px; background: #fff; font-size: 30px; padding: 8px 0;
}
.emoji-pick button.on, .color-pick button.on { border-color: var(--blue); }
.color-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.color-pick button { height: 48px; }

/* ---------- Scanner ---------- */
.scan-wrap {
  position: relative; border-radius: 24px; overflow: hidden; background: #0d1226;
  height: calc(100dvh - 340px - var(--safe-b) - var(--safe-t)); min-height: 320px;
}
.scan-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame {
  position: absolute; left: 50%; top: 54%; transform: translate(-50%, -50%);
  border: 4px solid var(--yellow); border-radius: 16px;
  box-shadow: 0 0 0 9999px rgba(10, 14, 35, .45);
  display: grid; pointer-events: none;
}
.frame.page { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.frame.page i { border: 1.5px dashed rgba(255, 203, 5, .7); }
.scan-hint {
  position: absolute; left: 0; right: 0; top: 12px; text-align: center; color: #fff; font-weight: 700;
  font-size: 17px; text-shadow: 0 1px 4px rgba(0,0,0,.7); padding: 0 12px;
}
.cam-error { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; text-align: center; padding: 24px; font-size: 18px; }
.shutter-row { display: flex; align-items: center; justify-content: center; gap: 22px; margin-top: 16px; }
.shutter {
  width: 84px; height: 84px; border-radius: 50%; border: 6px solid #fff; background: var(--red);
  box-shadow: 0 0 0 4px var(--red), 0 6px 16px rgba(239,75,75,.4); font-size: 30px; color: #fff;
}
.shutter:active { transform: scale(.94); }
.side-btn { width: 64px; height: 64px; border-radius: 50%; border: 0; background: #fff; font-size: 28px; box-shadow: 0 3px 0 var(--line); }

.thinking { text-align: center; padding: 28px 0 10px; }
.spinner {
  width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 50%;
  border: 9px solid #dbe4ff; border-top-color: var(--red); border-right-color: var(--yellow);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 420px; margin: 0 auto; }
.tiles img { width: 100%; aspect-ratio: 63/88; object-fit: cover; border-radius: 10px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* Scan results */
.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.res {
  position: relative; background: #fff; border-radius: 18px; padding: 8px; border: 4px solid transparent;
  box-shadow: 0 2px 8px rgba(27,35,64,.08); display: flex; flex-direction: column; gap: 6px;
}
.res.on { border-color: var(--green); }
.res.empty-pocket { opacity: .55; }
.res .pics { position: relative; }
.res .pics img.main { width: 100%; aspect-ratio: 63/88; object-fit: cover; border-radius: 10px; background: #eef1fa; display: block; }
.res .pics img.photo { position: absolute; width: 38%; right: -4px; bottom: -4px; border-radius: 8px; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.25); aspect-ratio: 63/88; object-fit: cover; }
.res .tick {
  position: absolute; top: 6px; left: 6px; width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.9); font-size: 22px; box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.res.on .tick { background: var(--green); color: #fff; }
.res .nm { font-weight: 800; font-size: 16px; line-height: 1.15; }
.res .meta { font-size: 13px; color: var(--muted); }
.res .vars { display: flex; gap: 4px; }
.res .vars button { flex: 1; border: 2px solid var(--line); background: #fff; border-radius: 10px; font-size: 12px; font-weight: 800; padding: 6px 0; }
.res .vars button.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.res .wrong { border: 0; background: #fff2d6; color: #8a5a00; border-radius: 10px; font-size: 13px; font-weight: 800; padding: 7px; }
.badge { display: inline-block; border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 800; }
.badge.new { background: var(--yellow); color: var(--ink); }
.badge.have { background: #e3e8f7; color: var(--muted); }
.badge.price { background: #e3f7ec; color: #17784a; }
.sticky-save {
  position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + 10px); margin-top: 16px; z-index: 5;
}

/* ---------- Card grid ---------- */
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat { background: #fff; border-radius: 18px; padding: 14px; text-align: center; box-shadow: 0 2px 8px rgba(27,35,64,.06); }
.stat b { display: block; font-size: 28px; }
.stat span { color: var(--muted); font-weight: 700; font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; margin-top: 12px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); } }
.gcard { position: relative; border: 0; padding: 0; background: none; text-align: left; }
.gcard img { width: 100%; aspect-ratio: 63/88; object-fit: cover; border-radius: 9px; background: #e6ebf7; display: block; box-shadow: 0 2px 6px rgba(27,35,64,.15); }
.gcard .qty { position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff; font-weight: 800; border-radius: 999px; min-width: 28px; height: 28px; display: grid; place-items: center; font-size: 14px; border: 3px solid var(--bg); }
.gcard .cap { font-size: 12px; font-weight: 700; color: var(--muted); margin-top: 4px; display: flex; justify-content: space-between; gap: 4px; }
.gcard.missing img { filter: grayscale(1); opacity: .35; }
.gcard.missing .miss { position: absolute; left: 50%; top: 40%; transform: translate(-50%,-50%); background: #fff; border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 800; color: var(--muted); box-shadow: 0 2px 6px rgba(0,0,0,.15); white-space: nowrap; }
.gcard.owned .ok { position: absolute; top: -6px; left: -6px; background: var(--green); color: #fff; border-radius: 50%; width: 28px; height: 28px; display: grid; place-items: center; font-size: 15px; border: 3px solid var(--bg); }
.stars { color: #e6a700; letter-spacing: -1px; }

/* ---------- Sets ---------- */
.set-row { display: flex; align-items: center; gap: 14px; background: #fff; border: 0; width: 100%; text-align: left; border-radius: 20px; padding: 14px; margin-bottom: 10px; box-shadow: 0 2px 8px rgba(27,35,64,.06); }
.set-row .logo { width: 92px; height: 44px; object-fit: contain; flex: none; }
.set-row .logo.ph { display: grid; place-items: center; font-size: 26px; background: #eef1fa; border-radius: 10px; }
.set-row .info { flex: 1; min-width: 0; }
.set-row .info b { display: block; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 14px; border-radius: 999px; background: #e7ecf8; overflow: hidden; margin-top: 7px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--yellow), #ff9d00); border-radius: 999px; }
.set-head { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.set-head img { max-width: 240px; max-height: 90px; object-fit: contain; }
.big-progress { font-size: 34px; font-weight: 900; }

/* ---------- Sheet / toast / banner ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(13,18,38,.5); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: var(--bg);
  border-radius: 28px 28px 0 0; padding: 12px 18px calc(22px + var(--safe-b));
  max-height: 88dvh; overflow-y: auto; max-width: 700px; margin: 0 auto;
  animation: up .22s ease-out;
}
.sheet::before { content: ''; display: block; width: 52px; height: 6px; border-radius: 3px; background: #c9d1e6; margin: 0 auto 12px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet .close { position: absolute; right: 14px; top: 12px; border: 0; background: #e3e8f7; border-radius: 50%; width: 42px; height: 42px; font-size: 20px; }
.detail-img { display: block; width: 70%; max-width: 300px; margin: 6px auto 14px; border-radius: 14px; box-shadow: 0 8px 24px rgba(27,35,64,.25); }
.var-row { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 16px; padding: 10px 12px; margin-bottom: 8px; }
.var-row b { flex: 1; font-size: 18px; }
.step { width: 48px; height: 48px; border-radius: 14px; border: 0; background: #eaf0ff; color: var(--blue); font-size: 26px; font-weight: 900; }
.var-row .n { min-width: 30px; text-align: center; font-size: 22px; font-weight: 900; }
.cand-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-top: 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 14px 22px; border-radius: 999px; font-weight: 800; font-size: 18px;
  z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.25); white-space: nowrap;
}
.update-banner {
  position: fixed; top: calc(8px + var(--safe-t)); left: 12px; right: 12px; z-index: 70;
  background: var(--green); color: #fff; border-radius: 18px; padding: 12px 14px; display: flex; align-items: center;
  justify-content: space-between; gap: 10px; font-weight: 800; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.update-banner[hidden], .sheet[hidden], .sheet-backdrop[hidden], .toast[hidden] { display: none; }

/* Photo frame adjust */
.adjust { position: relative; touch-action: none; margin: 0 auto; }
.adjust img { width: 100%; display: block; border-radius: 12px; }
.adjust .box { position: absolute; border: 4px solid var(--yellow); box-shadow: 0 0 0 9999px rgba(10,14,35,.45); display: grid; grid-template-columns: repeat(3,1fr); grid-template-rows: repeat(3,1fr); }
.adjust .box.single { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.adjust .box i { border: 1.5px dashed rgba(255,203,5,.8); }
.adjust .h { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; background: var(--yellow); border: 4px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.adjust-wrap { overflow: hidden; border-radius: 12px; }
