:root {
  color-scheme: light;
  --ink: #151515;
  --muted: #5d646b;
  --line: #d9ded8;
  --paper: #fffdf7;
  --panel: #ffffff;
  --field: #ffffff;
  --wanted: #efe8ff;
  --sale: #e3f5df;
  --deleted: #ffdede;
  --completed: #dcebff;
  --button: #191919;
  --buttonText: #ffffff;
  --header: rgba(255, 253, 247, .94);
  --shadow: rgba(0,0,0,.16);
}

body[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f7f4ed;
  --muted: #c4beb3;
  --line: #3d4646;
  --paper: #101414;
  --panel: #181d1d;
  --field: #202828;
  --wanted: #372e4f;
  --sale: #243f2f;
  --deleted: #542b2f;
  --completed: #24384f;
  --button: #ffe86a;
  --buttonText: #181400;
  --header: rgba(16, 20, 20, .94);
  --shadow: rgba(0,0,0,.5);
}

body[data-theme="light"] {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

button, input, select, textarea {
  font: inherit;
  letter-spacing: 0;
}

.poster-head {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(12px, 3vw, 28px) 16px;
  border-bottom: 1px solid var(--line);
  background: var(--header);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1, h2, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.1rem, 5vw, 3.6rem);
  line-height: .95;
}

.title-block {
  min-width: 0;
}

.domain-line {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: clamp(1.45rem, 2.9vw, 1.98rem);
  font-weight: 900;
}

.domain-line span {
  position: relative;
  top: -.34em;
  color: #ff2456;
  font-size: .58em;
  margin-right: 1px;
}

.domain-line em {
  color: var(--muted);
  font-style: normal;
  font-size: .64em;
  font-weight: 800;
}

.corner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle, .menu-button {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border: 2px solid var(--button);
  border-radius: 999px;
  background: var(--button);
  color: var(--buttonText);
  box-shadow: 0 8px 24px var(--shadow);
  cursor: pointer;
  font-size: .84rem;
}

.menu-button {
  font-size: 1rem;
}

.app-menu {
  position: absolute;
  top: calc(100% - 8px);
  right: clamp(12px, 3vw, 28px);
  z-index: 40;
  display: grid;
  min-width: 190px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: var(--panel);
  box-shadow: 0 14px 38px var(--shadow);
}

.app-menu button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font-weight: 750;
}

.app-menu button:hover {
  background: var(--field);
}

main {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 16px clamp(10px, 2vw, 28px) 40px;
}

.toolbar, .send-panel, .account-panel, .setup-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.global-search {
  display: grid;
  grid-template-columns: 1fr 38px;
  gap: 8px;
  padding: 10px 0 14px;
  border-bottom: 1px solid var(--line);
}

.global-search input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: var(--field);
  color: var(--ink);
}

.filter-stack {
  display: grid;
  gap: 8px;
}

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

.subfilters .tab {
  min-height: 32px;
  padding: 6px 10px;
  font-size: .88rem;
}

.tab, .ghost-button, .primary-button, .icon-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-weight: 750;
}

.tab, .ghost-button, .primary-button {
  padding: 8px 12px;
}

.tab.active, .primary-button {
  border-color: var(--button);
  background: var(--button);
  color: var(--buttonText);
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.search input, .inline-form input, dialog input, dialog select, dialog textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: var(--field);
  color: var(--ink);
}

.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.table-head h2 {
  margin-bottom: 4px;
}

.table-head p {
  margin-bottom: 0;
  color: var(--muted);
}

.save-state {
  white-space: nowrap;
  font-weight: 800;
}

.collections-root {
  display: grid;
  gap: 18px;
  padding-top: 16px;
}

.collection-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.collection-row:hover {
  border-color: #54b36d;
  box-shadow: 0 0 0 3px rgba(84, 179, 109, .18);
}

.collection-row span {
  display: grid;
  gap: 4px;
}

.collection-row small {
  color: var(--muted);
}

.collection-panel {
  display: grid;
  gap: 10px;
}

.collection-summary {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.collection-summary h2,
.collection-summary p {
  margin-bottom: 0;
}

.collection-summary p {
  color: var(--muted);
}

.collection-summary strong {
  font-size: 1.1rem;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  padding-top: 14px;
}

.price-table {
  width: 100%;
  min-width: 940px;
  border-collapse: collapse;
  background: var(--panel);
}

.price-table th,
.price-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: middle;
}

.price-table th {
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
}

.price-table td.median {
  background: rgba(255, 232, 106, .32);
  color: var(--ink);
  font-weight: 900;
}

.collection-table tr.owned {
  background: rgba(89, 181, 111, .18);
}

.collection-card.owned,
.search-card.owned,
.search-table tr.owned {
  background: rgba(125, 202, 142, .2);
  box-shadow: inset 0 0 0 2px rgba(88, 177, 105, .45);
}

.collection-card.needed,
.search-card.needed,
.search-table tr.needed {
  background: rgba(189, 154, 80, .16);
  box-shadow: inset 0 0 0 2px rgba(189, 154, 80, .28);
}

