:root {
  --blue: #2b59c3; --blue-dark: #1d3f91; --yellow: #ffcb05; --red: #e3350d;
  --bg: #f3f5fb; --card: #fff; --text: #1a1d29; --muted: #6b7185; --border: #dde1ee;
  --good: #1f9d55;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11131a; --card: #1c1f2b; --text: #eef0f7; --muted: #9aa0b5; --border: #2c3142; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--text); background: var(--card);
  border: 2px solid var(--border); border-radius: 12px; padding: 10px 12px; min-width: 0; }

/* Login */
.screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-box { text-align: center; max-width: 320px; width: 100%; }
.login-box h1 { margin: 8px 0; }
.login-box form { display: grid; gap: 12px; margin-top: 16px; }
.error { color: var(--red); min-height: 1.4em; }

/* Header */
.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px; color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--blue-dark)); }
.label { opacity: .85; font-size: 14px; }
.total { font-size: 34px; font-weight: 800; color: var(--yellow); letter-spacing: -.5px; }
.sub { opacity: .85; font-size: 14px; }
.icon-btn { background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 50%;
  width: 48px; height: 48px; font-size: 24px; }
.icon-btn.spin { animation: spin 1s linear infinite; }

.tab { padding: 12px 16px 100px; max-width: 900px; margin: 0 auto; }
.toolbar { display: flex; gap: 8px; margin: 8px 0 12px; }
.toolbar input { flex: 1; }
.toolbar .num { flex: 0 0 90px; }

/* Top 3 */
.top3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 4px; }
.top3:empty { display: none; }
.top3 .trophy { background: var(--card); border-radius: 14px; padding: 8px; text-align: center;
  border: 2px solid var(--yellow); }
.top3 img { width: 100%; border-radius: 6px; }
.top3 .medal { font-size: 20px; }
.top3 .v { font-weight: 800; color: var(--good); }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.tile { background: var(--card); border: 0; border-radius: 14px; padding: 8px; text-align: left; color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.08); position: relative; }
.tile img { width: 100%; aspect-ratio: 63/88; object-fit: cover; border-radius: 8px; background: var(--border); display: block; }
.tile .name { font-weight: 700; margin-top: 6px; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .meta { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .price { font-weight: 800; color: var(--good); }
.tile .qty { position: absolute; top: 12px; right: 12px; background: var(--red); color: #fff;
  border-radius: 999px; padding: 2px 8px; font-weight: 800; font-size: 13px; }
.set-heading { grid-column: 1 / -1; margin: 12px 0 0; font-size: 16px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* Scan */
.scan-start { text-align: center; padding-top: 24px; }
.camera-btn { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 0 auto;
  max-width: 320px; padding: 40px 20px; background: var(--yellow); color: #1a1d29; border-radius: 24px;
  font-size: 20px; font-weight: 800; box-shadow: 0 6px 0 #c99f00; }
.camera-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #c99f00; }
.camera-btn .emoji { font-size: 64px; }
.tip { color: var(--muted); }
.link { background: none; border: 0; color: var(--blue); text-decoration: underline; padding: 8px; }
.busy { text-align: center; padding: 60px 0; }
.spinner { width: 56px; height: 56px; border: 6px solid var(--border); border-top-color: var(--red);
  border-radius: 50%; margin: 0 auto 16px; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.match { display: grid; grid-template-columns: 140px 1fr; gap: 16px; background: var(--card);
  border-radius: 16px; padding: 12px; }
.match img { width: 100%; border-radius: 8px; }
.match h2 { margin: 0 0 4px; font-size: 22px; }
.others h3 { font-size: 15px; color: var(--muted); margin: 18px 0 8px; }
.others .grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }

.big { background: var(--red); color: #fff; border: 0; border-radius: 14px; padding: 14px 18px;
  font-size: 18px; font-weight: 800; width: 100%; }
.big.secondary { background: var(--card); color: var(--text); border: 2px solid var(--border); }
.small { background: var(--blue); color: #fff; border: 0; border-radius: 12px; padding: 10px 14px; font-weight: 700; }
.row { display: flex; gap: 8px; margin-top: 12px; }
.row > * { flex: 1; }
.field { display: grid; gap: 4px; margin-top: 10px; font-size: 14px; color: var(--muted); }

/* Sheet */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-body { background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
.sheet .hero { display: grid; grid-template-columns: 45% 1fr; gap: 14px; }
.sheet .hero img { width: 100%; border-radius: 10px; }
.sheet h2 { margin: 0; }
.sheet .value { font-size: 28px; font-weight: 800; color: var(--good); }
.close { float: right; background: var(--card); border: 0; border-radius: 50%; width: 40px; height: 40px; font-size: 20px; color: var(--text); }

.grades { width: 100%; border-collapse: separate; border-spacing: 0 6px; margin-top: 8px; }
.grades td { background: var(--card); padding: 10px 12px; }
.grades td:first-child { border-radius: 10px 0 0 10px; font-weight: 700; }
.grades td:last-child { border-radius: 0 10px 10px 0; text-align: right; font-weight: 800; }
.grades tr.mine td { background: var(--yellow); color: #1a1d29; }
.note { font-size: 13px; color: var(--muted); }
.qty-ctl { display: flex; align-items: center; gap: 12px; }
.qty-ctl button { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--border); background: var(--card); color: var(--text); font-size: 20px; }

/* Bottom tabs */
.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tabs button { flex: 1; background: none; border: 0; padding: 8px 0 10px; font-size: 24px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; }
.tabs button span { font-size: 12px; font-weight: 700; }
.tabs button.active { color: var(--blue); }
.tabs button.active span { color: var(--blue); }

.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: #1a1d29; color: #fff;
  padding: 12px 18px; border-radius: 12px; z-index: 30; max-width: 90vw; text-align: center; }
