:root {
  --bg: #0b0b0d;
  --panel: #121217;
  --card: #11141a;
  --border: #222839;
  --chip: #1b2131;
  --muted: #8b95a7;
  --text: #e7ecf3;
  --site-header-offset: 0px;
  --app-header-offset: 0px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, Segoe UI, Roboto, Inter, Arial;
}

/* Header */
.site-header {
  position: static;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
}

.app-header {
  position: static;
  top: var(--site-header-offset);
  left: 0;
  right: 0;
  background: linear-gradient(180deg, var(--panel), #151923d9);
  backdrop-filter: blur(6px);
  z-index: 15;
  border-bottom: 1px solid var(--border);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
h1 {
  margin: 0;
  padding: 10px 14px;
  font-size: 22px;
  letter-spacing: .2px;
  color: #cfe7ff;
}

.experimental-banner {
  margin: 0;
  padding: 10px 14px;
  background: linear-gradient(90deg, rgba(255,196,0,0.1), rgba(255,73,0,0.12));
  border-bottom: 1px solid rgba(255,196,0,0.35);
  color: #ffd27f;
  font-size: 15px;
  text-align: center;
  letter-spacing: 0.15px;
}

.experimental-banner strong {
  font-weight: 600;
  color: #ffe8b5;
}

/* Layout */
.wrap {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 10px;
  padding: 8px;
}

.wrap.app-layout {
  padding-top: calc(8px + var(--site-header-offset) + var(--app-header-offset));
}
.col {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 0;
}
.col--items {
  display: flex;
  flex-direction: column;
}
.col h2 {
  font-size: 18px;
  margin: 0;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  color: #cfe7ff;
  text-align: center;
}
.section { padding: 8px; }
.row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 6px;
  align-items: flex-start;
  width: 100%;
}
.row.tight { gap: 4px; margin-bottom: 4px; }
.row.inline { flex-direction: row; align-items: center; gap: 6px; flex-wrap: wrap; }
.row.center-inline { justify-content: center; align-items: center; flex-direction: row; gap: 6px; flex-wrap: wrap; }
.section__header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}
.section__header h3 {
  margin: 0;
  font-size: 16px;
  color: #cfe7ff;
}
.muted-text {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}
.muted-text--centered { text-align: center; }

.result-panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}
.result-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.result-panel--full {
  grid-column: 1 / -1;
}
.result-panel__label {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.2px;
}
.result-panel__body {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #0f131c;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: center;
}

.result-panel__body > .pill {
  align-self: flex-start;
}
.result-panel__body--empty {
  border-style: dashed;
  color: var(--muted);
  text-align: center;
}
.result-panel__context {
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.15px;
  color: #cfe7ff;
}
.result-panel__text {
  margin: 0;
  line-height: 1.5;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  padding: 4px 10px;
  margin-bottom: 4px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  color: #e7ecf3;
  background: var(--chip);
  border: 1px solid var(--border);
}

.pill--success {
  background: rgba(37, 88, 58, 0.6);
  border-color: #2d6a46;
  color: #9ef7c0;
  box-shadow: 0 0 0 1px rgba(46, 135, 89, 0.35);
}

.pill--failure {
  background: rgba(98, 33, 44, 0.6);
  border-color: #7c2c38;
  color: #ffc3cb;
  box-shadow: 0 0 0 1px rgba(130, 51, 65, 0.35);
}

/* Inputs */
input[type=text],
input[type=number],
select,
textarea {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  outline: none;
  font-size: 14px;
  height: 36px;
  line-height: 18px;
  width: 100%;
}
input.price-input,
input.qty-input { -moz-appearance: textfield; width: 8ch; }
input.price-input::-webkit-outer-spin-button,
input.price-input::-webkit-inner-spin-button,
input.qty-input::-webkit-outer-spin-button,
input.qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
textarea { height: 120px; resize: vertical; width: 100%; }
td textarea { width: 100%; height: 80px; }

