:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #111827;
  background: #f6f7fb;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #ffffff 0%, #f6f7fb 45%, #eef1f7 100%);
}

button, input, select { font: inherit; }

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 56px 0 40px;
}

/* ------------------------------------------------------------------ *
 * Hero
 * ------------------------------------------------------------------ */

.hero {
  max-width: 820px;
  margin-bottom: 28px;
}

.eyebrow, .section-kicker {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #52627a;
}

h1 {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 5.1rem);
  line-height: 0.98;
  letter-spacing: -0.055em;
}

.lede {
  max-width: 720px;
  margin: 22px 0 0;
  font-size: clamp(1.05rem, 2vw, 1.3rem);
  line-height: 1.6;
  color: #4b5563;
}

.lesson-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.lesson-strip span {
  padding: 8px 11px;
  border: 1px solid #dfe4ec;
  border-radius: 999px;
  background: rgba(255, 255, 255, .76);
  color: #52627a;
  font-size: .86rem;
}

.lesson-strip b {
  color: #111827;
  margin-right: 4px;
}

/* ------------------------------------------------------------------ *
 * Layout
 * ------------------------------------------------------------------ */

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 0.78fr) minmax(0, 1.4fr);
  gap: 20px;
  align-items: start;
}

.card {
  border: 1px solid #e0e5ed;
  border-radius: 22px;
  background: rgba(255, 255, 255, .93);
  box-shadow: 0 18px 50px rgba(26, 39, 63, 0.08);
}

.controls { padding: 24px; }
.result { padding: 24px; }

.step {
  display: flex;
  gap: 13px;
  align-items: flex-start;
}

.step-number {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 50%;
  background: #111827;
  color: white;
  font-size: 0.82rem;
  font-weight: 750;
}

.grow { flex: 1; }
.control-label { font-weight: 700; }
.sample-title { margin: 0; }

.helper {
  margin: 6px 0 0;
  color: #667085;
  font-size: 0.92rem;
  line-height: 1.5;
}

.file-input {
  width: 100%;
  margin-top: 16px;
  padding: 11px;
  border: 1px dashed #bac3d2;
  border-radius: 14px;
  background: #fafbfc;
}

.divider {
  height: 1px;
  margin: 22px 0;
  background: #eceff4;
}

.slider-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-top: 14px;
}

.slider-row label { font-weight: 650; }

.slider-row output {
  min-width: 48px;
  text-align: right;
  color: #334155;
  font-variant-numeric: tabular-nums;
}

.slider-row + input[type="range"] {
  width: 100%;
  margin-top: 9px;
  accent-color: #111827;
}

.run-button {
  width: 100%;
  margin-top: 24px;
  padding: 13px 18px;
  border: 0;
  border-radius: 14px;
  background: #111827;
  color: white;
  font-weight: 750;
  cursor: pointer;
  transition: transform .15s ease, opacity .15s ease;
}

.run-button:not(:disabled):hover { transform: translateY(-1px); }
.run-button:disabled { opacity: .38; cursor: not-allowed; }

.status {
  min-height: 1.4em;
  margin: 14px 0 0;
  color: #52627a;
  font-size: .9rem;
}

.progress-wrap {
  height: 5px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf0f5;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: #111827;
  transition: width .2s ease;
}

/* ------------------------------------------------------------------ *
 * Image picking
 * ------------------------------------------------------------------ */

.or-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 14px;
  color: #98a2b3;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.or-row::before, .or-row::after {
  content: '';
  height: 1px;
  flex: 1;
  background: #eceff4;
}

.sample-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.coco-head { margin-top: 18px; }

.input-kicker {
  margin: 0 0 4px;
  color: #344054;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.shuffle-button {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid #d8dee8;
  border-radius: 10px;
  background: #fff;
  color: #344054;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 700;
}

