:root {
  --bg: #101114;
  --panel: #191b20;
  --panel-2: #22252c;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --line: #333741;
  --accent: #8b5cf6;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: rgba(16, 17, 20, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.site-header h1 {
  margin: 0;
  font-size: 1.35rem;
}

.site-header h1 a {
  text-decoration: none;
}

.site-header p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.site-header nav {
  display: flex;
  gap: 0.75rem;
}

.site-header nav form {
  display: contents;
}

.site-header nav a,
.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.25rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: var(--panel-2);
  color: var(--text);
  text-decoration: none;
  font: inherit;
  cursor: pointer;
}

.site-header nav a:hover,
.button:hover,
button:hover {
  border-color: var(--accent);
}

.button.ghost,
button.ghost {
  background: transparent;
}

main {
  width: min(1800px, 100%);
  margin: 0 auto;
  padding: 1.25rem;
}

footer {
  padding: 2rem 1.5rem 3rem;
  color: var(--muted);
  text-align: center;
}

code {
  padding: 0.1rem 0.25rem;
  border-radius: 0.3rem;
  background: rgba(255, 255, 255, 0.08);
}

.flash-wrap {
  width: min(1200px, calc(100% - 2rem));
  margin: 1rem auto 0;
}

.flash {
  margin: 0.5rem 0;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: var(--panel);
}

.flash.success { border-color: rgba(34, 197, 94, 0.55); }
.flash.warning { border-color: rgba(245, 158, 11, 0.65); }
.flash.error { border-color: rgba(239, 68, 68, 0.65); }
.flash.info { border-color: rgba(139, 92, 246, 0.65); }

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: linear-gradient(180deg, var(--panel), rgba(25, 27, 32, 0.72));
  box-shadow: var(--shadow);
}

.stat strong {
  display: block;
  font-size: 1.5rem;
}

.stat span {
  display: block;
  color: var(--muted);
  margin-top: 0.2rem;
}

.card-panel,
.set-block,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.toolbar {
  margin-bottom: 1rem;
  padding: 1rem;
}

.filters,
.stacked {
  display: grid;
  gap: 0.85rem;
}

.filters {
  grid-template-columns: minmax(220px, 1fr) auto auto auto auto auto;
  align-items: end;
}

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

input[type="text"],
input[type="search"],
input[type="file"],
input[type="password"],
select {
  width: 100%;
  min-height: 2.35rem;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  background: #0d0f13;
  color: var(--text);
  padding: 0.45rem 0.65rem;
  font: inherit;
}

input[type="file"] {
  padding: 0.45rem;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
  color: var(--text);
}

.checkline input {
  width: 1rem;
  height: 1rem;
}

.grid-stack {
  display: grid;
  gap: 1.25rem;
}

.set-block {
  overflow: hidden;
}

.set-block.complete {
  border-color: rgba(34, 197, 94, 0.45);
}

.set-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
}

.set-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.set-head h2 a {
  text-decoration: none;
}

.set-head h2 a:hover {
  text-decoration: underline;
}

