/* Toy Analyzer — dark theme, "field guide for collectors" */

:root {
  --bg: #0d0d0c;
  --bg-2: #121211;
  --surface: #1a1a19;
  --surface-2: #212120;
  --surface-3: #292927;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.16);

  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;

  --accent: #eb6834;       /* warm orange — brand */
  --accent-strong: #ff7f45;
  --accent-ink: #2a1206;   /* text on accent-filled surfaces */

  --series-1: #3987e5;     /* chart line — blue */
  --series-1-wash: rgba(57, 135, 229, 0.14);

  --good: #0ca30c;
  --bad: #e66767;

  --gridline: #2c2c2a;
  --baseline: #383835;

  --rarity-common-bg: rgba(137, 135, 129, 0.16);
  --rarity-common-fg: #c3c2b7;
  --rarity-uncommon-bg: rgba(25, 158, 112, 0.18);
  --rarity-uncommon-fg: #4fd6a6;
  --rarity-rare-bg: rgba(144, 133, 233, 0.18);
  --rarity-rare-fg: #b3a9f5;
  --rarity-legendary-bg: rgba(235, 104, 52, 0.20);
  --rarity-legendary-fg: #ff9a68;
  --rarity-unknown-bg: rgba(137, 135, 129, 0.12);
  --rarity-unknown-fg: #898781;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -8px rgba(0, 0, 0, 0.5);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.35), 0 16px 40px -12px rgba(0, 0, 0, 0.6);

  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

.glow-decor {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(560px 320px at 18% -6%, rgba(235, 104, 52, 0.16), transparent 65%),
    radial-gradient(520px 360px at 88% 8%, rgba(57, 135, 229, 0.10), transparent 60%),
    var(--bg);
}

a { color: inherit; }

.muted { color: var(--text-muted); }
.small { font-size: 0.8125rem; }

/* ---------- Header ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px clamp(16px, 5vw, 48px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex: none;
}
.status-dot.online { background: var(--good); box-shadow: 0 0 0 3px rgba(12, 163, 12, 0.18); }
.status-dot.offline { background: var(--bad); box-shadow: 0 0 0 3px rgba(230, 103, 103, 0.18); }

/* ---------- Layout ---------- */

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 clamp(16px, 5vw, 48px) 80px;
}

/* ---------- Hero ---------- */

.hero {
  text-align: center;
  padding: clamp(24px, 6vh, 56px) 0 8px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-strong);
  margin: 0 0 14px;
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 3.1rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
  margin: 0 0 16px;
  font-weight: 800;
}

.hero-sub {
  color: var(--text-secondary);
  font-size: clamp(1rem, 2vw, 1.15rem);
  max-width: 46ch;
  margin: 0 auto 36px;
}

/* ---------- Input card ---------- */

.input-card {
  max-width: 620px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  padding: 10px;
  text-align: left;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 6px;
  margin-bottom: 4px;
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab:hover { color: var(--text-secondary); background: rgba(255, 255, 255, 0.04); }
.tab.active { color: var(--text-primary); background: var(--surface-3); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tab-panel { padding: 22px 20px 26px; }

/* ---------- Dropzone ---------- */

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  color: var(--text-secondary);
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: rgba(235, 104, 52, 0.06);
}

.dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.dropzone-icon { color: var(--accent); margin-bottom: 10px; }

.dropzone-title {
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 4px;
}

.dropzone .muted { margin: 4px 0 16px; font-size: 0.875rem; }

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-strong); }

.btn-secondary {
  background: var(--surface-3);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-3); border-color: var(--accent); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--border-strong); }

.btn-small { padding: 6px 12px; font-size: 0.8125rem; }

/* ---------- Camera ---------- */

.camera-wrap {
  position: relative;
  background: var(--bg-2);
  border-radius: var(--radius-md);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
}

#cameraVideo, #cameraCanvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.camera-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
}

