:root {
  --bg: #f3f0e8;
  --ink: #1b2028;
  --muted: #66707c;
  --line: rgba(27, 32, 40, 0.14);
  --panel: #fffdfa;
  --red: #d92232;
  --yellow: #ffd321;
  --blue: #0057b8;
  --green: #00a75f;
  --dark: #111820;
  --shadow: 0 18px 42px rgba(27, 32, 40, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(255, 211, 33, 0.14), transparent 28%),
    linear-gradient(225deg, rgba(0, 87, 184, 0.1), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

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

.app-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px clamp(16px, 3.5vw, 52px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(17, 24, 32, 0.92);
  color: white;
  backdrop-filter: blur(18px);
}

.brand-lockup {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 0;
  border-radius: 18px;
  width: clamp(168px, 16vw, 230px);
  height: 54px;
  padding: 1px;
  background: white;
  color: white;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}

.brand-lockup.active,
.brand-lockup:hover {
  background: white;
}

.header-logo {
  display: block;
  width: 116%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

.app-nav {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.app-nav::-webkit-scrollbar {
  display: none;
}

.nav-button {
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.96rem;
  font-weight: 900;
  line-height: 1.02;
}

.nav-word {
  display: inline;
}

.nav-button.active,
.nav-button:hover {
  background: var(--yellow);
  color: var(--ink);
}

.nav-button[data-view-target="scan"] {
  border-color: rgba(217, 34, 50, 0.82);
  color: #ff4b5d;
  box-shadow:
    inset 0 0 0 1px rgba(217, 34, 50, 0.18),
    0 0 18px rgba(217, 34, 50, 0.2);
  font-size: 1.02rem;
}

.nav-button[data-view-target="scan"].active,
.nav-button[data-view-target="scan"]:hover {
  border-color: rgba(217, 34, 50, 0.95);
  background: var(--red);
  color: var(--ink);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.18),
    0 0 24px rgba(217, 34, 50, 0.42);
}

.brand-lockup.nav-button,
.brand-lockup.nav-button.active,
.brand-lockup.nav-button:hover {
  border-radius: 18px;
  padding: 1px;
  background: white;
}

main {
  padding: clamp(18px, 3.5vw, 52px);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.home-view.active {
  display: grid;
}

.home-view {
  position: relative;
  min-height: calc(100vh - 112px);
  grid-template-columns: minmax(280px, 560px) minmax(420px, 1fr);
  gap: 28px;
  align-content: center;
  align-items: center;
  justify-content: stretch;
}

.home-view.intro-complete {
  min-height: auto;
  grid-template-columns: minmax(0, 860px);
  padding-top: 0;
  gap: 16px;
  align-content: start;
  align-items: center;
  justify-content: center;
}

.home-copy {
  position: relative;
  z-index: 3;
}

.home-view.intro-complete .home-copy {
  text-align: center;
}

.home-view.intro-complete .home-copy p:not(.eyebrow) {
  margin-right: auto;
  margin-left: auto;
}

.intro-stage {
  display: flex;
  position: relative;
  order: 2;
  min-height: clamp(360px, 47vw, 680px);
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 8px;
  background: radial-gradient(circle at 50% 78%, rgba(255, 255, 255, 0.96), rgba(232, 236, 241, 0.72) 62%, rgba(212, 218, 226, 0.42));
  box-shadow: inset 0 -1px 0 rgba(27, 32, 40, 0.1);
  transition:
    min-height 760ms ease,
    opacity 520ms ease,
    transform 760ms ease,
    visibility 760ms ease;
}

.home-view.intro-complete .intro-stage {
  order: 0;
  min-height: clamp(170px, 23vw, 290px);
  background: transparent;
  box-shadow: none;
  opacity: 1;
  transform: none;
  visibility: visible;
}

.intro-stage::after {
  position: absolute;
  right: 8%;
  bottom: 12%;
  left: 8%;
  height: 13%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(27, 32, 40, 0.16), transparent 68%);
  content: "";
  pointer-events: none;
}

.intro-stage canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  min-height: inherit;
}

.home-view.intro-complete .intro-stage::after,
.home-view.intro-complete .intro-stage canvas {
  opacity: 0;
  visibility: hidden;
}

.home-logo-lockup {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.96);
  transition:
    opacity 420ms ease,
    transform 520ms ease;
}

.home-logo-lockup img {
  width: min(720px, 86%);
  max-height: 86%;
  object-fit: contain;
}

.home-view.intro-complete .home-logo-lockup {
  opacity: 1;
  transform: none;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.home-copy p:not(.eyebrow) {
  max-width: 580px;
  margin-bottom: 26px;
  color: #3d4652;
  font-size: clamp(1rem, 1.5vw, 1.22rem);
  line-height: 1.6;
}

.home-actions,
.preset-row,
.card-actions,
.progress-row,
.title-line {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button.primary {
  background: var(--yellow);
  box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.18);
}

.button.secondary {
  border: 1px solid var(--line);
  background: white;
}

.stats-strip {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(580px, 100%);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.stats-strip div {
  position: relative;
  z-index: 1;
  padding: 18px;
  border-right: 1px solid var(--line);
}

.stats-strip div:last-child {
  border-right: 0;
}

.stats-strip strong {
  display: block;
  font-size: clamp(1.45rem, 3vw, 2.25rem);
  line-height: 1;
}

.stats-strip span {
  color: var(--muted);
  font-size: 0.88rem;
}

.panel,
.match-card,
.inventory-dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: clamp(18px, 2.5vw, 28px);
}

.section-heading {
  margin-bottom: 18px;
}

.section-heading h2 {
  margin-bottom: 0;
  font-size: clamp(1.6rem, 3vw, 2.6rem);
  line-height: 1.05;
}

.page-label {
  margin-bottom: 0;
  color: var(--blue);
  font-size: clamp(1.15rem, 2.4vw, 1.6rem);
  line-height: 1.05;
  text-transform: none;
}

.section-heading.wide {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.collection-view,
.parts-view,
.scan-view {
  max-width: 980px;
}

.scan-view {
  max-width: 1180px;
}

.owned-list {
  display: grid;
  gap: 10px;
}

.collection-topbar {
  display: grid;
  grid-template-columns: minmax(170px, 0.42fr) minmax(320px, 1fr);
  gap: 16px;
  align-items: start;
  margin-bottom: 14px;
}

.collection-title {
  margin-bottom: 0;
}

.collection-title .page-label {
  margin-bottom: 6px;
}

.collection-title h2 {
  font-size: clamp(1.05rem, 2.4vw, 1.45rem);
  line-height: 1.12;
}

.collection-tools {
  display: grid;
  gap: 6px;
}

.add-set-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(260px, auto);
  gap: 10px;
  align-items: end;
  margin-bottom: 0;
}

.collection-add-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 8px;
}

.collection-add-buttons .button {
  min-height: 38px;
  padding: 8px 10px;
  font-size: 0.84rem;
  line-height: 1.08;
}

.collection-tool-row {
  display: grid;
  grid-template-columns: minmax(170px, 240px);
  gap: 10px;
  align-items: end;
}

.scan-set-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0;
}

