@import url("https://fonts.googleapis.com/css2?family=Google+Sans+Code:wght@300..800&family=Google+Sans+Flex:opsz,wght,ROND@8..144,300..900,0..100&display=swap");

:root {
  --font-ui: "Google Sans Flex", "Google Sans Text", "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  --font-code: "Google Sans Code", "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  --ink: #2c2b31;
  --muted: #6e6a73;
  --paper: #f8f5fa;
  --panel: #ffffff;
  --soft-violet: #ece6f2;
  --soft-green: #e5eee9;
  --soft-blue: #e8eef7;
  --soft-rose: #f4e4e8;
  --button: #333139;
  --button-hover: #1f1d24;
  --accent: #8f4d6b;
  --accent-strong: #6f3151;
  --accent-soft: #f5e5ee;
  --control-card: rgba(244, 237, 246, 0.74);
  --field-surface: #fffafd;
  --danger: #963d44;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-variation-settings: "ROND" 78, "opsz" 18;
}

button,
input,
select {
  font: inherit;
}

img {
  display: block;
  max-width: 100%;
}

.shell {
  width: min(1880px, calc(100% - 44px));
  margin: 0 auto;
  padding: 22px 0 28px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 0;
}

h1 {
  margin: 0;
  font-size: clamp(2.05rem, 4vw, 3.9rem);
  line-height: 0.96;
  letter-spacing: 0;
  font-weight: 760;
  font-variation-settings: "ROND" 64, "opsz" 72;
}

.topbar code {
  flex: 0 0 auto;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
  font-size: 0.9rem;
}

.lab-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 460px;
  gap: 16px;
  align-items: stretch;
  min-height: 0;
}

.preview-column {
  display: grid;
  align-content: center;
  gap: 16px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: center;
}

.image-panel,
.side-panel,
.metric-tile,
.chart-panel {
  border: 0;
  border-radius: 26px;
}

.image-panel {
  margin: 0;
  padding: 14px;
}

.reference-panel {
  background: var(--soft-blue);
}

.output-panel {
  background: var(--soft-violet);
}

figcaption,
.chart-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 30px;
  margin-bottom: 10px;
  font-weight: 780;
}

code,
.metric-tile strong,
.chart-heading code {
  font-family: var(--font-code);
  font-variation-settings: "wght" 520;
}

figcaption code,
.chart-heading code {
  color: var(--muted);
  font-size: 0.86rem;
}

.image-frame {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.58);
}

.image-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-frame canvas {
  width: 100%;
  height: 100%;
}

.side-panel {
  display: grid;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 12px;
  padding: 14px;
  background: #eee9f1;
  min-height: 0;
}

.media-picker-field,
.model-field,
.resolution-field,
.slider-row {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 20px;
  background: var(--control-card);
  color: var(--muted);
  font-weight: 760;
}

.model-field {
  align-content: start;
  overflow: hidden;
  transition: background-color 180ms ease, opacity 180ms ease;
}

.media-picker-field,
.resolution-field,
.slider-row,
.control-strip {
  transition: opacity 180ms ease;
}

body[data-state="training"] .control-strip,
body[data-state="working"] .control-strip {
  opacity: 0.72;
}

body[data-state="training"] .media-picker-field,
body[data-state="training"] .model-field,
body[data-state="training"] .resolution-field,
body[data-state="training"] .slider-row,
body[data-state="working"] .media-picker-field,
body[data-state="working"] .model-field,
body[data-state="working"] .resolution-field,
body[data-state="working"] .slider-row {
  opacity: 0.78;
}

.model-field.is-expanded {
  background: rgba(248, 241, 248, 0.84);
}

.model-toggle {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 24px;
  gap: 8px;
  align-items: center;
  min-height: 36px;
  padding: 0;
  background: transparent;
  color: var(--ink);
  border-radius: 14px;
}

.model-toggle:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.5);
}

.model-toggle span,
.model-toggle code {
  min-width: 0;
}

.model-toggle span {
  justify-self: start;
  font-weight: 820;
}

.model-toggle code {
  justify-self: end;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.82rem;
}

.caret-icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 180ms ease;
}

.model-toggle[aria-expanded="true"] .caret-icon {
  transform: rotate(180deg);
}

.media-picker {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 7px;
}

