:root {
  --paper: #f7f3e8;
  --paper-deep: #ece1c8;
  --ink: #1f2a29;
  --muted: #68726d;
  --line: rgba(31, 42, 41, .16);
  --panel: rgba(255, 253, 246, .86);
  --red: #d94a3a;
  --gold: #d99b2b;
  --teal: #0f8b8d;
  --leaf: #50745b;
  --shadow: 0 24px 70px rgba(31, 42, 41, .16);
  --radius: 8px;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(217, 74, 58, .10), transparent 34%),
    radial-gradient(circle at 82% 12%, rgba(15, 139, 141, .18), transparent 30%),
    linear-gradient(180deg, var(--paper), #fffaf0 52%, #ebe0c8);
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .32;
  background-image:
    linear-gradient(rgba(31,42,41,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31,42,41,.04) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, #000, transparent 76%);
}

button, input, select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px clamp(16px, 3vw, 42px) 42px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 58px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: linear-gradient(#e84f3d 0 48%, #1f2a29 48% 53%, #fff8e8 53%);
  box-shadow: inset 0 0 0 5px rgba(255,255,255,.55);
}

.brand strong,
h1,
h2 {
  font-family: Georgia, "Times New Roman", serif;
}

.brand strong {
  display: block;
  line-height: 1;
  font-size: 1.05rem;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: .78rem;
  margin-top: 2px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-actions a,
.text-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255,255,255,.45);
  padding: 9px 14px;
  text-decoration: none;
  font-weight: 700;
  font-size: .9rem;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, .72fr);
  align-items: center;
  gap: clamp(28px, 5vw, 80px);
  min-height: min(760px, calc(100vh - 78px));
  padding: 38px 0 22px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 10px;
  color: var(--red);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1 {
  max-width: 900px;
  margin: 0;
  font-size: clamp(3.4rem, 8vw, 8.6rem);
  line-height: .88;
  letter-spacing: 0;
}

.lead {
  max-width: 720px;
  margin: 24px 0 0;
  color: #46514c;
  font-size: clamp(1.08rem, 1.5vw, 1.32rem);
  line-height: 1.58;
}

.hero-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 30px;
}

.hero-metrics span {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,.52);
}

.hero-metrics b {
  color: var(--teal);
  font-size: 1.4rem;
}

.hero-visual {
  min-height: 500px;
  display: grid;
  place-items: center;
}

.card-stack {
  position: relative;
  width: min(430px, 84vw);
  height: 520px;
}

.sample-card {
  position: absolute;
  width: 270px;
  height: 382px;
  border: 12px solid #f2cb57;
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sample-card::before {
  content: "";
  position: absolute;
  inset: 16px 16px 74px;
  border: 2px solid rgba(31,42,41,.25);
  border-radius: 8px;
  background:
    radial-gradient(circle at 58% 36%, rgba(255,255,255,.75), transparent 12%),
    linear-gradient(135deg, rgba(255,255,255,.32), transparent 38%),
    var(--card-color);
}

.sample-card::after {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 22px;
  height: 52px;
  border-radius: 6px;
  background: rgba(255, 248, 218, .9);
  border: 1px solid rgba(31,42,41,.20);
}

.sample-card-a {
  --card-color: linear-gradient(135deg, #d95333, #f2a038 48%, #1d6173);
  left: 10px;
  top: 72px;
  rotate: -10deg;
}

.sample-card-b {
  --card-color: linear-gradient(135deg, #243c5f, #0f8b8d 52%, #e9d6a2);
  right: 4px;
  top: 20px;
  rotate: 8deg;
}

.card-name,
.card-set {
  position: absolute;
  z-index: 2;
  left: 23px;
  right: 23px;
}

.card-name {
  top: 18px;
  font-weight: 800;
  font-size: 1.05rem;
}

.card-set {
  bottom: 34px;
  color: #5c4c24;
  font-size: .82rem;
  font-weight: 700;
}

.card-glint {
  position: absolute;
  inset: -40%;
  background: linear-gradient(110deg, transparent 35%, rgba(255,255,255,.45), transparent 56%);
  animation: glint 4.4s linear infinite;
  z-index: 4;
}

.scan-frame {
  position: absolute;
  inset: 98px 42px 58px 64px;
  border: 2px solid rgba(31,42,41,.74);
  border-radius: 18px;
  animation: float 5s ease-in-out infinite;
}

.scan-frame::before {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  top: 46%;
  height: 3px;
  background: var(--red);
  box-shadow: 0 0 20px rgba(217,74,58,.65);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, .95fr) minmax(300px, .82fr) minmax(340px, .95fr);
  gap: 16px;
  align-items: start;
}

.panel,
.collection {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(31, 42, 41, .09);
  backdrop-filter: blur(18px);
}

.panel {
  padding: clamp(16px, 2vw, 24px);
}

.panel-head,
.collection {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.panel-head {
  align-items: flex-start;
  margin-bottom: 18px;
}

h2 {
  margin: 0;
  font-size: clamp(1.55rem, 2vw, 2.15rem);
  line-height: 1;
}

.status-pill {
  border: 1px solid rgba(15,139,141,.28);
  border-radius: 999px;
  color: #086769;
  background: rgba(15,139,141,.10);
  padding: 8px 11px;
  font-size: .82rem;
  font-weight: 800;
  white-space: nowrap;
}

.dropzone {
  min-height: 230px;
  display: grid;
  place-items: center;
  text-align: center;
  gap: 10px;
  padding: 24px;
  border: 1.5px dashed rgba(31,42,41,.35);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(217,155,43,.16), rgba(15,139,141,.10)),
    rgba(255,255,255,.42);
  transition: transform .2s ease, border-color .2s ease, background .2s ease;
}

.dropzone:hover,
.dropzone.is-over {
  transform: translateY(-2px);
  border-color: var(--teal);
  background-color: rgba(255,255,255,.66);
}

.dropzone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.dropzone strong {
  font-size: 1.12rem;
}

.dropzone small {
  max-width: 34ch;
  color: var(--muted);
  line-height: 1.45;
}

.drop-icon {
  width: 58px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
}

.drop-icon svg,
.icon-button svg {
  width: 24px;
  fill: currentColor;
}

.drop-icon svg {
  color: #fff8e8;
}

.preview-box {
  position: relative;
  margin-top: 14px;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  aspect-ratio: 4 / 3;
  background: #1f2a29;
}

.preview-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.icon-button {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(31,42,41,.82);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

label span,
.grade-select span,
legend {
  display: block;
  margin-bottom: 7px;
  color: #394541;
  font-size: .82rem;
  font-weight: 800;
}

input[type="text"],
input[type="search"],
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,.78);
  color: var(--ink);
  padding: 10px 12px;
  outline: 0;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15,139,141,.16);
}

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

