:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4f46e5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.9rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { flex: 1; min-width: 0; font-size: 1.1rem; margin: 0; overflow-wrap: anywhere; }
.icon-btn { color: var(--text); font-size: 1.3rem; text-decoration: none; padding: 0 0.4rem; }
.link-btn { background: none; border: none; color: var(--muted); font: inherit; font-size: 0.85rem; cursor: pointer; }

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: 5rem;
}

input, button, textarea { font: inherit; }
input, textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  font-size: 1rem; /* 16px stops iOS zooming on focus */
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  font-weight: 600;
  cursor: pointer;
}

.form { display: flex; flex-direction: column; gap: 0.9rem; }
.form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }

.entry { display: flex; gap: 0.5rem; padding: 0.5rem 0; background: var(--bg); }
/* Stays in reach while scrolling, since adding cards is the main job here. */
.entry.sticky { position: sticky; top: 0; z-index: 10; }

.tabs { display: flex; gap: 0.25rem; margin-bottom: 0.75rem; }
.tab-btn {
  flex: 1;
  padding: 0.5rem 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
}
.tab-btn.active { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }
.tab-panel:not(.active) { display: none; }

.filters { display: flex; gap: 0.25rem; margin: 0.5rem 0 0.75rem; }
.filter-btn {
  flex: 1;
  padding: 0.45rem;
  background: none;
  border: none;
  border-bottom: 2px solid var(--border);
  color: var(--muted);
  cursor: pointer;
}
.filter-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.collection-list { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.collection {
  display: block;
  padding: 0.8rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: inherit;
  text-decoration: none;
}
.collection-name { font-weight: 600; overflow-wrap: anywhere; }
.collection-stats { margin-top: 0.2rem; color: var(--muted); font-size: 0.82rem; }

.card-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.card {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.card.owned { border-color: var(--accent); }
.card img { width: 43px; height: 60px; object-fit: contain; border-radius: 4px; flex: none; }
.card-info { flex: 1; min-width: 0; }
.card-name { display: block; color: inherit; text-decoration: none; font-size: 0.92rem; overflow-wrap: anywhere; }
.card-prices { color: var(--muted); font-size: 0.78rem; margin-top: 0.15rem; }
.stepper { display: flex; align-items: center; gap: 0.3rem; flex: none; }
.stepper button {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}
.stepper button:disabled { opacity: 0.35; cursor: default; }
.stepper span { min-width: 1.4rem; text-align: center; font-variant-numeric: tabular-nums; }
.set-scroll { overflow-x: auto; }
.set-grid { display: grid; gap: 0.3rem; align-items: center; justify-items: center; width: max-content; min-width: 100%; }
.set-head { font-size: 0.72rem; font-weight: 600; text-align: center; line-height: 1.25; }
.set-head small { display: block; color: var(--muted); font-weight: 400; }
.set-number { color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.set-slot { width: 43px; height: 60px; object-fit: contain; border-radius: 3px; background: var(--border); }
.set-slot.missing { filter: grayscale(1); opacity: 0.3; }
.empty { text-align: center; color: var(--muted); padding: 2rem 0; }

.hint { margin: 0; color: var(--muted); font-size: 0.8rem; line-height: 1.45; }
ol.hint { padding-left: 1.2rem; }
textarea { font-family: ui-monospace, Menlo, monospace; resize: vertical; }
.export-buttons { display: flex; gap: 0.5rem; }
.export-buttons button { flex: 1; }
.manage { display: flex; justify-content: space-between; margin-top: 1.25rem; }
.link-btn.danger { color: #dc2626; }

.totals {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 1rem;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}

.toast {
  position: fixed;
  bottom: 3.8rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1c1e21;
  color: white;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  max-width: 90%;
  text-align: center;
  z-index: 50;
}
