:root {
  --bg: #050608;
  --panel: #0e1014;
  --panel-2: #14171d;
  --line: #1f242c;
  --text: #e8eaee;
  --muted: #7d848f;
  --accent: #6ee7ff;
  --accent-2: #ffd166;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  height: 100%;
  width: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  background-image:
    radial-gradient(circle at 20% 0%, rgba(110, 231, 255, 0.05), transparent 50%),
    radial-gradient(circle at 80% 100%, rgba(255, 209, 102, 0.04), transparent 50%);
}

h1, h2, h3 { font-weight: 600; letter-spacing: 0.3px; margin: 0 0 8px 0; }
h1 { font-size: 32px; }
h2 { font-size: 22px; margin: 0 0 12px 0; }
h3 { font-size: 16px; }
p { margin: 0 0 12px 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 12px; }
.col { display: flex; flex-direction: column; }

#stage.stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
}

.stage-page {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 12px;
  margin: auto;
  opacity: 1;
  transform: translateY(0) scale(1);
}

.kv {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  appearance: none;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: background 0.1s ease, border-color 0.1s ease, transform 0.05s ease;
  min-height: 44px;
}
button:active, .btn:active { transform: translateY(1px); }
button:hover, .btn:hover { background: #1a1e25; border-color: #2a2f38; }
button.primary, .btn.primary {
  background: var(--accent);
  color: #051519;
  border-color: var(--accent);
}
button.primary:hover, .btn.primary:hover { background: #8eebff; }
button.warn { color: var(--warn); border-color: rgba(251, 191, 36, 0.4); }
button.danger { color: var(--err); border-color: rgba(248, 113, 113, 0.4); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-group { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-group.center { justify-content: center; }

input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 14px;
}

/* ── HOME ───────────────────────────────────────────────────────────── */
.home-page { gap: 32px; padding-top: 8vh; }
.home-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.home-brand h1 { letter-spacing: 1px; }
.home-brand p { margin: 0; }

.logo {
  width: 32px;
  height: 32px;
  display: inline-block;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'><path d='M448 96 L80 240 L208 280 L256 416 L296 312 L448 96 Z' fill='%236ee7ff' stroke='%23a4f4ff' stroke-width='6' stroke-linejoin='round'/><path d='M448 96 L208 280 L296 312 Z' fill='%233ea9c0' opacity='0.55'/></svg>") center/contain no-repeat;
}
.logo.big {
  width: 96px;
  height: 96px;
  margin-bottom: 4px;
  filter: drop-shadow(0 6px 24px rgba(110, 231, 255, 0.35));
}

.home-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.tile-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: 18px;
  transition: border-color 0.15s ease, transform 0.05s ease, background 0.15s ease;
}
.tile-btn .tile-icon {
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text);
}
.tile-btn .tile-icon svg { width: 100%; height: 100%; }
.tile-btn.primary {
  background: var(--accent);
  color: #051519;
  border-color: var(--accent);
}
.tile-btn.primary .tile-icon { color: #051519; }
.tile-btn:hover { background: #1a1e25; }
.tile-btn.primary:hover { background: #8eebff; }

.home-foot { text-align: center; opacity: 0.6; }
.home-foot a { color: var(--muted); }

/* ── QR ─────────────────────────────────────────────────────────────── */
.qr-page { gap: 14px; }
.step-label { color: var(--muted); font-size: 12px; letter-spacing: 1px; text-transform: uppercase; text-align: center; }
.qr-frame {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 4px auto;
  width: 100%;
  max-width: 360px;
}
.qr-stage {
  width: 100%;
  aspect-ratio: 1;
  background: white;
  padding: 12px;
  border-radius: 16px;
  position: relative;
  overflow: hidden;
}
.qr-stage canvas { display: block; width: 100%; height: 100%; }

/* ── Scan ──────────────────────────────────────────────────────────── */
.scan-stage {
  position: relative;
  width: 100%;
  max-width: 380px;
  aspect-ratio: 1;
  margin: 0 auto;
  background: black;
  border-radius: 16px;
  overflow: hidden;
}
.scan-stage video { width: 100%; height: 100%; object-fit: cover; }
.scan-overlay {
  position: absolute;
  inset: 12%;
  border: 2px solid rgba(110, 231, 255, 0.7);
  border-radius: 12px;
  pointer-events: none;
  box-shadow: 0 0 0 2000px rgba(0,0,0,0.35);
}

/* ── Splash / Done / Error ─────────────────────────────────────────── */
.splash-page, .done-page {
  flex: 1;
  align-items: center;
  justify-content: center;
}
.splash-success {
  font-size: 36px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 1px;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(110, 231, 255, 0.45);
  animation: pulse-glow 1.4s ease-in-out infinite alternate;
}
@keyframes pulse-glow {
  0% { transform: scale(1); }
  100% { transform: scale(1.04); }
}
.error-page h2 { color: var(--err); }

/* ── Busy / spinner ────────────────────────────────────────────────── */
.busy-page { align-items: center; }
.spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  margin: 0 auto;
  animation: spin 0.85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Transfer progress ─────────────────────────────────────────────── */
.transfer-page { gap: 12px; }
.progress {
  width: 100%;
  height: 8px;
  background: var(--panel-2);
  border-radius: 4px;
  overflow: hidden;
}
.progress.big { height: 14px; border-radius: 7px; }
.progress > div {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.15s ease;
}
.progress.ok > div { background: var(--ok); }

.recv-row { font-size: 13px; color: var(--text); }

/* ── Build pill ────────────────────────────────────────────────────── */
.build-pill {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 8px);
  right: 8px;
  font-family: var(--mono);
  font-size: 10px;
  opacity: 0.4;
  z-index: 5;
}
.build-pill a { color: var(--muted); text-decoration: none; }
.build-pill a:hover { color: var(--text); }

/* ── Diagnostics tweaks ───────────────────────────────────────────── */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-family: var(--mono);
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
}
.tag.ok { color: var(--ok); border-color: rgba(74, 222, 128, 0.3); }
.tag.err { color: var(--err); border-color: rgba(248, 113, 113, 0.3); }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.log {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  max-height: 180px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Mobile tweaks ─────────────────────────────────────────────────── */
@media (max-width: 420px) {
  h1 { font-size: 28px; }
  h2 { font-size: 20px; }
  .splash-success { font-size: 30px; }
  .home-actions { grid-template-columns: 1fr; }
  .tile-btn { padding: 24px 16px; font-size: 18px; }
}