.scan-set-actions .form-note {
  min-height: 0;
  margin: 0;
}

.file-button {
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.add-set-form input,
.collection-controls select,
.loose-controls select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 9px 10px;
}

.collection-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: start;
  margin: 0;
}

.loose-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr)) minmax(140px, 0.72fr);
  gap: 10px;
  align-items: start;
  margin: 14px 0 0;
}

.match-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
  align-items: start;
  margin: 0 0 14px;
}

.ranked-results-heading {
  margin-top: 18px;
}

.set-results-heading {
  margin-bottom: 10px;
}

.set-results-heading h2,
.ranked-results-heading h2 {
  font-size: clamp(1.05rem, 3.2vw, 1.45rem);
  line-height: 1;
  white-space: nowrap;
}

.match-controls select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 9px 10px;
}

.filter-group {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.88);
}

.collapsible-filter {
  padding: 0;
  overflow: hidden;
}

.collapsible-filter summary {
  display: flex;
  min-height: 32px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 950;
  list-style: none;
}

.collapsible-filter summary::-webkit-details-marker {
  display: none;
}

.collapsible-filter summary::after {
  content: "+";
  display: grid;
  width: 19px;
  height: 19px;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: rgba(27, 32, 40, 0.08);
  color: var(--ink);
  font-weight: 950;
}