.match-card {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,.62);
  padding: 13px;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.match-card:hover,
.match-card.is-selected {
  transform: translateY(-1px);
  border-color: rgba(217,74,58,.55);
  box-shadow: 0 12px 30px rgba(31,42,41,.10);
}

.match-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  font-weight: 900;
}

.match-card small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.35;
}

.score {
  color: var(--teal);
  font-weight: 900;
  white-space: nowrap;
}

.controls {
  display: grid;
  gap: 16px;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented,
.toggle-grid {
  display: grid;
  gap: 8px;
}

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

.segmented button,
.toggle-grid label {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,.58);
  color: var(--ink);
  padding: 9px 10px;
  font-weight: 800;
}

.segmented button.is-active {
  color: #fff8e8;
  background: var(--ink);
  border-color: var(--ink);
}

.toggle-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.toggle-grid label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.toggle-grid input {
  accent-color: var(--red);
}

.value-card {
  margin-top: 18px;
  padding: 18px;
  border-radius: var(--radius);
  color: #fff8e8;
  background:
    linear-gradient(135deg, rgba(255,255,255,.08), transparent 36%),
    #1f2a29;
}

.muted {
  display: block;
  color: rgba(255,248,232,.66);
  font-size: .82rem;
  font-weight: 800;
}

#valueRange {
  display: block;
  margin-top: 6px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.2rem, 4vw, 4.8rem);
  line-height: .95;
}

.confidence {
  height: 9px;
  margin: 18px 0 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,248,232,.16);
}

.confidence span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--gold), var(--teal));
  transition: width .35s ease;
}

#valueNote {
  margin: 0;
  color: rgba(255,248,232,.78);
  line-height: 1.45;
}

.evidence-box {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,.58);
  padding: 14px;
}

.evidence-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

#liveStatus {
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.45;
}

.source-list {
  display: grid;
  gap: 8px;
}

.source-item {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  color: inherit;
  background: rgba(255,255,255,.52);
  text-decoration: none;
}

.source-item strong {
  font-size: .94rem;
}

.source-item span {
  color: var(--muted);
  font-size: .84rem;
  line-height: 1.35;
}

.collection {
  align-items: flex-start;
  margin-top: 16px;
  padding: clamp(16px, 2vw, 24px);
}

.collection-list {
  width: min(720px, 100%);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.saved-card,
.empty-state {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,.54);
  padding: 13px;
}

.saved-card strong,
.saved-card span {
  display: block;
}

.saved-card span,
.empty-state {
  color: var(--muted);
}

@keyframes glint {
  from { transform: translateX(-40%) rotate(8deg); }
  to { transform: translateX(40%) rotate(8deg); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

@media (max-width: 1120px) {
  .hero,
  .workspace {
    grid-template-columns: 1fr;
  }

  .hero {
    min-height: auto;
  }

  .hero-visual {
    min-height: 420px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding-inline: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .top-actions {
    display: none;
  }

  h1 {
    font-size: clamp(3rem, 17vw, 4.7rem);
  }

  .field-grid,
  .segmented,
  .toggle-grid {
    grid-template-columns: 1fr;
  }

  .hero-visual {
    min-height: 330px;
  }

  .card-stack {
    height: 330px;
  }

  .sample-card {
    width: 190px;
    height: 270px;
    border-width: 9px;
  }

  .scan-frame {
    inset: 54px 28px 34px 44px;
  }

  .collection {
    display: grid;
  }
}
