:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --text: #f2f3f5;
  --text-dim: #9aa0ab;
  --primary: #4f7cff;
  --primary-dim: #3a5ecb;
  --success: #35c46a;
  --fail: #e5484d;
  color-scheme: dark;
}

* {
  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;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
  margin: 8px 0 32px;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.screen.hidden {
  display: none;
}

label {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.device-picker {
  position: relative;
}

.device-picker-trigger {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  border-radius: 12px;
  border: 1px solid #2a2e38;
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  text-align: left;
}

.device-picker-trigger:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.device-picker-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-picker-label.placeholder {
  color: var(--text-dim);
}

.device-picker-chevron {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.15s ease;
}

.device-picker.open .device-picker-chevron {
  transform: rotate(-135deg) translateY(2px);
}

.device-picker-dropdown {
  position: absolute;
  z-index: 10;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  border-radius: 12px;
  border: 1px solid #2a2e38;
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.device-picker-dropdown.hidden {
  display: none;
}

.device-picker-search {
  width: 100%;
  padding: 12px 16px;
  font-size: 1rem;
  border: none;
  border-bottom: 1px solid #2a2e38;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.device-picker-search::placeholder {
  color: var(--text-dim);
}

.device-picker-list {
  list-style: none;
  margin: 0;
  padding: 8px 0;
  max-height: min(280px, 45vh);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.device-picker-option {
  padding: 12px 16px;
  font-size: 1rem;
  cursor: pointer;
}

.device-picker-option:hover,
.device-picker-option:focus {
  background: rgba(79, 124, 255, 0.12);
  outline: none;
}

.device-picker-option.selected {
  color: var(--primary);
}

.device-picker-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.btn {
  width: 100%;
  padding: 16px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn:active {
  transform: scale(0.98);
}

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

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

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

.btn-secondary {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid #2a2e38;
}

.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 16px;
  overflow: hidden;
  background: #000;
}

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

.scan-frame {
  position: absolute;
  inset: 15% 12%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  border-radius: 16px;
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.hint {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin: 0;
}

.spinner {
  width: 48px;
  height: 48px;
  margin: auto auto 0;
  border: 4px solid #2a2e38;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

#screen-sending {
  align-items: center;
  justify-content: center;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#screen-result {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.result-icon {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  line-height: 1;
}

.result-icon.success {
  background: rgba(53, 196, 106, 0.15);
  color: var(--success);
  animation: pop 0.35s ease;
}

.result-icon.fail {
  background: rgba(229, 72, 77, 0.15);
  color: var(--fail);
  animation: shake 0.4s ease;
}

@keyframes pop {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

.result-message {
  font-size: 1.1rem;
  font-weight: 500;
  max-width: 320px;
}

.error-banner {
  background: rgba(229, 72, 77, 0.15);
  color: var(--fail);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.85rem;
  text-align: center;
  margin-top: 16px;
}

.error-banner.hidden {
  display: none;
}
