:root {
  color-scheme: light;
  --bg: #FAFAFC;
  --card: #FFFFFF;
  --shadow: 0 1px 2px rgba(21, 21, 31, 0.06);
  --text: #15151F;
  --muted: #6B6B7B;
  --faint: #9A9AA8;
  --faintest: #B4B4BE;
  --soft: #F1F1F5;
  --rule: #F0F0F4;
  --rule-light: #F5F5F8;
  --disc: #201F2B;
  --code-bg: #201F2B;
  --code-fg: #E9E7FB;
  --accent: #7C5CFC;
  --eyebrow: #7C5CFC;
  --ring: #7C5CFC;
  --ring-track: #ECEAFB;
  --format-fg: #9A6BFF;
  --format-bg: #F3EEFF;
  --dot: #C9C9D4;
  --logo-filter: none;

  --pink: #FF4FA3;
  --pink-fg: #BE123C;
  --pink-bg: #FFE4EA;
  --pink-tile: #FFEAF1;
  --amber: #FFA733;
  --amber-fg: #B45309;
  --amber-bg: #FFF4E0;
  --amber-tile: #FFF3E0;
  --green: #22C55E;
  --green-fg: #15803D;
  --green-bg: #E8FBF0;
  --status-bg: #EFFBF3;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121118;
    --card: #1C1B24;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    --text: #F5F4FA;
    --muted: #9A98AC;
    --faint: #77748C;
    --faintest: #5C5A6E;
    --soft: #26242F;
    --rule: #2A2935;
    --rule-light: #232230;
    --disc: #2A2836;
    --code-bg: #26242F;
    --eyebrow: #9B82FF;
    --ring: #9B82FF;
    --ring-track: rgba(155, 130, 255, 0.16);
    --format-fg: #B79CFF;
    --format-bg: rgba(154, 107, 255, 0.16);
    --dot: #4A4858;
    --logo-filter: invert(1);

    --pink: #FF6FB5;
    --pink-fg: #FF8DC2;
    --pink-bg: rgba(255, 79, 163, 0.18);
    --pink-tile: rgba(255, 79, 163, 0.16);
    --amber: #FFB84D;
    --amber-fg: #FFB84D;
    --amber-bg: rgba(255, 167, 51, 0.18);
    --amber-tile: rgba(255, 167, 51, 0.16);
    --green: #4ADE80;
    --green-fg: #4ADE80;
    --green-bg: rgba(34, 197, 94, 0.16);
    --status-bg: rgba(34, 197, 94, 0.14);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Manrope', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.num { font-family: 'Space Grotesk', system-ui, sans-serif; }

.report {
  max-width: 430px;
  margin: 0 auto;
  padding: 20px 16px 56px;
}

.loading, .error { color: var(--muted); font-size: 14px; text-align: center; margin-top: 40vh; }

.card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.section { margin-top: 26px; }
.section-title { display: block; font-size: 13px; font-weight: 800; }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; }
.logo { display: block; height: 31px; width: auto; filter: var(--logo-filter); }
.status {
  display: flex; align-items: center; gap: 6px;
  background: var(--status-bg); padding: 5px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700; color: var(--green-fg);
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--green); }

