:root {
  color-scheme: light;
  --paper: #fff8e5;
  --white: #fffdf7;
  --ink: #172033;
  --muted: #697286;
  --green: #00a884;
  --green-soft: #ddf8ef;
  --yellow: #ffd84d;
  --blue: #4361ee;
  --red: #e5484d;
  --comic:
    "Comic Sans MS", "Comic Sans", "Chalkboard SE", "Comic Neue",
    "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  background: var(--paper);
  font-family: var(--comic);
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(67, 97, 238, 0.42);
  outline-offset: 3px;
}

button svg {
  width: 1.2em;
  height: 1.2em;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.boot {
  display: flex;
  min-height: 100svh;
  align-items: center;
  justify-content: center;
  gap: 13px;
  font-size: 20px;
}

.boot > span {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(23, 32, 51, 0.22);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.page {
  display: grid;
  width: 100%;
  height: 100svh;
  min-height: 720px;
  padding: clamp(12px, 1.7vh, 19px) clamp(16px, 1.8vw, 28px);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(9px, 1.2vh, 14px);
  overflow: hidden;
}

.page-header {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.page-header small {
  display: block;
  color: var(--blue);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.18em;
}

.page-header h1 {
  margin: 1px 0 0;
  font-size: clamp(30px, 3vw, 48px);
  letter-spacing: -0.04em;
  line-height: 0.98;
}

.page-header h1 em {
  color: var(--blue);
  font-style: normal;
}

.page-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: clamp(11px, 0.9vw, 14px);
  font-weight: 700;
}

.model-status {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--white);
  box-shadow: 3px 3px 0 var(--ink);
  font-size: 11px;
}

.model-status > span {
  width: 12px;
  height: 12px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
}

.model-status.ready > span {
  background: #31d39b;
}

.model-status.error > span {
  background: var(--red);
}

.lab-grid {
  display: grid;
  min-height: 0;
  grid-template-columns: minmax(480px, 1.18fr) minmax(520px, 0.82fr);
  gap: clamp(12px, 1.4vw, 20px);
}

.camera-panel,
.control-panel {
  min-width: 0;
  min-height: 0;
  border: 3px solid var(--ink);
  border-radius: 19px;
  background: var(--white);
  box-shadow: 6px 6px 0 var(--ink);
}

.camera-panel {
  display: grid;
  padding: clamp(11px, 1vw, 15px);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 9px;
}

.control-panel {
  display: grid;
  padding: clamp(11px, 1vw, 15px);
  grid-template-rows: auto minmax(210px, 1.15fr) auto minmax(128px, 0.78fr);
  gap: 9px;
}

.section-title,
.train-label,
.prediction-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title > span,
.train-label > span,
.prediction-title > span {
  display: grid;
  width: 35px;
  height: 35px;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 17px;
  font-weight: 900;
}

.section-title small,
.train-label small,
.prediction-title small {
  display: block;
  color: var(--blue);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.14em;
}

.section-title h2,
.train-label h2,
.prediction-title h2 {
  margin: 1px 0 0;
  font-size: clamp(15px, 1.25vw, 20px);
  line-height: 1.05;
}

.camera-stage {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 15px;
  background: #20283a;
}

#camera-video {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
  background: #20283a;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.2s ease;
}

#camera-video.visible {
  opacity: 1;
}

.camera-guide {
  position: absolute;
  z-index: 2;
  width: min(70%, 470px);
  aspect-ratio: 1;
  border: 3px dashed rgba(255, 255, 255, 0.58);
  border-radius: 20px;
  pointer-events: none;
}