/* Buttons */
button {
  background: var(--chip);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  height: 36px;
}
button.primary { background: #1b2744; border-color: #2a3a66; }
button.warn    { background: #3a2f12; border-color: #6a5320; color: #ffd889; }
button.danger  { background: #47202a; border-color: #6a2a36; color: #ffc1c7; }
#genBtn { font-size: 16px; padding: 10px 20px; height: auto; }

/* Table */
.tablewrap {
  margin-top: 0;
  overflow: auto;
  position: relative;
}
.section--history .tablewrap {
  /* Let the history table size itself to its rows instead of reserving extra space. */
  height: auto;
  max-height: 60vh;
  overflow-y: auto;
}

.history-disclosure {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0f131c;
}

.history-disclosure__summary {
  display: flex;
  align-items: center;
  gap: 10px;
  list-style: none;
  cursor: pointer;
  margin: 0;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s ease;
}

.history-disclosure__summary::-webkit-details-marker { display: none; }

.history-disclosure__summary::before {
  content: '▸';
  font-size: 24px;
  color: #cfe7ff;
  transform-origin: center;
  transition: transform 0.2s ease;
}

.history-disclosure[open] .history-disclosure__summary::before {
  transform: rotate(90deg);
}

.history-disclosure__summary:focus-visible {
  outline: 2px solid rgba(147, 51, 234, 0.6);
  outline-offset: 2px;
}

.history-disclosure .section__header { margin: 0; }

.history-disclosure > .tablewrap { padding: 10px 12px 12px; }
.tablewrap--latest {
  margin-top: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #0f131c;
}
.col--items .tablewrap {
  flex: 1;
  min-height: 0;
}
.tablewrap table {
  position: relative;
  z-index: 1;
}
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td {
  padding: 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  text-align: center;
  font-size: 14px;
  word-wrap: break-word;
}
.section--history tbody {
  height: auto;
  min-height: 0;
}
th {
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
  color: #cfe7ff;
  text-align: center;
}
.items--latest th { background: #0d111a; }
.items--latest td { background: #0f131c; }

.items__row--latest {
  background: linear-gradient(90deg, rgba(40, 87, 133, 0.32), rgba(19, 51, 89, 0.18));
  box-shadow: inset 0 0 0 1px rgba(78, 153, 255, 0.35);
}
tr:hover { background: #0b0b0d; }

.items th:nth-child(1),
.items td:nth-child(1),
.items th:nth-child(2),
.items td:nth-child(2) {
  font-size: 12px;
  text-align: center;
}

.items th:nth-child(3),
.items td:nth-child(3) {
  text-align: left;
}

.items td:nth-child(3) {
  font-size: 15px;
  line-height: 1.5;
}

.type-cell {
  text-align: center;
}

.type-cell .pill {
  margin-left: auto;
  margin-right: auto;
}

.empty-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
  pointer-events: none;
  z-index: 0;
}

.empty-overlay__content {
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.empty-overlay__section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.empty-overlay__section h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: #cfe7ff;
}

.empty-overlay__section p {
  margin: 0;
  color: var(--muted);
}

/* Cards */
.cards-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(6, 8, 15, 0.78);
  z-index: 60;
}

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

.cards-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 12, 0.65);
}

.cards-modal__dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0;
  width: min(960px, 100%);
  max-height: 90vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 18px 64px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  z-index: 1;
}

.cards-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(12, 16, 24, 0.85);
}

.cards-modal__header h2 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.3px;
  color: #cfe7ff;
}

.cards-modal__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.cards-modal__body {
  position: relative;
  padding: 18px 20px 24px 20px;
  overflow: auto;
  display: grid;
  gap: 16px;
  align-content: flex-start;
}

.cards-modal__empty {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
  text-align: center;
  padding: 40px 20px;
}

.cards-modal__empty strong {
  color: #e7ecf3;
}

.cards-modal__body .cards[hidden] {
  display: none !important;
}

body.cards-modal-open {
  overflow: hidden;
}

.licensing-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(6, 8, 15, 0.78);
  z-index: 70;
}

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

.licensing-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 12, 0.65);
}

.licensing-modal__dialog {
  position: relative;
  width: min(520px, 100%);
  max-height: 90vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  padding: 24px;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.licensing-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.licensing-modal__header h2 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.3px;
  color: #cfe7ff;
}

.licensing-modal__close {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  color: inherit;
  border-radius: 999px;
  padding: 6px 16px;
  cursor: pointer;
}
.licensing-modal__close:hover,
.licensing-modal__close:focus {
  background: rgba(255, 255, 255, 0.16);
}

