:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #d2d2d7;
  --accent: #0071e3;
  --accent-text: #ffffff;
  --danger: #c9341f;
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
h1, h2, h3 { letter-spacing: -0.02em; line-height: 1.1; }
h1 { font-size: clamp(2rem, 5vw, 3rem); margin: 0 0 0.5em; }

main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 96px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Header and footer */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; position: sticky; top: 0; z-index: 10;
  background: rgba(245, 245, 247, 0.8); backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
.brand { font-weight: 600; color: var(--text); font-size: 1.05rem; }
.topbar nav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; font-size: 0.9rem; }
.topbar nav a { color: var(--text); }
.inline { display: inline; }
.footer { max-width: 1100px; margin: 0 auto; padding: 24px 16px 40px; font-size: 0.75rem; color: var(--muted); }

/* Controls */
.button, button.button {
  display: inline-block; border: 0; border-radius: 980px; cursor: pointer;
  background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 500;
  padding: 11px 22px; text-decoration: none;
}
.button:hover { text-decoration: none; filter: brightness(1.08); }
.button.secondary { background: #e8e8ed; color: var(--text); }
.button.danger { background: transparent; color: var(--danger); }
.button.small { padding: 6px 14px; font-size: 0.85rem; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--text); cursor: pointer; }

input[type=text], input[type=password], input[type=search], select {
  font: inherit; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text); width: 100%;
}
select { width: auto; }
.stack { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 500; }
.help, .muted { color: var(--muted); font-size: 0.9em; }
.errors { color: var(--danger); font-size: 0.9rem; }
.errors p { margin: 0; }
.narrow { max-width: 520px; margin: 0 auto; }
.lead { font-size: 1.15rem; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.page-head h1 { margin: 0; }

.messages { max-width: 1100px; margin: 12px auto 0; padding: 0 16px; }
.message { background: var(--surface); border-radius: 12px; padding: 10px 14px; margin: 0 0 8px; border-left: 4px solid var(--accent); }
.message.error { border-left-color: var(--danger); }
.note { background: #fff8e1; border-radius: 12px; padding: 10px 14px; }
.empty { background: var(--surface); border-radius: var(--radius); padding: 32px; text-align: center; }

.intro { text-align: center; padding: 10vh 0; }
.intro h1 { font-size: clamp(2.5rem, 7vw, 4.5rem); }
.intro .lead { max-width: 640px; margin: 0 auto 32px; }

/* Upload */
.upload-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.upload-choice {
  display: grid; justify-items: center; gap: 8px; padding: 28px 12px; cursor: pointer;
  background: var(--surface); border: 2px dashed var(--line); border-radius: var(--radius); font-weight: 500;
}
.upload-choice:focus-within { border-color: var(--accent); }
.upload-icon { font-size: 2rem; }

/* Review */
.photo { margin: 32px 0; }
.working::before {
  content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px;
  border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.detections { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); }
.detection { background: var(--surface); border-radius: var(--radius); padding: 14px; display: grid; gap: 12px; align-content: start; }
.crop img { max-height: 220px; margin: 0 auto; border-radius: 10px; }
.crop { margin: 0; }
.crop figcaption { font-size: 0.8rem; color: var(--muted); text-align: center; margin-top: 4px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; margin-bottom: 6px; }
.candidates { display: grid; gap: 8px; }
.candidate {
  display: grid; grid-template-columns: auto 52px 1fr; align-items: center; gap: 10px;
  padding: 8px; border: 2px solid var(--line); border-radius: 12px; cursor: pointer;
}
.candidate.skip { grid-template-columns: auto 1fr; }
.candidate:has(input:checked) { border-color: var(--accent); background: #f0f6ff; }
.candidate img { width: 52px; border-radius: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips legend { width: 100%; }
.chip input { position: absolute; opacity: 0; }
.chip span { display: inline-block; padding: 6px 14px; border-radius: 980px; border: 1px solid var(--line); cursor: pointer; }
.chip input:checked + span { background: var(--text); color: #fff; border-color: var(--text); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.condition { display: flex; align-items: center; gap: 10px; }
.search summary { cursor: pointer; color: var(--accent); }
.search input { margin-top: 8px; }
.result-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); margin-top: 12px; }
.result { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px; cursor: pointer; font: inherit; font-size: 0.8rem; display: grid; gap: 4px; }
.result:hover { border-color: var(--accent); }
.sticky-actions {
  position: sticky; bottom: 0; padding: 14px 0 calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%); text-align: center;
}
.sticky-actions .button { min-width: 240px; font-size: 1.05rem; }

/* Manual search */
.search-form { display: flex; gap: 10px; margin-bottom: 16px; }
.card-choice { display: grid; grid-template-columns: minmax(0, 220px) 1fr; gap: 20px; background: var(--surface); border-radius: var(--radius); padding: 16px; margin: 16px 0; }
.card-choice h2 { margin: 0; }

/* My collection */
.item-list { list-style: none; padding: 0; display: grid; gap: 12px; }
.item { display: grid; grid-template-columns: 72px 1fr auto; gap: 14px; align-items: start; background: var(--surface); border-radius: var(--radius); padding: 12px; }
.item img { width: 72px; border-radius: 5px; }
.item-info { display: grid; gap: 2px; }
.item-edit { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-top: 6px; font-size: 0.85rem; }
.item-edit label { display: grid; gap: 2px; }
.item-edit select { padding: 4px 8px; }
.item-actions { display: grid; gap: 6px; justify-items: end; }

@media (max-width: 640px) {
  .item { grid-template-columns: 56px 1fr; }
  .item img { width: 56px; }
  .item-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
  .card-choice { grid-template-columns: 1fr; }
  .card-choice img { max-width: 220px; margin: 0 auto; }
}

/* Showcase */
body.showcase { --bg: #000; --text: #f5f5f7; --muted: #a1a1a6; --surface: #1d1d1f; --line: #424245; background: #000; color: var(--text); }
body.showcase .topbar { background: rgba(0, 0, 0, 0.7); border-bottom-color: rgba(255, 255, 255, 0.08); }
body.showcase .topbar nav a, body.showcase .brand, body.showcase button.link { color: var(--text); }
body.showcase .footer { color: var(--muted); }
body.showcase main { max-width: none; padding: 0 16px; }
.showcase section { max-width: 1100px; margin: 0 auto; }
.showcase h2 { font-size: clamp(2.2rem, 6vw, 4rem); text-align: center; margin: 0 0 0.2em; }
.section-lead { text-align: center; color: var(--muted); font-size: 1.25rem; margin: 0 0 48px; }

.hero { text-align: center; padding: 8vh 0 12vh; }
.hero h1 { font-size: clamp(2.8rem, 9vw, 5.5rem); margin: 0.1em 0; background: linear-gradient(180deg, #fff, #a1a1a6); -webkit-background-clip: text; background-clip: text; color: transparent; }
.eyebrow { color: #f5a623; font-weight: 600; margin: 0; }
.hero-sub { color: var(--muted); font-size: 1.2rem; margin: 0 0 6vh; }
.hero .holo-card { margin: 0 auto; }
.motion-permission { margin-top: 32px; background: rgba(255, 255, 255, 0.12); color: #fff; border: 0; border-radius: 980px; padding: 10px 20px; font: inherit; cursor: pointer; }

.top-three { padding: 10vh 0; }
.top-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 48px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.top-card { text-align: center; position: relative; }
.top-card h3 { font-size: 1.6rem; margin: 24px 0 4px; }
.top-card p { margin: 4px 0; }
.top-card .value { font-size: 2rem; font-weight: 600; background: linear-gradient(90deg, #f5a623, #f76b1c); -webkit-background-clip: text; background-clip: text; color: transparent; }
.rank { position: absolute; top: -18px; left: 8px; z-index: 2; font-size: 4rem; font-weight: 700; color: rgba(255, 255, 255, 0.14); }
.top-card:nth-child(2) { transition-delay: 0.12s; }
.top-card:nth-child(3) { transition-delay: 0.24s; }

.numbers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; padding: 10vh 0; text-align: center; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.numbers strong { display: block; font-size: clamp(1.8rem, 6vw, 3.5rem); letter-spacing: -0.03em; }
.numbers span { color: var(--muted); }

.artists { padding: 12vh 0 6vh; }
.artist-list { list-style: none; padding: 0; display: grid; gap: 32px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }
.artist { display: grid; justify-items: center; gap: 4px; text-align: center; }
.artist-fan { position: relative; height: 150px; width: 160px; margin-bottom: 12px; }
.artist-fan img { position: absolute; left: 50%; top: 0; width: 100px; border-radius: 6px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6); transform-origin: 50% 120%; }
.artist-fan img:nth-child(1) { transform: translateX(-50%) rotate(-10deg); }
.artist-fan img:nth-child(2) { transform: translateX(-50%) rotate(0deg); }
.artist-fan img:nth-child(3) { transform: translateX(-50%) rotate(10deg); }
.artist-fan img:only-child { transform: translateX(-50%); }

.all-cards { padding: 8vh 0; }
.card-grid { list-style: none; padding: 0; display: grid; gap: 28px 18px; grid-template-columns: repeat(auto-fill, minmax(min(45%, 180px), 1fr)); margin-top: 40px; }
.grid-card { display: grid; gap: 2px; font-size: 0.85rem; }
.grid-card .holo-card { margin-bottom: 10px; }
.grid-card .value { font-weight: 600; }

/* Reveal on scroll (only when JavaScript runs) */
.js .showcase .reveal { opacity: 0; transform: translateY(40px); transition: opacity 0.9s ease, transform 0.9s cubic-bezier(0.2, 0.7, 0.2, 1); }
.js .showcase .reveal.is-visible { opacity: 1; transform: none; }

/* Holo card: tilt with --rx/--ry, light position --px/--py (set by showcase.js) */
.holo-card {
  --rx: 0deg; --ry: 0deg; --px: 50%; --py: 50%; --shine: 0;
  width: 100%; max-width: 260px; margin: 0 auto; perspective: 900px;
}
.holo-card--large { max-width: min(380px, 78vw); }
.holo-card__inner {
  position: relative; aspect-ratio: 600 / 825; border-radius: 4.5% / 3.3%; overflow: hidden;
  transform: rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.06);
  background: #222; will-change: transform;
}
.holo-card.is-active .holo-card__inner { transition: transform 0.08s linear; }
.holo-card__inner img { width: 100%; height: 100%; object-fit: cover; }
.holo-card__placeholder { display: grid; place-items: center; height: 100%; padding: 16px; text-align: center; color: #aaa; }
.holo-card__shine, .holo-card__glare { position: absolute; inset: 0; pointer-events: none; transition: opacity 0.4s ease; }
.holo-card__glare {
  background: radial-gradient(circle at var(--px) var(--py), rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 55%);
  mix-blend-mode: overlay; opacity: calc(var(--shine) * 0.8);
}
.holo-card__shine {
  background:
    repeating-linear-gradient(110deg,
      hsl(0 100% 70%) 0%, hsl(50 100% 65%) 6%, hsl(120 90% 65%) 12%,
      hsl(190 100% 65%) 18%, hsl(260 100% 72%) 24%, hsl(330 100% 70%) 30%, hsl(0 100% 70%) 36%);
  background-size: 300% 300%;
  background-position: var(--px) var(--py);
  mix-blend-mode: color-dodge; filter: saturate(1.2) brightness(0.7);
  opacity: 0;
}
.holo-card[data-finish="foil"] .holo-card__shine { opacity: calc(var(--shine) * 0.45); }
.holo-card[data-finish="plain"] .holo-card__shine { opacity: calc(var(--shine) * 0.08); }

@media (prefers-reduced-motion: reduce) {
  .holo-card__inner { transform: none; }
}

@media (max-width: 640px) {
  .numbers { grid-template-columns: 1fr; gap: 32px; }
  .upload-choices { grid-template-columns: 1fr; }
}