.collapsible-filter[open] summary::after {
  content: "-";
}

.collapsible-filter summary small {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.collapsible-filter .checkbox-grid {
  margin: 0 8px 8px;
  border-top: 1px solid rgba(27, 32, 40, 0.08);
  padding-top: 8px;
}

.theme-filter-list {
  display: grid;
  gap: 8px;
  margin: 0 8px 8px;
  border-top: 1px solid rgba(27, 32, 40, 0.08);
  padding-top: 8px;
}

.theme-filter-section {
  display: grid;
  gap: 6px;
}

.filter-section-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

.theme-filter-section .checkbox-grid {
  max-height: 154px;
  margin: 0;
  border-top: 0;
  padding-top: 0;
}

.all-theme-section {
  border: 1px solid rgba(27, 32, 40, 0.1);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.82);
}

.all-theme-section summary {
  display: flex;
  min-height: 30px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 950;
  list-style: none;
}

.all-theme-section summary::-webkit-details-marker {
  display: none;
}

.all-theme-section summary small {
  color: var(--muted);
  font-weight: 850;
}

.all-theme-section .checkbox-grid {
  margin: 0 8px 8px;
  border-top: 1px solid rgba(27, 32, 40, 0.08);
  padding-top: 8px;
}

.filter-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.filter-group legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(124px, 1fr));
  gap: 8px;
  max-height: 184px;
  overflow: auto;
  padding-right: 2px;
}

.checkbox-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  max-height: none;
}

.checkbox-pill {
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 7px;
  border: 1px solid rgba(27, 32, 40, 0.12);
  border-radius: 8px;
  padding: 7px 9px;
  background: white;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 850;
}

.checkbox-pill input {
  width: 15px;
  height: 15px;
  accent-color: var(--yellow);
}

.form-note {
  min-height: 22px;
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.form-note.success {
  color: #067045;
}

.form-note.warning {
  color: #a15a00;
}

.empty-state {
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--muted);
  font-weight: 750;
}

.owned-card {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
}

.owned-card img {
  width: 76px;
  height: 56px;
  border-radius: 6px;
  object-fit: cover;
  background: #eef1f5;
}

.owned-card h3 {
  margin-bottom: 4px;
  font-size: 1rem;
}

.owned-card p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.owned-card input {
  width: 22px;
  height: 22px;
  accent-color: var(--red);
}

.collection-report {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.report-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.report-heading h3 {
  margin: 0;
  font-size: 1.1rem;
}

.report-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.report-summary {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
}

.report-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.collection-report-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

.collection-report-table th,
.collection-report-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  font-size: 0.86rem;
}

.collection-report-table th {
  background: #f7f8fa;
  color: var(--ink);
  font-weight: 950;
}

.collection-report-table td {
  color: var(--muted);
  font-weight: 750;
}

.collection-report-table tr:last-child td {
  border-bottom: 0;
}

.preset-row {
  margin-bottom: 18px;
}

.preset-row .button {
  border: 1px solid var(--line);
  background: white;
}

.part-form {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) 120px auto;
  gap: 10px;
  align-items: end;
}

.add-part-panel {
  display: block;
  margin: 10px 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.inventory-filter-panel {
  margin-bottom: 12px;
}

.inventory-filter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
  margin: 0 8px 8px;
  border-top: 1px solid rgba(27, 32, 40, 0.08);
  padding-top: 10px;
}

.inventory-filter-grid .filter-group {
  background: #fff;
}

.inventory-filter-grid .checkbox-grid {
  margin: 0;
  border-top: 0;
  padding-top: 0;
}