.licensing-modal__body {
  display: grid;
  gap: 14px;
  color: #e2e8f6;
  font-size: 0.95rem;
  overflow-y: auto;
}

.licensing-modal__body a {
  color: #93c5fd;
}
.licensing-modal__body a:hover,
.licensing-modal__body a:focus {
  color: #cfe7ff;
}

body.licensing-modal-open {
  overflow: hidden;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px,1fr));
  gap: 8px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card .printBtn { height: 28px; font-size: 12px; padding: 2px 6px; }
.card > .printBtn { position: absolute; top: 8px; right: 8px; }
.card .actions-bottom .printBtn { position: static; top: auto; right: auto; height: 32px; font-size: 14px; padding: 6px 8px; }

.card-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-title .name {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.25;
}

.card-title .rarity {
  font-size: 0.85rem;
  opacity: 0.85;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
  font-size: 0.9rem;
}

.card-meta .price {
  margin-left: auto;
  font-weight: 600;
}

.card-body {
  display: grid;
  gap: 12px;
}

.card-section {
  display: grid;
  gap: 4px;
}

.card-section__title {
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  opacity: 0.85;
}

.card-section__content {
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-line;
}

.print-base {
  white-space: pre-line;
}

.card-section--empty {
  display: none;
}

.card.card--editing .card-section--empty {
  display: grid;
}