.qty-overlay {
  position: absolute;
  right: 7px;
  bottom: 98px;
  z-index: 5;
  min-width: 34px;
  border-radius: 8px;
  padding: 5px 7px;
  background: rgba(20, 24, 24, .76);
  color: #fff;
  text-align: center;
  font-weight: 900;
}

.collection-table input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--button);
}

.table-thumb {
  width: 48px;
  height: 64px;
  object-fit: contain;
  display: block;
  background: rgba(255,255,255,.45);
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
  gap: 12px;
  padding-top: 16px;
}

.card {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--wanted);
}

.card.sale {
  background: var(--sale);
}

.card.deleted {
  background: var(--deleted);
}

.card.completed {
  background: var(--completed);
}

.product-card.deleted {
  border-color: #d02828;
  background: var(--deleted);
}

.image-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}

.card img {
  display: block;
  width: 100%;
  aspect-ratio: 734 / 1024;
  object-fit: contain;
  background: rgba(255,255,255,.45);
}

body[data-theme="dark"] .card img {
  background: rgba(255,255,255,.08);
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px;
}

.card-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.16;
}

.meta, .notes, .price {
  margin: 0;
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.25;
}

.price {
  color: var(--ink);
  font-weight: 800;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.badge {
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 999px;
  padding: 2px 7px;
  background: rgba(255,255,255,.62);
  font-size: .75rem;
  font-weight: 800;
}

body[data-theme="dark"] .badge {
  border-color: rgba(255,255,255,.16);
  background: rgba(255,255,255,.11);
}

.actions {
  position: absolute;
  top: 7px;
  right: 7px;
  display: flex;
  gap: 5px;
}

.icon-button, .gf-badge {
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .82);
  box-shadow: 0 2px 10px var(--shadow);
}

body[data-theme="dark"] .icon-button,
body[data-theme="dark"] .gf-badge {
  background: rgba(20, 24, 24, .9);
}

.new-card {
  min-height: 260px;
  display: grid;
  place-items: center;
  border-style: dashed;
  background: var(--panel);
  color: var(--muted);
  font-size: 2rem;
}

.new-card:hover {
  border-color: #54b36d;
  box-shadow: 0 0 0 3px rgba(84, 179, 109, .2);
  color: var(--ink);
}

.set-placeholder {
  display: grid;
  place-items: center;
  aspect-ratio: 734 / 1024;
  background: var(--field);
  color: var(--muted);
  font-weight: 900;
}

.gf-badge {
  position: absolute;
  top: 7px;
  left: 7px;
  border-radius: 8px;
  pointer-events: none;
}

.stars {
  min-height: 18px;
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: .78;
}

.stars.urgent {
  opacity: .98;
}

.rating-star {
  --fill: 0%;
  --star-fill: #ffd22f;
  --star-empty: rgba(255,255,255,.62);
  position: relative;
  width: 14px;
  height: 14px;
  display: inline-block;
  background: #101010;
  clip-path: polygon(50% 0%, 61% 34%, 97% 34%, 68% 55%, 79% 90%, 50% 68%, 21% 90%, 32% 55%, 3% 34%, 39% 34%);
  flex: 0 0 auto;
}

.rating-star::after {
  content: "";
  position: absolute;
  inset: 1.4px;
  background: linear-gradient(90deg, var(--star-fill) 0 var(--fill), var(--star-empty) var(--fill) 100%);
  clip-path: inherit;
}

.stars.urgent .rating-star {
  --star-fill: #ff3434;
  --star-empty: #ff3434;
}

body[data-theme="dark"] .rating-star {
  background: #f3efe5;
  --star-empty: rgba(16,20,20,.75);
}

.send-panel, .account-panel {
  margin-top: 24px;
}

.send-panel p, .account-panel p, .setup-panel p {
  margin-bottom: 0;
}

.inline-form, .account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.fine-print {
  width: 100%;
  color: var(--muted);
  font-size: .84rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 50;
  width: min(520px, calc(100% - 24px));
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
  box-shadow: 0 14px 38px var(--shadow);
}

.undo-row {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 9px;
}

.similar-choice {
  display: grid;
  gap: 8px;
}

.undo-row img {
  width: 46px;
  height: 64px;
  object-fit: cover;
  border-radius: 4px;
}

