:root {
  --bg: #070b18;
  --bg-glow-1: #1b3a6b;
  --bg-glow-2: #0e2444;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-line: rgba(255, 255, 255, 0.10);
  --ink: #eef3ff;
  --ink-dim: #94a3c4;
  --accent: #4cc2ff;
  --accent-2: #7d8cff;
  --danger: #ff6b81;
  --ok: #46d39a;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.4vh, 14px);
  padding: max(10px, env(safe-area-inset-top)) 14px max(10px, env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 80% at 15% -10%, var(--bg-glow-1) 0%, transparent 55%),
    radial-gradient(100% 70% at 90% 110%, var(--bg-glow-2) 0%, transparent 60%),
    var(--bg);
  color: var(--ink);
  font: 400 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

/* ---------- masthead ---------- */

.masthead { text-align: center; flex: 0 0 auto; }

.masthead h1 {
  margin: 0;
  font-size: clamp(20px, 5.2vw, 30px);
  font-weight: 700;
  letter-spacing: 0.02em;
  background: linear-gradient(100deg, var(--accent), var(--accent-2) 70%, #e5ecff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.slogan {
  margin: 2px 0 0;
  font-size: clamp(11px, 3vw, 13px);
  color: var(--ink-dim);
  letter-spacing: 0.06em;
  text-transform: lowercase;
}

/* ---------- the four sections ---------- */

.stack {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr 1fr auto auto;
  gap: clamp(6px, 1.4vh, 14px);
}

.panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(4px, 1vh, 10px);
  padding: clamp(8px, 1.6vh, 14px) 12px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
}

.panel__title {
  margin: 0;
  font-size: clamp(10px, 2.8vw, 12px);
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.panel__buttons {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ---------- buttons ---------- */

.big {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(2px, 0.8vh, 8px);
  min-height: clamp(56px, 11vh, 104px);
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 13px;
  background: linear-gradient(160deg, rgba(76, 194, 255, 0.16), rgba(125, 140, 255, 0.10));
  color: var(--ink);
  font-size: clamp(13px, 3.6vw, 16px);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.big svg {
  width: clamp(20px, 5.5vw, 28px);
  height: clamp(20px, 5.5vw, 28px);
  fill: var(--accent);
}

.big:hover { background: linear-gradient(160deg, rgba(76, 194, 255, 0.26), rgba(125, 140, 255, 0.16)); }
.big:active { transform: scale(0.97); }
.big:disabled { opacity: 0.5; cursor: default; transform: none; }

.wide {
  width: 100%;
  padding: 13px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
  color: #06101f;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.wide:active { transform: scale(0.99); }

.ghost {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-line);
  color: var(--ink);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.ghost svg { width: 18px; height: 18px; fill: var(--ink-dim); display: block; }
.ghost.is-on svg { fill: var(--accent); }

/* ---------- settings rows ---------- */

.row { display: flex; gap: 8px; align-items: center; }
.row > input[type="password"], .row > input[type="text"] { flex: 1 1 auto; min-width: 0; }
.row > input[type="number"] { flex: 0 0 5.5em; }
.row > select { flex: 1 1 auto; min-width: 0; }

input, select, textarea {
  padding: 10px 12px;
  border: 1px solid var(--panel-line);
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-dim) 50%),
                    linear-gradient(135deg, var(--ink-dim) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

select option { background: #0f1730; color: var(--ink); }

.hint {
  margin: 0;
  font-size: clamp(10px, 2.7vw, 12px);
  color: var(--ink-dim);
}

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 7, 16, 0.82);
  backdrop-filter: blur(6px);
  animation: fade 0.16s ease;
}

.overlay[hidden] { display: none; }

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

.sheet {
  width: min(420px, 100%);
  max-height: 92dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  border: 1px solid var(--panel-line);
  border-radius: 20px;
  background: #101a33;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.sheet h3 { margin: 0; font-size: 19px; }
.sheet__sub { margin: 0; font-size: 13px; color: var(--ink-dim); }

.qr {
  background: #fff;
  border-radius: 14px;
  padding: 10px;
  align-self: center;
  width: min(260px, 62vw);
  aspect-ratio: 1;
  display: flex;
}

.qr svg { width: 100%; height: 100%; display: block; }

.code {
  margin: 0;
  font: 700 clamp(22px, 7vw, 30px)/1 ui-monospace, "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
  color: var(--accent);
}

.countdown { margin: 0; font-size: 12px; color: var(--ink-dim); }

.preview {
  margin: 0;
  max-height: 22dvh;
  overflow: auto;
  padding: 10px;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.35);
  text-align: left;
  font: 13px/1.45 ui-monospace, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink-dim);
}

.error { margin: 0; font-size: 13px; color: var(--danger); }

/* ---------- scanner ---------- */

.sheet--scan { gap: 10px; }

.scanner {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-height: 46dvh;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
}

.scanner video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scanner__frame {
  position: absolute;
  inset: 14%;
  border: 2px solid rgba(76, 194, 255, 0.85);
  border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35);
}

.scanner__msg {
  position: absolute;
  inset: auto 8px 8px;
  margin: 0;
  padding: 8px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.7);
  font-size: 12px;
  color: var(--ink-dim);
}

/* Shown in place of the viewfinder when the camera cannot be opened at all. */
.scanner__fault {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 16px;
  background: #0d1730;
  text-align: center;
}

.scanner__fault[hidden] { display: none; }
.scanner__fault svg { width: 30px; height: 30px; fill: var(--ink-dim); opacity: 0.65; }
.scanner__fault-title { margin: 0; font-size: 14px; font-weight: 600; color: var(--ink); }

.scanner__fault-help {
  margin: 0;
  max-width: 30ch;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink-dim);
}

.scanner__fault-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}

.scanner__fault button { padding: 8px 14px; font-size: 13px; }

.linkish {
  background: none;
  border: 0;
  padding: 2px;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- diagnostics ---------- */

.diag {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 42dvh;
  overflow-y: auto;
  padding: 10px;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.35);
  text-align: left;
}

.diag__row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  line-height: 1.35;
}

.diag__key { color: var(--ink-dim); flex: 0 0 auto; }

.diag__val {
  font-family: ui-monospace, Consolas, monospace;
  text-align: right;
  word-break: break-word;
}

.diag__val.is-bad { color: var(--danger); }
.diag__val.is-good { color: var(--ok); }

/* When the camera is unavailable the typed code stops being the fallback. */
#manual-form.is-primary > input { outline: 2px solid var(--accent); outline-offset: 1px; }

#manual-code { text-transform: uppercase; letter-spacing: 0.14em; text-align: center; }

textarea { width: 100%; resize: vertical; font-size: 15px; }

/* ---------- toast + busy ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  max-width: min(420px, calc(100vw - 24px));
  padding: 11px 16px;
  border-radius: 12px;
  background: #16233f;
  border: 1px solid var(--panel-line);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  font-size: 14px;
  text-align: center;
  animation: rise 0.18s ease;
}

.toast[hidden] { display: none; }
.toast.is-error { border-color: var(--danger); color: #ffd9df; }
.toast.is-ok { border-color: var(--ok); }

@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.busy {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(4, 7, 16, 0.5);
}

.busy__label { margin: 0; font-size: 13px; color: var(--ink-dim); }

.busy[hidden] { display: none; }

.busy__spinner {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Landscape phones: the four sections still have to fit. */
@media (max-height: 460px) and (orientation: landscape) {
  .masthead .slogan { display: none; }
  .stack { grid-template-rows: 1fr 1fr auto auto; }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
