:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #22c55e;
  --accent-dark: #16a34a;
  --error: #f87171;
}

* { box-sizing: border-box; }

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

body { display: flex; flex-direction: column; min-height: 100dvh; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
}
.brand { color: var(--muted); letter-spacing: 0.02em; text-decoration: none; }
.brand:hover strong { text-decoration: underline; }
.brand strong { color: var(--text); }

main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.hidden { display: none !important; }

/* Auth card */
.card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
}
.card h1 { margin: 0 0 20px; font-size: 1.35rem; text-align: center; }

.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; margin-bottom: 20px; }
.tab {
  flex: 1; padding: 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); font: inherit; cursor: pointer;
}
.tab.active { background: var(--surface); color: var(--text); }

form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
input, select {
  padding: 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit; font-size: 16px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.primary {
  margin-top: 6px; padding: 13px; border: 0; border-radius: 10px;
  background: var(--accent); color: #052e16; font: inherit; font-weight: 600; cursor: pointer;
}
.primary:hover { background: var(--accent-dark); }
.primary:disabled { opacity: 0.6; cursor: wait; }

.link { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 6px; }
.link:hover { color: var(--text); }

select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.field-row { display: flex; flex-direction: column; gap: 14px; }
.field-row:empty { display: none; }
.info { color: var(--accent); margin: 8px 0 0; text-align: center; font-size: 0.9rem; }
.info:empty { display: none; }
.error { color: var(--error); min-height: 1.2em; margin: 14px 0 0; text-align: center; font-size: 0.9rem; }

/* Gate */
#gate { display: flex; flex-direction: column; align-items: center; gap: 22px; width: 100%; }
.hello { margin: 0; color: var(--muted); }

.gate-button {
  /* Fit the space left after top bar, greeting and status line */
  width: min(78vw, 340px, calc(100vh - 210px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  width: min(78vw, 340px, calc(100dvh - 210px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  min-width: 140px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0;
  background: radial-gradient(circle at 30% 25%, #4ade80, var(--accent) 45%, var(--accent-dark));
  color: #052e16;
  font: inherit;
  font-size: clamp(1.4rem, 6vw, 2rem);
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 0 0 10px rgba(34, 197, 94, 0.12), 0 20px 50px rgba(0, 0, 0, 0.45);
  transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s;
  user-select: none;
}
.gate-button svg { width: 28%; fill: currentColor; }
.gate-button:active { transform: scale(0.96); }
.gate-button:disabled { filter: grayscale(0.6) brightness(0.8); cursor: wait; }
.gate-button.success { box-shadow: 0 0 0 18px rgba(34, 197, 94, 0.25), 0 20px 50px rgba(0, 0, 0, 0.45); }
.gate-button.fail { background: radial-gradient(circle at 30% 25%, #fca5a5, #ef4444 45%, #b91c1c); color: #450a0a; }

.status { margin: 0; min-height: 1.4em; color: var(--muted); text-align: center; }
.status.error { color: var(--error); }
.gate-button.cooldown {
  background: radial-gradient(circle at 30% 25%, #64748b, #475569 45%, #334155);
  color: #cbd5e1;
  box-shadow: 0 0 0 10px rgba(100, 116, 139, 0.12), 0 20px 50px rgba(0, 0, 0, 0.45);
  filter: none;
  cursor: not-allowed;
}
.topbar-actions { display: flex; gap: 4px; }

/* User app: exactly one screen tall, the page itself never scrolls */
body.app { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
body.app main { min-height: 0; overflow-y: auto; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
body.app .topbar { padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: 12px; }
input::placeholder { color: transparent; }

/* Shorter phones: tighter form, field names move into the boxes */
@media (max-height: 860px) {
  body.app .card { padding: 18px 18px 14px; }
  body.app .card h1 { display: none; }
  body.app .tabs { margin-bottom: 14px; }
  body.app form, body.app .field-row { gap: 10px; }
  body.app input, body.app select { padding: 10px 12px; }
  body.app .primary { margin-top: 2px; padding: 11px; }
  body.app .error { margin-top: 8px; }
  body.app .lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  body.app input::placeholder { color: var(--muted); }
}
