:root {
  color-scheme: light dark;
  --fg: #1a1a1a;
  --bg: #fafafa;
  --card-bg: #fff;
  --border: #ddd;
  --accent: #6b46c1;
  --table-card-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #eee;
    --bg: #121212;
    --card-bg: #1e1e1e;
    --border: #333;
    --accent: #a78bfa;
    --table-card-shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, sans-serif;
  color: var(--fg);
  background: var(--bg);
  margin: 0;
  padding: 1.5rem;
}

main { max-width: 960px; margin: 0 auto; }
main.narrow { max-width: 360px; }

header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.3rem 1rem;
  margin-bottom: 1rem;
}

@media (max-width: 480px) {
  body {
    padding: 1rem;
  }
}

h1 { font-size: 1.4rem; }

.hint {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
}

textarea {
  width: 100%;
  font-family: ui-monospace, monospace;
  font-size: 0.9rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--fg);
}

input[type="password"] {
  width: 100%;
  padding: 0.5rem;
  margin: 0.5rem 0 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.narrow input[type="text"] {
  width: 100%;
  padding: 0.5rem;
  margin: 0.5rem 0 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--fg);
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1.2rem;
  font-size: 0.95rem;
  cursor: pointer;
  margin-top: 0.75rem;
}

button.primary {
  display: block;
  width: 100%;
  margin-top: 2rem;
  font-size: 1.1rem;
}

.error { color: #e05555; }

.danger-link {
  background: none;
  color: #e05555;
  border: none;
  padding: 0;
  margin: 0 0 0 0.75rem;
  font-size: 0.85rem;
  text-decoration: underline;
  cursor: pointer;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 3rem 1.5rem;
  text-align: center;
  cursor: pointer;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: var(--card-bg);
}

.capture-buttons {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.capture-button {
  flex: 1;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1.5rem 1rem;
  background: var(--card-bg);
  color: var(--fg);
  border: 2px dashed var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.95rem;
  margin-top: 0;
}

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

.capture-button svg {
  width: 32px;
  height: 32px;
}

#result {
  margin-top: 1.5rem;
}

#warnings {
  font-size: 0.85rem;
  color: #e05555;
  padding-left: 1.2rem;
}

.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.hub-card {
  display: block;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  background: var(--card-bg);
  color: var(--fg);
  text-decoration: none;
}

.hub-card:hover {
  border-color: var(--accent);
}

.hub-card h2 {
  margin: 0 0 0.5rem;
  color: var(--accent);
}

.hub-card p {
  margin: 0;
  opacity: 0.8;
  font-size: 0.9rem;
}

.hidden { display: none; }

.card-line {
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
}

.choice-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.choice {
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem;
  background: var(--card-bg);
  text-align: center;
  width: fit-content;
}

.choice.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent) inset;
}

.qty-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  margin-top: 0.4rem;
}

.qty-control button {
  margin: 0;
  padding: 0.1rem 0.55rem;
  font-size: 1rem;
  line-height: 1.3;
}

/* The Want List's per-row "Remove" sits inside a .qty-control next to the +/- steppers,
   but it's a destructive action, not another stepper button -- needs to visually read
   as a link, not a third accent-colored button that looks like part of the stepper. */
.qty-control .link-button {
  margin-left: 0.4rem;
  padding: 0;
  font-size: 0.8rem;
  white-space: nowrap;
}

/* Deck Builder's allocation picker uses bare .qty-dec/.qty-inc buttons (no
   .qty-control wrapper), which would otherwise fall back to the large default
   button style (and its margin-top), so they need the same compact treatment. */
.qty-dec, .qty-inc {
  margin: 0;
  padding: 0.1rem 0.55rem;
  font-size: 1rem;
  line-height: 1.3;
}

/* Comfortable thumb targets -- these steppers are tapped repeatedly to allocate
   or adjust quantities, so they get extra room specifically on touch-sized screens
   rather than bulking up the desktop table/picker density. */
@media (max-width: 720px) {
  .qty-control button,
  .qty-dec,
  .qty-inc {
    padding: 0.5rem 0.9rem;
    font-size: 1.15rem;
  }
}

.qty-input {
  width: 2.8rem;
  text-align: center;
  padding: 0.2rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card-bg);
  color: var(--fg);
}

