:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --line: #e3ddd0;
  --line-strong: #d2caba;
  --text: #1c2128;
  --muted: #6c7480;
  --accent: #cf8320;
  --accent-soft: #f6e7cf;
  --good: #2f8f63;
  --warn: #c07a2f;
  --bad: #cc4b42;
  --shadow: 0 1px 2px rgba(28, 33, 40, 0.06), 0 8px 24px rgba(28, 33, 40, 0.06);
  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10131a;
    --surface: #191e28;
    --surface-2: #1f2531;
    --line: #2c3542;
    --line-strong: #3a4553;
    --text: #e7ebf1;
    --muted: #94a0b0;
    --accent: #eaa63f;
    --accent-soft: #3a2f1a;
    --good: #57b98a;
    --warn: #e0954c;
    --bad: #e0625a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #10131a;
  --surface: #191e28;
  --surface-2: #1f2531;
  --line: #2c3542;
  --line-strong: #3a4553;
  --text: #e7ebf1;
  --muted: #94a0b0;
  --accent: #eaa63f;
  --accent-soft: #3a2f1a;
  --good: #57b98a;
  --warn: #e0954c;
  --bad: #e0625a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.frame {
  max-width: 780px;
  margin: 0 auto;
  padding: 32px 20px 64px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.masthead {
  display: flex;
  align-items: center;
  gap: 14px;
}
.mark {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.08em;
  color: var(--surface);
  background: var(--accent);
  padding: 8px 10px;
  border-radius: 8px;
}
.masthead h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.tag {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.step-label {
  margin: 0 0 16px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

/* mode toggle --------------------------------------------------- */
.mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 18px;
}
.mode-btn {
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.mode-btn.active {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.fs {
  border: 0;
  margin: 0;
  padding: 0;
}

/* smaller segmented control, reused for singles/sealed */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.seg-btn {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.seg-btn.active {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--text);
}

/* autocomplete ------------------------------------------------- */
.ac-wrap {
  position: relative;
}
.ac {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 260px;
  overflow-y: auto;
}
.ac-row {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 13px;
  padding: 8px 11px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  cursor: pointer;
}
.ac-row:last-child {
  border-bottom: 0;
}
.ac-row:hover,
.ac-row:focus-visible,
.ac-row.active {
  background: var(--surface-2);
}
.ac-row.active {
  box-shadow: inset 2px 0 0 var(--accent);
}
.ac-dim {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}
.ac-tag {
  float: right;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--muted);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 1px 5px;
}

.chosen-card {
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface-2);
}
.chosen-card img {
  width: 46px;
  height: 64px;
  object-fit: cover;
  border-radius: 5px;
  background: var(--line);
  flex-shrink: 0;
}
.chosen-card strong {
  display: block;
  font-size: 14px;
}
.muted-line {
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
}

/* kind-aware visibility on the value screen ------------------- */
#value-body[data-kind="tcg"] .sports-only {
  display: none;
}

/* form ------------------------------------------------------------ */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field.span-2 {
  grid-column: 1 / -1;
}
.field > span {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.field > span i {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
input,
select {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
  appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 14px center, right 9px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
input:focus,
select:focus,
.btn:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input:invalid:not(:placeholder-shown) {
  border-color: var(--bad);
}
.hint {
  font-size: 12px;
  color: var(--bad);
  font-style: normal;
  min-height: 0;
}
.hint.note {
  color: var(--muted);
}

.preview {
  margin: 18px 0 16px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  display: flex;
  gap: 10px;
  align-items: baseline;
}
.preview-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  flex-shrink: 0;
}
.preview code {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  word-break: break-word;
}

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 9px;
  padding: 11px 18px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
.btn.primary {
  background: var(--accent);
  color: #1c2128;
  width: 100%;
}
.btn.primary:hover:not(:disabled) {
  filter: brightness(1.05);
}
.btn.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line-strong);
}
.btn.ghost:hover {
  background: var(--surface-2);
}
.form-error {
  color: var(--bad);
  font-size: 13px;
  margin: 10px 0 0;
  min-height: 0;
}

