:root {
  --navy: #1f3a5f;
  --navy-dark: #152a45;
  --yellow: #ffd23f;
  --orange: #f28c28;
  --bg: #faf8f2;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #5d6576;
  --border: #e3dfd3;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}
a { color: var(--navy); }
img { max-width: 100%; height: auto; }
h1 { font-size: 1.7rem; margin: 0 0 0.25rem; }
.h3 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }
.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.placeholder { font-style: italic; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header */
.demo-banner { background: var(--yellow); color: var(--navy-dark); text-align: center; font-size: 0.85rem; padding: 6px 16px; }
.site-header { background: var(--navy); color: #fff; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-top: 12px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 800; font-size: 1.3rem; letter-spacing: 0.01em; }
.brand-domain { font-size: 0.8rem; color: var(--yellow); }
.site-nav { display: flex; gap: 1.25rem; align-items: center; }
.site-nav a { color: #fff; text-decoration: none; font-weight: 600; }
.site-nav a:hover { text-decoration: underline; }
.cart-count { display: inline-block; min-width: 1.5em; padding: 0 0.4em; margin-left: 4px; border-radius: 999px; background: var(--yellow); color: var(--navy-dark); text-align: center; font-size: 0.85rem; }

main.container { padding-top: 1.25rem; padding-bottom: 3rem; min-height: 60vh; }
.page-head { margin-bottom: 1rem; }
.page-head p { margin: 0; }
.flash { background: #e9f6ec; border: 1px solid #b9dfc2; color: #1f5130; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 1rem; }

/* Buttons */
.btn {
  display: inline-block; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--navy); color: #fff; font: inherit; font-weight: 600;
  padding: 0.55rem 1rem; text-decoration: none; line-height: 1.2;
}
.btn:hover { background: var(--navy-dark); }
.btn:disabled { background: #a3abb8; cursor: not-allowed; }
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn-ghost { background: transparent; color: var(--navy); box-shadow: inset 0 0 0 1px var(--border); }
.btn-ghost:hover { background: #f0ede4; }

/* Controls */
.controls {
  display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 1.25rem; box-shadow: var(--shadow);
}
.control { display: flex; flex-direction: column; gap: 4px; min-width: 150px; flex: 1 1 150px; }
.control label { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.control-check label { text-transform: none; font-size: 0.95rem; color: var(--text); font-weight: 500; display: flex; align-items: center; gap: 6px; padding: 0.5rem 0; }
.control-search { flex: 2 1 220px; }
.control-actions { flex-direction: row; gap: 8px; flex: 0 0 auto; min-width: 0; }
.controls input[type="search"], .controls select {
  font: inherit; padding: 0.5rem; border: 1px solid var(--border); border-radius: 8px; background: #fff; width: 100%;
}

/* Grid */
.card-grid { list-style: none; padding: 0; margin: 0; display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.card-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.tile-link { text-decoration: none; color: inherit; }
.tile-link:hover .tile-name { text-decoration: underline; }
.tile-image { aspect-ratio: 245 / 342; display: flex; align-items: center; justify-content: center; margin-bottom: 8px; }
.tile-image img { width: 100%; height: 100%; object-fit: contain; }
.tile-name { font-size: 1rem; margin: 0; }
.tile-meta { margin: 2px 0 6px; color: var(--muted); font-size: 0.85rem; }
.tile-badges { margin: 0 0 10px; display: flex; flex-wrap: wrap; gap: 4px; }
.badge { font-size: 0.72rem; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: #eef1f6; color: var(--navy); }
.badge-cond { background: #e9f6ec; color: #1f5130; }
.badge-cond.cond-lp { background: #f3f7dc; color: #4b5a12; }
.badge-cond.cond-mp { background: #fdf0d9; color: #7a4c07; }
.badge-cond.cond-hp, .badge-cond.cond-dmg { background: #fbe3e1; color: #7d1f17; }
.tile-buy { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tile-buy form { margin: 0; }
.price { font-weight: 800; font-size: 1.1rem; }
.sold-out { color: #9b2c22; font-weight: 600; font-size: 0.9rem; }
.tile-stock { margin: 6px 0 0; font-size: 0.8rem; color: var(--muted); }
.empty { text-align: center; padding: 3rem 1rem; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* Detail */
.breadcrumb { margin: 0 0 1rem; font-size: 0.9rem; }
.card-detail { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 2rem; }
.detail-image img { width: 100%; border-radius: 14px; }
.detail-sub { color: var(--muted); margin: 0 0 0.75rem; }
.detail-price { font-size: 2rem; font-weight: 800; margin: 0 0 1rem; }
.attrs { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 1.25rem; }
.attrs dt { font-weight: 600; color: var(--muted); }
.attrs dd { margin: 0; }
.add-form { display: flex; align-items: center; gap: 8px; }
.add-form input { width: 5rem; font: inherit; padding: 0.5rem; border: 1px solid var(--border); border-radius: 8px; }
.other-conditions { padding-left: 1.1rem; }

/* Cart */
.cart-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cart-table th, .cart-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.cart-table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: #f6f4ec; }
.cart-table .num { text-align: right; white-space: nowrap; }
.cart-table form { margin: 0; }
.qty-form { display: flex; gap: 6px; align-items: center; }
.qty-form input { width: 4.2rem; font: inherit; padding: 0.35rem; border: 1px solid var(--border); border-radius: 6px; }
.cart-summary { margin-top: 1rem; text-align: right; }
.cart-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.cart-actions form { margin: 0; }

/* Checkout stub */
.notice { background: #fff8e1; border: 1px solid #f1d98a; border-radius: var(--radius); padding: 4px 18px 10px; }
.summary-list { list-style: none; padding: 0; max-width: 640px; }
.summary-list li { display: flex; justify-content: space-between; gap: 1rem; padding: 6px 0; border-bottom: 1px solid var(--border); }
.summary-total { font-weight: 800; }

/* Footer */
.site-footer { background: var(--navy-dark); color: #d7deea; font-size: 0.85rem; }
.site-footer .placeholder { color: #aeb9cc; }
.footer-inner { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; padding-top: 20px; padding-bottom: 20px; }
.fineprint { color: #9aa6ba; }
.fineprint a { color: #c9d3e3; }

/* Admin */
.admin-header { background: #2b2f3a; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }
.table-scroll { overflow-x: auto; }
.admin-table th a { color: inherit; text-decoration: none; }
.admin-table th a:hover { text-decoration: underline; }
.admin-table td { vertical-align: middle; }
.admin-table tr.is-soldout td { background: #fdf6f5; }
.admin-table tr:target td { background: #fff8e1; }
.admin-thumb { width: 40px; height: auto; border-radius: 3px; display: block; }
.admin-thumb-lg { width: 90px; height: auto; border-radius: 5px; }
.qty-quick { flex-wrap: nowrap; }
.qty-quick input { width: 4.5rem; }
.admin-actions { white-space: nowrap; }
.admin-actions a { margin-right: 8px; }
.danger { color: #9b2c22; }
.btn-danger { background: #9b2c22; }
.btn-danger:hover { background: #7a1f17; }
/* Admin add/edit card page: Step 1 and Step 2 share one panel style */
.page-lead { max-width: 860px; color: var(--muted); margin: 0.25rem 0 1.25rem; }
.panel { max-width: 860px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px 20px; margin: 0 0 1.25rem; box-shadow: var(--shadow); }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px 12px; padding-bottom: 12px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.panel-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; font-size: 1.2rem; }
.panel-note { margin: 0; color: var(--muted); font-size: 0.85rem; }
.panel-intro { margin: 0 0 16px; color: var(--muted); font-size: 0.92rem; }
.step { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; background: var(--navy); color: #fff; border-radius: 999px; padding: 3px 10px; }
.step-done { font-size: 0.82rem; font-weight: 600; color: #1f5130; background: #e9f6ec; border: 1px solid #b9dfc2; border-radius: 999px; padding: 2px 10px; }
.admin-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px 20px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: 0.9rem; }
.field input, .field select { font: inherit; padding: 0.5rem; border: 1px solid var(--border); border-radius: 8px; background: #fff; width: 100%; min-width: 0; }
.field input[readonly] { background: #f3f1ea; color: var(--muted); }
.field [aria-invalid="true"] { border-color: #c0392b; box-shadow: 0 0 0 1px #c0392b; }
.field-error { color: #9b2c22; font-size: 0.85rem; margin: 0; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 0; }
.req { color: #9b2c22; }
/* Admin: TCGdex finder on the add-a-card page */
.finder-form { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: flex-end; }
.finder-form .finder-q { flex: 2 1 260px; }
.finder-form .finder-set { flex: 1 1 200px; }
.finder-form .finder-submit { flex: none; min-width: 7rem; min-height: 2.6rem; }
.finder-form .finder-hint { flex-basis: 100%; }
.finder-error { margin: 0 0 16px; background: #fff3e0; border: 1px solid #f3c98b; color: #6b4200; border-radius: 8px; padding: 8px 12px; }
.finder-results-wrap { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.finder-count, .finder-empty { margin: 0 0 10px; font-size: 0.92rem; }
.finder-manual { margin: 14px 0 0; text-align: center; font-size: 0.9rem; }
.finder-results { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(115px, 1fr)); }
.finder-result { display: flex; flex-direction: column; gap: 2px; padding: 6px; border: 1px solid var(--border); border-radius: 8px; text-decoration: none; color: inherit; height: 100%; background: #fff; }
.finder-result:hover, .finder-result:focus-visible { border-color: var(--navy); box-shadow: 0 0 0 2px rgba(31, 58, 95, 0.25); }
.finder-result img { width: 100%; height: auto; aspect-ratio: 245 / 342; object-fit: contain; }
.finder-result-name { font-weight: 600; font-size: 0.88rem; }
.finder-result-meta { color: var(--muted); font-size: 0.78rem; }
.finder-pages { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 14px; }
.finder-picked { display: flex; gap: 16px; align-items: flex-start; background: #f4faf5; border: 1px solid #b9dfc2; border-radius: 8px; padding: 10px 12px; }
.finder-picked img { width: 90px; height: auto; border-radius: 4px; flex: none; }
.finder-picked p { margin: 0 0 4px; }
.finder-notes { margin: 6px 0; padding-left: 1.1rem; font-size: 0.88rem; }
.finder-picked-links { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 6px !important; }

.admin-form .form-section { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px 20px; border: 0; border-top: 1px solid var(--border); margin: 0; padding: 16px 0 0; min-width: 0; }
.admin-form .form-section:first-of-type { border-top: 0; padding-top: 0; }
/* float takes the legend out of the fieldset border so it becomes a normal,
   full-width grid row (floats themselves have no effect on grid items). */
.form-section legend { float: left; grid-column: 1 / -1; margin: 0 0 -4px; padding: 0; font-weight: 700; font-size: 0.95rem; color: var(--navy); }
.optional { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.advanced summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; padding: 4px 0; }
.advanced[open] summary { margin-bottom: 6px; }
.advanced input { width: 100%; font: inherit; padding: 0.5rem; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 4px; }
.form-errors a { color: inherit; }
.form-errors:focus { outline: 2px solid #c0392b; outline-offset: 2px; }
.form-errors { background: #fbe3e1; border: 1px solid #efb4ae; color: #7d1f17; border-radius: 8px; padding: 10px 16px; margin: 0 0 16px; }
.form-errors ul { margin: 6px 0 0; padding-left: 1.2rem; }
.form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.admin-form .form-actions { margin-top: 4px; padding-top: 16px; border-top: 1px solid var(--border); }
.push-right { margin-left: auto; }
.notice-danger { background: #fdf3f2; border-color: #efb4ae; max-width: 720px; }
.delete-card { display: flex; gap: 18px; align-items: flex-start; }

@media (max-width: 720px) {
  .card-detail { grid-template-columns: 1fr; }
  .detail-image { max-width: 300px; margin: 0 auto; }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile-buy { flex-direction: column; align-items: flex-start; }
  .cart-table thead { display: none; }
  .cart-table, .cart-table tbody, .cart-table tr, .cart-table td { display: block; width: 100%; }
  .cart-table tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  .cart-table td { border: 0; padding: 4px 12px; }
  .cart-table .num { text-align: left; }
  .cart-actions { justify-content: stretch; }
}