a.download-single {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: none;
}

a.download-single:hover { text-decoration: underline; }

.qty-total {
  font-size: 0.8rem;
  font-weight: normal;
  opacity: 0.7;
}

#zip-progress {
  margin-top: 1.5rem;
}

#zip-progress-text {
  font-size: 0.85rem;
  opacity: 0.8;
}

.thumbs { display: flex; gap: 0.3rem; }

.scanner-preview {
  display: block;
  max-width: 100%;
  max-height: 50vh;
  margin: 0 auto 1rem;
  border-radius: 3%;
}

.scanner-add-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.scanner-add-actions button {
  flex: 1;
  min-width: 140px;
  margin-top: 0;
}

.choice img {
  max-width: 140px;
  border-radius: 4%;
  display: block;
}

.thumbs img { cursor: zoom-in; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 2rem;
}

@media (max-width: 480px) {
  .modal {
    padding: 0.75rem;
  }

  .card-modal-content {
    padding: 1rem;
  }
}

.modal.hidden { display: none; }

.modal-content {
  text-align: center;
  max-width: 90vw;
  max-height: 90vh;
}

.modal-content img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: 3%;
  display: block;
  margin: 0 auto;
}

.modal-content .meta {
  color: #fff;
  font-size: 1rem;
  margin-top: 0.75rem;
  opacity: 0.9;
}

.meta {
  display: block;
  font-size: 0.75rem;
  opacity: 0.7;
  margin-top: 0.3rem;
}

.deck-row {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.deck-row:last-child { border-bottom: none; }

.deck-card-name {
  font-weight: 600;
  display: inline-block;
  margin-right: 0.75rem;
}

.deck-card-name.hover-preview {
  cursor: help;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.tool-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0.75rem 0;
}

.tool-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: normal;
}

.tool-checkbox input {
  margin: 0;
}

.user-row {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.user-row:last-child { border-bottom: none; }

.user-row-header {
  margin-bottom: 0.25rem;
}

.user-row-actions {
  display: flex;
  justify-content: flex-end;
}

.user-row-actions button {
  margin-top: 0;
}

.owned-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.3rem;
}

.owned-printing {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
}

.owned-printing .meta { margin: 0; }

.not-owned {
  font-size: 0.85rem;
  opacity: 0.6;
  font-style: italic;
}

.qty-total.mismatch {
  color: #e05555;
  opacity: 1;
}

.hover-preview-popup {
  position: fixed;
  pointer-events: none;
  z-index: 200;
  max-width: 220px;
}

.hover-preview-popup img {
  width: 100%;
  display: block;
  border-radius: 4%;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  margin: 0;
  font-size: 0.85rem;
  text-decoration: underline;
  cursor: pointer;
}

.collection-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1.25rem;
  margin: 0.4rem 0 0.75rem;
}

.column-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin: 0.5rem 0;
  font-size: 0.85rem;
}

.column-picker label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap;
}

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

table {
  width: 100%;
  min-width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

th {
  cursor: pointer;
  user-select: none;
  color: var(--accent);
  font-weight: 600;
}

th:hover {
  text-decoration: underline;
}

/* Below this width the table stops scrolling sideways and each row becomes
   its own card instead, with the column header re-injected as a label via
   data-label (set per-cell in collection.js). */
@media screen and (max-width: 720px) {
  .table-scroll {
    overflow-x: visible;
  }

  .responsive-table {
    min-width: 0;
  }

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

  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }

  .responsive-table tr {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 10px;
    margin-bottom: 0.85rem;
    box-shadow: var(--table-card-shadow);
    overflow: hidden;
  }

  .responsive-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.55rem 0.9rem;
    border: none;
    border-bottom: 1px solid var(--border);
    white-space: normal;
    text-align: right;
  }

  .responsive-table td:last-child {
    border-bottom: none;
  }

  .responsive-table td::before {
    content: attr(data-label);
    flex-shrink: 0;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent);
  }

  /* The name is the card's title, not another label/value row. */
  .responsive-table td[data-label="Name"] {
    padding: 0.9rem 0.9rem 0.6rem;
    justify-content: flex-start;
    font-size: 1.05rem;
    font-weight: 700;
  }

  .responsive-table td[data-label="Name"]::before {
    content: none;
  }
}

