:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3f56;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #c9a227;
  --accent-dim: #8a7020;
  --danger: #e05c5c;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

header {
  background: linear-gradient(135deg, #1a2332 0%, #0f1419 100%);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}

header h1 span { color: var(--muted); font-weight: 400; font-size: 0.85rem; display: block; }

nav {
  display: flex;
  gap: 0.5rem;
}

nav button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.45rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s;
}

nav button:hover { border-color: var(--accent-dim); color: var(--text); }
nav button.active { background: var(--accent); color: #0f1419; border-color: var(--accent); font-weight: 600; }

main { max-width: 960px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

.panel { display: none; }
.panel.active { display: block; }

.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-bar input, .search-bar select {
  flex: 1;
  min-width: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.search-bar input:focus { outline: 2px solid var(--accent-dim); border-color: transparent; }

.btn {
  background: var(--accent);
  color: #0f1419;
  border: none;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
}

.btn:hover { filter: brightness(1.1); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }

.card-grid, .deck-list { display: flex; flex-direction: column; gap: 0.6rem; }

.card-row, .deck-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
}

.card-row img {
  width: 44px;
  height: 62px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--surface2);
}

.card-placeholder {
  width: 44px;
  height: 62px;
  background: var(--surface2);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--muted);
}

.card-info, .deck-info { flex: 1; min-width: 0; }
.card-info h3, .deck-info h3 { font-size: 0.95rem; font-weight: 600; }
.card-info p, .deck-info p { font-size: 0.8rem; color: var(--muted); }

.qty {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 2.5rem;
  text-align: center;
}

.actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.empty h2 { font-size: 1.1rem; margin-bottom: 0.4rem; color: var(--text); }

.search-results {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s;
}

.chip:hover { background: var(--accent); color: #0f1419; border-color: var(--accent); }

.deck-detail-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  width: 100%;
  max-width: 360px;
}

.modal-wide { max-width: 480px; }
.modal-hint { font-size: 0.85rem; color: var(--muted); margin-bottom: 1rem; line-height: 1.45; }

.file-drop {
  display: block;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  margin-bottom: 1rem;
  transition: border-color 0.15s;
}

.file-drop:hover, .file-drop.has-file { border-color: var(--accent); }
.file-drop input { display: none; }
.file-drop span { color: var(--muted); font-size: 0.9rem; }

.import-mode {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.88rem;
}

.import-mode label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; color: var(--muted); }
.import-mode input { accent-color: var(--accent); }

.import-result {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 0.75rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  line-height: 1.5;
}

.import-result.hidden { display: none; }
.import-result .ok { color: #6fcf97; }
.import-result .err { color: var(--danger); }

.modal h3 { margin-bottom: 0.75rem; }
.modal input { width: 100%; margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.65rem 1rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s;
  z-index: 200;
  max-width: 320px;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: var(--danger); color: var(--danger); }

@media (max-width: 600px) {
  .card-row, .deck-row { flex-wrap: wrap; }
  .actions { width: 100%; justify-content: flex-end; }
}