.shape-lab {
  --lab-ink: #11221c;
  --lab-muted: #66746e;
  --lab-line: #dce4df;
  --lab-soft: #edf2ef;
  --lab-coral: #df624c;
  --lab-coral-dark: #bc4734;
  --lab-mint: #8be0bd;
  --lab-stage: #0d1c17;
  max-width: 1180px;
  margin: 0 auto;
}

.shape-lab button,
.shape-lab input {
  font: inherit;
}

.shape-lab button {
  -webkit-tap-highlight-color: transparent;
}

.shape-lab svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.shape-lab__back {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  margin: 0 0 1.7rem;
  color: var(--lab-muted);
  font-size: .82rem;
  font-weight: 750;
  text-decoration: none;
}

.shape-lab__back:hover {
  color: var(--lab-coral-dark);
}

.shape-lab__back svg {
  width: 1rem;
  height: 1rem;
}

.shape-lab__intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 3rem;
  margin-bottom: 2.5rem;
}

.shape-lab__intro > div:first-child {
  max-width: 750px;
}

.shape-lab__intro h1 {
  margin: .35rem 0 1rem;
  color: var(--lab-ink);
  font: 700 clamp(3rem, 6.6vw, 5.65rem)/.91 Georgia, serif;
  letter-spacing: -.055em;
}

.shape-lab__lead {
  max-width: 680px;
  color: var(--lab-muted);
  font-size: clamp(1rem, 1.6vw, 1.16rem);
  line-height: 1.65;
}

.local-badge {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: .75rem;
  min-width: 245px;
  padding: .8rem 1rem;
  color: #d5e9e0;
  background: var(--lab-ink);
  border-radius: .8rem;
  box-shadow: 0 12px 28px rgba(17, 34, 28, .16);
}

.local-badge__mark {
  display: grid;
  width: 2.3rem;
  height: 2.3rem;
  place-items: center;
  color: var(--lab-mint);
  background: rgba(139, 224, 189, .11);
  border-radius: 50%;
}

.local-badge__mark svg {
  width: 1.3rem;
  height: 1.3rem;
}

.local-badge > span:last-child {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.local-badge strong {
  color: #fff;
  font-size: .84rem;
}

.local-badge small {
  margin-top: .18rem;
  color: #9eb5ac;
  font-size: .68rem;
}

.shape-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  align-items: start;
  gap: 1.1rem;
}

.vision-card,
.shape-controls {
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--lab-line);
  border-radius: 1rem;
  box-shadow: 0 14px 40px rgba(19, 42, 33, .07);
}

.vision-card__topbar,
.vision-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .9rem 1.1rem;
}

.vision-card__topbar > div:first-child {
  display: flex;
  min-width: 0;
  flex-direction: column;
  line-height: 1.25;
}