/* Title */
.titleblock { margin-top: 22px; }
.eyebrow { font-size: 11px; font-weight: 800; letter-spacing: 1.6px; color: var(--eyebrow); }
.titleblock h1 { margin: 6px 0 0; font-size: 26px; font-weight: 700; letter-spacing: -0.4px; }
.byline { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.artist { font-size: 14px; font-weight: 600; color: var(--muted); }
.sep { width: 3px; height: 3px; border-radius: 50%; background: var(--dot); }
.format { font-size: 12px; font-weight: 700; color: var(--format-fg); background: var(--format-bg); padding: 2px 8px; border-radius: 6px; }

/* Stat tiles */
.stats { display: flex; gap: 10px; margin-top: 20px; }
.stat {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 14px 10px;
}
.stat-wide { flex: 1.2; padding: 14px; }
.stat-label { font-size: 10px; font-weight: 700; color: var(--muted); text-align: center; line-height: 1.3; }
.stat-value { font-size: 20px; font-weight: 700; }
.stat-value small { font-size: 12px; font-weight: 600; color: var(--faint); }
.ring {
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.ring span {
  width: 50px; height: 50px; border-radius: 50%; background: var(--card);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; line-height: 1;
}
.stat-icon { width: 30px; height: 30px; border-radius: 9px; display: flex; align-items: center; justify-content: center; }
.stat-icon.pink { background: var(--pink-tile); color: var(--pink); }
.stat-icon.amber { background: var(--amber-tile); color: var(--amber); }

/* Disc viewer */
.viewer { margin-top: 22px; border-radius: 20px; padding: 18px; }
.viewer-head { display: flex; align-items: center; justify-content: space-between; }
.segmented { display: flex; background: var(--soft); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  padding: 6px 10px; border-radius: 8px;
  font: 700 11px 'Manrope', system-ui, sans-serif; color: var(--faint);
  transition: background 0.15s, color 0.15s;
}
.segmented button[aria-pressed="true"] { background: var(--accent); color: #FFFFFF; }
.segmented button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.discs { display: flex; gap: 14px; margin-top: 16px; }
.side { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.side-label { font-size: 12px; font-weight: 800; }
.zoomable {
  appearance: none; border: 0; padding: 0; margin: 0; background: none; color: inherit; font: inherit;
  cursor: zoom-in; -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease;
}
.zoomable:hover { transform: scale(1.03); }
.zoomable:active { transform: scale(0.98); }
.zoomable:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.disc { display: block; position: relative; width: 100%; max-width: 150px; aspect-ratio: 1; }
.disc.zoomable:focus-visible { border-radius: 50%; }
.disc-photo { position: absolute; inset: 0; border-radius: 50%; overflow: hidden; background: var(--disc); }
.disc-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.marks { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.marks, .legend { transition: opacity 0.2s; }
.viewer[data-view="raw"] .marks,
.viewer[data-view="raw"] .legend { opacity: 0; }
.mark { fill-opacity: 0.18; stroke-width: 1.8; }
.mark.pink { fill: var(--pink); stroke: var(--pink); }
.mark.amber { fill: var(--amber); stroke: var(--amber); }

.legend {
  display: flex; align-items: center; gap: 14px;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--rule);
}
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 10px; font-weight: 600; color: var(--muted); }
.swatch { width: 8px; height: 8px; border-radius: 2px; }
.swatch.pink { background: var(--pink); }
.swatch.amber { background: var(--amber); }

/* Matrix codes */
.codes { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.code {
  font-family: 'Space Grotesk', system-ui, sans-serif; font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
  color: var(--code-fg); background: var(--code-bg); padding: 7px 12px; border-radius: 8px;
}

/* Scores */
.score { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 7px; }
.score.good { color: var(--green-fg); background: var(--green-bg); }
.score.warn { color: var(--amber-fg); background: var(--amber-bg); }
.score.bad { color: var(--pink-fg); background: var(--pink-bg); }

/* Tracks */
.tracks { margin-top: 12px; padding: 6px 14px; }
.row { display: flex; align-items: center; justify-content: space-between; }
.tracks-head { padding: 10px 0; border-bottom: 1px solid var(--rule); font-size: 12px; font-weight: 800; }
.track { padding: 12px 0; border-bottom: 1px solid var(--rule-light); }
.track:last-child { border-bottom: 0; }
.track-name { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; }
.track-n {
  width: 22px; height: 22px; border-radius: 50%; background: var(--soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: var(--muted);
}

/* Defect cards */
.defect { margin-top: 12px; padding: 14px; display: flex; gap: 12px; cursor: zoom-in; }
.defect-thumb { display: block; width: 56px; height: 56px; border-radius: 12px; background: var(--disc); flex-shrink: 0; overflow: hidden; }
.defect-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.defect-body { flex: 1; min-width: 0; }
.defect-title { font-size: 13px; font-weight: 800; }
.badge { font-size: 9px; font-weight: 800; padding: 3px 8px; border-radius: 6px; letter-spacing: 0.3px; text-transform: uppercase; }
.badge.high { color: var(--pink-fg); background: var(--pink-bg); }
.badge.medium { color: var(--amber-fg); background: var(--amber-bg); }
.badge.low { color: var(--green-fg); background: var(--green-bg); }
.defect-where { display: block; font-size: 11px; font-weight: 600; color: var(--faint); }
.defect-line { display: flex; align-items: center; gap: 5px; margin-top: 5px; font-size: 11px; }
.defect-line svg { flex-shrink: 0; }
.impact { margin-top: 7px; font-weight: 700; }
.impact.high { color: var(--pink); }
.impact.medium { color: var(--amber-fg); }
.impact.low { color: var(--green-fg); }
.defect-time { color: var(--muted); font-weight: 600; }
.defect-time svg { color: var(--faint); }

/* Record identity */
.identity { margin-top: 26px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.identity-label { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; color: var(--muted); }
.identity-label svg.accent { color: var(--eyebrow); }
.identity hr { width: 100%; height: 1px; margin: 0; border: 0; background: var(--rule); }
.record-id { font-size: 12px; font-weight: 700; letter-spacing: 0.3px; background: var(--soft); padding: 4px 10px; border-radius: 7px; }
.identity-value { font-size: 12px; font-weight: 700; }

.footer { margin-top: 30px; text-align: center; font-size: 10px; font-weight: 600; color: var(--faintest); }

/* Enlarged view */
html:has(dialog.zoom[open]) { overflow: hidden; }
.zoom {
  width: min(92vw, 640px); max-height: 92dvh; padding: 0; border: 0; border-radius: 20px;
  background: var(--card); color: var(--text); box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  overflow: auto; overscroll-behavior: contain;
}
.zoom::backdrop { background: rgba(10, 10, 15, 0.72); }
.zoom[open] { animation: zoom-in 0.18s ease-out; }
.zoom[open]::backdrop { animation: fade-in 0.18s ease-out; }
@keyframes zoom-in { from { opacity: 0; transform: scale(0.96); } }
@keyframes fade-in { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .zoom[open], .zoom[open]::backdrop { animation: none; }
  .zoomable { transition: none; }
}
.zoom-inner { padding: 14px 16px 18px; }
.zoom-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.zoom-title { font-size: 13px; font-weight: 800; }
.zoom-close {
  appearance: none; border: 0; cursor: pointer; width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--soft); color: var(--muted);
}
.zoom-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.zoom-media { display: flex; justify-content: center; }
.zoom-disc { position: relative; width: min(100%, calc(92dvh - 170px)); aspect-ratio: 1; }
.zoom-disc[data-view="raw"] .marks { opacity: 0; }
.zoom .mark { stroke-width: 2.5; }
.zoom-defect {
  display: block; width: 100%; max-height: calc(92dvh - 210px); object-fit: contain;
  border-radius: 12px; background: var(--disc);
}
.zoom-caption { margin-top: 14px; }
.zoom-details { max-width: 420px; }
.zoom-details .defect-title { font-size: 15px; }
.zoom-details .defect-where, .zoom-details .defect-line { font-size: 12px; }
.zoom-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.zoom-chip {
  appearance: none; border: 0; cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 10px; border-radius: 10px; background: var(--soft); color: var(--text);
  font: 700 12px 'Manrope', system-ui, sans-serif;
}
.zoom-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.zoom-note { margin: 0; font-size: 12px; color: var(--muted); }