.camera-guide::after {
  position: absolute;
  right: 50%;
  bottom: -25px;
  transform: translateX(50%);
  color: rgba(255, 255, 255, 0.78);
  content: "KEEP THE OBJECT INSIDE THE SQUARE";
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.camera-off {
  position: relative;
  z-index: 4;
  display: grid;
  width: min(420px, calc(100% - 30px));
  padding: 22px;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 17px;
  background: var(--paper);
  box-shadow: 6px 6px 0 var(--ink);
  text-align: center;
}

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

.camera-icon {
  display: grid;
  width: 62px;
  height: 62px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: var(--yellow);
}

.camera-icon svg {
  width: 33px;
  height: 33px;
  fill: none;
  stroke: var(--ink);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.camera-off h2 {
  margin: 10px 0 3px;
  font-size: 24px;
}

.camera-off p {
  margin: 0 0 13px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.camera-off > button {
  display: flex;
  width: min(270px, 100%);
  min-height: 50px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--green);
  box-shadow: 4px 4px 0 var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.camera-off > button:hover {
  transform: translate(-1px, -1px);
  box-shadow: 6px 6px 0 var(--ink);
}

.camera-off > small {
  min-height: 13px;
  margin-top: 8px;
  color: var(--red);
  font-size: 9px;
  font-weight: 800;
}

.recording-badge {
  position: absolute;
  top: 13px;
  left: 13px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.recording-badge[hidden] {
  display: none;
}

.recording-badge i {
  width: 10px;
  height: 10px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: var(--red);
  animation: pulse 0.6s ease-in-out infinite alternate;
}

@keyframes pulse {
  to {
    transform: scale(0.65);
    opacity: 0.55;
  }
}

.live-answer {
  position: absolute;
  right: 13px;
  bottom: 13px;
  z-index: 5;
  display: grid;
  min-width: 210px;
  padding: 10px 13px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  box-shadow: 4px 4px 0 var(--ink);
}

.live-answer[hidden] {
  display: none;
}

.live-answer small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 7px;
  font-weight: 900;
  letter-spacing: 0.11em;
}

.live-answer strong {
  margin-top: 2px;
  font-size: 26px;
  line-height: 1;
}

.live-answer b {
  font-size: 12px;
}

.camera-bottom {
  display: flex;
  min-height: 31px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.camera-bottom p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(9px, 0.72vw, 12px);
  font-weight: 800;
}

.camera-bottom button,
footer button {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border: 1.5px solid var(--ink);
  border-radius: 7px;
  background: #fff;
  font-size: 8px;
  font-weight: 900;
  cursor: pointer;
}

.examples-title {
  min-width: 0;
}

.examples-title > div:nth-child(2) {
  min-width: 0;
}

.class-toolbar {
  display: flex;
  min-width: max-content;
  margin-left: auto;
  align-items: center;
  gap: 7px;
}

.class-toolbar b {
  color: var(--muted);
  font-size: 7px;
  letter-spacing: 0.08em;
}

.add-class-button {
  min-height: 29px;
  padding: 5px 8px;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  background: var(--yellow);
  box-shadow: 2px 2px 0 var(--ink);
  font-size: 7px;
  font-weight: 900;
  cursor: pointer;
}

.add-class-button:disabled {
  background: #d7d9df;
  box-shadow: none;
  color: var(--muted);
  cursor: not-allowed;
}

.class-grid {
  display: grid;
  min-height: 0;
  padding: 1px 3px 6px 1px;
  grid-auto-columns: minmax(215px, 1fr);
  grid-auto-flow: column;
  grid-template-columns: none;
  gap: 9px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-inline: contain;
  scroll-snap-type: inline proximity;
  scrollbar-color: #aab1c0 transparent;
  scrollbar-width: thin;
}

.class-card {
  --class-color: #ff6b4a;
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: 9px;
  grid-template-rows: auto auto minmax(45px, 1fr) auto;
  gap: 7px;
  border: 2px solid var(--ink);
  border-top: 8px solid var(--class-color);
  border-radius: 13px;
  background: #fff;
  overflow: hidden;
  scroll-snap-align: start;
}

.class-card.recording {
  background: color-mix(in srgb, var(--class-color) 9%, white);
  box-shadow: inset 0 0 0 2px var(--class-color);
}

.class-top {
  display: grid;
  min-width: 0;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
}

.class-actions {
  display: flex;
  align-items: center;
  gap: 3px;
}

.class-dot {
  width: 11px;
  height: 11px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--class-color);
}

.class-top input {
  min-width: 0;
  padding: 2px 3px;
  border: 0;
  border-bottom: 1.5px dashed #aab1c0;
  background: transparent;
  font-size: clamp(13px, 1vw, 17px);
  font-weight: 900;
}

.clear-button,
.remove-button {
  padding: 3px 5px;
  border: 1px solid #b6bbc6;
  border-radius: 5px;
  background: #fff;
  color: var(--muted);
  font-size: 6px;
  font-weight: 900;
  cursor: pointer;
}

.remove-button {
  border-color: #e5a4a7;
  color: #a52e34;
}

.clear-button:disabled,
.remove-button:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.frame-count {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 5px;
}

.frame-count b {
  color: var(--class-color);
  font-size: clamp(23px, 2vw, 34px);
  line-height: 1;
}

.frame-count span {
  color: var(--muted);
  font-size: 8px;
  font-weight: 800;
}

.frame-count em {
  padding: 3px 5px;
  border: 1px solid #b6bbc6;
  border-radius: 999px;
  color: var(--muted);
  font-size: 6px;
  font-style: normal;
  font-weight: 900;
  white-space: nowrap;
}

.frame-count em.ready {
  border-color: var(--ink);
  background: var(--green-soft);
  color: #08755e;
}

.recent-frames {
  display: grid;
  min-height: 45px;
  grid-template-columns: repeat(3, minmax(38px, 1fr));
  grid-template-rows: repeat(2, minmax(38px, 1fr));
  gap: 4px;
}

.recent-frames img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 38px;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  object-fit: cover;
}

.empty-frames {
  display: grid;
  min-height: 45px;
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  place-items: center;
  border: 1.5px dashed #afb5c1;
  border-radius: 7px;
  color: var(--muted);
  font-size: 7px;
  font-weight: 800;
  text-align: center;
}

.record-button {
  display: grid;
  position: relative;
  min-height: 62px;
  padding: 9px 8px 8px 32px;
  place-content: center;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--class-color);
  box-shadow: 3px 3px 0 var(--ink);
  color: #fff;
  text-align: left;
  touch-action: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.record-button:disabled {
  background: #aeb4c0;
  box-shadow: 2px 2px 0 #7d8595;
  cursor: not-allowed;
}

.record-button:not(:disabled):active,
.record-button.recording {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.record-dot {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 13px;
  height: 13px;
  transform: translateY(-50%);
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--red);
}

.record-button.recording .record-dot {
  animation: pulse 0.55s ease-in-out infinite alternate;
}

.record-button strong,
.record-button small {
  display: block;
}

.record-button strong {
  font-size: clamp(8px, 0.72vw, 11px);
  letter-spacing: 0.03em;
}

.record-button small {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.84);
  font-size: 7px;
  font-weight: 700;
}

