:root {
  color-scheme: light;
  --bg: #f7f8f4;
  --panel: #ffffff;
  --ink: #1d2520;
  --muted: #5b675f;
  --line: #d9ded6;
  --green: #1fa35b;
  --green-dark: #0f6c39;
  --red: #d23f31;
  --yellow: #f1c232;
  --shadow: 0 18px 45px rgba(31, 42, 35, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
select,
input {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  min-height: 100vh;
  padding: 20px;
}

.scanner,
.results {
  min-width: 0;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
}

#status {
  margin-top: 6px;
  color: var(--muted);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

button,
.file-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  padding: 10px 12px;
  line-height: 1;
}

.controls select {
  width: min(260px, 100%);
}

button:hover,
.file-button:hover {
  border-color: var(--green);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

#startButton {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.file-button input {
  display: none;
}

.stage {
  position: relative;
  overflow: hidden;
  min-height: 420px;
  height: calc(100vh - 112px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151a17;
  box-shadow: var(--shadow);
}

video,
#stillImage,
canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

video,
#stillImage {
  object-fit: contain;
}

#stillImage {
  display: none;
}

canvas {
  pointer-events: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #dce4dd;
  text-align: center;
}

.results {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 40px);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.results-head button {
  padding: 8px 10px;
  font-size: 13px;
}

.detections {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding-right: 2px;
}

.detection {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf8;
}

.figure-image {
  width: 76px;
  height: 76px;
  object-fit: contain;
  border-radius: 6px;
  background: #eef2eb;
}

.detection-body {
  min-width: 0;
}

.detection.unknown .figure-image {
  display: none;
}

.detection.unknown {
  grid-template-columns: 1fr;
  border-color: #e3c874;
  background: #fffaf0;
}

.figure-name {
  overflow-wrap: anywhere;
  font-weight: 700;
}

.series-name {
  overflow-wrap: anywhere;
  margin-top: 1px;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 700;
}

.raw-value {
  overflow: visible;
  overflow-y: hidden;
  white-space: nowrap;
  margin: 6px 0 8px;
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.25;
  letter-spacing: 0;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px;
}

@media (max-width: 920px) {
  .app {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .controls {
    justify-content: flex-start;
  }

  .stage {
    height: 68vh;
  }

  .results {
    max-height: none;
  }
}

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

  h1 {
    font-size: 22px;
  }

  .stage {
    min-height: 320px;
    height: 62vh;
  }

  .detection {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .figure-image {
    width: 64px;
    height: 64px;
  }
}
