:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-muted: #edf2f7;
  --text: #16202a;
  --muted: #617080;
  --line: #d9e0e7;
  --accent: #087f5b;
  --accent-strong: #066a4c;
  --accent-soft: #dff5ed;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(22, 32, 42, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: #aab6c2;
}

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

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

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.65fr);
  gap: 20px;
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0;
  align-items: center;
}

.scanner-panel,
.result-card,
.history-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.scanner-panel {
  padding: 20px;
}

.top-bar,
.section-heading,
.controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-bar,
.section-heading {
  justify-content: space-between;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 4vw, 2.5rem);
  line-height: 1.05;
}

h2 {
  font-size: 0.95rem;
  line-height: 1.2;
}

.status-text,
.format-text,
.empty-history,
.camera-select-label {
  color: var(--muted);
}

.status-text {
  margin-top: 8px;
}

.support-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 8px 10px;
  background: var(--panel-muted);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.support-badge.supported {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.support-badge.unsupported {
  background: #fff1f0;
  color: var(--danger);
}

.camera-stage {
  position: relative;
  overflow: hidden;
  width: 100%;
  margin-top: 20px;
  aspect-ratio: 16 / 10;
  border-radius: 8px;
  background: #111820;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 160ms ease;
}

video.is-live {
  opacity: 1;
}

.scan-frame {
  position: absolute;
  inset: 16%;
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  pointer-events: none;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.18);
}

.scan-frame span {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 50%;
  height: 2px;
  background: #12b886;
  transform: translateY(-50%);
  opacity: 0.9;
}

.camera-stage.detected .scan-frame {
  border-color: #12b886;
}

.camera-message {
  position: absolute;
  left: 50%;
  bottom: 18px;
  max-width: min(88%, 520px);
  transform: translateX(-50%);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  text-align: center;
  font-weight: 700;
}

.controls {
  flex-wrap: wrap;
  margin-top: 18px;
}

.camera-select-label {
  display: grid;
  gap: 6px;
  min-width: min(100%, 260px);
  margin-left: auto;
  font-size: 0.82rem;
  font-weight: 700;
}

select {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 36px 0 12px;
  background: #fff;
  color: var(--text);
}

.results-panel {
  display: grid;
  gap: 16px;
}

.result-card,
.history-card {
  padding: 16px;
}

.last-result {
  display: block;
  overflow-wrap: anywhere;
  min-height: 76px;
  margin-top: 14px;
  border-radius: 8px;
  padding: 16px;
  background: var(--panel-muted);
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.25;
}

.format-text {
  min-height: 20px;
  margin-top: 10px;
  font-size: 0.9rem;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 380px;
  margin: 14px 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.history-list li {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.history-value {
  overflow-wrap: anywhere;
  font-weight: 800;
}

.history-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.empty-history {
  margin-top: 14px;
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    align-items: start;
    width: min(100% - 24px, 620px);
    padding: 12px 0 24px;
  }

  .top-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .camera-stage {
    aspect-ratio: 4 / 5;
  }

  .controls > button {
    flex: 1 1 132px;
  }

  .camera-select-label {
    width: 100%;
    margin-left: 0;
  }
}
