/* ------------------------------------------------------------------
   Login layer: a paper card floating in the sky
   ------------------------------------------------------------------ */
.login {
  --lblue: #2a6fe0;          /* 💙 */
  --lblue-deep: #1b4fa8;
  position: fixed;
  inset: 0;
  z-index: 60;
  height: var(--vvh, 100dvh);
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  transition: opacity 0.75s ease 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.login__card {
  --tilt: -1.6deg;
  width: min(100%, 380px);
  transform: rotate(var(--tilt));
  animation: card-in 1s var(--ease-out) both;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(18px) rotate(calc(var(--tilt) + 2deg)); }
  to { opacity: 1; transform: translateY(0) rotate(var(--tilt)); }
}

.login__inner {
  position: relative;
  background: var(--paper);
  padding: 34px 26px 26px;
  border-radius: 3px;
  box-shadow:
    0 1px 1px rgba(20, 30, 50, 0.06),
    0 10px 24px -8px rgba(20, 30, 50, 0.25),
    0 30px 60px -24px rgba(20, 30, 50, 0.4);
  text-align: center;
  cursor: text;
}
.login__inner::after {                /* faint ruled-paper lines */
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(180deg, transparent 0 31px, rgba(31, 42, 58, 0.05) 31px 32px);
  pointer-events: none;
  border-radius: inherit;
}

.login__for {
  font-family: var(--font-hand);
  font-size: 1.55rem;
  color: var(--lblue);
  margin: 0 0 0.1em;
}
.login__hint {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--ink-2);
  margin: 0 0 22px;
}

/* the eight blanks: dd . mm . yyyy */
.cells {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 6px;
  padding: 10px 0 6px;
  user-select: none;
  -webkit-user-select: none;
}
.cell {
  width: 30px;
  height: 44px;
  border-bottom: 2px solid var(--ink-3);
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 2.1rem;
  line-height: 1;
  color: var(--ink);
  display: grid;
  place-items: center;
  position: relative;
  transition: border-color 0.25s ease, transform 0.25s var(--ease-out);
}
.cell.filled { border-color: var(--lblue-deep); color: var(--lblue-deep); animation: cell-pop 0.28s var(--ease-out); }
.cell.active { border-color: var(--lblue); }
.cell.active::after {                 /* blinking caret */
  content: "";
  position: absolute;
  bottom: 8px;
  width: 2px;
  height: 22px;
  background: var(--lblue);
  animation: caret 1.1s steps(2, start) infinite;
}
@keyframes caret { to { visibility: hidden; } }
@keyframes cell-pop { 0% { transform: scale(0.8); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
.sep {
  font-family: var(--font-hand);
  font-size: 2rem;
  color: var(--ink-3);
  line-height: 1;
  padding: 0 1px 8px;
}

/* real input sits over the cells so a tap on any cell opens the keyboard */
#code {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font-size: 16px;                    /* >= 16px: no focus zoom on iOS */
  opacity: 0;
  -webkit-appearance: none;
  appearance: none;
  z-index: 2;
}

/* the thread that stitches through the digits on success */
.stitch {
  position: absolute;
  left: -6px;
  right: -6px;
  top: 6px;
  width: calc(100% + 12px);
  height: 54px;
  pointer-events: none;
  z-index: 1;
}
.stitch path {
  fill: none;
  stroke: var(--lblue);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0.95;
}

.login__status {
  font-family: var(--font-hand);
  font-size: 1.3rem;
  color: var(--lblue);
  min-height: 1.4em;
  margin: 10px 0 0;
}

/* wrong code */
.login__inner.shake { animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}
.login.checking .cell.filled { color: var(--ink-2); }

/* right code: digits bloom red, the thread draws through them, the card lifts into the sky */
.login.is-ok .cell {
  color: var(--lblue);
  border-color: var(--lblue);
  animation: bloom 0.55s var(--ease-out) both;
  animation-delay: calc(var(--i) * 45ms);
}
.login.is-ok .cell.active::after { display: none; }
@keyframes bloom {
  0% { transform: scale(1); }
  45% { transform: scale(1.28) translateY(-5px); }
  100% { transform: scale(1); }
}
.login.is-ok .stitch path { transition: stroke-dashoffset 1s cubic-bezier(0.4, 0, 0.2, 1) 0.15s; stroke-dashoffset: 0; }
.login.is-ok .login__card { animation: card-lift 1.1s cubic-bezier(0.4, 0, 0.2, 1) 0.95s forwards; }
@keyframes card-lift {
  to { transform: translateY(-56px) scale(1.05) rotate(0deg); opacity: 0; }
}
body.is-open .login { opacity: 0; pointer-events: none; }
.login.login--skip { opacity: 0; pointer-events: none; transition: none; }
.login.login--skip .login__card { animation: none; }

/* the hero title is hidden while the card is on screen, then floats in */
body.is-locked .hero__title { opacity: 0; transform: translateY(14px); }
.hero__title { transition: opacity 1.1s ease 0.25s, transform 1.2s var(--ease-out) 0.25s; }

@media (prefers-reduced-motion: reduce) {
  .login__card, .login.is-ok .login__card, .login.is-ok .cell, .cell.filled { animation: none; }
  .login.is-ok .login__card { opacity: 0; }
}
