.gate {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  padding:
    calc(env(safe-area-inset-top, 0px) + 3.25rem)
    1.5rem
    calc(env(safe-area-inset-bottom, 0px) + 1.5rem);
  background: var(--page);
  overflow: hidden;
  transition: opacity 0.4s ease;
}
body.leaving .gate { opacity: 0; }

.gate__head, .keypad, .gate__actions { position: relative; z-index: 1; }

.gate__head {
  width: 100%;
  max-width: 22rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* Ổ khóa */
.gate__badge {
  width: 4.75rem;
  height: 4.75rem;
  margin-bottom: 1rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--emblem-bg);
  color: var(--accent);
  box-shadow: 0 8px 28px -6px var(--emblem-glow);
}
.lock { display: block; }
.lock--open { display: none; }
.gate--ok .lock--closed { display: none; }
.gate--ok .lock--open { display: block; }

.gate__title {
  margin: 0;
  font-family: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  font-weight: 500;
  font-size: clamp(1.9rem, 8vw, 2.4rem);
  letter-spacing: 0.1em;
  line-height: 1.15;
  color: var(--text);
}
.gate__hint {
  margin: 0.4rem 0 1.25rem;
  font-size: 1rem;
  color: var(--text-soft);
}
.gate__hint.is-ok { color: var(--accent); font-weight: 600; }

/* 8 chấm */
.dots {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.7rem 1.35rem;
  border-radius: 999px;
  background: var(--pill-bg);
  box-shadow: 0 0 0 1px var(--line);
}
.dots span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--dot-empty);
  background: transparent;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}
.dots span.on {
  background: var(--dot-fill);
  border-color: var(--dot-fill);
  box-shadow: 0 0 8px var(--dot-glow);
  transform: scale(1.1);
}
.dots.is-error span { background: var(--error); border-color: var(--error); box-shadow: none; }
.dots.shake { animation: shake 0.4s ease; }
.gate.is-checking .dots span.on { animation: pulse 1s ease-in-out infinite; }

/* Chỗ giữ sẵn cho thông báo lỗi, để bố cục không nhảy */
.gate__slot {
  min-height: 3rem;
  margin-top: 0.75rem;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.gate__error {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background: var(--error-bg);
  color: var(--error);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.3;
}
.gate__error[hidden] { display: none; }
.gate__error::before {
  content: "!";
  flex: none;
  width: 1.1rem;
  height: 1.1rem;
  display: grid;
  place-items: center;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
}

/* Bàn phím số */
.keypad {
  width: 100%;
  max-width: 19rem;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem 1rem;
}
.key {
  height: clamp(52px, 8.5dvh, 64px);
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--key-bg);
  color: var(--key-text);
  font: 500 1.5rem/1 "Plus Jakarta Sans", system-ui, sans-serif;
  font-variant-numeric: lining-nums;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, background 0.12s ease, opacity 0.2s ease;
}
.key:active { transform: scale(0.94); background: var(--key-bg-active); }
.key:disabled { opacity: 0.5; cursor: default; transform: none; }
.key--util { background: transparent; }
.key--ghost { background: transparent; pointer-events: none; }

.gate__actions { width: 100%; display: flex; justify-content: center; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
