@font-face {
    font-family: "Hyperlegible Mono";
    src: url("fonts/hyperlegible-mono-500.woff2") format("woff2");
    font-weight: 500;
    font-display: swap;
}
@font-face {
    font-family: "Hyperlegible";
    src: url("fonts/hyperlegible-next-400.woff2") format("woff2");
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: "Hyperlegible";
    src: url("fonts/hyperlegible-next-700.woff2") format("woff2");
    font-weight: 700;
    font-display: swap;
}

:root {
    --ultramarine: #1F33B8;
    --deep: #14237F;        /* shadows cast on the page */
    --raised: #3446CF;      /* keys that are switched off */
    --raised-side: #24369F;
    --ink: #101A4D;         /* text on every cap */
    --paper: #FFFFFF;
    --muted: #C7CEFF;
    --white: #F5F7FF;
    --white-side: #B9C3EE;
    --sun: #FFC83D;
    --sun-side: #D9971A;
    --coral: #FF7A8F;
    --coral-side: #D04B63;
    --alert: #FFD3DA;
    --tray: #1A2CA4;
    --go: #23C26B;
    --go-side: #17924F;

    --mono: "Hyperlegible Mono", ui-monospace, "DejaVu Sans Mono", monospace;
    --sans: "Hyperlegible", system-ui, sans-serif;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

body {
    background: var(--ultramarine);
    color: var(--paper);
    font: 400 1.0625rem/1.5 var(--sans);
    -webkit-font-smoothing: antialiased;
}

html, body { height: 100%; }
body { overflow: hidden; }

.page {
    max-width: 46rem;
    height: 100dvh;
    margin: 0 auto;
    padding: clamp(1rem, 4vh, 2.75rem) 16px clamp(0.75rem, 3vh, 1.75rem);
    display: flex;
    flex-direction: column;
    gap: clamp(1rem, 3.2vh, 2rem);
}

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

:focus-visible {
    outline: 3px solid var(--sun);
    outline-offset: 3px;
}

.logo {
    display: block;
    height: 2.5rem;
    width: auto;
}

/* ---------- Keycaps: the shared physical language ---------- */
/* A cap is a colored top face with a darker side showing below it. */
.cap,
.key,
.toggle-face {
    --top: var(--white);
    --side: var(--white-side);
    --depth: 0.3rem;
    background: var(--top);
    color: var(--ink);
    border-radius: 0.55rem;
    box-shadow: inset 0 calc(var(--depth) * -1) 0 var(--side), 0 0.2rem 0 var(--deep);
}

/* ---------- The password ---------- */
.result {
    flex: 1;
    min-height: 0;          /* lets the tray shrink and scroll instead of the page */
    display: flex;
    flex-direction: column;
}

/* The caps sit in a recessed keyboard tray; long passwords scroll inside it. */
.password {
    --cap: clamp(2.2rem, 6.5vw, 3.25rem);
    flex: 1;
    min-height: calc(var(--cap) * 1.15 + 1.6rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-wrap: wrap;
    align-content: safe center;   /* centered like a display; "safe" keeps the top row reachable when it scrolls */
    gap: 0.75rem 1.1rem;
    padding: 0.8rem;
    margin: -0.8rem;        /* tray padding hangs outside the column so caps stay aligned */
    border-radius: 0.9rem;
    background: var(--tray);
    box-shadow: inset 0 0.25rem 0.5rem var(--deep);
    scrollbar-color: var(--raised) transparent;
    cursor: copy;
}
.password[data-size="m"] { --cap: 2.35rem; }
.password[data-size="s"] { --cap: 1.85rem; gap: 0.6rem 0.8rem; }
.password[data-size="xs"] { --cap: 1.5rem; gap: 0.5rem 0.6rem; }

.group {
    display: flex;
    gap: calc(var(--cap) * 0.1);
}

.cap {
    --depth: calc(var(--cap) * 0.11);
    display: inline-grid;
    place-items: center;
    width: var(--cap);
    height: calc(var(--cap) * 1.12);
    padding-bottom: var(--depth);
    border-radius: calc(var(--cap) * 0.17);
    font: 500 calc(var(--cap) * 0.6)/1 var(--mono);
}
.c-digit { --top: var(--sun); --side: var(--sun-side); }
.c-symbol { --top: var(--coral); --side: var(--coral-side); }

/* One moment of motion: the caps press in sequence when a password arrives. */
.press .cap {
    animation: press 240ms ease-out both;
    animation-delay: calc(min(var(--i), 48) * 12ms);
}
@keyframes press {
    40% {
        transform: translateY(calc(var(--depth) * 0.8));
        box-shadow: inset 0 calc(var(--depth) * -0.2) 0 var(--side), 0 0 0 var(--deep);
    }
}

.password:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }

.password-fallback {
    font: 500 1.25rem/1.4 var(--mono);
    color: var(--muted);
}

.result-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex: none;
    margin-top: 1.6rem;
}
.strength { color: var(--muted); }
.strength[data-level="weak"] { color: var(--alert); font-weight: 700; }

