/* Code box 1.0.0 (house standard, 2026-11-17). Pairs with code-box.js. GLITCH- is printed in the box and reads as filled
   in; the person types the rest, the hyphens fill in, and the empty places stay blank. The password box beside it has
   the same size and colors, with the eye button inside.

   Colors come from the page's ramp. Set these on any ancestor (or on .codebox / .pwbox with a more specific selector):
     --cb-fill     box ground (dark site: ramp step 3; light site: white or a pale tint)
     --cb-ink      text, including the printed GLITCH- (dark: step 6; light: step 1)
     --cb-quiet    the eye at rest, 4.5:1 or better on --cb-fill (dark: step 5; light: step 4)
     --cb-hover    the eye's ground on hover and focus (one step lighter than --cb-fill on a dark site)
     --cb-edge     edge at rest
     --cb-ring     focus ring and the edge when the code is complete
     --cb-bad      error edge (the ramp's pop), shown when the input has aria-invalid="true"
     --cb-sheen    the glint that crosses the box once when the code is complete
   Defaults are the slate ramp (hue 210): #08121C #101D2A #1E2E3E #374A5D #8DA2B6 #CFD9E3, pop #E3A64F.
   The boxes are a plain fill, so they sit inside a glass panel with no blur inside blur. Add .codebox--glass only
   when a box sits straight on a photograph. Corners are the control tier (3px). Code text 22px, 19px on a phone. */

