* { box-sizing: border-box; margin: 0; padding: 0; }

/* Ensure [hidden] attribute always wins over display rules in this file */
[hidden] { display: none !important; }

body {
  font-family: system-ui, sans-serif;
  background: #1a1a2e;
  color: #eee;
  height: 100dvh;
  overflow: hidden; /* app handles its own scroll */
}

/* ── Password overlay ────────────────────────────────────── */
#password-overlay {
  position: fixed; inset: 0;
  background: #1a1a2e;
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
#password-picker {
  text-align: center;
  padding: 2rem;
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
}
#password-picker h2 { font-size: 2rem; margin-bottom: 0.5rem; }
#password-input {
  font-size: 1.2rem;
  padding: 0.6rem 1rem;
  border-radius: 10px;
  border: 2px solid #444;
  background: #2a2a4e;
  color: #eee;
  width: 220px;
  text-align: center;
}
#password-btn {
  font-size: 1.1rem;
  padding: 0.6rem 2rem;
  border-radius: 10px;
  border: none;
  background: #e63946;
  color: white;
  font-weight: bold;
  cursor: pointer;
}
#password-error { color: #e63946; font-size: 0.9rem; }

/* ── Profile overlay ─────────────────────────────────────── */
#profile-overlay {
  position: fixed; inset: 0;
  background: #1a1a2e;
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
#profile-picker {
  text-align: center;
  padding: 2rem;
}
#profile-picker h2 {
  font-size: 1.8rem;
  margin-bottom: 2rem;
}
#profile-buttons {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  flex-wrap: wrap;
}
.profile-btn {
  width: 160px; height: 160px;
  border-radius: 20px;
  border: none;
  font-size: 1.2rem;
  font-weight: bold;
  cursor: pointer;
  color: white;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0.5rem;
  margin: 0;
}
.profile-btn .profile-avatar { font-size: 3rem; }

/* ── App shell ───────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1200px;
  margin: 0 auto;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: #0f1b35;
  flex-shrink: 0;
}
header h1 { font-size: 1.2rem; }

#profile-switch-btn {
  width: auto; margin: 0; padding: 0.4rem 0.9rem;
  font-size: 0.9rem; border-radius: 20px;
  background: #333a5c;
}

/* ── Tab bar (bottom) ────────────────────────────────────── */
#tab-bar {
  display: flex;
  background: #0f1b35;
  flex-shrink: 0;
  order: 999; /* always last */
}
.tab {
  flex: 1; margin: 0; padding: 0.8rem;
  border-radius: 0; border-top: 3px solid transparent;
  background: transparent; color: #888;
  font-size: 0.95rem;
}
.tab.active {
  color: #eee;
  border-top-color: #e63946;
}

/* ── Scanner tab ─────────────────────────────────────────── */
#tab-scanner {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  gap: 0;
}

#scanner-panel {
  padding: 1rem;
  flex-shrink: 0;
}

#result-panel {
  padding: 1rem;
  flex: 1;
}

/* Tablet: side by side */
@media (min-width: 768px) {
  #tab-scanner {
    flex-direction: row;
    overflow: hidden;
  }
  #scanner-panel {
    flex: 0 0 520px;
    overflow-y: auto;
    border-right: 1px solid #ffffff18;
  }
  #result-panel {
    overflow-y: auto;
  }
}

/* ── Viewfinder ──────────────────────────────────────────── */
#viewfinder {
  position: relative;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 4/3;
}

@media (min-width: 768px) {
  #viewfinder { max-height: 75vh; }
}

#video {
  width: 100%; height: 100%;
  object-fit: cover;
}

/* ── Card positioning bracket ────────────────────────────── */
/* Pokémon card is 5:7 portrait. In a 4:3 viewfinder:
   height = 86% of VF height → width ≈ 86% × (3/4) × (5/7) ≈ 46% of VF width */
#card-frame {
  position: absolute;
  top: 7%; bottom: 7%;
  width: 46%;
  left: 50%; transform: translateX(-50%);
  /* spotlight: dims everything outside the bracket */
  box-shadow: 0 0 0 100vw rgba(0,0,0,0.45);
  border-radius: 3px;
  pointer-events: none;
}

.frm-corner {
  position: absolute;
  width: 24px; height: 24px;
  border-color: #ffdc00;
  border-style: solid;
  border-width: 0;
}
.frm-corner.tl { top: 0;    left: 0;   border-top-width: 3px; border-left-width: 3px;  border-top-left-radius: 3px; }
.frm-corner.tr { top: 0;    right: 0;  border-top-width: 3px; border-right-width: 3px; border-top-right-radius: 3px; }
.frm-corner.bl { bottom: 0; left: 0;   border-bottom-width: 3px; border-left-width: 3px;  border-bottom-left-radius: 3px; }
.frm-corner.br { bottom: 0; right: 0;  border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 3px; }

/* Dashed line showing the OCR scan zone (card number area) */
#num-zone {
  position: absolute;
  bottom: 13%; left: 0; right: 0;
  border-top: 1.5px dashed rgba(255,220,0,0.55);
}

#frame-hint {
  text-align: center;
  font-size: 0.78rem;
  color: rgba(255,220,0,0.7);
  margin-top: 0.4rem;
}

/* ── Buttons (generic) ───────────────────────────────────── */
button {
  display: block; width: 100%;
  margin-top: 0.75rem; padding: 0.85rem;
  font-size: 1rem; font-weight: bold;
  border: none; border-radius: 10px;
  cursor: pointer;
  background: #e3350d; color: white;
}
button:active { opacity: 0.8; }