dialog {
  width: min(720px, calc(100% - 18px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(0,0,0,.46);
}

.dialog-body {
  position: relative;
  display: grid;
  gap: 12px;
  padding: 18px;
}

.close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  cursor: pointer;
  font-size: 1.3rem;
}

fieldset {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.tcg-search {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.search-row {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) minmax(90px, .7fr) auto;
  gap: 8px;
  align-items: end;
}

.tcg-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.tcg-result {
  display: grid;
  gap: 5px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: left;
}

.tcg-result img {
  width: 100%;
  aspect-ratio: 734 / 1024;
  object-fit: contain;
}

.tcg-result strong {
  line-height: 1.12;
}

.tcg-result.selected {
  border-color: #54b36d;
  box-shadow: 0 0 0 3px rgba(84, 179, 109, .28);
}

.import-next-step {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 2;
  width: min(420px, calc(100vw - 32px));
  margin: 10px 0 0;
  padding: 9px 12px;
  border: 1px solid #54b36d;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 5px 16px var(--shadow);
  color: var(--ink);
  font-weight: 700;
  transform: translateX(-50%);
}

.import-confirm {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.import-confirm-card {
  display: grid;
  grid-template-columns: minmax(110px, 160px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.import-confirm-card img {
  width: 100%;
  aspect-ratio: 734 / 1024;
  object-fit: contain;
}

.import-confirm-card > div {
  display: grid;
  gap: 9px;
}

.import-confirm-card p {
  margin: 0;
}

@media (max-width: 460px) {
  .import-confirm-card {
    grid-template-columns: 1fr;
  }

  .import-confirm-card img {
    max-height: 240px;
  }
}

.view-toggle,
.table-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-panel {
  position: fixed;
  z-index: 45;
  width: min(220px, calc(100vw - 16px));
}

.collection-picker,
.collection-menu {
  position: relative;
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
  box-shadow: 0 10px 28px var(--shadow);
}

.collection-options {
  display: grid;
  gap: 2px;
  font-size: .9rem;
}

.collection-option {
  width: 100%;
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  border: 0;
  border-radius: 4px;
  padding: 4px 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font-weight: 800;
}

.collection-option span {
  color: #8d68d8;
  font-size: 1.1rem;
}

.collection-option:hover {
  background: var(--field);
}

.collection-view-tools {
  display: flex;
  align-items: center;
  gap: 14px;
}

.rapid-fire-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-weight: 800;
}

.collection-gallery.rapid-fire .image-button {
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.collection-gallery.rapid-fire img {
  -webkit-user-drag: none;
  user-select: none;
}

.inline-close {
  position: absolute;
}

.dialog-body label {
  display: grid;
  gap: 5px;
  font-weight: 750;
}

.dialog-body .checkbox, fieldset label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.drop-zone {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 190px;
  border: 2px dashed #a8b0aa;
  border-radius: 8px;
  background: var(--field);
  text-align: center;
  color: var(--muted);
  overflow: hidden;
}

.drop-zone.dragging {
  border-color: #111;
  background: var(--sale);
}

.drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-zone img {
  max-width: 180px;
  max-height: 250px;
  display: none;
  object-fit: contain;
}

.drop-zone.has-image span {
  display: none;
}

.drop-zone.has-image img {
  display: block;
}

.drop-zone.compact {
  min-height: 120px;
}

.drop-zone.compact img {
  max-height: 90px;
}

.edit-only {
  display: none !important;
}

.add-dialog.editing .tcg-search {
  display: none;
}

.add-dialog.editing .drop-zone {
  min-height: 250px;
}

.add-dialog.editing .edit-only {
  display: flex !important;
}

.add-dialog.product-editing .offer-only {
  display: none !important;
}

.form-error {
  min-height: 1.2em;
  color: #b00020;
  font-weight: 700;
}

#lightbox {
  width: min(96vw, 980px);
  max-height: 96vh;
  background: #111;
}

#lightbox img {
  display: block;
  width: 100%;
  max-height: 92vh;
  object-fit: contain;
}

.lightbox-close {
  z-index: 2;
}

.hidden {
  display: none !important;
}

.empty {
  padding: 28px 0;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

@media (max-width: 720px) {
  .toolbar, .send-panel, .account-panel, .setup-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .poster-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 8px 14px;
  }

  .title-block {
    grid-row: 1 / span 2;
  }

  .corner-actions {
    display: contents;
  }

  .menu-button {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }

  #refreshBtn {
    grid-column: 2;
    grid-row: 2;
    justify-self: end;
  }

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

  .gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-row {
    grid-template-columns: 1fr 1fr;
  }

  .card-body {
    padding: 8px;
  }
}

.optional-fields { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.optional-fields summary { cursor: pointer; font-weight: 700; }
.optional-fields[open] summary { margin-bottom: 12px; }
.optional-fields > label, .optional-fields > .drop-zone { margin-top: 12px; }
/* Keep subset boundaries visible even when a gallery row has spare space. */
.collection-set-heading { grid-column: 1 / -1; margin: 1rem 0 0; }
.clearable-select { display: flex; align-items: center; gap: .4rem; }
.clearable-select select { flex: 1; min-width: 0; }
.clearable-select button { flex: 0 0 auto; }
.set-card { position: relative; }
.set-edit-button { position: absolute; top: .5rem; right: .5rem; z-index: 1; }

.settings-panel { max-width: 680px; margin: 1rem auto; padding: 1rem; border: 1px solid var(--line); border-radius: 12px; }
.settings-panel label, .settings-form { display: grid; gap: .5rem; }
.settings-form { margin-top: 1rem; gap: 1rem; }
.settings-panel input, .settings-panel select { width: 100%; min-width: 0; box-sizing: border-box; }
.settings-panel > button { margin-top: .75rem; }
.settings-form .fine-print { margin: 0; }