.codebox,
.pwbox {
  position: relative;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  width: 100%;
  min-height: 58px;
  margin: 0;
  background: var(--cb-fill, #1E2E3E);
  color: var(--cb-ink, #CFD9E3);
  border: 1px solid var(--cb-edge, rgb(207 217 227 / 0.28));
  border-radius: 3px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.06);
  text-align: left;
  transition: border-color 0.18s ease;
}
.codebox {
  --cb-track: 0.16em;
  padding: 12px 14px;
  overflow: hidden;
  font: 600 22px/1.6 ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "Roboto Mono", "Liberation Mono", monospace;
  letter-spacing: var(--cb-track);
  cursor: text;
}

.codebox:focus-within,
.pwbox:focus-within {
  background: var(--cb-fill, #1E2E3E);
  color: var(--cb-ink, #CFD9E3);
  border-color: var(--cb-ring, #8DA2B6);
  outline: 2px solid var(--cb-ring, #8DA2B6);
  outline-offset: 2px;
}
.codebox.is-done {
  background: var(--cb-fill, #1E2E3E);
  color: var(--cb-ink, #CFD9E3);
  border-color: var(--cb-ring, #8DA2B6);
}
.codebox:has(.codebox__in[aria-invalid="true"]),
.pwbox:has(.pwbox__in[aria-invalid="true"]) {
  background: var(--cb-fill, #1E2E3E);
  color: var(--cb-ink, #CFD9E3);
  border-color: var(--cb-bad, #E3A64F);
  outline: 2px solid var(--cb-bad, #E3A64F);
  outline-offset: 2px;
}
.codebox:has(.codebox__in:disabled),
.pwbox:has(.pwbox__in:disabled) {
  background: var(--cb-fill, #1E2E3E);
  color: var(--cb-quiet, #8DA2B6);
  cursor: default;
}

/* GLITCH- is printed: the same color as the typed text, so it reads as filled in. It cannot be deleted. */
.codebox .codebox__pre {
  flex: none;
  background: transparent;
  color: var(--cb-ink, #CFD9E3);
  font-weight: 400;
  user-select: none;
}

.codebox .codebox__in {
  flex: 1 1 auto;
  box-sizing: border-box;
  display: block;
  width: auto;
  min-width: 0;
  height: 1.6em;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  box-shadow: none;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  color: var(--cb-ink, #CFD9E3);
  caret-color: var(--cb-ink, #CFD9E3);
  font: inherit;
  letter-spacing: inherit;
  line-height: 1.6em;
  text-align: left;
  text-transform: none;
  text-indent: 0;
}
.codebox .codebox__in:disabled,
.pwbox .pwbox__in:disabled {
  background: transparent;
  color: var(--cb-quiet, #8DA2B6);
  -webkit-text-fill-color: var(--cb-quiet, #8DA2B6);
  opacity: 1;
}
.codebox .codebox__in::selection,
.pwbox .pwbox__in::selection {
  background: var(--cb-ring, #8DA2B6);
  color: var(--cb-fill, #1E2E3E);
}
/* A password manager fill keeps the box colors (Chrome paints its own fill on autofilled inputs). */
.codebox .codebox__in:-webkit-autofill,
.codebox .codebox__in:-webkit-autofill:hover,
.codebox .codebox__in:-webkit-autofill:focus,
.pwbox .pwbox__in:-webkit-autofill,
.pwbox .pwbox__in:-webkit-autofill:hover,
.pwbox .pwbox__in:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--cb-ink, #CFD9E3);
  caret-color: var(--cb-ink, #CFD9E3);
  transition: background-color 600000s 0s, color 600000s 0s;
}

/* The check: drawn, not a glyph, so it looks the same on every system. */
.codebox .codebox__ok {
  flex: none;
  width: 8px;
  height: 15px;
  margin: 0 6px 0 10px;
  border-right: 3px solid var(--cb-ring, #8DA2B6);
  border-bottom: 3px solid var(--cb-ring, #8DA2B6);
  transform: translateY(-2px) rotate(45deg) scale(0.4);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.25s ease;
}
.codebox.is-done .codebox__ok {
  opacity: 1;
  transform: translateY(-2px) rotate(45deg) scale(1);
}

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

/* The glint: once, when the code becomes complete. */
.codebox::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(100deg, transparent 35%, var(--cb-sheen, rgb(207 217 227 / 0.16)) 50%, transparent 65%);
  transform: translateX(-110%);
  opacity: 0;
}
.codebox.is-done::before { animation: codebox-glint 0.75s ease-out 1; }
@keyframes codebox-glint {
  0% { transform: translateX(-110%); opacity: 1; }
  100% { transform: translateX(110%); opacity: 1; }
}

/* Password box with the eye. Monospace, so a shown password is easy to check (l and 1, O and 0). */
.pwbox { padding: 0 4px 0 14px; }
.pwbox .pwbox__in {
  flex: 1 1 auto;
  box-sizing: border-box;
  display: block;
  width: auto;
  min-width: 0;
  height: 56px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  box-shadow: none;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  color: var(--cb-ink, #CFD9E3);
  caret-color: var(--cb-ink, #CFD9E3);
  font: 400 20px/1.4 ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "Roboto Mono", "Liberation Mono", monospace;
  letter-spacing: 0.06em;
  text-align: left;
}
.pwbox .pwbox__eye {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--cb-quiet, #8DA2B6);
  cursor: pointer;
}
.pwbox .pwbox__eye:hover {
  background: var(--cb-hover, #2A3D50);
  color: var(--cb-ink, #CFD9E3);
}
.pwbox .pwbox__eye:focus-visible {
  background: var(--cb-hover, #2A3D50);
  color: var(--cb-ink, #CFD9E3);
  outline: 2px solid var(--cb-ring, #8DA2B6);
  outline-offset: -2px;
}
.pwbox .pwbox__eye[aria-pressed="true"] {
  background: transparent;
  color: var(--cb-ink, #CFD9E3);
}
.pwbox .pwbox__eye[aria-pressed="true"]:hover,
.pwbox .pwbox__eye[aria-pressed="true"]:focus-visible {
  background: var(--cb-hover, #2A3D50);
  color: var(--cb-ink, #CFD9E3);
}
.pwbox .pwbox__eye svg { display: block; width: 24px; height: 24px; }
.pwbox .pwbox__eye .pwbox__slash { display: none; }
.pwbox .pwbox__eye[aria-pressed="true"] .pwbox__slash { display: inline; }

/* The save checkbox. The label takes the panel's text color (it sets no background). 44px row for a finger. */
.codebox-save {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin: 0;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: normal;
  cursor: pointer;
}
.codebox-save input[type="checkbox"] {
  flex: none;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--cb-ring, #8DA2B6);
  cursor: pointer;
}
.codebox-save input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--cb-ring, #8DA2B6);
  outline-offset: 2px;
}

/* On a photograph only. Inside a glass panel, keep the plain fill. */
.codebox.codebox--glass {
  background: var(--cb-fill, #1E2E3E);
  color: var(--cb-ink, #CFD9E3);
}
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .codebox.codebox--glass {
    background: rgb(30 46 62 / 0.62);
    color: var(--cb-ink, #CFD9E3);
    -webkit-backdrop-filter: blur(12px) saturate(160%);
    backdrop-filter: blur(12px) saturate(160%);
  }
}

/* Light sites: put this class on any ancestor, or set the tokens yourself from the page ramp. */
.codebox-skin-light {
  --cb-fill: #FFFFFF;
  --cb-ink: #08121C;
  --cb-quiet: #4A5C6A;
  --cb-hover: #E4EAF0;
  --cb-edge: #8DA2B6;
  --cb-ring: #374A5D;
  --cb-bad: #9C6418;
  --cb-sheen: rgb(141 162 182 / 0.22);
}

@media (max-width: 480px) {
  .codebox {
    --cb-track: 0.12em;
    min-height: 54px;
    padding: 10px 12px;
    font-size: 19px;
  }
  .pwbox { min-height: 54px; padding-left: 12px; }
  .pwbox .pwbox__in { height: 52px; font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .codebox, .pwbox, .codebox .codebox__ok { transition: none; }
  .codebox.is-done::before { animation: none; }
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  .codebox.codebox--glass {
    background: var(--cb-fill, #1E2E3E);
    color: var(--cb-ink, #CFD9E3);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