.train-section {
  display: grid;
  min-width: 0;
  padding: 9px;
  grid-template-columns: minmax(150px, 0.76fr) minmax(220px, 1.24fr);
  grid-template-rows: auto auto;
  align-items: center;
  gap: 6px 10px;
  border: 3px solid var(--ink);
  border-radius: 13px;
  background: #eef1ff;
}

.train-label {
  grid-row: 1 / 3;
}

.train-label > span {
  background: var(--blue);
}

.train-button {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--blue);
  box-shadow: 4px 4px 0 var(--ink);
  color: #fff;
  font-size: clamp(12px, 1vw, 15px);
  font-weight: 900;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.train-button:hover:not(:disabled) {
  transform: translate(-1px, -1px);
  box-shadow: 6px 6px 0 var(--ink);
}

.train-button:disabled {
  background: #aeb4c0;
  box-shadow: 2px 2px 0 #7d8595;
  cursor: not-allowed;
}

.train-progress {
  height: 7px;
  overflow: hidden;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: #fff;
}

.train-progress[hidden] {
  display: none;
}

.train-progress i {
  display: block;
  height: 100%;
  background: var(--green);
  transition: width 0.14s ease;
}

#train-help {
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 8px;
  font-weight: 800;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prediction-section {
  display: grid;
  min-height: 0;
  padding: 9px;
  grid-template-columns: minmax(145px, 0.72fr) minmax(230px, 1.28fr);
  align-items: center;
  gap: 10px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #f1fff8;
}

.prediction-title > span {
  background: var(--green);
}

.prediction-empty {
  display: grid;
  min-height: 70px;
  place-items: center;
  border: 2px dashed #aeb5c1;
  border-radius: 9px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  text-align: center;
}

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

.prediction-bars {
  display: grid;
  max-height: 92px;
  padding-right: 3px;
  gap: 6px;
  overflow-y: auto;
  scrollbar-color: #aab1c0 transparent;
  scrollbar-width: thin;
}

.prediction-bars[hidden] {
  display: none;
}

.prediction-row {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(62px, 0.8fr) minmax(90px, 1.7fr) 35px;
  align-items: center;
  gap: 7px;
  font-size: 9px;
  font-weight: 900;
}

.prediction-row > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prediction-row > div {
  height: 12px;
  overflow: hidden;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: #fff;
}

.prediction-row i {
  display: block;
  width: 0;
  height: 100%;
  transition: width 0.16s ease;
}

footer {
  display: flex;
  min-height: 25px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
}

footer button {
  color: var(--ink);
}

@media (max-height: 820px) and (min-width: 1001px) {
  .page {
    min-height: 680px;
    padding-top: 9px;
    padding-bottom: 9px;
    gap: 7px;
  }

  .page-header {
    min-height: 54px;
  }

  .page-header p {
    display: none;
  }

  .page-header h1 {
    font-size: 34px;
  }

  .control-panel {
    grid-template-rows: auto minmax(195px, 1fr) auto minmax(110px, 0.72fr);
  }

  .record-button {
    min-height: 54px;
  }

  .recent-frames {
    grid-template-rows: repeat(2, minmax(31px, 1fr));
  }
}

@media (max-width: 1000px) {
  .page {
    display: block;
    height: auto;
    min-height: 100svh;
    padding: 12px 12px 22px;
    overflow: visible;
  }

  .page-header {
    margin-bottom: 12px;
  }

  .model-status {
    display: none;
  }

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

  .camera-panel {
    min-height: 620px;
    margin-bottom: 14px;
  }

  .control-panel {
    min-height: 700px;
  }

  footer {
    margin-top: 15px;
  }
}

@media (max-width: 620px) {
  .page-header h1 {
    font-size: 32px;
  }

  .page-header p {
    font-size: 10px;
  }

  .camera-panel {
    min-height: 520px;
  }

  .control-panel {
    display: block;
    min-height: 0;
  }

  .control-panel > * + * {
    margin-top: 10px;
  }

  .examples-title {
    flex-wrap: wrap;
  }

  .class-toolbar {
    width: 100%;
    margin-left: 45px;
    justify-content: space-between;
  }

  .class-grid {
    grid-auto-columns: minmax(230px, 82vw);
    grid-template-columns: none;
  }

  .class-card {
    min-height: 250px;
  }

  .train-section,
  .prediction-section {
    grid-template-columns: 1fr;
  }

  .train-label {
    grid-row: auto;
  }
}