.set-head h2 span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.set-head p {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.progress-summary {
  min-width: 7rem;
  text-align: right;
}

.progress-summary strong,
.progress-summary span {
  display: block;
}

.progress-summary span {
  color: var(--muted);
}

.progress-bar {
  height: 0.45rem;
  background: #0d0f13;
}

.progress-bar span {
  display: block;
  height: 100%;
  max-width: 100%;
  background: var(--accent-2);
}


.summary-progress-cell {
  min-width: 13rem;
}

.summary-progress {
  display: grid;
  grid-template-columns: minmax(7rem, 1fr) 3.5rem;
  align-items: center;
  gap: 0.65rem;
}

.summary-progress-bar {
  height: 0.65rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #0d0f13;
}

.summary-progress-bar span {
  display: block;
  height: 100%;
  max-width: 100%;
  border-radius: inherit;
  background: var(--accent-2);
}

.summary-progress-label {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.treatment-section {
  padding: 1rem;
  border-top: 1px solid var(--line);
}

.treatment-section h3 {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.land-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(120px, 1fr));
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

.land-grid.headings {
  margin-bottom: 0.45rem;
}

.land-heading {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
}

.land-cell {
  min-width: 0;
}

.empty-cell {
  min-height: 12rem;
  border: 1px dashed rgba(255, 255, 255, 0.08);
  border-radius: 0.9rem;
}

.card-tile {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: #0d0f13;
}

.card-tile img {
  display: block;
  width: 100%;
  aspect-ratio: 488 / 680;
  object-fit: cover;
  transition: filter 160ms ease, opacity 160ms ease, transform 160ms ease;
}

.card-tile:hover img {
  transform: scale(1.015);
}

.card-tile.unowned img {
  filter: grayscale(100%);
  opacity: 0.32;
}

.card-tile.owned {
  border-color: rgba(34, 197, 94, 0.55);
}

.missing-image {
  display: grid;
  place-items: center;
  aspect-ratio: 488 / 680;
  color: var(--muted);
  background: var(--panel-2);
}

.card-meta {
  display: grid;
  gap: 0.15rem;
  padding: 0.6rem 0.65rem 0.45rem;
  font-size: 0.8rem;
}

.card-meta strong {
  font-size: 0.9rem;
}

.card-meta span {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.finish-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0 0.65rem 0.65rem;
}

.finish-row form {
  margin: 0;
}

.finish-pill {
  min-height: 1.8rem;
  min-width: 2.15rem;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
}

.lang-badge {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 800;
  vertical-align: middle;
  color: var(--bg);
  background: var(--warning);
}

.finish-owned {
  border-color: rgba(34, 197, 94, 0.75);
  background: rgba(34, 197, 94, 0.16);
}

.finish-missing {
  border-color: rgba(255, 255, 255, 0.12);
  background: transparent;
  color: var(--muted);
}

.empty-state {
  padding: 2rem;
  text-align: center;
}

.import-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}

.import-grid .card-panel,
.danger-zone,
.set-list {
  padding: 1rem;
}

.card-panel h2:first-child {
  margin-top: 0;
}

.danger {
  border-color: rgba(239, 68, 68, 0.65);
  background: rgba(239, 68, 68, 0.12);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  font-weight: 700;
}

.path-cell {
  max-width: 26rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.backline {
  margin-bottom: 1rem;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .filters,
  .import-grid,
  .stats-row {
    grid-template-columns: 1fr 1fr;
  }

  .land-grid {
    grid-template-columns: repeat(var(--cols), minmax(95px, 1fr));
    gap: 0.55rem;
  }
}

@media (max-width: 740px) {
  .site-header {
    align-items: flex-start;
    flex-direction: column;
  }

  main {
    padding: 0.8rem;
  }

  .filters,
  .import-grid,
  .stats-row {
    grid-template-columns: 1fr;
  }

  .checkline {
    white-space: normal;
  }

  .set-head {
    flex-direction: column;
  }

  .progress-summary {
    text-align: left;
  }

  .land-grid {
    overflow-x: auto;
    grid-template-columns: repeat(var(--cols), minmax(140px, 1fr));
    padding-bottom: 0.25rem;
  }
}

/* Collapsible set grid headers */
.set-title {
  min-width: 0;
}

.set-head-actions {
  display: grid;
  grid-template-columns: minmax(9rem, 13rem) auto;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.set-progress-summary {
  display: grid;
  grid-template-columns: minmax(5rem, 1fr) 3.5rem;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.set-progress-summary strong {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.set-progress-bar {
  height: 0.7rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #0d0f13;
}

.set-progress-bar span {
  display: block;
  height: 100%;
  max-width: 100%;
  border-radius: inherit;
  background: var(--accent-2);
}

.set-toggle {
  min-width: 4.5rem;
}

.set-block.collapsed .set-body {
  display: none;
}

.set-block.collapsed .progress-bar {
  border-bottom: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 740px) {
  .set-head-actions {
    width: 100%;
    grid-template-columns: 1fr auto;
    margin-left: 0;
  }
}

/* Manual "My Collection" page */
.add-land-panel,
.collection-panel {
  padding: 1rem;
  margin-bottom: 1rem;
}

.collection-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.collection-panel-head h2 {
  margin: 0;
}

.add-land-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 0.6fr);
  gap: 0.85rem;
}

.add-land-actions {
  display: flex;
  gap: 0.65rem;
  margin-top: 0.85rem;
}

.lookup-status {
  min-height: 1.2rem;
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.lookup-status.success {
  color: var(--accent-2);
}

.lookup-status.error {
  color: var(--danger);
}

.lookup-preview {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-top: 0.85rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: var(--panel-2);
}

.lookup-preview img {
  width: 4.5rem;
  border-radius: 0.5rem;
  display: block;
}

.lookup-preview-meta {
  display: grid;
  gap: 0.2rem;
  font-size: 0.85rem;
}

.lookup-preview-meta span {
  color: var(--muted);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.table-scroll {
  overflow-x: auto;
}

.thumb-cell {
  width: 3.5rem;
}

.thumb {
  display: block;
  width: 3rem;
  border-radius: 0.4rem;
}

.missing-image.small {
  display: grid;
  place-items: center;
  width: 3rem;
  aspect-ratio: 488 / 680;
  border-radius: 0.4rem;
  color: var(--muted);
  background: var(--panel-2);
  font-size: 0.65rem;
  text-align: center;
}

.collection-table td form {
  margin: 0;
}

@media (max-width: 900px) {
  .add-land-fields {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 740px) {
  .add-land-fields {
    grid-template-columns: 1fr;
  }

  .add-land-actions {
    flex-direction: column;
  }
}
