:root {
  --bg: #E3E5E1;          /* concrete */
  --ink: #1F2528;
  --muted: #5D666A;
  --field: #F3F4F1;
  --line: #C3C8C3;
  --face: #262C2F;        /* asphalt button face */
  --beacon: #F2A900;      /* gate warning lamp amber */
  --on-beacon: #1F2528;
  --error: #B3261E;
  --focus: #2457C5;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1B1F21;
    --ink: #E8EAE6;
    --muted: #98A1A4;
    --field: #252A2D;
    --line: #3A4246;
    --face: #30373B;
    --error: #FF8A80;
    --focus: #8AB4FF;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.screen {
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
}

.title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  font-stretch: 72%;
  font-variation-settings: "wdth" 72;
  letter-spacing: 0.01em;
}

/* Login */

.login {
  width: 100%;
  max-width: 340px;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-mark {
  width: 56px;
  height: 56px;
  color: var(--beacon);
  background: var(--face);
  border-radius: 16px;
  padding: 7px;
}

.login .title { font-size: 34px; margin-bottom: 18px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 15px; color: var(--muted); }

input {
  font: inherit;
  font-size: 18px;
  color: var(--ink);
  background: var(--field);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  width: 100%;
}

input:focus-visible, button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.error {
  margin: 0;
  min-height: 1.45em;
  font-size: 15px;
  color: var(--error);
}

.primary {
  font: inherit;
  font-weight: 650;
  font-size: 18px;
  color: var(--beacon);
  background: var(--face);
  border: 0;
  border-radius: 12px;
  padding: 15px;
  cursor: pointer;
}
.primary:disabled { opacity: 0.6; }

/* Gate */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.icon-button {
  width: 44px;
  height: 44px;
  margin-right: -10px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}
.icon-button svg { width: 24px; height: 24px; }

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding-bottom: 6vh;
  text-align: center;
}

.gate-button {
  --size: min(72vw, 46vh, 300px);
  position: relative;
  width: var(--size);
  height: var(--size);
  margin-bottom: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--beacon);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.ring circle { fill: none; stroke-width: 3; }
.ring-track { stroke: var(--line); }
.ring-progress {
  stroke: var(--beacon);
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  opacity: 0;
}
.gate-button[data-state="sending"] .ring-progress,
.gate-button[data-state="sent"] .ring-progress { opacity: 1; }

.face {
  position: absolute;
  inset: 9%;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--face);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08) inset, 0 10px 24px -12px rgba(20, 24, 26, 0.55);
  transition: transform 120ms ease, background-color 200ms ease, color 200ms ease;
}

.glyph { width: 46%; height: 46%; }

.gate-button:active .face { transform: scale(0.96); }

/* sending: a segment of the ring sweeps while we wait for the device */
.gate-button[data-state="sending"] .ring-progress {
  stroke-dashoffset: 75;
  transform-box: view-box;
  transform-origin: 50% 50%;
  animation: sweep 900ms linear infinite;
}
.gate-button[data-state="sending"] .glyph { opacity: 0.55; }

/* sent: the face turns into the gate's amber warning lamp and blinks while the cooldown ring drains */
.gate-button[data-state="sent"] .face {
  background: var(--beacon);
  color: var(--on-beacon);
  animation: beacon 1s steps(1, end) infinite;
}
.gate-button[data-state="sent"],
.gate-button[data-state="sending"] { cursor: default; }

.status {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}
.status.is-error { color: var(--error); }

.last {
  margin: 0;
  min-height: 1.45em;
  font-size: 15px;
  color: var(--muted);
}

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

@keyframes beacon {
  0% { background: var(--beacon); }
  60% { background: color-mix(in srgb, var(--beacon) 55%, var(--face)); }
}

@media (prefers-reduced-motion: reduce) {
  .gate-button[data-state="sending"] .ring-progress { animation: none; }
  .gate-button[data-state="sent"] .face { animation: none; }
  .face { transition: none; }
}

.sprite { position: absolute; }
