/* The `hidden` attribute MUST win. Rules like `.scanner{display:flex}` otherwise
   override the UA `[hidden]{display:none}` and leave overlays stuck on screen even
   after JS sets `.hidden = true` (this hid scan results behind the camera overlay). */
[hidden] { display: none !important; }

:root {
  --bg: #0b0f1a;
  --bg-2: #111726;
  --panel: #151c2e;
  --panel-2: #1b2338;
  --border: #263149;
  --border-soft: #1f2842;
  --text: #e8ecf5;
  --muted: #8894ac;
  --accent: #ffcb05;      /* Pokémon yellow */
  --accent-2: #3b6ef6;    /* Pokémon blue */
  --green: #2ec16a;
  --red: #ff5a6a;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --shadow-hover: 0 18px 45px rgba(0,0,0,.5);
  --tabbar-h: 74px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(59,110,246,.18), transparent 60%),
    radial-gradient(900px 500px at 0% 0%, rgba(255,203,5,.10), transparent 55%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
}

.muted { color: var(--muted); }
.accent { color: var(--accent); }

/* ========================= HERO ========================= */
.hero {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 14px clamp(16px, 4vw, 40px) 18px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: linear-gradient(180deg, rgba(11,15,26,.96), rgba(11,15,26,.80));
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-soft);
}
.hero-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.brand { display: flex; align-items: center; gap: 11px; }
.logo {
  font-size: 22px;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), #ffb300);
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(255,203,5,.25);
}
.brand-title { font-weight: 800; font-size: 17px; letter-spacing: -.02em; }

.hero-scan {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 18px; cursor: pointer;
  display: grid; place-items: center; transition: border-color .2s, transform .12s;
}
.hero-scan:hover { border-color: var(--accent-2); }
.hero-scan:active { transform: scale(.94); }

.hero-value { text-align: center; }
.hero-label {
  font-size: 12px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .12em; font-weight: 600;
}
.hero-big {
  font-size: clamp(38px, 11vw, 56px); font-weight: 900; letter-spacing: -.03em;
  line-height: 1.05; margin: 2px 0 12px;
  background: linear-gradient(120deg, #fff 20%, var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-stats { display: flex; gap: 10px; justify-content: center; }
.hero-chip {
  display: flex; align-items: baseline; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 16px;
}
.hero-chip b { font-size: 16px; font-weight: 800; }
.hero-chip span { font-size: 12px; color: var(--muted); }

/* ========================= LAYOUT ========================= */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: clamp(18px, 4vw, 34px) clamp(14px, 4vw, 40px) 40px;
}
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.section-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 6px;
}
.section-head h2 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.section-head p { margin: 0; width: 100%; font-size: 14px; }
.section-count {
  font-size: 13px; font-weight: 700; color: var(--accent);
  background: rgba(255,203,5,.12); border: 1px solid rgba(255,203,5,.28);
  border-radius: 999px; padding: 2px 12px;
}