.inventory-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.inventory-stats div {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: linear-gradient(180deg, #ffffff, #f7f8fa);
}

.inventory-stats span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.inventory-stats strong {
  color: var(--ink);
  font-size: clamp(1.15rem, 3vw, 1.75rem);
  line-height: 1;
}

.inventory-list-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.inventory-list-heading h3 {
  margin: 0;
  font-size: 1.1rem;
}

.inventory-sort-control {
  width: min(220px, 42vw);
}

.inventory-sort-control select {
  min-height: 36px;
  padding: 7px 9px;
}

.add-part-panel .part-form {
  margin: 0 8px 10px;
  border-top: 1px solid rgba(27, 32, 40, 0.08);
  padding-top: 10px;
}

.part-add-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 8px 10px;
}

.part-add-actions .form-note {
  min-height: 0;
  margin: 0;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

select,
input[type="number"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 9px 10px;
}

.chip-board {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 88px;
  margin-top: 18px;
  border: 1px dashed rgba(29, 32, 37, 0.2);
  border-radius: 8px;
  padding: 12px;
  background: #fff8e1;
}

.brick-inventory-list {
  display: grid;
  gap: 6px;
  margin: 8px 0 0;
}

.inventory-part-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.94);
}

.part-swatch {
  width: 18px;
  height: 18px;
  border: 1px solid rgba(27, 32, 40, 0.18);
  border-radius: 5px;
  background: var(--swatch, #ccd2d8);
  box-shadow: inset 0 1px 3px rgba(255, 255, 255, 0.45);
}

.part-main {
  min-width: 0;
}

.part-main strong,
.part-main small,
.part-qty strong,
.part-qty small {
  display: block;
}

.part-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.part-main small,
.part-qty small {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 750;
}

.part-qty {
  min-width: 88px;
  text-align: right;
}

.part-qty strong {
  font-size: 1rem;
}

.inventory-part-row button {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #edf0f4;
  color: var(--ink);
  font-weight: 950;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 8px 10px;
  background: white;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 850;
}

.chip button {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #edf0f4;
}

.loose-chip {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.loose-chip strong,
.loose-chip small {
  display: block;
}

.loose-chip small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 750;
}

.upload-box {
  display: grid;
  min-height: 220px;
  place-items: center;
  border: 2px dashed rgba(0, 87, 184, 0.35);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(0, 87, 184, 0.08), rgba(255, 211, 33, 0.16));
  color: var(--ink);
  text-align: center;
}

.vision-mode-control {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  background: #f2f5f8;
}

.vision-mode-control label {
  display: block;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 950;
  text-align: center;
  cursor: pointer;
}

.vision-mode-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.vision-mode-control span {
  display: block;
  border-radius: 6px;
  padding: 9px 8px;
  transition:
    background 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
}

.vision-mode-control input:checked + span {
  background: var(--yellow);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(17, 24, 39, 0.12);
}

.vision-mode-note {
  margin: 0 0 10px;
}

.locator-target-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  border: 1px solid rgba(0, 87, 184, 0.18);
  border-radius: 8px;
  padding: 12px;
  background: linear-gradient(135deg, rgba(0, 87, 184, 0.08), rgba(255, 255, 255, 0.95));
}

.locator-target-panel[hidden] {
  display: none;
}

.locator-target-panel h3,
.locator-target-panel p {
  margin: 0;
}

.locator-target-panel p:not(.eyebrow) {
  color: var(--muted);
  font-weight: 650;
}

.scan-view.vision-mode-live .upload-box,
.scan-view.vision-mode-live .box-scan-panel,
.scan-view.vision-mode-live .photo-list {
  display: none;
}

.upload-box.dragging {
  border-color: var(--red);
  background: linear-gradient(135deg, rgba(217, 34, 50, 0.1), rgba(255, 211, 33, 0.22));
  box-shadow: inset 0 0 0 3px rgba(255, 211, 33, 0.28);
}