.vision-card__eyebrow {
  color: var(--lab-muted);
  font-size: .61rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.vision-card__topbar strong {
  max-width: min(48vw, 520px);
  margin-top: .15rem;
  overflow: hidden;
  color: var(--lab-ink);
  font-size: .82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: .42rem;
  padding: .36rem .62rem;
  color: #53615b;
  background: #f1f4f2;
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 750;
}

.status-pill > span:first-child {
  width: .42rem;
  height: .42rem;
  background: #92a19a;
  border-radius: 50%;
}

.status-pill[data-state="working"] {
  color: #825021;
  background: #fff1de;
}

.status-pill[data-state="working"] > span:first-child {
  background: #e59a43;
  animation: lab-pulse 1s ease-in-out infinite;
}

.status-pill[data-state="done"] {
  color: #196948;
  background: #e4f6ed;
}

.status-pill[data-state="done"] > span:first-child {
  background: #34a977;
}

.status-pill[data-state="error"] {
  color: #9d392e;
  background: #fde8e4;
}

.status-pill[data-state="error"] > span:first-child {
  background: #d65042;
}

@keyframes lab-pulse {
  50% { opacity: .3; transform: scale(.75); }
}

.vision-stage {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 590px;
  place-items: center;
  overflow: hidden;
  background: var(--lab-stage);
  isolation: isolate;
}

.vision-stage canvas,
.vision-stage video {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  max-height: 680px;
  object-fit: contain;
}

.vision-stage canvas[hidden],
.vision-stage video[hidden] {
  display: none;
}

.vision-stage[data-state="camera"] video {
  min-height: 590px;
  background: #08110e;
}

.stage-grid {
  position: absolute;
  z-index: 0;
  inset: 0;
  opacity: .32;
  background-image:
    linear-gradient(rgba(151, 203, 181, .055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(151, 203, 181, .055) 1px, transparent 1px);
  background-size: 32px 32px;
  -webkit-mask-image: radial-gradient(circle at center, #000 20%, transparent 85%);
  mask-image: radial-gradient(circle at center, #000 20%, transparent 85%);
}

.vision-empty {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  flex-direction: column;
  padding: 2rem;
  color: #fff;
  text-align: center;
}

.vision-empty__icon {
  display: grid;
  width: 5rem;
  height: 5rem;
  margin-bottom: 1.2rem;
  place-items: center;
  color: var(--lab-mint);
  background: rgba(139, 224, 189, .08);
  border: 1px solid rgba(139, 224, 189, .18);
  border-radius: 1.35rem;
  transform: rotate(-3deg);
}

.vision-empty__icon svg {
  width: 3.2rem;
  height: 3.2rem;
  stroke-width: 1.25;
}

.vision-empty h2 {
  margin: 0;
  font: 700 1.6rem/1.2 Georgia, serif;
}

.vision-empty > p {
  margin: .45rem 0 1.15rem;
  color: #8ea39b;
  font-size: .78rem;
}

.vision-empty__actions {
  display: flex;
  align-items: center;
  gap: .85rem;
}

.button,
.text-button,
.source-button {
  border: 0;
  cursor: pointer;
}

.button {
  display: inline-flex;
  min-height: 2.8rem;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  padding: .7rem 1rem;
  border-radius: .62rem;
  font-size: .78rem;
  font-weight: 780;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease, opacity .16s ease;
}

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

.button:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.button svg {
  width: 1.15rem;
  height: 1.15rem;
}

.button--light {
  color: var(--lab-ink);
  background: #fff;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .2);
}

.text-button {
  padding: .55rem .1rem;
  color: var(--lab-mint);
  background: transparent;
  font-size: .76rem;
  font-weight: 750;
  border-bottom: 1px solid rgba(139, 224, 189, .35);
}

.drop-prompt {
  position: absolute;
  z-index: 6;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: .65rem;
  inset: 1rem;
  color: #fff;
  background: rgba(18, 50, 40, .93);
  border: 2px dashed var(--lab-mint);
  border-radius: .85rem;
  pointer-events: none;
}

.drop-prompt svg {
  width: 2.25rem;
  height: 2.25rem;
  color: var(--lab-mint);
}

.vision-stage.is-dragging .drop-prompt {
  display: flex;
}

.shape-message {
  margin: 0;
  padding: .75rem 1rem;
  color: #8d3028;
  background: #fff0ed;
  border-top: 1px solid #f2c9c2;
  font-size: .76rem;
}

.vision-card__footer {
  min-height: 58px;
  border-top: 1px solid var(--lab-line);
}

.result-counts {
  display: flex;
  min-width: 0;
  align-items: center;
  flex-wrap: wrap;
  gap: .42rem;
}

.result-counts__empty,
.image-meta {
  color: var(--lab-muted);
  font-size: .69rem;
}

.result-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .28rem .48rem;
  color: #43504b;
  background: #f0f3f1;
  border-radius: 999px;
  font-size: .64rem;
  font-weight: 760;
}

.result-chip::before {
  width: .4rem;
  height: .4rem;
  background: var(--chip-colour, #79857f);
  border-radius: 50%;
  content: "";
}

.result-chip[data-kind="lines"] { --chip-colour: #f5b642; }
.result-chip[data-kind="circles"] { --chip-colour: #60d8aa; }
.result-chip[data-kind="triangles"] { --chip-colour: #ff8067; }
.result-chip[data-kind="rectangles"] { --chip-colour: #72a7ff; }

.image-meta {
  flex: 0 0 auto;
  text-align: right;
}

.shape-controls {
  position: sticky;
  top: 100px;
}

.control-section {
  padding: 1.15rem 1.2rem;
  border-bottom: 1px solid var(--lab-line);
}

.control-heading {
  display: flex;
  align-items: flex-start;
  gap: .8rem;
  margin-bottom: 1rem;
}

.control-heading__number {
  display: grid;
  width: 1.8rem;
  height: 1.8rem;
  flex: 0 0 auto;
  place-items: center;
  color: var(--lab-coral-dark);
  background: #fae8e3;
  border-radius: 50%;
  font-size: .58rem;
  font-weight: 850;
}

.control-heading h2 {
  margin: .02rem 0 .12rem;
  color: var(--lab-ink);
  font: 700 1rem/1.2 Georgia, serif;
}

.control-heading p {
  color: var(--lab-muted);
  font-size: .67rem;
  line-height: 1.35;
}

.source-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem;
}

.source-button {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: .55rem;
  padding: .68rem;
  color: var(--lab-ink);
  background: #f6f8f6;
  border: 1px solid var(--lab-line);
  border-radius: .62rem;
  text-align: left;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}

.source-button:hover {
  background: #fff;
  border-color: #aebfb7;
  transform: translateY(-1px);
}

.source-button svg {
  width: 1.2rem;
  height: 1.2rem;
  flex: 0 0 auto;
  color: var(--lab-coral-dark);
}

.source-button > span {
  display: flex;
  min-width: 0;
  flex-direction: column;
  line-height: 1.25;
}

.source-button strong {
  overflow: hidden;
  font-size: .69rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-button small {
  margin-top: .12rem;
  color: var(--lab-muted);
  font-size: .55rem;
}

.camera-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .55rem;
}

.camera-actions[hidden] {
  display: none;
}

.button--primary {
  color: #fff;
  background: var(--lab-coral);
  box-shadow: 0 8px 18px rgba(199, 72, 52, .18);
}

.button--primary:hover:not(:disabled) {
  background: var(--lab-coral-dark);
  box-shadow: 0 10px 23px rgba(199, 72, 52, .25);
}

.button--quiet {
  color: var(--lab-ink);
  background: #edf1ee;
}

.shape-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .48rem;
}

.shape-option {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 54px;
  align-items: center;
  gap: .52rem;
  padding: .55rem .58rem;
  background: #fff;
  border: 1px solid var(--lab-line);
  border-radius: .58rem;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}

.shape-option--all {
  grid-column: 1 / -1;
}

.shape-option:has(input:checked) {
  background: #fdf4f1;
  border-color: #e89180;
  box-shadow: inset 0 0 0 1px rgba(223, 98, 76, .14);
}

.shape-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.shape-option > span:last-child {
  display: flex;
  min-width: 0;
  flex-direction: column;
  line-height: 1.18;
}

.shape-option strong {
  font-size: .67rem;
}

.shape-option small {
  margin-top: .15rem;
  color: var(--lab-muted);
  font-size: .53rem;
}

.shape-option__icon {
  position: relative;
  display: block;
  width: 1.55rem;
  height: 1.55rem;
  flex: 0 0 auto;
  color: var(--lab-coral);
  background: #f8e6e2;
  border-radius: .4rem;
}

.shape-option__icon--line::after {
  position: absolute;
  width: 1rem;
  height: 2px;
  top: 11px;
  left: 4px;
  background: currentColor;
  content: "";
  transform: rotate(-33deg);
}

.shape-option__icon--circle::after {
  position: absolute;
  width: .78rem;
  height: .78rem;
  top: 5px;
  left: 5px;
  border: 2px solid currentColor;
  border-radius: 50%;
  content: "";
}

.shape-option__icon--triangle::after {
  position: absolute;
  width: 0;
  height: 0;
  top: 5px;
  left: 5px;
  border-right: 7px solid transparent;
  border-bottom: 12px solid currentColor;
  border-left: 7px solid transparent;
  content: "";
}

.shape-option__icon--triangle::before {
  position: absolute;
  z-index: 1;
  width: 0;
  height: 0;
  top: 8px;
  left: 7px;
  border-right: 5px solid transparent;
  border-bottom: 8px solid #f8e6e2;
  border-left: 5px solid transparent;
  content: "";
}

.shape-option__icon--rectangle::after {
  position: absolute;
  width: 1rem;
  height: .7rem;
  top: 6px;
  left: 4px;
  border: 2px solid currentColor;
  content: "";
}

.shape-option__icon--all i {
  position: absolute;
  display: block;
}

.shape-option__icon--all i:nth-child(1) {
  width: .7rem;
  height: 2px;
  top: 6px;
  left: 4px;
  background: currentColor;
  transform: rotate(-25deg);
}

.shape-option__icon--all i:nth-child(2) {
  width: .5rem;
  height: .5rem;
  right: 4px;
  bottom: 4px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
}

.shape-option__icon--all i:nth-child(3) {
  width: .35rem;
  height: .35rem;
  bottom: 4px;
  left: 4px;
  border: 1.5px solid currentColor;
}

.range-control {
  display: block;
  margin-top: .9rem;
}

.range-control + .range-control {
  margin-top: 1.05rem;
}

.range-control > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.range-control strong,
.view-control legend {
  color: var(--lab-ink);
  font-size: .68rem;
}

.range-control output {
  min-width: 2.1rem;
  padding: .12rem .35rem;
  color: var(--lab-coral-dark);
  background: #f9e9e5;
  border-radius: 999px;
  font-size: .59rem;
  font-weight: 800;
  text-align: center;
}

.range-control input[type="range"] {
  width: 100%;
  height: 4px;
  margin: .75rem 0 .45rem;
  accent-color: var(--lab-coral);
  background: #dfe6e2;
  border-radius: 999px;
  cursor: pointer;
}

.range-control small {
  display: block;
  color: var(--lab-muted);
  font-size: .57rem;
  line-height: 1.45;
}

.view-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .35rem;
  margin-top: 1rem;
  padding: 0;
  border: 0;
}

.view-control legend {
  margin-bottom: .4rem;
  font-weight: 700;
}

.view-control label {
  position: relative;
  cursor: pointer;
}

.view-control input {
  position: absolute;
  opacity: 0;
}

.view-control span {
  display: block;
  padding: .43rem;
  color: var(--lab-muted);
  background: #f1f4f2;
  border: 1px solid transparent;
  border-radius: .42rem;
  font-size: .61rem;
  font-weight: 750;
  text-align: center;
}

.view-control input:checked + span {
  color: var(--lab-ink);
  background: #fff;
  border-color: #aebcb6;
  box-shadow: 0 2px 8px rgba(18, 40, 32, .08);
}

.control-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem;
  padding: 1.1rem 1.2rem .8rem;
}

.button--detect {
  grid-column: 1 / -1;
}

.button--download {
  grid-column: 1 / -1;
  color: var(--lab-ink);
  background: #eef2ef;
  border: 1px solid #d8e0dc;
}

.privacy-note {
  display: flex;
  align-items: flex-start;
  gap: .42rem;
  margin: 0;
  padding: 0 1.2rem 1.1rem;
  color: var(--lab-muted);
  font-size: .55rem;
  line-height: 1.45;
}

.privacy-note svg {
  width: .95rem;
  height: .95rem;
  flex: 0 0 auto;
  color: #4b9274;
}

.shape-method {
  display: grid;
  grid-template-columns: .72fr 1.28fr;
  gap: 4rem;
  margin-top: 4.5rem;
  padding: 3rem 0 1.5rem;
  border-top: 1px solid var(--lab-line);
}

.shape-method__intro h2 {
  margin: .28rem 0 .7rem;
  color: var(--lab-ink);
  font: 700 clamp(1.9rem, 3.5vw, 2.7rem)/1.05 Georgia, serif;
  letter-spacing: -.035em;
}

.shape-method__intro > p:last-child {
  color: var(--lab-muted);
  font-size: .87rem;
}

.shape-method ol {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.shape-method li {
  display: grid;
  grid-template-columns: 2.4rem 1fr;
  gap: .9rem;
  padding: 1rem 0;
  border-top: 1px solid var(--lab-line);
}

.shape-method li:first-child {
  border-top: 0;
}

.shape-method li > span {
  color: var(--lab-coral);
  font-size: .64rem;
  font-weight: 850;
  letter-spacing: .08em;
}

.shape-method li strong {
  color: var(--lab-ink);
  font: 700 1rem/1.2 Georgia, serif;
}

.shape-method li p {
  margin-top: .28rem;
  color: var(--lab-muted);
  font-size: .75rem;
  line-height: 1.5;
}

.shape-lab :is(button, input, label, a):focus-visible {
  outline: 3px solid rgba(223, 98, 76, .42);
  outline-offset: 2px;
}

@media (max-width: 1040px) {
  .shape-workspace {
    grid-template-columns: minmax(0, 1fr) 330px;
  }

  .vision-stage,
  .vision-stage[data-state="camera"] video {
    min-height: 520px;
  }
}

@media (max-width: 880px) {
  .shape-lab__intro {
    align-items: flex-start;
    flex-direction: column;
    gap: 1.25rem;
  }

  .shape-lab__intro h1 br {
    display: none;
  }

  .shape-workspace {
    grid-template-columns: 1fr;
  }

  .shape-controls {
    position: static;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .control-section {
    border-right: 1px solid var(--lab-line);
  }

  .control-section:nth-child(3) {
    grid-column: 1 / -1;
    border-right: 0;
  }

  .control-actions,
  .privacy-note {
    grid-column: 1 / -1;
  }

  .shape-method {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

@media (max-width: 620px) {
  .shape-lab__back {
    margin-bottom: 1rem;
  }

  .shape-lab__intro {
    margin-bottom: 1.6rem;
  }

  .shape-lab__intro h1 {
    font-size: clamp(2.65rem, 14vw, 4rem);
  }

  .local-badge {
    width: 100%;
    min-width: 0;
  }

  .vision-card__topbar,
  .vision-card__footer {
    padding: .8rem;
  }

  .vision-stage,
  .vision-stage[data-state="camera"] video {
    min-height: 390px;
  }

  .vision-card__topbar strong {
    max-width: 54vw;
  }

  .vision-card__footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .image-meta {
    text-align: left;
  }

  .shape-controls {
    display: block;
  }

  .control-section {
    border-right: 0;
  }

  .shape-method {
    margin-top: 3rem;
  }
}

@media (max-width: 390px) {
  .vision-stage,
  .vision-stage[data-state="camera"] video {
    min-height: 330px;
  }

  .vision-empty__actions,
  .source-actions {
    align-items: stretch;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .shape-options {
    grid-template-columns: 1fr;
  }

  .shape-option--all {
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .shape-lab *,
  .shape-lab *::before,
  .shape-lab *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
