:root {
  --bg: #f7f8fa;
  --ink: #1f2937;
  --panel: #ffffff;
  --accent: #0f766e;
  --line: #e5e7eb;
  --muted: #6b7280;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.page-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 24px 18px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

.lede {
  color: var(--muted);
  line-height: 1.6;
  margin: 10px 0 16px;
}

.control-group {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.control-group.compact {
  grid-template-columns: 1fr 1fr;
}

button,
.upload-card {
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 160ms ease, opacity 160ms ease;
}

button {
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent);
}

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

button.secondary {
  background: #0f766e;
}

button.ghost {
  background: #ffffff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.upload-card {
  display: block;
  background: #ffffff;
  border: 1px dashed #94a3b8;
  color: var(--ink);
  margin-bottom: 12px;
}

.upload-card input {
  display: block;
  margin-top: 10px;
}

.slider-card,
.status-card,
.class-card,
.viewer-card,
.results-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.slider-card,
.status-card,
.class-card {
  padding: 12px;
  margin-bottom: 12px;
}

.slider-card label {
  display: block;
  font-weight: 700;
  margin-bottom: 10px;
}

.slider-card input {
  width: 100%;
}

#threshold-label {
  display: inline-block;
  margin-top: 8px;
  color: var(--accent);
  font-weight: 700;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.status-row:last-of-type {
  border-bottom: none;
}

.progress-block {
  padding-top: 10px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
}

.progress-label strong {
  color: var(--accent);
  white-space: nowrap;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #e6f4f1;
  overflow: hidden;
}

.progress-bar {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0f766e 0%, #14b8a6 100%);
  transition: width 180ms ease;
}

.class-card h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.class-card ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.class-card li {
  background: #f9fafb;
  border-radius: 8px;
  padding: 8px 10px;
}

.stage {
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-areas: "viewer results";
  align-items: start;
  gap: 14px;
}

.viewer-card,
.results-card {
  padding: 12px;
}

.viewer-card {
  grid-area: viewer;
  position: sticky;
  top: 16px;
}

.results-card {
  grid-area: results;
  min-height: 0;
  max-height: calc(100vh - 32px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-weight: 700;
}

#fps-badge {
  padding: 6px 10px;
  background: #f0fdfa;
  border-radius: 999px;
  color: var(--accent);
}

.canvas-stack {
  position: relative;
  background: #0d1117;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

.canvas-stack video,
.canvas-stack img,
.canvas-stack canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#camera,
#image-preview {
  display: none;
  background: #0d1117;
}

.results-list {
  display: grid;
  gap: 12px;
  overflow: auto;
  padding-right: 4px;
  min-height: 220px;
}

.result-item,
.empty-state {
  border-radius: 10px;
  padding: 10px 12px;
  background: #f9fafb;
}

.result-item strong {
  color: var(--accent);
}

.result-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

@media (max-width: 980px) {
  .page-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .stage {
    grid-template-columns: 1fr;
    grid-template-areas:
      "viewer"
      "results";
  }

  .viewer-card {
    position: static;
  }

  .results-card {
    max-height: none;
  }

  .control-group.compact {
    grid-template-columns: 1fr;
  }
}