.upload-box input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.upload-box span {
  font-size: 1.08rem;
  font-weight: 950;
}

.upload-box small {
  max-width: 260px;
  color: var(--muted);
  font-weight: 650;
}

.box-scan-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.box-scan-panel h3,
.box-scan-panel p {
  margin: 0;
}

.box-scan-panel p:not(.eyebrow) {
  color: var(--muted);
  font-weight: 650;
}

.box-scan-panel input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.box-scan-panel .form-note {
  grid-column: 1 / -1;
}

.camera-panel {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.camera-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

#cameraPreview {
  display: none;
  width: 100%;
  max-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111820;
  object-fit: contain;
}

#cameraPreview.active {
  display: block;
}

.photo-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

.photo-tile {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: white;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.photo-tile.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 87, 184, 0.12);
}

.photo-tile img {
  width: 58px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  background: #e8edf3;
}

.photo-tile strong,
.photo-tile small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-tile strong {
  font-size: 0.84rem;
  font-weight: 900;
}

.photo-tile small {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
}

.scan-workbench {
  display: grid;
  grid-template-columns: minmax(320px, 1.2fr) minmax(280px, 0.8fr);
  gap: 16px;
  margin-top: 18px;
}

.scan-preview,
.analysis-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.scan-preview {
  display: grid;
  min-height: 360px;
  place-items: center;
  overflow: hidden;
}

.scan-preview canvas {
  width: 100%;
  max-height: 520px;
  object-fit: contain;
}

.vision-dialog {
  width: min(1240px, calc(100vw - 30px));
  max-width: none;
  border: 0;
  border-radius: 10px;
  padding: 0;
  background: transparent;
}

.vision-dialog::backdrop {
  background: rgba(17, 24, 32, 0.72);
  backdrop-filter: blur(6px);
}

.vision-stage {
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  background: #fffdfa;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.34);
}

.vision-stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: white;
}

.vision-stage-header h2 {
  margin: 0;
}

.vision-stage-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 0;
  min-height: min(760px, calc(100vh - 150px));
}

.vision-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 540px;
  background: #f4f1ea;
}

.vision-stage-panel {
  border-left: 1px solid var(--line);
  padding: 18px;
  background: rgba(255, 255, 255, 0.82);
}

.vision-stage-panel p {
  margin-bottom: 14px;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.45;
}

.vision-meter {
  margin-bottom: 16px;
}

.vision-stage-list {
  display: grid;
  gap: 8px;
  max-height: 560px;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
}

.vision-stage-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
  font-size: 0.86rem;
  font-weight: 800;
}

.vision-stage-list small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-weight: 750;
}

.analysis-panel {
  display: grid;
  gap: 18px;
  align-content: start;
  padding: 18px;
}

.analysis-panel h3 {
  margin-bottom: 0;
  font-size: 1.25rem;
}

.color-bars,
.candidate-list {
  display: grid;
  gap: 10px;
}

.color-bar {
  display: grid;
  grid-template-columns: 22px minmax(100px, 1fr) 52px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.swatch {
  width: 22px;
  height: 22px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 6px;
}

.bar-track {
  overflow: hidden;
  height: 9px;
  border-radius: 999px;
  background: #e8edf3;
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.candidate-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.candidate-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 9px;
  color: var(--muted);
  font-size: 0.9rem;
}

.candidate-list strong {
  color: var(--ink);
}

.match-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.owned-match-grid {
  margin-bottom: 10px;
}

.match-card {
  overflow: hidden;
}

.match-card[data-detail-set] {
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease;
}

.match-card[data-detail-set]:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 48px rgba(27, 32, 40, 0.16);
}

.box-art {
  aspect-ratio: 4 / 3;
  background: #e8edf3;
}

.box-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-body {
  padding: 16px;
}

.card-title {
  margin-bottom: 10px;
}

.title-line {
  align-items: center;
  flex-wrap: nowrap;
  justify-content: space-between;
  gap: 8px;
}

.title-cluster {
  display: flex;
  min-width: 0;
  flex: 1 1 auto;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
}