#add-to-collection-btn {
  background: #2a9d5c;
  font-size: 1.1rem;
  padding: 1rem;
}

/* ── Card info (scan result) ─────────────────────────────── */
#card-info {
  background: #16213e;
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.card-info-top {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

#card-image {
  width: 100px; border-radius: 8px; flex-shrink: 0;
}

@media (min-width: 768px) {
  #card-image { width: 140px; }
}

#card-details h2 { font-size: 1.2rem; margin-bottom: 0.4rem; }
#card-details p  { font-size: 0.9rem; color: #aaa; margin-top: 0.25rem; }
#card-owned      { font-size: 1rem !important; color: #7ed9a8 !important; font-weight: bold; }

/* ── Multi-match ─────────────────────────────────────────── */
#multi-match { margin-top: 0.5rem; }
#match-list  { list-style: none; padding: 0; margin-top: 0.5rem; }
#match-list li {
  background: #16213e;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  cursor: pointer;
  display: flex; align-items: center; gap: 0.75rem;
}
#match-list li:hover { background: #0f3460; }

#error-msg {
  margin-top: 1rem; padding: 1rem;
  background: #3d0000; border-radius: 8px; color: #ff8888;
}

/* ── Manual entry ────────────────────────────────────────── */
#manual-entry {
  margin-top: 0.75rem;
  text-align: center;
  font-size: 0.85rem; color: #aaa;
}
#manual-row {
  display: flex; gap: 0.5rem; margin-top: 0.4rem;
}
#manual-num, #manual-total {
  width: 5rem; padding: 0.7rem 0.4rem;
  font-size: 1rem; border-radius: 8px; border: none;
  background: #16213e; color: #eee; text-align: center;
}
#manual-slash {
  font-size: 1.4rem; align-self: center; color: #aaa;
}
#manual-btn {
  width: auto; margin-top: 0; padding: 0.7rem 1rem;
}

/* ── Spinner ─────────────────────────────────────────────── */
.spinner {
  display: inline-block; width: 1.2rem; height: 1.2rem;
  border: 3px solid #fff3; border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle; margin-right: 0.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading { margin-top: 1rem; text-align: center; }

/* ── Collection tab ──────────────────────────────────────── */
#tab-collection {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden;
}

#collection-header {
  padding: 0.75rem 1rem;
  font-weight: bold; font-size: 1rem;
  background: #16213e; flex-shrink: 0;
}

#card-grid {
  flex: 1; overflow-y: auto;
  padding: 0.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.6rem;
  align-content: start;
}

@media (min-width: 768px) {
  #card-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    padding: 1rem;
  }
}

.grid-card {
  position: relative;
  background: #16213e;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 2/3;
  display: flex; align-items: center; justify-content: center;
}
.grid-card img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.grid-card:hover { outline: 2px solid #e63946; }

.qty-badge {
  position: absolute; top: 4px; right: 4px;
  background: #e63946;
  color: white; font-size: 0.7rem; font-weight: bold;
  border-radius: 10px; padding: 1px 6px;
  min-width: 20px; text-align: center;
}

.grid-card-name {
  position: absolute;
  top: 8%; left: 0; right: 0;
  background: linear-gradient(rgba(0,0,0,0.72), rgba(0,0,0,0));
  font-size: 0.7rem; font-weight: bold;
  padding: 4px 8px 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  pointer-events: none;
}

/* ── Card detail overlay ─────────────────────────────────── */
#detail-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  padding: 1rem;
}
#detail-content {
  background: #16213e;
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 420px; width: 100%;
  position: relative;
  max-height: 90dvh; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center;
  gap: 0.75rem;
}
#detail-close {
  position: absolute; top: 0.75rem; right: 0.75rem;
  width: auto; margin: 0; padding: 0.3rem 0.7rem;
  background: #333a5c; font-size: 1rem;
}
#detail-image {
  width: 180px; border-radius: 10px;
}
#detail-content h2 { font-size: 1.2rem; text-align: center; }
#detail-content p   { font-size: 0.9rem; color: #aaa; text-align: center; }

#detail-qty-row {
  display: flex; align-items: center; gap: 1rem;
  margin-top: 0.5rem;
}
#detail-qty-row button {
  width: 48px; height: 48px; margin: 0; padding: 0;
  font-size: 1.5rem; border-radius: 50%;
  background: #333a5c;
}
#detail-qty { font-size: 1.5rem; font-weight: bold; min-width: 2rem; text-align: center; }

#detail-remove-row { width: 100%; }
#detail-remove-btn  { background: #7a1c1c; }
#detail-confirm     { margin-top: 0.5rem; text-align: center; font-size: 0.9rem; }
#detail-confirm button { display: inline-block; width: auto; margin: 0.4rem 0.3rem 0; padding: 0.5rem 1.2rem; }
#detail-confirm-yes { background: #e63946; }
#detail-confirm-no  { background: #333a5c; }

/* ── Chip bar (collection sort/filter) ───────────────────── */
#chip-bar {
  padding: 0.5rem 0.75rem;
  background: #16213e;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border-bottom: 1px solid #ffffff12;
}
.chip-group {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.chip-group::-webkit-scrollbar { display: none; }
.chip {
  display: inline-block;
  width: auto; margin: 0; padding: 0.3rem 0.8rem;
  font-size: 0.8rem; font-weight: 600;
  border-radius: 20px;
  background: #1e2a4a;
  color: #aaa;
  white-space: nowrap;
  flex-shrink: 0;
}
.chip.active { background: #e63946; color: white; }

/* ── Debug ───────────────────────────────────────────────── */
#debug { margin-top: 1rem; font-size: 0.8rem; color: #888; }
