/* The password field: a soft grey field on a white page, with an eye at its end, four bars and four rules under
   it. */
:root {
  --page: #ffffff;          /* the page */
  --ink: #1c1b22;
  --muted: #7a7882;
  --field: #f4f3f0;         /* the field at rest */
  --line: #dcdad4;
  --accent: #6c47ff;        /* the caret, the focus and the iris */
  --ok: #16a34a;            /* a rule that is met */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Rubik Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

.pw {
  width: min(420px, 100%);
}

.pw__label {
  display: block;
  margin: 0 0 10px 4px;
  font-size: 15px;
  font-weight: 600;
}

/* ---------------------------------------------------------------- the field */
.pw__field {
  position: relative;
  height: 60px;
  border-radius: 16px;
  background: var(--field);
  box-shadow: 0 0 0 0 transparent;
  transition: background-color 0.25s, box-shadow 0.3s;
}

.pw__field:focus-within,
.pw__field.is-pretend {
  background: #ffffff;
  box-shadow: 0 0 0 2px var(--accent), 0 0 0 6px rgba(108, 71, 255, 0.16);
}

/* the real input: over the whole field, with its letters and its caret invisible */
.pw__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0 60px 0 18px;
  border: 0;
  border-radius: 16px;
  outline: none;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: transparent;
  font: 500 20px 'Rubik Variable', system-ui, sans-serif;
  cursor: text;
}

.pw__input::selection {
  background: transparent;
}

.pw__input::-ms-reveal {
  display: none;
}

/* what the input holds, drawn: the row fades at both ends when the password is longer than the field */
.pw__row {
  position: absolute;
  left: 6px;
  right: 56px;
  top: 0;
  bottom: 0;
  overflow: hidden;
  pointer-events: none;
  perspective: 240px;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 12px), transparent);
  mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 12px), transparent);
}

.pw__chars {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
}

/* a character: a box 40 pixels wide, moved by the script to the middle of its place in the row */
.ch {
  position: absolute;
  left: 0;
  top: 50%;
  display: grid;
  place-items: center;
  width: 40px;
  height: 32px;
  margin: -16px 0 0 -20px;
  transform-style: preserve-3d;
}

.ch > * {
  grid-area: 1 / 1;
}

.ch__glyph {
  font-size: 20px;
  font-weight: 500;
  line-height: 1;
  white-space: pre;
}

.ch__star {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.8;
  stroke-linecap: round;
}

.pw__caret {
  position: absolute;
  left: -1px;
  top: 50%;
  width: 2px;
  height: 26px;
  margin-top: -13px;
  border-radius: 1px;
  background: var(--accent);
  opacity: 0;
}

.pw__caret.is-on {
  opacity: 1;
  animation: blink 1.06s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .pw__caret.is-on {
    animation: none;
  }
}

@keyframes blink {
  0%, 46% {
    opacity: 1;
  }

  56%, 92% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

.pw__sel {
  position: absolute;
  left: 0;
  top: 50%;
  width: 0;
  height: 32px;
  margin-top: -16px;
  border-radius: 7px;
  background: rgba(108, 71, 255, 0.2);
  opacity: 0;
}

/* ---------------------------------------------------------------- the eye */
.pw__eye {
  position: absolute;
  right: 8px;
  top: 50%;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-top: -22px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .pw__eye:hover {
    background: rgba(28, 27, 34, 0.06);
  }
}

.pw__eye:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.pw__eye svg {
  width: 32px;
  height: 32px;
  overflow: visible;
}

.eye__white {
  fill: #ffffff;
}

.eye__iris {
  fill: var(--accent);
}

.eye__pupil {
  fill: var(--ink);
}

.eye__line,
.eye__lashes {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------------------------------------------------------------- the strength */
.pw__meter {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 16px 4px 0;
}

.pw__bars {
  position: relative;
  display: flex;
  flex: 1;
  gap: 6px;
  overflow: hidden;
  border-radius: 3px;
}

.pw__bars span {
  position: relative;
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: #ecebe7;
  overflow: hidden;
}

.pw__bars i {
  position: absolute;
  inset: 0;
  border-radius: 3px;
  background: #e5484d;
  transform: scaleX(0);
  transform-origin: 0 50%;
}

/* the shine that runs across the bars when the password becomes strong */
.pw__shine {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 60px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0));
  transform: translateX(-80px);
  pointer-events: none;
}

.pw__word-clip {
  display: block;
  min-width: 70px;
  overflow: hidden;
  text-align: right;
}

.pw__word {
  display: inline-block;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

/* ---------------------------------------------------------------- the rules */
.pw__rules {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  margin: 18px 4px 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
  color: var(--muted);
}

.rule {
  display: flex;
  align-items: center;
  gap: 9px;
  transition: color 0.3s;
}

.rule.is-met {
  color: var(--ink);
}

.rule__box {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  transition: background-color 0.25s, border-color 0.25s;
}

.rule.is-met .rule__box {
  border-color: var(--ok);
  background: var(--ok);
}

.rule__box svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: #ffffff;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