.card-title h3 {
  min-width: 0;
  overflow: hidden;
  margin-bottom: 0;
  font-size: 1.08rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-title p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 850;
}

.set-number {
  flex: 0 0 auto;
  border-radius: 6px;
  background: var(--red);
  color: white;
  padding: 5px 7px;
  font-size: 0.78rem;
  font-weight: 950;
}

.owned-pill {
  border-radius: 999px;
  background: rgba(0, 167, 95, 0.12);
  color: #067045;
  padding: 5px 8px;
  font-size: 0.76rem;
  font-weight: 950;
}

.progress-row {
  align-items: center;
  flex-wrap: nowrap;
  margin: 14px 0;
}

.meter {
  overflow: hidden;
  flex: 1 1 auto;
  height: 13px;
  border-radius: 999px;
  background: #e8edf3;
}

.meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--yellow));
}

.percent-pill {
  flex: 0 0 auto;
  min-width: 54px;
  border-radius: 999px;
  padding: 8px 10px;
  background: var(--yellow);
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 950;
  text-align: center;
}

.missing-list {
  display: grid;
  gap: 8px;
  min-height: 110px;
  margin: 14px 0 16px;
  padding: 0;
  list-style: none;
}

.missing-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.missing-list a {
  color: var(--blue);
  font-weight: 950;
  text-decoration: none;
}

.missing-list small {
  display: block;
  margin-top: 2px;
  color: #7b8491;
  font-size: 0.74rem;
  font-weight: 850;
}

.missing-list strong {
  color: var(--ink);
}

.card-actions a,
.card-actions button {
  border: 0;
  background: transparent;
  color: var(--blue);
  padding: 0;
  font-weight: 950;
  text-decoration: none;
}

.card-actions a:hover,
.card-actions button:hover,
.card-actions a:focus-visible,
.card-actions button:focus-visible {
  text-decoration: underline;
}

.target-preview {
  position: fixed;
  z-index: 50;
  left: 16px;
  right: 16px;
  bottom: 16px;
  display: none;
  max-width: 960px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(17, 24, 32, 0.94);
  color: white;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  font-weight: 800;
}

.target-preview.visible {
  display: block;
}

.inventory-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 32px));
  border: 0;
  padding: 22px;
}

.inventory-dialog::backdrop {
  background: rgba(17, 24, 32, 0.58);
  backdrop-filter: blur(6px);
}

.dialog-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}

.dialog-heading h2 {
  margin-bottom: 0;
  font-size: clamp(1.4rem, 3vw, 2rem);
}

.dialog-meta {
  color: var(--muted);
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font-weight: 950;
}