.webcam-button {
  justify-content: flex-start;
  min-height: 46px;
  margin-bottom: 6px;
  padding: 0 14px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.webcam-button::before {
  content: "";
  width: 9px;
  height: 9px;
  margin-right: 9px;
  border-radius: 50%;
  background: currentColor;
}

.webcam-button.is-active {
  background: var(--accent);
  color: #ffffff;
}

.media-option {
  position: relative;
  display: block;
  min-height: 0;
  padding: 3px;
  border: 0;
  border-radius: 16px;
  aspect-ratio: 1;
  background: transparent;
  isolation: isolate;
  transition: background-color 160ms ease, opacity 160ms ease, transform 160ms ease;
}

.media-option img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 13px;
}

.media-option:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.72);
}

.media-option.is-selected::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 17px;
  background: var(--accent-soft);
  outline: 2px solid var(--accent);
  outline-offset: 0;
  z-index: 0;
}

.media-option.is-selected {
  transform: translateY(-1px);
}

.media-option.is-pending:not(.is-selected) {
  background: rgba(143, 77, 107, 0.14);
}

.media-option:disabled {
  opacity: 0.6;
}

.media-option[data-kind="video"]::before {
  content: "";
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 2;
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 11px solid rgba(255, 255, 255, 0.92);
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.28));
}

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

.model-option {
  min-width: 0;
  min-height: 48px;
  border-radius: 18px;
  padding: 7px 9px;
  display: grid;
  gap: 1px;
  background: rgba(255, 255, 255, 0.68);
}

.model-option span,
.model-option code {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-option span {
  color: var(--ink);
}

.model-option code {
  color: var(--muted);
  font-size: 0.78rem;
}

.model-option.is-selected {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.resolution-field {
  grid-template-columns: minmax(0, 1fr) minmax(234px, auto);
  align-items: center;
  color: var(--ink);
}

.resolution-field > span,
.slider-row > span:first-child {
  min-width: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 780;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resolution-picker {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr));
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.54);
}

.resolution-option {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--muted);
  font-family: var(--font-code);
  font-size: 0.82rem;
  font-weight: 620;
}

.resolution-option.is-selected {
  background: var(--accent);
  color: #ffffff;
}

.resolution-option.is-selected:hover:not(:disabled) {
  background: var(--accent-strong);
  color: #ffffff;
}

.model-advanced {
  display: grid;
  gap: 8px;
  max-height: 0;
  overflow: hidden;
  padding-top: 0;
  opacity: 0;
  transform: translateY(-6px);
  transition:
    max-height 520ms cubic-bezier(0.2, 0, 0, 1),
    opacity 360ms ease,
    padding-top 360ms ease,
    transform 360ms ease;
  will-change: max-height, opacity, transform;
}

.model-field.is-expanded .model-advanced {
  max-height: 500px;
  padding-top: 4px;
  opacity: 1;
  transform: translateY(0);
}

.setting-row,
.lr-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 116px;
  gap: 8px;
  align-items: center;
  min-width: 0;
  color: var(--ink);
  font-weight: 720;
}

.lr-row {
  grid-template-columns: minmax(0, 1fr) minmax(96px, 1fr) 76px;
}

.setting-row span,
.lr-row span {
  min-width: 0;
  color: var(--muted);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

select {
  width: 100%;
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 16px;
  appearance: auto;
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  font-weight: 760;
}

select:hover:not(:disabled) {
  background: #ffffff;
}

select:disabled {
  color: rgba(44, 43, 49, 0.48);
}

.toggle-row {
  grid-template-columns: minmax(0, 1fr) 54px;
}

.toggle-row input {
  justify-self: end;
  width: 48px;
  height: 30px;
  margin: 0;
  border-radius: 999px;
  appearance: none;
  background: #d9d0dc;
  position: relative;
  cursor: pointer;
  transition: background-color 160ms ease;
}

.toggle-row input::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 4px;
  top: 4px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 160ms ease;
}

.toggle-row input:checked {
  background: var(--accent);
}

.toggle-row input:checked::before {
  transform: translateX(18px);
}

.control-strip {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr);
  grid-auto-rows: 56px;
  gap: 8px;
  width: min(720px, 100%);
  justify-self: center;
  padding: 8px;
  border-radius: 999px;
  background: #ebe5ee;
}

.control-strip .expressive-button {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
  cursor: pointer;
  font-weight: 760;
  transition: background-color 160ms ease, color 160ms ease, opacity 180ms ease, transform 160ms ease;
}

button:hover:not(:disabled) {
  background: #ffffff;
}

.expressive-button.primary-button:hover:not(:disabled) {
  background: var(--accent-strong);
  color: #ffffff;
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

button:focus-visible,
input:focus-visible,
.media-option:focus-visible {
  outline: 3px solid rgba(143, 77, 107, 0.22);
  outline-offset: 2px;
}

button:disabled {
  cursor: default;
  opacity: 0.46;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-strong);
}

