:root {
  --bg: #0a0a0c;
  --surface: #141418;
  --border: #2a2a32;
  --text: #f4f4f6;
  --muted: #9a9aa8;
  --accent: #ff9800;
  --green: #2e7d32;
  --green-bright: #66bb6a;
  --red: #c62828;
  --red-bright: #ef5350;
  --amber: #e65100;
  --purple: #7b1fa2;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(12px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
}

.scanner-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.brand-mark {
  font-size: 1.75rem;
  line-height: 1;
}

.brand-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

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

.connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.connection-pill.online {
  color: var(--green-bright);
}

.connection-pill.offline {
  color: var(--red-bright);
}

.connection-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.connection-pill.online .dot {
  background: var(--green-bright);
  box-shadow: 0 0 8px var(--green-bright);
}

.connection-pill.offline .dot {
  background: var(--red-bright);
}

.scanner-auth-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  max-width: 9.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scanner-auth-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.scanner-auth-pill.linked {
  color: var(--green-bright);
}

.scanner-auth-pill.linked .dot {
  background: var(--green-bright);
  box-shadow: 0 0 8px var(--green-bright);
}

.scanner-auth-pill.expired,
.scanner-auth-pill.no-key {
  color: var(--red-bright);
}

.scanner-auth-pill.expired .dot,
.scanner-auth-pill.no-key .dot {
  background: var(--red-bright);
}

.scanner-auth-pill.testing {
  color: var(--accent);
}

.scanner-auth-pill.testing .dot {
  background: var(--accent);
}

.scanner-auth-banner {
  margin: -4px 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(239, 83, 80, 0.45);
  background: rgba(198, 40, 40, 0.18);
  color: #ffcdd2;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
}

.settings-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
}

.scanner-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.scan-hint {
  text-align: center;
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: var(--muted);
}

.scan-hint-idle {
  font-size: clamp(1.35rem, 5.5vw, 1.9rem);
  font-weight: 800;
  color: var(--text);
  line-height: 1.25;
  padding: 0 10px;
  letter-spacing: 0.01em;
}

.camera-shell {
  position: relative;
  flex: 1;
  min-height: 45vh;
  max-height: 62vh;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid var(--border);
  background: #000;
}

.camera-view {
  width: 100%;
  height: 100%;
  min-height: 45vh;
}

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

.scan-frame {
  pointer-events: none;
  position: absolute;
  inset: 12%;
  border: 2px solid rgba(255, 152, 0, 0.65);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25);
}

.camera-shell.scan-paused .camera-view {
  filter: grayscale(0.85) brightness(0.55);
}

.offline-banner {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
  text-align: center;
  background: rgba(80, 12, 12, 0.92);
  border: 2px solid var(--red-bright);
}

.offline-banner-emoji {
  margin: 0;
  font-size: 2.5rem;
  line-height: 1;
}

.offline-banner-title {
  margin: 0;
  font-size: clamp(1.35rem, 5vw, 1.75rem);
  font-weight: 800;
  color: #fff;
}

.offline-banner-detail {
  margin: 0;
  max-width: 320px;
  font-size: 1rem;
  line-height: 1.45;
  color: #ffcdd2;
}

.offline-banner-detail strong {
  color: var(--green-bright);
}

.status-line {
  margin: 14px 0 0;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 600;
}

.status-line.waiting {
  color: var(--accent);
  font-size: clamp(0.95rem, 3.5vw, 1.1rem);
  font-weight: 600;
}

.status-line.processing {
  color: var(--muted);
}

.status-line.error {
  color: var(--red-bright);
}

.hidden {
  display: none !important;
}

.setup-screen,
.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.82);
}

.setup-card,
.settings-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 20px;
}

.setup-card h2,
.settings-card h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.setup-lead,
.settings-status {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

.setup-input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0e0e12;
  color: var(--text);
  font-size: 1rem;
}

.primary-btn,
.danger-btn,
.ghost-btn {
  width: 100%;
  padding: 12px 14px;
  margin-top: 8px;
  border-radius: 10px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

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

.danger-btn {
  background: #3a1212;
  color: #ffcdd2;
  border: 1px solid var(--red);
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.setup-error {
  margin: 12px 0 0;
  color: var(--red-bright);
  font-size: 0.9rem;
}

.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  animation: fade-in 0.15s ease-out;
}

.result-overlay.success {
  background: rgba(27, 94, 32, 0.94);
}

.result-overlay.reward {
  background: rgba(27, 94, 32, 0.96);
}

.result-overlay.lockout {
  background: rgba(21, 101, 192, 0.94);
}

.result-overlay.warn {
  background: rgba(230, 81, 0, 0.94);
}

.result-overlay.error {
  background: rgba(183, 28, 28, 0.94);
}

.result-overlay.bingo-win {
  background: rgba(22, 163, 74, 0.96);
}

.result-overlay.bingo-pending {
  background: rgba(217, 119, 6, 0.94);
}

.result-winning-tracks {
  margin: 12px auto 0;
  padding-left: 1.2rem;
  max-width: 22rem;
  text-align: left;
  font-size: 0.95rem;
  line-height: 1.4;
}

.bingo-award-btn {
  margin-top: 16px;
  width: min(100%, 22rem);
}

.result-emoji {
  margin: 0;
  font-size: 3.5rem;
  line-height: 1;
}

.result-title {
  margin: 12px 0 8px;
  font-size: clamp(1.6rem, 6vw, 2.35rem);
  font-weight: 800;
  line-height: 1.2;
}

.result-detail {
  margin: 0 auto;
  max-width: 22rem;
  font-size: clamp(1.05rem, 4vw, 1.25rem);
  line-height: 1.45;
  opacity: 0.95;
}

.camera-error {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  background: var(--bg);
  text-align: center;
}

.camera-error p {
  max-width: 360px;
  color: var(--muted);
  line-height: 1.5;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