/* Print */
@media (max-width:980px) { .wrap { grid-template-columns: 1fr; } }
@media print {
  header, .wrap>.col:first-child, .printBtn { display: none !important; }
  body { background: #fff; color: #000; }
  .col { border: none; }
  .cards { grid-template-columns: repeat(3,1fr); }
  .card {
    break-inside: avoid;
    border: 1px solid #000;
    background: #f2f2f2;
    color: #000;
  }
}

/* ===== Column widths & behavior (no <colgroup>, so use nth-child) ===== */
/* Order:
   1:#  2:Name  3:Category  4:Rarity  5:StoreType
   6:Price (gp) 7:Price (sp) 8:Price (cp)
   9:Quantity 10:Description 11:Notes 12:Actions
*/
th:nth-child(1),  td:nth-child(1)  { width: 42px; }
th:nth-child(2),  td:nth-child(2)  { width: 10.5%; }
th:nth-child(3),  td:nth-child(3)  { width: 8%;    }
th:nth-child(4),  td:nth-child(4)  { width: 6%;    }
th:nth-child(5),  td:nth-child(5)  { width: 8%;    }
th:nth-child(6),  td:nth-child(6)  { width: 6%;    }
th:nth-child(7),  td:nth-child(7)  { width: 4.5%;  }
th:nth-child(8),  td:nth-child(8)  { width: 4.5%;  }
th:nth-child(9),  td:nth-child(9)  { width: 6%;    }
th:nth-child(10), td:nth-child(10) { width: 19%;   }
th:nth-child(11), td:nth-child(11) { width: 17.5%; }
th:nth-child(12), td:nth-child(12) { width: 10%;   }


/* Actions layout */
td:last-child .actions-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
td:last-child .actions-top { display: flex; gap: 6px; flex-wrap: wrap; }
td:last-child .actions-bottom { display: flex; gap: 6px; }
td:last-child .actions-top > button,
td:last-child .actions-bottom > button { height: 32px; }
.hidden { display:none !important; }
.advanced-max-hidden { display:none !important; }


/* Card actions under content */
.card { position: relative; }
.card .card-actions {
  margin-top: auto;
  padding-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.card .card-actions .actions-top,
.card .card-actions .actions-bottom {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.card .card-actions .actions-bottom {
  margin-left: auto;
}

.card .card-delete { background:#3a2f12; border-color:#6a5320; color:#ffd889; }


/* Ensure card grid centers items and no overlay blocks clicks */
.cards{ justify-items:center; }
.card * { pointer-events:auto; } /* in case earlier CSS disabled clicks */


/* Card inline-print overlay */
#cardPrintOverlay{ position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: white; z-index: 9999; }
#cardPrintOverlay .card{ width: 400px; border: 1px solid #000; border-radius: 10px; padding: 12px; color: #000; background: #f2f2f2; }
@media print {
  body.card-printing * { visibility: hidden !important; }
  body.card-printing #cardPrintOverlay,
  body.card-printing #cardPrintOverlay * { visibility: visible !important; }
  body.card-printing #cardPrintOverlay { background: #fff !important; }
}


/* === Rarity Colors (drop-in) === */
.rarity-common{color:grey;}
.rarity-uncommon{color:green;}
.rarity-rare{color:blue;}
.rarity-very-rare{color:purple;}
.rarity-legendary{color:orange;}
@media print{*{-webkit-print-color-adjust:exact;print-color-adjust:exact;}}

/* Rarity attribute selectors (fallback if JS classes not applied) */
*[data-rarity="Common"]    { color: grey; }
*[data-rarity="Uncommon"]  { color: green; }
*[data-rarity="Rare"]      { color: blue; }
*[data-rarity="Very Rare"] { color: purple; }
*[data-rarity="Legendary"] { color: orange; }


/* === Rarity Colors (forced) === */
td.rarity-common, .rarity-common, .card .rarity-common { color: grey !important; }
td.rarity-uncommon, .rarity-uncommon, .card .rarity-uncommon { color: green !important; }
td.rarity-rare, .rarity-rare, .card .rarity-rare { color: blue !important; }
td.rarity-very-rare, .rarity-very-rare, .card .rarity-very-rare { color: purple !important; }
td.rarity-legendary, .rarity-legendary, .card .rarity-legendary { color: orange !important; }

/* Attribute fallback with priority */
td[data-rarity="Common"], .card [data-rarity="Common"]    { color: grey !important; }
td[data-rarity="Uncommon"], .card [data-rarity="Uncommon"]{ color: green !important; }
td[data-rarity="Rare"], .card [data-rarity="Rare"]        { color: blue !important; }
td[data-rarity="Very Rare"], .card [data-rarity="Very Rare"] { color: purple !important; }
td[data-rarity="Legendary"], .card [data-rarity="Legendary"] { color: orange !important; }

/* === Header compact style === */
.site-header {
  min-height: 72px;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
}

.site-header .wrap.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  width: 44%;
  max-width: min(1200px, 100%);
  margin: 0 auto;
  padding: 0;
}

.site-header .brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-right: 2rem;
  flex: 1 1 auto;
  min-width: 0;
}

.site-header .nav-links {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;      /* slightly smaller gap between links */
  flex: 0 1 auto;
}

.site-header .donate {
  margin-left: 1rem;         /* tuck donate button in closer */
}

/* Kill any flex on the shared containers */
.site-footer .wrap,
.site-footer .max-w-7xl {
  display: block !important;
  max-width: none !important;
  margin: 0 auto !important;
  text-align: center !important;
}

/* Make the inner row render as one centered line */
.site-footer .max-w-7xl > span {
  display: inline-block !important;
}

/* Tidy link spacing and hover */
.site-footer a {
  display: inline-block;
  margin: 0 0.35rem;
  color: #9333ea;
}
.site-footer a:hover { color: #fff; }
.site-footer .footer-link {
  display: inline-block;
  margin: 0 0.35rem;
  background: none;
  border: none;
  color: #9333ea;
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-decoration: underline;
}
.site-footer .footer-link:hover,
.site-footer .footer-link:focus {
  color: #fff;
}
.site-footer .footer-link:focus-visible {
  outline: 2px solid rgba(147, 51, 234, 0.6);
  outline-offset: 2px;
}

/* Optional: keep the CSV sentence from stretching super wide on 4k */
.site-footer .wrap.text-center {
  max-width: 900px !important;
}



/* Neutralize the shared .wrap max-width for YOUR app containers */
body > .wrap {
  max-width: none !important;
  width: 100% !important;
  margin: 0 !important;
}

/* If your app nests more .wraps directly under body in the future, keep them full width too */
body > .wrap + .wrap,
body > .wrap ~ .wrap {
  max-width: none !important;
  width: 100% !important;
  margin: 0 !important;
}
/* CritGen-specific button styles */
button.success { background: #14532d; border-color: #15803d; color: #d1fae5; }
