/* The password generator with the shuffling characters: a dark card of an invented password manager on a near black
   page with two soft lights and a little grain. The password sits in a recessed well; its characters are spans that
   the script shuffles and lands one by one. A light on the card's edge (--lx, --ly) goes where the action is. */
:root {
  --page: #07080b;          /* the page */
  --card: #11131a;          /* the card, at the top */
  --card-low: #0c0e13;      /* the card, at the bottom */
  --well: #08090d;          /* the recessed well of the password */
  --ink: #eceef4;           /* letters and titles */
  --muted: #868c9b;         /* small words */
  --faint: #3a3f4c;         /* empty bars, tracks */
  --accent: #7c95ff;        /* numbers, the light, the slider */
  --warm: #ffb45e;          /* symbols, a weak password */
  --button: #f1f2f6;        /* the Copy button */
  --button-ink: #0b0c10;    /* the words on it */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

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

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

/* the page: a cold light above the card, a warm one below, and grain */
.stage {
  position: relative;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: hidden;
  background:
    radial-gradient(60% 45% at 38% 22%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
    radial-gradient(45% 35% at 68% 86%, color-mix(in srgb, var(--warm) 7%, transparent), transparent 70%),
    var(--page);
}

.stage::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.5 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------------------------------------------------------------- the card */
.gen {
  --lx: 50%;
  --ly: 0%;
  --glow: 1;
  position: relative;
  z-index: 1;
  width: min(92vw, 368px);
  border-radius: 22px;
  background: linear-gradient(180deg, var(--card), var(--card-low));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 0 0 1px rgba(255, 255, 255, 0.055),
    0 1px 2px rgba(0, 0, 0, 0.5),
    0 14px 28px -10px rgba(0, 0, 0, 0.65),
    0 44px 90px -24px rgba(0, 0, 0, 0.8);
  opacity: 0;
}

/* a faint light on the surface and a brighter one on the 1px edge, both at the same place */
.gen__spot,
.gen__edge {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: var(--glow);
}

.gen__spot {
  background: radial-gradient(240px circle at var(--lx) var(--ly), color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%);
}

.gen__edge {
  padding: 1px;
  background: radial-gradient(170px circle at var(--lx) var(--ly), color-mix(in srgb, var(--accent) 75%, white), transparent 72%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}

.gen__body {
  position: relative;
  padding: clamp(14px, 3.6vh, 22px) clamp(14px, 4.6vw, 22px) clamp(14px, 3.6vh, 20px);
  display: grid;
  gap: clamp(9px, 2.5vh, 15px);
}

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

.gen__app {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.gen__logo {
  width: 22px;
  height: 22px;
  flex: none;
  filter: drop-shadow(0 2px 6px color-mix(in srgb, var(--accent) 40%, transparent));
}

.gen__title {
  font-size: 14.5px;
  font-weight: 600;
  font-variation-settings: 'wdth' 104;
  white-space: nowrap;
}

.gen__site {
  font-size: 11.5px;
  color: var(--muted);
  padding: 4px 9px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- the well */
.gen__well {
  position: relative;
  height: clamp(58px, 15vh, 82px);
  display: flex;
  align-items: center;
  padding: 0 clamp(12px, 3.4vw, 16px);
  border-radius: 14px;
  background: var(--well);
  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.7),
    inset 0 0 0 1px rgba(255, 255, 255, 0.045),
    0 1px 0 rgba(255, 255, 255, 0.04);
  overflow: hidden;
  cursor: pointer;
}

/* a faint reflection along the top of the well, like a pane of dark glass */
.gen__well::after {
  content: '';
  position: absolute;
  left: 10%;
  right: 10%;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.09), transparent);
  pointer-events: none;
}

.gen__pw {
  position: relative;
  z-index: 1;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  font-family: 'JetBrains Mono Variable', ui-monospace, monospace;
  font-size: clamp(15px, min(4.7vw, 4.3vh), 19px);
  font-weight: 500;
  line-height: 1.45;
  font-variant-ligatures: none;
}

.gen__pw .ch {
  display: inline-block;
  width: 1ch;
  text-align: center;
  color: var(--ink);
  transition: color 0.25s;
}

.gen__pw .ch.is-d {
  color: var(--accent);
  text-shadow: 0 0 14px color-mix(in srgb, var(--accent) 40%, transparent);
}

.gen__pw .ch.is-s {
  color: var(--warm);
  text-shadow: 0 0 14px color-mix(in srgb, var(--warm) 35%, transparent);
}

.gen__pw .ch.is-scr {
  color: #5b6172;
  transition: none;
}

/* the selection that sweeps over the password on Copy */
.gen__sel {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  border-radius: 5px;
  background: color-mix(in srgb, var(--accent) 26%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent);
  transform-origin: 0 50%;
  transform: scaleX(0);
  opacity: 0;
}

/* a diagonal glint that crosses the well when a new password lands */
.gen__sheen {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
  border-radius: inherit;
}

.gen__sheen-band {
  position: absolute;
  top: -40%;
  left: 0;
  width: 70px;
  height: 180%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.07), transparent);
  transform: translateX(-120px) rotate(18deg);
}

/* ---------------------------------------------------------------- the strength */
.gen__meter {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}