/* ---------- Keys (buttons) ---------- */
.key {
    font: 700 1rem/1 var(--sans);
    border: 0;
    padding: 0.8rem 1.4rem calc(0.8rem + var(--depth));
    cursor: pointer;
    transition: transform 80ms, box-shadow 80ms;
}
.key:not(:disabled):active {
    transform: translateY(calc(var(--depth) * 0.7));
    box-shadow: inset 0 calc(var(--depth) * -0.3) 0 var(--side), 0 0 0 var(--deep);
}
.key:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.key-sun { --top: var(--sun); --side: var(--sun-side); }
.btn-copy { min-width: 6.5rem; transition: background-color 120ms, box-shadow 120ms; }
/* Same green as the Caps Lock lights: the copy went through. */
.btn-copy.copied { --top: var(--go); --side: var(--go-side); }
.btn-generate {
    font-size: 1.125rem;
    min-width: 12rem;
    padding-block: 1rem calc(1rem + var(--depth));
}

.btn-quiet {
    font: 700 1rem/1 var(--sans);
    background: none;
    border: 0;
    color: var(--muted);
    text-decoration: underline;
    text-underline-offset: 3px;
    padding: 0.75rem 0.5rem;
    cursor: pointer;
}
.btn-quiet:hover { color: var(--paper); }

/* ---------- Options ---------- */
.options {
    display: grid;
    gap: clamp(0.9rem, 2.4vh, 1.5rem);
}
.field {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem 0.875rem;
    border: 0;
    padding: 0;
}
.field-label {
    font-weight: 700;
    min-width: 6.5rem;
    float: left;
}

.length input[type="range"] {
    flex: 1 1 12rem;
    appearance: none;
    height: 0.6rem;
    border-radius: 0.3rem;
    background: var(--deep);
    cursor: pointer;
}
.length input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 1.6rem;
    height: 1.75rem;
    border-radius: 0.4rem;
    background: var(--sun);
    box-shadow: inset 0 -0.25rem 0 var(--sun-side);
}
.length input[type="range"]::-moz-range-thumb {
    width: 1.6rem;
    height: 1.75rem;
    border: 0;
    border-radius: 0.4rem;
    background: var(--sun);
    box-shadow: inset 0 -0.25rem 0 var(--sun-side);
}
.length input[type="number"] {
    width: 5.5rem;
    font: 500 1.125rem var(--mono);
    color: var(--ink);
    background: var(--white);
    border: 0;
    border-radius: 0.45rem;
    padding: 0.45rem 0.6rem 0.6rem;
    box-shadow: inset 0 0.2rem 0 var(--white-side);
}

/* Toggles behave like keys with a Caps Lock light: lit and colored when on. */
.toggle input {
    position: absolute;
    opacity: 0;
}
.toggle-face {
    --top: var(--raised);
    --side: var(--raised-side);
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--paper);
    font: 500 1.0625rem/1 var(--mono);
    padding: 0.7rem 0.95rem calc(0.7rem + var(--depth));
    cursor: pointer;
    user-select: none;
    transition: transform 80ms;
}
.toggle-face::before {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--deep);
    flex: none;
}
.toggle input:checked + .toggle-face {
    color: var(--ink);
    transform: translateY(0.12rem);
    box-shadow: inset 0 -0.18rem 0 var(--side), 0 0.08rem 0 var(--deep);
}
.toggle input:checked + .toggle-face::before { background: var(--go); box-shadow: 0 0 0.4rem var(--go); }
.toggle[data-kind="letter"] input:checked + .toggle-face { --top: var(--white); --side: var(--white-side); }
.toggle[data-kind="digit"] input:checked + .toggle-face { --top: var(--sun); --side: var(--sun-side); }
.toggle[data-kind="symbol"] input:checked + .toggle-face { --top: var(--coral); --side: var(--coral-side); }
.toggle input:focus-visible + .toggle-face {
    outline: 3px solid var(--sun);
    outline-offset: 3px;
}
.toggle-wide { justify-self: start; }
.toggle-wide .toggle-face { font-family: var(--sans); font-weight: 700; }
.sample {
    font: 500 1rem var(--mono);
    opacity: 0.75;
    white-space: nowrap;
}

.error {
    color: var(--alert);
    font-weight: 700;
}
.error:empty { display: none; }

.actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* Privacy note: the one promise worth stating, set like a key legend. */
.privacy {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    background: var(--tray);
    color: var(--muted);
    font-size: 0.9375rem;
    line-height: 1.4;
}
.privacy svg {
    flex: none;
    width: 2rem;
    height: 2rem;
}
.privacy strong {
    display: block;
    color: var(--paper);
    font-size: 1rem;
}
.privacy code { font-family: var(--mono); color: var(--sun); }

@media (max-width: 480px) {
    .field-label { min-width: 4.75rem; }
    .length input[type="range"] { flex-basis: 5rem; }
    .strength { font-size: 0.9375rem; }
    .types .field-label { min-width: 100%; }
    .toggle-face { padding-inline: 0.75rem; gap: 0.45rem; }
    .privacy { font-size: 0.875rem; padding: 0.6rem 0.8rem; }
    .privacy svg { width: 1.6rem; height: 1.6rem; }
    .result-bar { align-items: flex-start; }
    .btn-generate { min-width: 0; flex: 1; }
}

/* Short screens: smaller caps so more rows fit in the tray. */
@media (max-height: 760px) {
    .password { --cap: clamp(1.9rem, 6vw, 2.5rem); }
    .password[data-size="m"] { --cap: 2rem; }
}

/* Too short to fit everything (landscape phones): let the page scroll after all. */
@media (max-height: 560px) {
    body { overflow: auto; }
    .page { height: auto; }
    .password { max-height: 40vh; }
}

@media (prefers-reduced-motion: reduce) {
    .press .cap { animation: none; }
    .key, .toggle-face { transition: none; }
}