#filter-input {
  width: 100%;
  padding: 0.5rem;
  margin: 0.5rem 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--fg);
  font-size: 0.95rem;
}

.card-name-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

.has-sticky-footer {
  padding-bottom: 4.5rem;
}

.totals-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1.5rem;
  font-size: 0.85rem;
  z-index: 50;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.15);
}

.totals-footer.hidden { display: none; }

.card-modal-content {
  background: var(--card-bg);
  color: var(--fg);
  border-radius: 10px;
  padding: 1.5rem;
  text-align: left;
  max-width: 820px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--fg);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.card-modal-body {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.card-modal-body img {
  width: 320px;
  max-width: 100%;
  aspect-ratio: 63 / 88;
  object-fit: contain;
  border-radius: 4.5% / 3.2%;
  display: block;
  flex-shrink: 0;
}

.card-modal-details {
  flex: 1;
  min-width: 220px;
}

.card-modal-details h2 {
  margin: 0 0 0.3rem;
}

.card-modal-details .meta {
  margin: 0.2rem 0;
}

#card-modal-oracle {
  white-space: pre-line;
  margin: 0.75rem 0;
}

.foil-badge {
  display: inline-block;
  background: linear-gradient(135deg, #d4af37, #f4e5a1, #d4af37);
  color: #3a2f00;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  margin-left: 0.4rem;
  vertical-align: middle;
}

#card-modal-name .foil-badge {
  font-size: 0.8rem;
  vertical-align: super;
}

#card-modal-qty-status {
  min-height: 1em;
}

.cs100-video {
  display: block;
  width: 100%;
  max-height: 40vh;
  margin: 0 auto 1rem;
  border-radius: 3%;
  background: #000;
}

.destination-picker {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.destination-picker label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.cs100-log {
  margin-top: 1rem;
}

.log-status {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.log-status.added { background: #1f8b4c33; color: #1f8b4c; }
.log-status.skipped { opacity: 0.7; }
.log-status.error { background: #e0555533; color: #e05555; }

#debug-log {
  max-height: 150px;
  overflow-y: auto;
  font-size: 0.75rem;
  white-space: pre-wrap;
  margin: 0.5rem 0 0;
}

.add-dialog-content {
  max-width: 420px;
}

.add-dialog-title {
  margin-top: 0;
  font-size: 1.1rem;
}

.add-dialog-destination {
  flex: 1 1 45%;
}

.add-dialog-cancel {
  flex: 1 1 100%;
  opacity: 0.6;
  border-style: dashed;
}

.add-dialog-new-row {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.add-dialog-new-row input[type="text"] {
  flex: 1;
  padding: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--fg);
}

.add-dialog-subpicker {
  margin: 0.5rem 0;
}

#detail-destinations {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

#detail-scryfall-link {
  display: block;
  margin: 0.5rem 0 0;
}

.add-dialog-duplicate-warning {
  margin: 0.75rem 0;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
}

.add-dialog-duplicate-warning p {
  margin: 0 0 0.5rem;
}

.add-dialog-duplicate-yes {
  margin-top: 0;
  margin-right: 0.75rem;
}

#chat-log {
  display: flex;
  flex-direction: column;
}

.chat-message {
  max-width: 80%;
  margin: 0.5rem 0;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.chat-message p {
  margin: 0;
}

.chat-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chat-assistant {
  align-self: flex-start;
  background: var(--card-bg);
}

.chat-candidate {
  margin-top: 0.6rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.chat-candidate .meta {
  margin: 0 0 0.3rem;
}

.chat-candidate code {
  display: block;
  padding: 0.5rem;
  border-radius: 4px;
  background: var(--card-bg);
  color: var(--fg);
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: all;
}

.chat-candidate a.scryfall-search-link {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.chat-candidate a.scryfall-search-link:hover {
  text-decoration: underline;
}

#chat-input-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  z-index: 50;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.15);
}

#chat-form {
  display: flex;
  gap: 0.5rem;
  max-width: 960px;
  margin: 0 auto;
}

#chat-input {
  flex: 1;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.95rem;
}

#chat-form button {
  margin: 0;
  white-space: nowrap;
}

@media (max-width: 480px) {
  .chat-message {
    max-width: 92%;
  }
}