.shuffle-button:hover { background: #f7f8fa; }

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

.sample-card {
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid #e0e5ed;
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}

.sample-card:hover {
  transform: translateY(-1px);
  border-color: #aeb8c6;
  box-shadow: 0 8px 18px rgba(26,39,63,.08);
}

.sample-card.selected {
  border-color: #111827;
  box-shadow: 0 0 0 2px #111827;
}

.sample-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #eef1f5;
}

.sample-card span {
  display: block;
  padding: 8px 9px 4px;
  overflow: hidden;
  color: #475467;
  font-size: .78rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sample-card small {
  display: block;
  padding: 0 9px 9px;
  color: #8a94a4;
  font-size: .67rem;
  line-height: 1.2;
  letter-spacing: .01em;
}

/* ------------------------------------------------------------------ *
 * Experiment picker
 * ------------------------------------------------------------------ */

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

.experiment-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid #e0e5ed;
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.experiment-card:hover { border-color: #aeb8c6; }

.experiment-card.selected {
  border-color: #111827;
  background: #f8fafc;
  box-shadow: 0 0 0 2px #111827;
}

.experiment-family {
  color: #7a8595;
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.experiment-card strong {
  color: #111827;
  font-size: .95rem;
  letter-spacing: -.01em;
}

.experiment-card em {
  color: #667085;
  font-size: .74rem;
  font-style: normal;
  line-height: 1.35;
}

.experiment-note { margin-top: 12px; }
.experiment-note .helper { margin: 0; }

/* The "this model stands in for X" line, set apart from the plain description. */
.note-sub {
  margin-top: 9px !important;
  padding-top: 9px;
  border-top: 1px solid #eceff4;
  color: #7a8595;
  font-size: .85rem;
}

.panel { margin-top: 4px; }
.panel .control-label { display: block; }
.panel .helper:first-child { margin-top: 0; }

.model-select {
  width: 100%;
  margin-top: 10px;
  padding: 11px 12px;
  border: 1px solid #cfd7e3;
  border-radius: 12px;
  background: #fff;
  color: #111827;
}

.model-select:focus {
  outline: 2px solid #111827;
  outline-offset: 2px;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 14px;
  color: #344054;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
}

.check input { accent-color: #111827; }

.histogram-wrap { margin-top: 18px; }

#histogram {
  display: block;
  width: 100%;
  height: 118px;
  border: 1px solid #e8ebf0;
  border-radius: 10px;
  background: #fff;
}

/* ------------------------------------------------------------------ *
 * Result
 * ------------------------------------------------------------------ */

.result-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.result h2 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.badge {
  padding: 7px 10px;
  border-radius: 999px;
  background: #eef2f7;
  color: #536176;
  font-size: .82rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge.ready { background: #e8f7ef; color: #17623c; }
.badge.running { background: #fff4df; color: #805600; }
.badge.error { background: #fdecec; color: #9b2c2c; }

.view-switch {
  display: inline-flex;
  gap: 3px;
  margin-bottom: 12px;
  padding: 3px;
  border: 1px solid #e0e5ed;
  border-radius: 11px;
  background: #f2f4f7;
}

/* An author `display` beats the UA rule behind the `hidden` attribute. */
.view-switch[hidden] { display: none; }

.view-option {
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #52627a;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 700;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}

.view-option:hover { color: #111827; }

.view-option.selected {
  background: #fff;
  color: #111827;
  box-shadow: 0 1px 3px rgba(26, 39, 63, .12);
}

.canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 260px;
  overflow: hidden;
  border-radius: 16px;
  background: #101318;
}

/*
 * Size the canvas by its intrinsic aspect ratio, never by a fixed box: the
 * element box must match the painted image exactly, because SAM converts a
 * click through getBoundingClientRect() into image coordinates. A letterboxed
 * box (from `width:100%` + `object-fit:contain`) would offset every click on a
 * portrait photo. max-height only caps how tall a portrait frame can get.
 */
#result-canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 76vh;
}

#result-canvas.clickable { cursor: crosshair; }

.canvas-wrap.empty #result-canvas { display: none; }

#canvas-placeholder {
  margin: 0;
  padding: 32px;
  color: #9aa4b2;
  text-align: center;
}

.canvas-wrap:not(.empty) #canvas-placeholder { display: none; }

.sam-hint {
  margin: 12px 0 0;
  padding: 10px 13px;
  border: 1px solid #ffe0b2;
  border-radius: 12px;
  background: #fff8ec;
  color: #7a4d00;
  font-size: .88rem;
  font-weight: 650;
}

.summary {
  margin: 16px 0;
  padding: 13px 15px;
  border-radius: 13px;
  background: #f7f8fa;
  color: #344054;
  font-weight: 650;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid #e8ebf0;
  border-radius: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

th, td {
  padding: 11px 13px;
  border-bottom: 1px solid #edf0f4;
  text-align: left;
  vertical-align: top;
}

th {
  background: #fafbfc;
  color: #52627a;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: 0; }
.empty-row td { color: #7d899a; text-align: center; }

.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: #f7f8fa; }

/* ------------------------------------------------------------------ *
 * Comparison
 * ------------------------------------------------------------------ */

.compare {
  margin-top: 20px;
  padding: 22px 24px;
}

.compare-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.compare h2 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.compare-lede { margin: 10px 0 18px; }

.compare-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.compare-empty {
  grid-column: 1 / -1;
  margin: 0;
  padding: 26px;
  border: 1px dashed #dbe1ea;
  border-radius: 14px;
  color: #8a94a4;
  text-align: center;
  font-size: .9rem;
}

.compare-card {
  min-width: 0;
  padding: 11px;
  border: 1px solid #e5e9f0;
  border-radius: 14px;
  background: #fff;
}

.compare-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border-radius: 9px;
  background: #101318;
}

.compare-kicker {
  margin: 10px 0 2px;
  color: #7a8595;
  font-size: .64rem;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.compare-card h3 {
  margin: 0 0 5px;
  font-size: .95rem;
  letter-spacing: -.01em;
}

.compare-headline {
  margin: 0;
  color: #667085;
  font-size: .78rem;
  line-height: 1.45;
}

/* ------------------------------------------------------------------ *
 * Explanation + footer
 * ------------------------------------------------------------------ */

.explain {
  margin-top: 20px;
  padding: 22px 24px;
}

.explain-title {
  max-width: 820px;
  margin: 0;
  font-size: clamp(1.25rem, 2vw, 1.7rem);
  line-height: 1.25;
  letter-spacing: -.025em;
}

.explain-copy {
  max-width: 900px;
  margin: 12px 0 18px;
  color: #536176;
  line-height: 1.65;
}

.flow {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  font-weight: 700;
}

.flow span:not(.arrow) {
  padding: 8px 11px;
  border-radius: 10px;
  background: #f2f4f7;
}

.arrow { color: #98a2b3; }

.extension-note {
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px solid #eceff4;
  color: #5d6879;
  font-size: .92rem;
  line-height: 1.55;
}

footer {
  padding: 22px 2px 0;
  color: #7a8595;
  font-size: .84rem;
}

/* ------------------------------------------------------------------ *
 * Responsive
 * ------------------------------------------------------------------ */

@media (max-width: 1020px) {
  .compare-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .page-shell {
    width: min(100% - 20px, 720px);
    padding-top: 34px;
  }

  .workspace { grid-template-columns: 1fr; }
  .canvas-wrap { min-height: 280px; }
}

@media (max-width: 520px) {
  .card { border-radius: 17px; }
  .controls, .result, .explain, .compare { padding: 18px; }
  .result-head, .compare-head { align-items: center; }
  th, td { padding: 9px 10px; }
  .sample-grid { gap: 8px; }
  .compare-grid { grid-template-columns: 1fr; }
}
