:root {
  --bg: #0b0f14;
  --surface: #131a22;
  --surface-2: #1b2430;
  --border: #273241;
  --text: #eef3f8;
  --muted: #93a1b3;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #10b981;
  --accent-hover: #059669;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  min-height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 14px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.05rem, 0.9rem + 0.8vw, 1.3rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--warn);
  flex-shrink: 0;
}

.brand-dot.ready {
  background: var(--accent);
}

.brand-dot.error {
  background: var(--danger);
}

.status-pill {
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 62%;
}

.main-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.viewport-card,
.results-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.media-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #06090d;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}

@media (min-width: 640px) {
  .media-stage {
    aspect-ratio: 4 / 3;
  }
}

.scan-guide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scan-guide-box {
  width: 72%;
  height: 26%;
  border: 2px dashed rgba(255, 255, 255, 0.38);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.18);
}

.options-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-chip[aria-pressed="true"] {
  border-color: var(--warn);
  background: rgba(245, 158, 11, 0.18);
  color: #fde68a;
}

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

.media-stage canvas {
  pointer-events: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  color: var(--muted);
}

.empty-title {
  margin: 0 0 6px;
  color: var(--text);
  font-weight: 600;
  font-size: 1rem;
}

.empty-sub {
  margin: 0;
  font-size: 0.88rem;
  max-width: 30ch;
}

.progress-bar-wrap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.12);
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 120ms linear;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  min-height: 46px;
  padding: 10px 12px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: background-color 140ms ease, opacity 140ms ease, border-color 140ms ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
}

.btn-primary:not(:disabled):hover {
  background: var(--primary-hover);
}

.btn-accent {
  background: var(--accent);
  color: #062116;
}

.btn-accent:not(:disabled):hover {
  background: var(--accent-hover);
}

.btn-secondary {
  border-color: var(--border);
}

.btn-secondary[aria-pressed="true"] {
  border-color: var(--accent);
  background: rgba(16, 185, 129, 0.16);
  color: #a7f3d0;
}

.file-btn {
  position: relative;
  overflow: hidden;
}

.file-btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.options-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--muted);
  cursor: pointer;
  min-height: 32px;
}

.toggle-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.perf-badge {
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

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

.section-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 4px 6px;
  cursor: pointer;
}

.btn-link:hover {
  color: var(--text);
}

.latest-plate {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 58px;
}

.plate-placeholder {
  color: var(--muted);
  font-size: 0.88rem;
}

.plate-badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: clamp(1.2rem, 1rem + 1.2vw, 1.6rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fff;
}

.plate-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.conf-tag {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
}

.conf-tag.low {
  background: rgba(245, 158, 11, 0.16);
  color: #fcd34d;
}

.copy-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 34px;
}

.history-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.86rem;
}

.history-item code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 0.95rem;
}

.history-time {
  color: var(--muted);
  font-size: 0.76rem;
}