/* ========================= SCAN HERO (intro card) ========================= */
.scan-hero {
  max-width: 460px; margin: 6px auto 0; text-align: center;
  background: linear-gradient(180deg, rgba(27,35,56,.9), rgba(17,23,38,.9));
  border: 1px solid var(--border-soft); border-radius: 24px;
  padding: 30px 24px; box-shadow: var(--shadow);
}
.scan-hero h2 { margin: 6px 0 8px; font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.scan-hero p { font-size: 14.5px; }
.scan-hero-art { position: relative; height: 130px; display: grid; place-items: center; margin-bottom: 6px; }
.scan-hero-card {
  width: 86px; height: 120px; border-radius: 12px; position: relative; z-index: 1;
  background: linear-gradient(150deg, var(--accent-2), #7b2ff7);
  border: 2px solid rgba(255,255,255,.14);
  box-shadow: 0 18px 40px rgba(59,110,246,.35);
  transform: rotate(-8deg);
}
.scan-hero-card::after {
  content: "?"; position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 44px; font-weight: 900; color: rgba(255,255,255,.55);
}
.scan-hero-glow {
  position: absolute; width: 170px; height: 170px; border-radius: 50%;
  background: radial-gradient(circle, rgba(59,110,246,.35), transparent 65%);
  filter: blur(6px);
}
.scan-hero-alt { margin-top: 12px; }
.hint-note {
  margin-top: 16px !important; font-size: 12.5px !important; color: var(--muted);
  background: var(--bg-2); border: 1px solid var(--border-soft);
  border-radius: 12px; padding: 10px 14px; line-height: 1.45;
}

/* ========================= SEARCH ========================= */
.search-box { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.input {
  flex: 1; min-width: 180px; padding: 14px 16px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text); font-size: 15px; font-family: inherit;
  transition: border-color .2s, box-shadow .2s;
}
.input-sm { flex: 0 0 130px; min-width: 110px; }
.input::placeholder { color: #5c6884; }
.input:focus { outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(59,110,246,.2); }

/* ========================= BUTTONS ========================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 20px; border: none; border-radius: 12px;
  font-family: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
  transition: transform .12s, filter .2s, background .2s, border-color .2s; white-space: nowrap;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn-block { width: 100%; }
.btn-lg { padding: 16px 22px; font-size: 16px; border-radius: 14px; }
.btn-primary { background: linear-gradient(140deg, var(--accent-2), #2a54d6); color: #fff; box-shadow: 0 10px 24px rgba(59,110,246,.3); }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--accent-2); }
.btn-add { width: 100%; background: linear-gradient(140deg, var(--accent), #ffb300); color: #1a1400; margin-top: auto; }
.btn-add:hover { filter: brightness(1.05); }
.btn-danger { width: 100%; background: rgba(255,90,106,.12); color: var(--red); border: 1px solid rgba(255,90,106,.3); }
.btn-danger:hover { background: rgba(255,90,106,.2); }

/* ========================= OCR result (inline) ========================= */
.ocr-result {
  max-width: 640px; margin: 18px auto 0;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 16px; padding: 16px;
}
.ocr-status { font-size: 14px; margin-bottom: 12px; }
.ocr-status.err { color: var(--red); }
.ocr-status.ok { color: var(--green); }
.ocr-preview { display: flex; gap: 16px; align-items: flex-start; }
#ocrThumb { width: 84px; border-radius: 10px; border: 1px solid var(--border); object-fit: cover; display: none; }
#ocrThumb[src] { display: block; }
.ocr-fields { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.ocr-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ocr-tag { font-size: 13px; color: var(--muted); }
.chip {
  padding: 6px 12px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; font-size: 13px;
}
.chip-static { color: var(--accent); border-color: rgba(255,203,5,.35); font-weight: 700; }

/* ========================= CARD GRID ========================= */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px; margin-top: 18px;
}
.grid-sheet { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.card {
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border-soft); border-radius: 16px; padding: 10px;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-hover); border-color: var(--accent-2); }
.card-thumb { position: relative; }
.card img {
  width: 100%; aspect-ratio: 245 / 342; object-fit: contain;
  border-radius: 10px; background: #0a0d16;
}
.cond-badge {
  position: absolute; top: 8px; left: 8px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .02em;
  background: rgba(11,15,26,.82); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px; padding: 3px 9px;
  backdrop-filter: blur(4px);
}
.qty-badge {
  position: absolute; top: 8px; right: 8px;
  font-size: 11px; font-weight: 800; color: #1a1400;
  background: linear-gradient(140deg, var(--accent), #ffb300);
  border-radius: 999px; min-width: 22px; height: 22px; padding: 0 6px;
  display: grid; place-items: center;
}
.card .name { font-weight: 700; font-size: 14px; margin-top: 9px; letter-spacing: -.01em; line-height: 1.25; }
.card .set { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.card .price { font-size: 15px; font-weight: 800; color: var(--accent); margin-top: 7px; }
.card .price .sub { font-size: 11px; color: var(--muted); font-weight: 500; }
.card .rarity {
  display: inline-block; margin-top: 6px; font-size: 10.5px; color: var(--muted);
  background: var(--bg-2); border: 1px solid var(--border); padding: 2px 8px; border-radius: 999px;
}
.card .row { display: flex; gap: 8px; margin-top: 10px; }
.card .row .qtyInput {
  width: 54px; padding: 8px; text-align: center;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-family: inherit; font-size: 14px;
}
.card .row .condInput {
  flex: 1; padding: 8px; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-family: inherit; font-size: 12.5px; cursor: pointer;
}
.card .qtyInput:focus, .card .condInput:focus { outline: none; border-color: var(--accent-2); }
.card button { margin-top: 9px; padding: 10px; font-size: 13.5px; }

.empty {
  grid-column: 1 / -1; text-align: center; padding: 46px 20px; color: var(--muted);
  border: 1.5px dashed var(--border); border-radius: 16px; font-size: 15px;
}
.empty .empty-ic { font-size: 34px; display: block; margin-bottom: 10px; }
.empty .empty-cta {
  display: inline-block; margin-top: 14px; color: var(--accent-2);
  font-weight: 700; cursor: pointer;
}

.spinner {
  display: inline-block; width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,.25); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========================= TAB BAR ========================= */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex; align-items: stretch;
  background: rgba(15,19,32,.94); backdrop-filter: blur(18px);
  border-top: 1px solid var(--border-soft);
}
.tab {
  flex: 1; border: none; background: none; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-family: inherit; font-size: 11px; font-weight: 600; transition: color .2s;
}
.tab-ic { font-size: 20px; filter: grayscale(.4) opacity(.8); transition: filter .2s, transform .12s; }
.tab.active { color: var(--text); }
.tab.active .tab-ic { filter: none; transform: translateY(-1px); }
.tab:active .tab-ic { transform: scale(.9); }
.tab-scan { position: relative; }
.tab-scan-ring {
  width: 54px; height: 54px; margin-top: -22px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent-2), #7b2ff7);
  border: 4px solid var(--bg); box-shadow: 0 10px 24px rgba(59,110,246,.45);
  transition: transform .14s;
}
.tab-scan:active .tab-scan-ring { transform: scale(.92); }
.tab-scan-ic { font-size: 22px; }
.tab-scan .tab-lbl { margin-top: 2px; }

/* ========================= FULLSCREEN SCANNER ========================= */
.scanner {
  position: fixed; inset: 0; z-index: 100; background: #05070c;
  display: flex; flex-direction: column;
}
.scanner-stage { position: absolute; inset: 0; overflow: hidden; background: #000; }
#scanVideo, #scanFreeze {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}

/* reticle: dimmed surround + clear card window */
.reticle { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.frame {
  width: min(72vw, 300px); aspect-ratio: 5 / 7; position: relative;
  border-radius: 20px;
  box-shadow: 0 0 0 100vmax rgba(5,7,12,.60);
  outline: 2px solid rgba(255,255,255,.55);
  outline-offset: -2px;
}
.corner {
  position: absolute; width: 30px; height: 30px;
  border: 3px solid var(--accent); border-radius: 4px;
}
.corner.tl { top: -3px; left: -3px; border-right: none; border-bottom: none; border-top-left-radius: 20px; }
.corner.tr { top: -3px; right: -3px; border-left: none; border-bottom: none; border-top-right-radius: 20px; }
.corner.bl { bottom: -3px; left: -3px; border-right: none; border-top: none; border-bottom-left-radius: 20px; }
.corner.br { bottom: -3px; right: -3px; border-left: none; border-top: none; border-bottom-right-radius: 20px; }
.num-zone {
  position: absolute; left: 8%; right: 8%; bottom: 5%; height: 15%;
  border: 1.5px dashed rgba(255,203,5,.85); border-radius: 8px;
  display: grid; place-items: center;
}
.num-zone span {
  font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent); background: rgba(5,7,12,.5); padding: 2px 8px; border-radius: 999px;
}
.scanline {
  position: absolute; left: 6%; right: 6%; height: 2px; top: 8%;
  background: linear-gradient(90deg, transparent, var(--accent-2), transparent);
  box-shadow: 0 0 12px 2px rgba(59,110,246,.6);
  animation: scanmove 2.4s ease-in-out infinite;
}
@keyframes scanmove { 0%,100% { top: 8%; } 50% { top: 88%; } }
.reticle-hint {
  margin-top: 22px; font-size: 14px; font-weight: 600; color: #fff;
  background: rgba(5,7,12,.55); padding: 8px 16px; border-radius: 999px;
  backdrop-filter: blur(4px);
}

.scanner-bar {
  position: relative; z-index: 3; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; padding-top: calc(14px + env(safe-area-inset-top, 0px));
}
.scanner-close {
  width: 40px; height: 40px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(5,7,12,.5); color: #fff; font-size: 18px; backdrop-filter: blur(6px);
}
.scanner-title { font-size: 16px; font-weight: 700; color: #fff; text-shadow: 0 1px 4px rgba(0,0,0,.6); }

.scanner-controls {
  position: relative; z-index: 3; margin-top: auto;
  padding: 20px 16px calc(30px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.scan-status {
  min-height: 20px; font-size: 14px; font-weight: 600; color: #fff; text-align: center;
  text-shadow: 0 1px 4px rgba(0,0,0,.7);
}
.scan-status.err { color: #ffb3bb; }
.scan-status.ok { color: #8bf0b3; }
.shutter {
  width: 74px; height: 74px; border-radius: 50%; cursor: pointer;
  border: 5px solid rgba(255,255,255,.9); background: transparent;
  display: grid; place-items: center; transition: transform .12s;
}
.shutter span {
  width: 56px; height: 56px; border-radius: 50%;
  background: #fff; transition: transform .12s, background .2s;
}
.shutter:active span { transform: scale(.88); }
.shutter:disabled { opacity: .5; cursor: default; }
.shutter.busy span { background: var(--accent); }

/* fallback (no live camera) */
.scanner-fallback {
  position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 12px;
  padding: 30px; background: linear-gradient(180deg, #0b0f1a, #05070c);
}
.scanner-fallback .fb-ic { font-size: 46px; }
.scanner-fallback h3 { margin: 0; font-size: 20px; font-weight: 800; }
.scanner-fallback p { margin: 0; max-width: 380px; color: var(--muted); font-size: 14px; }
.scanner-fallback .btn { margin-top: 8px; }

/* results sheet */
.scan-sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  max-height: 82%; overflow-y: auto;
  background: var(--panel); border-top: 1px solid var(--border);
  border-radius: 22px 22px 0 0; padding: 10px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -14px 40px rgba(0,0,0,.5); animation: sheetup .3s ease;
}
@keyframes sheetup { from { transform: translateY(100%); } to { transform: none; } }
.sheet-handle { width: 42px; height: 5px; border-radius: 999px; background: var(--border); margin: 4px auto 12px; }
.sheet-status { font-size: 15px; font-weight: 600; text-align: center; margin-bottom: 4px; }
.sheet-status.err { color: var(--red); }
.sheet-status.ok { color: var(--green); }
.scan-sheet .btn-ghost { margin-top: 14px; }

/* ========================= RESPONSIVE ========================= */
@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