/* confirm ------------------------------------------------------- */
.confirm-card {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 500;
  margin: 0 0 4px;
}
.confirm-ask {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 16px;
}
.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.thumbs.single {
  grid-template-columns: minmax(0, 220px);
}
.thumbs a {
  display: block;
  aspect-ratio: 3 / 4;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}
.thumbs img {
  width: 100%;
  height: 100%;
  /* contain, not cover: cropping a slab hides the grade label on the flag,
     which is the whole reason this screen exists. */
  object-fit: contain;
  display: block;
}
.no-images {
  color: var(--warn);
  font-size: 13px;
}
.row-actions {
  display: flex;
  gap: 10px;
}
.row-actions .btn {
  flex: 1;
}

/* value ------------------------------------------------------- */
.headline {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.headline-cap,
.offer-cap,
.sig-cap,
.conf-cap {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}
.headline-num {
  font-family: var(--mono);
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  display: block;
  margin-top: 4px;
}
.headline-sub {
  font-size: 13px;
  color: var(--muted);
  font-family: var(--mono);
}
.conf {
  min-width: 150px;
}
.conf-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  overflow: hidden;
  margin: 6px 0 4px;
}
.conf-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
}
.conf-label {
  font-size: 13px;
  font-weight: 600;
}

.raw-comp {
  margin: 14px 0 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.raw-comp .dim {
  color: var(--muted);
}
.raw-comp.thin {
  border-left-color: var(--warn);
}
.raw-comp .warn-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--warn);
  color: var(--warn);
  font-size: 11px;
  white-space: nowrap;
}

.offers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 18px 0;
}
.offer {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
}
.offer.credit {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.offer-num {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 600;
  display: block;
  margin-top: 4px;
}
.offer-rate {
  font-size: 12px;
  color: var(--muted);
}

.signals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.sig {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}
.sig-val {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
  display: block;
  margin: 3px 0 1px;
}
.sig-note {
  font-size: 11px;
  color: var(--muted);
}
.sig-val.up {
  color: var(--good);
}
.sig-val.down {
  color: var(--bad);
}

.spark {
  width: 100%;
  height: 96px;
  margin-bottom: 14px;
  display: block;
}
.spark path.area {
  fill: var(--accent-soft);
}
.spark path.line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
}
.spark circle {
  fill: var(--accent);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.chip {
  font-size: 12px;
  font-family: var(--mono);
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--muted);
}
.chip.ok {
  color: var(--good);
  border-color: var(--good);
}
.chip.off {
  color: var(--bad);
  border-color: var(--bad);
}
.chip-action {
  cursor: pointer;
  color: var(--accent);
  border-color: var(--accent);
}
.chip-action:hover {
  background: var(--accent-soft);
}

.notes {
  margin: 0 0 18px;
  padding-left: 18px;
  color: var(--warn);
  font-size: 13px;
}
.notes:empty {
  display: none;
}

.tbl-head {
  font-size: 13px;
  font-weight: 700;
  margin: 6px 0 8px;
}
.tbl-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.tbl th,
.tbl td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.tbl th {
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
}
.tbl td.r,
.tbl th.r {
  text-align: right;
  font-family: var(--mono);
}
.tbl tbody tr:last-child td {
  border-bottom: none;
}
.tbl td a {
  color: var(--accent);
}
.fx-orig {
  color: var(--muted);
  font-size: 11px;
}
.tbl .title-cell {
  white-space: normal;
  max-width: 280px;
  color: var(--muted);
}

.rejected {
  margin: 14px 0 4px;
}
.rejected summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.disclaimer {
  font-size: 12px;
  color: var(--muted);
  margin: 16px 0 20px;
  line-height: 1.55;
}

.callout {
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--warn);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 14px;
  margin-bottom: 16px;
}

.foot {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* overlay ---------------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(2px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 50;
}
.overlay p {
  margin: 0;
  font-weight: 600;
}
.overlay .overlay-sub {
  font-weight: 400;
  font-size: 13px;
  color: var(--muted);
}
.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--line-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  margin-bottom: 6px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2s;
  }
}

@media (max-width: 560px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .signals {
    grid-template-columns: 1fr;
  }
  .headline-num {
    font-size: 32px;
  }
}