.dialog-inventory {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.dialog-inventory li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.dialog-inventory .signature-heading,
.dialog-inventory .signature-brick {
  grid-column: 1 / -1;
  border: 1px solid rgba(217, 34, 50, 0.24);
  border-radius: 8px;
  padding: 10px;
  background: linear-gradient(135deg, rgba(255, 211, 33, 0.2), rgba(217, 34, 50, 0.08));
  color: var(--ink);
}

.dialog-inventory .signature-heading strong,
.dialog-inventory .signature-brick strong {
  color: var(--red);
}

.dialog-inventory small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.dialog-inventory strong {
  color: var(--ink);
  flex: 0 0 auto;
}

@media (max-width: 1040px) {
  .home-view,
  .match-grid {
    grid-template-columns: 1fr;
  }

  .stats-strip {
    grid-column: 1 / -1;
  }

  .intro-stage {
    order: 0;
  }
}

@media (max-width: 760px) {
  .app-header {
    position: sticky;
    display: grid;
    grid-template-columns: 78px minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    padding: 8px 6px;
  }

  .app-nav {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px;
    min-width: 0;
    width: 100%;
    overflow-x: visible;
  }

  .brand-lockup {
    width: 78px;
    height: 44px;
    padding: 1px;
    overflow: hidden;
  }

  .header-logo {
    width: 116%;
    max-width: none;
    transform: none;
  }

  .nav-button {
    display: inline-flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 4px 3px;
    font-size: clamp(0.56rem, 2.35vw, 0.72rem);
    line-height: 0.98;
    text-align: center;
    white-space: normal;
  }

  .nav-button[data-view-target="scan"] {
    font-size: clamp(0.58rem, 2.55vw, 0.76rem);
  }

  .nav-word {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: clip;
  }

  .brand-lockup.nav-button,
  .brand-lockup.nav-button.active,
  .brand-lockup.nav-button:hover {
    width: 78px;
    min-height: 44px;
    padding: 1px;
  }

  .home-view {
    min-height: auto;
  }

  .intro-stage {
    min-height: 320px;
  }

  .part-form,
  .add-set-form,
  .collection-topbar,
  .collection-tool-row,
  .collection-controls,
  .match-controls,
  .loose-controls,
  .inventory-filter-grid,
  .locator-target-panel,
  .scan-workbench,
  .vision-stage-grid,
  .dialog-inventory {
    grid-template-columns: 1fr;
  }

  .inventory-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .vision-stage-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .vision-stage canvas {
    min-height: 360px;
  }

  .part-form button,
  .add-set-form button {
    width: 100%;
  }

  .stats-strip {
    grid-template-columns: 1fr;
  }

  .stats-strip div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stats-strip div:last-child {
    border-bottom: 0;
  }
}

@media (max-width: 560px) {
  main {
    padding: 16px;
  }

  .app-header {
    grid-template-columns: 70px minmax(0, 1fr);
    gap: 4px;
    padding: 7px 5px;
  }

  .brand-lockup {
    width: 70px;
    height: 40px;
    border-radius: 14px;
  }

  .brand-lockup.nav-button,
  .brand-lockup.nav-button.active,
  .brand-lockup.nav-button:hover {
    border-radius: 14px;
    padding: 1px;
  }

  .app-nav {
    gap: 2px;
  }

  .nav-button {
    min-height: 38px;
    padding: 3px 2px;
    font-size: clamp(0.52rem, 2.35vw, 0.64rem);
  }

  .nav-button[data-view-target="scan"] {
    font-size: clamp(0.55rem, 2.45vw, 0.68rem);
  }

  .inventory-stats {
    grid-template-columns: 1fr;
  }

  .inventory-part-row {
    grid-template-columns: 18px minmax(0, 1fr) auto;
  }

  .inventory-part-row button {
    grid-column: 3;
  }

  .brand-lockup.nav-button,
  .brand-lockup.nav-button.active,
  .brand-lockup.nav-button:hover {
    width: 70px;
    min-height: 40px;
    padding: 1px;
  }

  .owned-card {
    grid-template-columns: 62px minmax(0, 1fr) auto;
  }

  .owned-card img {
    width: 62px;
    height: 48px;
  }

  .owned-pill {
    align-self: flex-start;
  }
}

@media (max-width: 380px) {
  .app-header {
    grid-template-columns: 62px minmax(0, 1fr);
    padding: 6px 4px;
  }

  .brand-lockup,
  .brand-lockup.nav-button,
  .brand-lockup.nav-button.active,
  .brand-lockup.nav-button:hover {
    width: 62px;
    height: 36px;
    min-height: 36px;
  }

  .nav-button {
    min-height: 36px;
    font-size: 0.5rem;
    letter-spacing: 0;
  }

  .nav-button[data-view-target="scan"] {
    font-size: 0.53rem;
  }
}

@media print {
  body {
    background: white;
  }

  body * {
    visibility: hidden;
  }

  .collection-report,
  .collection-report * {
    visibility: visible;
  }

  .collection-report {
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
    margin: 0;
    border: 0;
    padding: 24px;
  }

  .report-actions {
    display: none;
  }

  .report-table-wrap {
    overflow: visible;
    border: 0;
  }

  .collection-report-table {
    min-width: 0;
  }

  .collection-report-table th,
  .collection-report-table td {
    border-color: #d7dbe2;
    color: #111827;
  }
}