.expressive-button {
  gap: 8px;
  min-height: 52px;
  border-radius: 24px;
  background: #fbf7fb;
  color: var(--ink);
}

.expressive-button.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.expressive-button:not(.primary-button) {
  background: #f6eef5;
  color: var(--accent-strong);
}

.expressive-button:not(.primary-button):hover:not(:disabled) {
  background: #fff7fc;
}

.button-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: currentColor;
}

.slider-row {
  grid-template-columns: minmax(0, 1fr) minmax(206px, 252px);
  align-items: center;
  color: var(--ink);
}

.slider-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 8px;
  align-items: center;
  justify-self: end;
  width: 100%;
}

.slider-control code,
.lr-row code {
  min-width: 0;
  justify-self: end;
  color: var(--muted);
  font-size: 0.74rem;
  text-align: right;
  white-space: nowrap;
}

input[type="range"] {
  --slider-progress: 0%;
  width: 100%;
  height: 32px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 14px;
  border-radius: 999px;
  background:
    linear-gradient(
      to right,
      var(--accent) 0,
      var(--accent) var(--slider-progress),
      #ded6e1 var(--slider-progress),
      #ded6e1 100%
    );
}

input[type="range"]::-webkit-slider-thumb {
  width: 24px;
  height: 24px;
  margin-top: -5px;
  border: 4px solid #ffffff;
  border-radius: 50%;
  appearance: none;
  background: var(--accent);
}

input[type="range"]::-moz-range-track {
  height: 14px;
  border-radius: 999px;
  background: #ded6e1;
}

input[type="range"]::-moz-range-progress {
  height: 14px;
  border-radius: 999px;
  background: var(--accent);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 4px solid #ffffff;
  border-radius: 50%;
  background: var(--accent);
}

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

.metric-tile {
  min-width: 0;
  padding: 10px;
  background: rgba(255, 255, 255, 0.62);
}

.metric-tile:nth-child(2) {
  background: var(--soft-rose);
}

.metric-tile:nth-child(3) {
  background: #efe2d8;
}

.metric-tile:nth-child(4) {
  background: var(--soft-blue);
}

.metric-tile:nth-child(5) {
  background: #e7ede2;
}

.metric-tile:nth-child(6) {
  background: #eee5d9;
}

.metric-tile span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 760;
}

.metric-tile strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(0.96rem, 1.05vw, 1.24rem);
}

.chart-panel {
  padding: 12px;
  background: rgba(255, 255, 255, 0.62);
}

.chart-canvas-wrap {
  position: relative;
}

#loss-chart {
  display: block;
  width: 100%;
  height: 196px;
  border-radius: 18px;
  background: #ffffff;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #b77b94;
  pointer-events: none;
}

.chart-empty svg {
  width: 92px;
  height: 70px;
  opacity: 0.74;
}

.chart-empty[hidden] {
  display: none;
}

.error-message {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 16px;
  background: #ffecee;
  color: var(--danger);
  font-weight: 720;
}

@media (min-width: 1181px) {
  .shell {
    height: 100vh;
    overflow: hidden;
  }

  .preview-column {
    align-self: center;
    max-height: calc(100vh - 124px);
    padding-top: min(100px, max(0px, calc((100vh - 760px) / 2)));
  }

  .topbar {
    margin-top: -20px;
  }

  .side-panel {
    align-self: center;
    height: calc(100vh - 84px);
    max-height: calc(100vh - 84px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }

  .side-panel::-webkit-scrollbar {
    width: 10px;
  }

  .side-panel::-webkit-scrollbar-track {
    background: transparent;
  }

  .side-panel::-webkit-scrollbar-thumb {
    border: 3px solid #eee9f1;
    border-radius: 999px;
    background: rgba(111, 49, 81, 0.34);
  }
}

@media (max-width: 1180px) {
  .shell {
    justify-content: start;
  }

  .lab-grid {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .preview-column {
    align-content: start;
  }

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

  .chart-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 24px, 640px);
    padding-top: 18px;
    min-height: 0;
  }

  .preview-grid,
  .side-panel,
  .resolution-field,
  .slider-row {
    grid-template-columns: 1fr;
  }

  .resolution-picker {
    width: 100%;
  }

  .slider-control {
    justify-self: stretch;
  }

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

  .topbar {
    align-items: start;
  }

  .control-strip {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr);
    border-radius: 24px;
    width: 100%;
  }
}
