:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1c1e21;
  --text-muted: #6b7280;
  --accent: #e3350d;
  --accent-dark: #b8280a;
  --owned: #2e9e4f;
  --owned-bg: #e6f7ea;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1e2126;
    --border: #2c2f36;
    --text: #f2f3f5;
    --text-muted: #9aa0aa;
    --owned: #3ecb6a;
    --owned-bg: #163021;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.title-row h1 {
  font-size: 1.25rem;
  margin: 0;
  flex: 1;
}

.pokeball-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--owned);
  transition: width 0.3s ease;
  width: 0%;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.search-input {
  flex: 1;
  min-width: 140px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.search-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.filter-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.filter-btn {
  padding: 8px 14px;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
}

.filter-btn + .filter-btn {
  border-left: 1px solid var(--border);
}

.filter-btn.active {
  background: var(--accent);
  color: #fff;
}

.action-btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
}

.action-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

.status-line {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
  font-size: 0.95rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 8px 12px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  position: relative;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}

.card:active {
  transform: translateY(0);
}

.card.owned {
  background: var(--owned-bg);
  border-color: var(--owned);
}

.card .dex-num {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  filter: grayscale(100%);
  opacity: 0.45;
  transition: filter 0.15s ease, opacity 0.15s ease;
}

.card.owned img {
  filter: none;
  opacity: 1;
}

.card .name {
  font-size: 0.8rem;
  margin-top: 2px;
  text-transform: capitalize;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.check-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--owned);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.card.owned .check-badge {
  opacity: 1;
  transform: scale(1);
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

#import-file-input {
  display: none;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 480px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 8px;
  }
  .title-row h1 {
    font-size: 1.05rem;
  }
}

.nav-link {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  white-space: nowrap;
}

.nav-link:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* TCG card grid (indexex.html) */
.grid.grid--tcg {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.card.card--tcg img {
  aspect-ratio: 245 / 342;
  filter: grayscale(100%) brightness(0.9);
  opacity: 0.35;
  border-radius: 6px;
}

.card.card--tcg.owned img {
  filter: none;
  opacity: 1;
}

.card--tcg .set-info {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 480px) {
  .grid.grid--tcg {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
}

/* Decks screen (decks.html) */
.hidden {
  display: none !important;
}

.action-btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.action-btn--primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #fff;
}

.action-btn--danger {
  color: var(--accent);
}

.action-btn--danger:hover {
  background: var(--accent);
  color: #fff;
}

.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.deck-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  gap: 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.deck-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}

.deck-card-sprite {
  width: 72px;
  height: 72px;
  object-fit: contain;
  flex-shrink: 0;
}

.deck-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
}

.deck-card-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.deck-card-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.deck-card-body .progress-wrap {
  margin-top: 4px;
}

.deck-detail-header {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.deck-detail-sprite {
  width: 64px;
  height: 64px;
  object-fit: contain;
}

.deck-detail-info {
  flex: 1;
  min-width: 160px;
}

.deck-detail-info h2 {
  margin: 0 0 2px;
  font-size: 1.15rem;
}

.deck-detail-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: capitalize;
  margin-bottom: 4px;
}

.deck-detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.add-card-row {
  display: flex;
  gap: 10px;
  margin: 16px 0;
  flex-wrap: wrap;
}

.add-card-row .search-input {
  flex: 1;
  min-width: 180px;
}

.qty-input {
  width: 70px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.card-search-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 1.2em;
  margin-bottom: 8px;
}

.card-search-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card-search-result {
  cursor: pointer;
  text-align: center;
  border-radius: 8px;
  padding: 4px;
  transition: background 0.12s ease, transform 0.12s ease;
}

.card-search-result:hover {
  background: var(--surface);
  transform: translateY(-2px);
}

.card-search-result img {
  width: 100%;
  aspect-ratio: 245 / 342;
  object-fit: contain;
  border-radius: 6px;
}

.card-search-result-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.deck-slot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.card--deck-slot {
  position: relative;
  padding-top: 18px;
}

.slot-remove-btn {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.card--deck-slot:hover .slot-remove-btn {
  opacity: 1;
}

.slot-remove-btn:hover {
  background: var(--accent);
  color: #fff;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.modal h2 {
  margin: 0 0 14px;
  font-size: 1.1rem;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.modal-field input {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

.modal-field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

/* Login screen (login.php) */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-title-row {
  justify-content: center;
  margin-bottom: 4px;
}

.login-title-row h1 {
  flex: none;
  font-size: 1.15rem;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.login-field input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

.login-field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.login-error {
  background: var(--owned-bg);
  color: var(--accent-dark);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
}

.login-submit {
  margin-top: 6px;
  padding: 11px 14px;
  font-size: 0.95rem;
}