.gen__bars {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.gen__bars i {
  height: 4px;
  border-radius: 4px;
  background: var(--faint);
  transition: background-color 0.35s, box-shadow 0.35s;
}

.gen__bars i:nth-child(2) { transition-delay: 0.05s; }
.gen__bars i:nth-child(3) { transition-delay: 0.1s; }
.gen__bars i:nth-child(4) { transition-delay: 0.15s; }

.gen__meter[data-level='1'] i:nth-child(-n+1),
.gen__meter[data-level='2'] i:nth-child(-n+2) {
  background: var(--warm);
}

.gen__meter[data-level='3'] i:nth-child(-n+3),
.gen__meter[data-level='4'] i:nth-child(-n+4) {
  background: var(--accent);
}

.gen__meter[data-level='4'] i {
  box-shadow: 0 0 10px -2px color-mix(in srgb, var(--accent) 70%, transparent);
}

.gen__grade {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12.5px;
  white-space: nowrap;
}

.gen__word {
  display: inline-block;
  font-weight: 600;
  min-width: 4.6em;
  text-align: right;
}

.gen__bits {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- the length */
.gen__row {
  display: grid;
  grid-template-columns: auto 1fr 2.2em;
  align-items: center;
  gap: 14px;
}

.gen__k {
  font-size: 13px;
  color: var(--muted);
}

.gen__slider {
  --p: 0.333;
  position: relative;
  height: 24px;
  cursor: pointer;
  touch-action: none;
  outline: none;
}

.gen__track {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 4px;
  margin-top: -2px;
  border-radius: 4px;
  background: var(--faint);
  overflow: hidden;
}

.gen__fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 55%, var(--faint)), var(--accent));
  transform-origin: 0 50%;
  transform: scaleX(var(--p));
}

.gen__thumb {
  position: absolute;
  top: 50%;
  left: calc(var(--p) * (100% - 18px));
  width: 18px;
  height: 18px;
  margin-top: -9px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffffff, #d9dce6);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25), 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 0 0 color-mix(in srgb, var(--accent) 30%, transparent);
  transition: box-shadow 0.3s, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.gen__slider.is-active .gen__thumb {
  transform: scale(1.12);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25), 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 0 6px color-mix(in srgb, var(--accent) 22%, transparent);
}

.gen__slider:focus-visible .gen__thumb {
  box-shadow: 0 0 0 2px var(--accent), 0 2px 6px rgba(0, 0, 0, 0.5);
}

.gen__len {
  display: inline-block;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ---------------------------------------------------------------- the switches */
.gen__opts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.gen__opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: clamp(36px, 8vh, 42px);
  padding: 0 10px 0 12px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.3s, background-color 0.3s;
}

.gen__opt.is-on {
  color: var(--ink);
}

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

.gen__sw {
  position: relative;
  width: 28px;
  height: 17px;
  border-radius: 999px;
  background: var(--faint);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.45);
  transition: background-color 0.3s;
}

.gen__opt.is-on .gen__sw {
  background: var(--accent);
}

.gen__knob {
  position: absolute;
  left: 2px;
  top: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  transition: transform 0.45s cubic-bezier(0.34, 1.7, 0.64, 1), width 0.2s;
}

.gen__opt.is-on .gen__knob {
  transform: translateX(11px);
}

/* ---------------------------------------------------------------- the buttons */
.gen__actions {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
}

.gen__regen,
.gen__copy {
  height: clamp(44px, 10vh, 52px);
  border: 0;
  padding: 0;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.gen__regen:focus-visible,
.gen__copy:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.gen__regen {
  width: clamp(44px, 10vh, 52px);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.025));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 0 0 1px rgba(255, 255, 255, 0.07), 0 4px 12px -4px rgba(0, 0, 0, 0.6);
  color: var(--ink);
  display: grid;
  place-items: center;
  transition: background-color 0.3s;
}

.gen__regen-icon {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.gen__copy {
  position: relative;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff, var(--button));
  color: var(--button-ink);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.12), 0 6px 18px -6px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.2);
  overflow: hidden;
}

.gen__copy-face {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 100%;
}

.gen__copy-words {
  display: inline-block;
  font-size: 14px;
  font-weight: 600;
  font-variation-settings: 'wdth' 100;
  transition: font-variation-settings 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.gen__copy-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
}

.gen__check {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

/* how long until the clipboard clears: a thin line at the bottom of the button that runs out */
.gen__clear {
  position: absolute;
  left: 22px;
  right: 22px;
  bottom: 7px;
  height: 2px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--button-ink) 22%, transparent);
  transform-origin: 0 50%;
  transform: scaleX(0);
}

@media (hover: hover) {
  .gen__opt:hover {
    background: rgba(255, 255, 255, 0.055);
  }

  .gen__regen:hover {
    background-color: rgba(255, 255, 255, 0.05);
  }

  .gen__copy:hover .gen__copy-words {
    font-variation-settings: 'wdth' 112;
  }

  .gen__slider:hover .gen__thumb {
    transform: scale(1.08);
  }
}

@media (prefers-reduced-motion: reduce) {
  .gen__knob,
  .gen__thumb,
  .gen__copy-words {
    transition: none;
  }
}
