:root {
  --bg: #f8f3e8;
  --text: #1b1a17;
  --panel: rgba(255, 252, 245, 0.82);
  --stroke: #d8ccb4;
  --accent: #bb3e03;
  --accent-soft: #ffe0c7;
  --muted: #5c5343;
  --ok: #2d6a4f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "IBM Plex Sans JP", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 10%, #f5d5a4 0%, transparent 38%),
    radial-gradient(circle at 82% 0%, #f8b8a8 0%, transparent 32%),
    linear-gradient(165deg, #f6efe4 0%, #efe3d2 60%, #ead9c2 100%);
  min-height: 100vh;
  overflow-x: hidden;
}

.bg-shape {
  position: fixed;
  z-index: 0;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.25;
  pointer-events: none;
}

.bg-shape-a {
  width: 320px;
  height: 320px;
  background: #a7c957;
  top: -80px;
  right: -80px;
  animation: driftA 12s ease-in-out infinite;
}

.bg-shape-b {
  width: 380px;
  height: 380px;
  background: #bc6c25;
  left: -130px;
  bottom: -110px;
  animation: driftB 14s ease-in-out infinite;
}

.shell {
  position: relative;
  z-index: 1;
  width: min(96vw, 1720px);
  margin: 0 auto;
  padding: 24px;
}

.hero {
  animation: fadeInUp 0.6s ease both;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.16em;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
}

h1 {
  margin: 4px 0 8px;
  font-size: clamp(2rem, 3.5vw, 3rem);
  line-height: 1.05;
}

.subtitle {
  margin: 0;
  max-width: 70ch;
  color: var(--muted);
}

.subtitle a {
  color: var(--accent);
  font-weight: 700;
}

.panel {
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid var(--stroke);
  border-radius: 16px;
  padding: 16px;
  margin-top: 16px;
  box-shadow: 0 14px 28px rgba(42, 33, 20, 0.09);
  animation: fadeInUp 0.6s ease both;
}

.controls {
  padding: 0.6rem 1rem;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 160px;
  display: flex;
  align-items: center;
}

.search-wrap .filter-search {
  width: 100%;
  padding-right: 28px;
}

.search-clear {
  position: absolute;
  right: 6px;
  background: none;
  border: none;
  padding: 0;
  width: 18px;
  height: 18px;
  font-size: 0.75rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.search-clear:hover {
  color: var(--text);
  background: var(--stroke);
}

.search-row {
  display: flex;
  gap: 8px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  border: 1px solid var(--stroke);
  border-radius: 10px;
  padding: 10px;
  background: #fffdf8;
  color: var(--text);
}

button {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  background: var(--accent);
  color: #fffaf0;
  transition: transform 0.15s ease, filter 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

button.secondary {
  background: transparent;
  border-color: var(--stroke);
  color: var(--text);
}

button.icon-btn {
  padding: 0.35rem 0.6rem;
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button.secondary.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

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

.sorting-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.sorting-row label {
  margin-right: 2px;
}

.sorting-row select {
  min-width: 160px;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

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

.results.results-table-mode {
  display: block;
}

.pagination {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

#pageInfo {
  color: var(--muted);
  font-size: 0.9rem;
  min-width: 110px;
  text-align: center;
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: #fffdf7;
}

.games-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
}

.games-table th,
.games-table td {
  border-bottom: 1px solid var(--stroke);
  padding: 8px;
  text-align: left;
  vertical-align: top;
  font-size: 0.84rem;
}

.games-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f6ecdd;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.table-sort-btn {
  border: none;
  background: transparent;
  color: inherit;
  font-size: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  padding: 0;
  cursor: pointer;
}

.table-sort-btn:hover {
  transform: none;
  filter: none;
  color: var(--accent);
}

.table-sort-btn.is-active {
  color: var(--accent);
}

.table-sort-btn:disabled {
  cursor: default;
  opacity: 0.55;
}

.games-table tbody tr:last-child td {
  border-bottom: none;
}

.table-title {
  min-width: 190px;
}

.table-title strong,
.table-title span,
.table-title small {
  display: block;
}

.table-title span {
  margin-top: 2px;
  color: var(--muted);
  font-family: "IBM Plex Sans JP", sans-serif;
}

.table-title small {
  margin-top: 4px;
  color: var(--muted);
}

.table-select,
.table-number-input {
  width: 100%;
  min-width: 72px;
}

.table-jpy-hint {
  display: block;
  margin-top: 4px;
  color: var(--accent);
  font-size: 0.8rem;
  min-height: 1em;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-width: 130px;
}

.table-actions .nescard-link {
  padding: 6px 8px;
}

.card {
  border: 1px solid var(--stroke);
  border-radius: 14px;
  padding: 12px;
  background: #fffdf7;
  display: grid;
  gap: 10px;
  animation: fadeInUp 0.35s ease both;
}

.card-head h3 {
  margin: 0;
  font-size: 1.08rem;
}

.title-jp {
  margin: 4px 0 0;
  font-family: "IBM Plex Sans JP", sans-serif;
  color: var(--muted);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.image-block {
  display: grid;
  gap: 8px;
}

.card-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: #f8f3e7;
}

.card-image.is-empty {
  opacity: 0.45;
}

.image-actions {
  display: flex;
  gap: 8px;
  align-items: end;
  flex-wrap: wrap;
}

.price-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.price-input-row input {
  flex: 1;
  min-width: 0;
}

.price-field-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.price-field-wrap .currency-prefix {
  position: absolute;
  left: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  pointer-events: none;
  user-select: none;
}

.price-field-wrap input {
  width: 100%;
  padding-left: 20px;
}

.price-jpy-display {
  white-space: nowrap;
  color: var(--accent);
  font-weight: 500;
  font-size: 0.9rem;
  min-width: 80px;
}

.price-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  min-height: 1.2em;
}

.nescard-link {
  text-decoration: none;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-size: inherit;
  font-family: inherit;
  display: inline-block;
  white-space: nowrap;
  transition: background 0.15s;
}

.nescard-link:hover {
  background: var(--accent-soft);
}

.upload-label {
  cursor: pointer;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  padding: 10px 14px;
  background: transparent;
  color: var(--text);
  font-size: inherit;
  font-family: inherit;
  display: inline-block;
  white-space: nowrap;
  transition: background 0.15s;
}

.upload-label:hover {
  background: var(--accent-soft);
}

.upload-label input[type="file"] {
  display: none;
}

.chip {
  border: 1px solid var(--stroke);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.78rem;
  background: #fff;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.notes-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.card-footer {
  display: flex;
  align-items: center;
  gap: 10px;
}

.save-status {
  color: var(--ok);
  font-size: 0.85rem;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes driftA {
  0%,
  100% {
    transform: translateY(0) translateX(0);
  }
  50% {
    transform: translateY(16px) translateX(-10px);
  }
}

@keyframes driftB {
  0%,
  100% {
    transform: translateY(0) translateX(0);
  }
  50% {
    transform: translateY(-18px) translateX(12px);
  }
}

@media (max-width: 720px) {
  .shell {
    padding: 14px;
  }

  .search-row {
    flex-direction: column;
  }

  .sorting-row {
    flex-direction: column;
    align-items: stretch;
  }

  .status-grid {
    grid-template-columns: 1fr;
  }

  .image-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .table-scroll {
    margin: 0 -4px;
  }
}

/* Add card form */
.add-card-panel {
  margin-top: 16px;
}

.add-card-summary {
  cursor: pointer;
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--muted);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  user-select: none;
}

.add-card-summary::before {
  content: "+";
  font-size: 1.1rem;
  color: var(--accent);
  font-weight: 700;
  transition: transform 0.2s ease;
  display: inline-block;
}

details[open] .add-card-summary::before {
  transform: rotate(45deg);
}

.add-card-form {
  margin-top: 14px;
  display: grid;
  gap: 12px;
}

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

.add-card-footer {
  display: flex;
  align-items: center;
  gap: 10px;
}

.field-required {
  color: var(--accent);
  font-weight: 700;
}

.field-optional {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}

.save-status.is-error {
  color: var(--accent);
}

/* Edit modal */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(27, 26, 23, 0.52);
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(3px);
}

.modal-backdrop:not([hidden]) {
  display: flex;
}

.modal-box {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 640px;
  box-shadow: 0 20px 48px rgba(42, 33, 20, 0.2);
  animation: fadeInUp 0.22s ease both;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.2rem;
  line-height: 1;
  padding: 4px 8px;
  color: var(--muted);
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
  transform: none;
  filter: none;
}

button.danger {
  border-color: var(--accent);
  color: var(--accent);
}

button.danger:hover {
  background: var(--accent-soft);
  transform: none;
}

/* ── Tag system ─────────────────────────────────────────────────────────────── */

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.missing-only-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.tag-filter-chip,
.tag-chip {
  --tag-color: #888888;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  border: 2px solid var(--tag-color);
  color: var(--tag-color);
  background: transparent;
  cursor: pointer;
  line-height: 1.4;
  transition: background 0.12s, color 0.12s;
}

.tag-filter-chip.is-active,
.tag-chip.is-active {
  background: var(--tag-color);
  color: #fff;
}

.tag-filter-chip:hover,
.tag-chip:hover {
  background: color-mix(in srgb, var(--tag-color) 15%, transparent);
  transform: none;
  filter: none;
}

.tag-filter-chip.is-active:hover,
.tag-chip.is-active:hover {
  background: color-mix(in srgb, var(--tag-color) 80%, #000);
}

.tag-priority-select {
  border: 1px solid var(--stroke);
  border-radius: 6px;
  background: var(--bg);
  font-size: 0.78rem;
  padding: 2px 4px;
  margin-left: 2px;
}

.game-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 4px 0;
}

.table-tags-cell {
  min-width: 140px;
}

.game-priority-row {
  padding: 4px 0;
}

.game-priority-label {
  font-size: 0.82rem;
  color: var(--fg-muted, #888);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Tags management panel */
.tags-management-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

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

.tag-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid var(--stroke);
}

.tag-color-input {
  width: 36px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--stroke);
  border-radius: 4px;
  cursor: pointer;
  background: none;
}

.modal-box--narrow {
  max-width: 420px;
}

.price-modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
}

.price-modal-body label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted, #888);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 12px;
}
