:root {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #111827;
  --panel-soft: #1f2937;
  --line: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --ok: #34d399;
  --warn: #f59e0b;
  --danger: #fb7185;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

.app-shell {
  display: flex;
  min-height: 100svh;
  width: min(100%, 760px);
  margin: 0 auto;
  flex-direction: column;
  gap: 16px;
  padding: 0 16px max(24px, env(safe-area-inset-bottom));
}

.app-header,
.install-strip,
.project-panel,
.scanner-panel,
.result-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 24, 39, 0.96);
}

.install-strip {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0 -16px;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(10px);
}

.install-button {
  display: block;
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--accent-strong);
  border-radius: 8px;
  background: var(--accent-strong);
  color: #ffffff;
  cursor: pointer;
  font-weight: 800;
}

.install-button.is-ready {
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.install-button.is-installed {
  border-color: #059669;
  background: #047857;
}

.install-button:disabled {
  cursor: not-allowed;
  opacity: 0.85;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
}

.brand-logo {
  width: 138px;
  height: auto;
  display: block;
}

.connection-state,
.selected-project,
.status-line {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.connection-state.is-ready {
  color: var(--ok);
}

.connection-state.is-missing {
  color: var(--warn);
}

.project-panel,
.scanner-panel,
.result-panel {
  padding: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  color: var(--text);
  font-size: 24px;
  line-height: 1.12;
}

h2 {
  font-size: 20px;
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.project-button,
.primary-button,
.secondary-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

.project-button {
  background: var(--panel-soft);
  color: var(--text);
  padding: 12px;
  text-align: left;
}

.project-button.is-selected {
  border-color: var(--accent);
  background: rgba(14, 165, 233, 0.18);
  color: #e0f2fe;
}

.scanner-heading,
.result-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.camera-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 58svh;
  min-height: 320px;
  margin-top: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #020617;
}

.camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-placeholder {
  position: absolute;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
}

.camera-frame.is-active .camera-placeholder {
  display: none;
}

.scan-reticle {
  position: absolute;
  width: min(70%, 300px);
  aspect-ratio: 1;
  border: 2px solid rgba(56, 189, 248, 0.95);
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(2, 6, 23, 0.35);
}

.camera-frame.is-reading .scan-reticle {
  border-color: var(--ok);
  box-shadow: 0 0 0 999px rgba(2, 6, 23, 0.42), 0 0 22px rgba(52, 211, 153, 0.7);
}

.camera-frame.is-reading::after {
  position: absolute;
  top: 14px;
  left: 14px;
  border: 1px solid rgba(52, 211, 153, 0.7);
  border-radius: 8px;
  background: rgba(4, 120, 87, 0.9);
  color: #ecfdf5;
  content: "Reading";
  font-size: 14px;
  font-weight: 800;
  padding: 8px 10px;
}

.scanner-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

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

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary-button {
  background: transparent;
  color: var(--text);
}

.payload-input {
  display: block;
  width: 100%;
  min-height: 116px;
  margin-top: 14px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #020617;
  color: var(--text);
  padding: 12px;
}

.payload-input::placeholder {
  color: #64748b;
}

.status-line {
  min-height: 20px;
  margin-top: 10px;
}

.status-line.is-error {
  color: var(--danger);
}

.status-line.is-ok {
  color: var(--ok);
}

.result-panel[hidden] {
  display: none;
}

.result-header strong {
  color: var(--ok);
  font-size: 14px;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 14px 0 0;
}

.result-grid div {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.result-grid dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.result-grid dd {
  margin: 3px 0 0;
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
}

@media (min-width: 680px) {
  .project-grid,
  .result-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .camera-frame {
    aspect-ratio: 16 / 10;
  }
}