.camera-controls {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

/* ---------- Loading / error states ---------- */

.loading-state, .error-state {
  max-width: 480px;
  margin: 48px auto 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: var(--text-secondary);
}

.error-state { color: var(--bad); }
.error-state p { color: var(--text-secondary); margin: 0; }

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Results ---------- */

.results {
  display: grid;
  grid-template-columns: minmax(220px, 340px) 1fr;
  gap: 24px;
  margin-top: 40px;
  align-items: start;
}

.result-media {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.media-frame {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-1);
}

.media-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-placeholder { color: var(--text-muted); }

.rarity-badge {
  align-self: flex-start;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--rarity-common-bg);
  color: var(--rarity-common-fg);
}
.rarity-badge.rarity-uncommon { background: var(--rarity-uncommon-bg); color: var(--rarity-uncommon-fg); }
.rarity-badge.rarity-rare { background: var(--rarity-rare-bg); color: var(--rarity-rare-fg); }
.rarity-badge.rarity-legendary { background: var(--rarity-legendary-bg); color: var(--rarity-legendary-fg); }
.rarity-badge.rarity-unknown { background: var(--rarity-unknown-bg); color: var(--rarity-unknown-fg); }

.result-info {
  grid-column: 2;
  grid-row: 1;
}

.unknown-note {
  background: rgba(235, 104, 52, 0.10);
  border: 1px solid rgba(235, 104, 52, 0.28);
  color: #ffb088;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin: 0 0 16px;
}

.result-info h2 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 16px;
}
.meta-row span:not(:last-child)::after {
  content: "·";
  margin-left: 10px;
  color: var(--text-muted);
}

.description {
  color: var(--text-secondary);
  max-width: 62ch;
  margin: 0 0 24px;
}

.block-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 10px;
}

.purchase-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.purchase-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.08s ease;
}
.purchase-link:hover { border-color: var(--accent); background: var(--surface-2); transform: translateY(-1px); }
.purchase-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.purchase-link .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* ---------- Price panel ---------- */

.price-panel {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 4px;
}

.price-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 92px;
}

.chip-label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
}

.chip-value {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: proportional-nums;
}

.chip-value.trend-up { color: var(--good); }
.chip-value.trend-down { color: var(--bad); }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px clamp(12px, 3vw, 24px) 12px;
  box-shadow: var(--shadow-1);
}

.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.chart-header .muted { margin: 2px 0 0; }

.chart-container {
  position: relative;
  width: 100%;
}

.chart-container svg { width: 100%; height: auto; display: block; overflow: visible; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.8125rem;
  box-shadow: var(--shadow-2);
  transform: translate(-50%, -110%);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.1s ease;
  z-index: 5;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .tt-value { font-weight: 700; color: var(--text-primary); font-size: 0.9rem; }
.chart-tooltip .tt-row { color: var(--text-secondary); }
.chart-tooltip .tt-key { display: inline-block; width: 10px; height: 2px; background: var(--series-1); margin-right: 6px; vertical-align: middle; }

.chart-source { margin: 10px 2px 0; }

.table-container { margin-top: 12px; overflow-x: auto; }
.table-container table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.table-container th, .table-container td {
  text-align: right;
  padding: 6px 10px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.table-container th:first-child, .table-container td:first-child { text-align: left; font-variant-numeric: initial; }
.table-container th { color: var(--text-muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); }

/* ---------- Footer ---------- */

.site-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8125rem;
  padding: 24px 16px 40px;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .results {
    grid-template-columns: 1fr;
  }
  .result-media { flex-direction: row; align-items: center; }
  .media-frame { width: 140px; height: 140px; flex: none; aspect-ratio: auto; }
  .result-info { grid-column: 1; grid-row: 2; }
  .price-panel { grid-column: 1; grid-row: 3; }
}

@media (max-width: 560px) {
  .tabs { flex-wrap: wrap; }
  .tab { font-size: 0.8125rem; padding: 9px 8px; }
  .result-media { flex-direction: column; align-items: flex-start; }
  .media-frame { width: 100%; aspect-ratio: 1 / 1; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: var(--accent); }
  .btn, .purchase-link, .dropzone { transition: none; }
}
