/* ============================================
   CIPHER // ditherfield chrome
   Calm, exact Linear-style surfaces floating over
   the living dither canvas. Ordered dither is the
   accent language: fills, meters, edges, motion.
   Colour follows html[data-mode] and TWEENS (@property).
   ============================================ */

/* --- Animatable mode tokens ---------------------------------- */
@property --accent    { syntax: '<color>'; inherits: true; initial-value: #ff5d8f; }
@property --highlight { syntax: '<color>'; inherits: true; initial-value: #ffb38a; }
@property --mid       { syntax: '<color>'; inherits: true; initial-value: #b02e6c; }
@property --deep      { syntax: '<color>'; inherits: true; initial-value: #2a0d24; }
/* strength meter: fill extent + colour (animated) */
/* inherits: true so #strength::before sees the values set on #strength */
@property --p { syntax: '<percentage>'; inherits: true; initial-value: 0%; }
@property --c { syntax: '<color>'; inherits: true; initial-value: #ff6b5a; }

:root {
    /* mode: dusk (encrypt) is the default */
    --accent:    #ff5d8f;
    --highlight: #ffb38a;
    --mid:       #b02e6c;
    --deep:      #2a0d24;

    /* Ink + surfaces (near-opaque; the field peeks at the edges) */
    --ink:       #07070a;
    --surface-0: rgba(9, 9, 13, 0.94);
    --surface-1: rgba(14, 14, 20, 0.92);
    --surface-2: #181821;
    --surface-3: #21212d;
    --border:        rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.18);
    --hairline-top:  rgba(255, 255, 255, 0.07);

    /* Text. muted/dim hold >= 4.5:1 on every surface above */
    --text:  #f7f8f8;
    --muted: #9aa0ab;
    --dim:   #868b96;

    --mint:  #5ef2b0;
    --coral: #ff6b5a;
    --amber: #ffc861;
    --on-accent: #07070a;

    /* Radii: 16 / 12 / 8 + pill */
    --r-lg: 16px;
    --r-md: 12px;
    --r-sm: 8px;
    --r-pill: 999px;

    /* 4px spacing grid */
    --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px;
    --pad: var(--s5);
    --rail: 18px;          /* desktop: thread centre sits this far outside the card */
    --gutter: 28px;        /* left room for the thread */
    --tx: calc(-1 * var(--rail));   /* thread centre, relative to the card's padding box */
    --padl: var(--pad);    /* left padding of the step cards (phones leave room for the rail) */
    --gap: var(--s4);      /* space between the passphrase card and the compose card */
    --tabs-h: 53px;        /* docked mode switch: 4 + 44 + 4 + 1 hairline */
    --foot-h: 36px;        /* the "03" row; the thread's last node is derived from it */
    --sky: 0px;            /* phones: open sky between the header and the passphrase card */

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    /* Motion tokens */
    --ease-out: cubic-bezier(.22, 1, .36, 1);
    --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
    --dur-1: 140ms;
    --dur-2: 260ms;
    --dur-3: 520ms;
    --dur-mode: 700ms;

    /* Type */
    --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI Variable', 'Segoe UI', 'Inter', Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;

    /* Derived accent shades (plain fallbacks, upgraded below) */
    --accent-soft:   rgba(255, 93, 143, 0.16);
    --accent-glow:   rgba(255, 93, 143, 0.38);
    --accent-line:   rgba(255, 93, 143, 0.55);

    /* Bayer-ish 2x2 checker used as the dither texture */
    --dither: repeating-conic-gradient(var(--accent) 0% 25%, transparent 0% 50%);

    font-synthesis-weight: none;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    color-scheme: dark;
}

@supports (color: color-mix(in srgb, red, blue)) {
    :root {
        --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
        --accent-glow: color-mix(in srgb, var(--accent) 38%, transparent);
        --accent-line: color-mix(in srgb, var(--accent) 55%, transparent);
    }
}

@supports (transition-timing-function: linear(0, 1)) {
    :root {
        --ease-spring: linear(0, .009, .035 2.1%, .141, .281 6.7%, .723 12.9%, .938 16.7%, 1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%, 1.129 32.8%, 1.051 39.6%, 1.017 43.1%, .991, .977 51%, .974 53.8%, .975 57.1%, .997 69.8%, 1.003 76.9%, 1);
    }
}

/* Decrypt = tide. Everything that reads --accent re-tints. */
html[data-mode="decrypt"] {
    --accent:    #7c8cff;
    --highlight: #7fe7ff;
    --mid:       #3b44d8;
    --deep:      #0b1433;
    --accent-soft: rgba(124, 140, 255, 0.16);
    --accent-glow: rgba(124, 140, 255, 0.38);
    --accent-line: rgba(124, 140, 255, 0.55);
}
@supports (color: color-mix(in srgb, red, blue)) {
    html[data-mode="decrypt"] {
        --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
        --accent-glow: color-mix(in srgb, var(--accent) 38%, transparent);
        --accent-line: color-mix(in srgb, var(--accent) 55%, transparent);
    }
}

/* The tween: flipping data-mode glides every accent together */
html {
    transition:
        --accent    var(--dur-mode) var(--ease-out),
        --highlight var(--dur-mode) var(--ease-out),
        --mid       var(--dur-mode) var(--ease-out),
        --deep      var(--dur-mode) var(--ease-out);
    background: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* --- Base --- */
body {
    margin: 0;
    padding: calc(var(--safe-top) + var(--s2)) 0 calc(var(--s6) + var(--safe-bottom));
    background-color: transparent;
    color: var(--text);
    font: 16px/1.55 var(--font-ui);
    overflow-x: hidden;
    min-height: 100vh;
    min-height: 100dvh;
}

main {
    max-width: 520px;
    margin: 0 auto;
    padding: 0 var(--s4) 0 var(--gutter);
    position: relative;
    z-index: 2;
    /* the waiting tab panel sits 20px off to the side; don't let it
       widen the page. clip (not hidden) keeps main from becoming a
       scroll container, and the thread lives inside the padding box. */
    overflow-x: clip;
}

/* Tiny uppercase eyebrows */
label,
.settings-title {
    display: block;
    font-size: 11px;
    font-weight: 600;
    line-height: 16px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin: 0;
}

/* ============================================
   BACKGROUND: the canvas is the whole story
   ============================================ */

#ditherField {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    z-index: 0;
    pointer-events: none;
    image-rendering: pixelated;
}

/* ============================================
   ENTRANCE: staggered rise
   ============================================ */

@keyframes rise {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: none; }
}

main > * {
    animation: rise var(--dur-3) var(--ease-out) backwards;
}
main > :nth-child(1) { animation-delay: 0ms; }
main > :nth-child(2) { animation-delay: 60ms; }
main > :nth-child(3) { animation-delay: 120ms; }
main > :nth-child(4) { animation-delay: 180ms; }
main > :nth-child(5) { animation-delay: 240ms; }

/* ============================================
   HEADER
   ============================================ */

header {
    display: flex;
    align-items: center;
    gap: var(--s3);
    padding: var(--s5) 0 var(--s5);
}

.logo-icon {
    position: relative;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    padding: 9px;
    border-radius: var(--r-md);
    background-color: color-mix(in srgb, var(--accent) 14%, var(--ink));
    background-image: var(--dither);
    background-size: 4px 4px;
    border: 1px solid var(--accent-line);
    box-shadow: 0 0 24px -4px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}
/* knock the dither back so the lock stays crisp */
.logo-icon::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--accent) 22%, var(--ink)) 40%, transparent 100%);
    opacity: 0.85;
}
.logo-icon svg { position: relative; width: 100%; height: 100%; }
.logo-icon svg rect[fill="white"] { fill: var(--text); }
.logo-icon svg rect[stroke="white"] { stroke: var(--text); }
.logo-icon svg rect[fill="black"] { fill: var(--accent); }

h1 {
    font-size: 20px;
    font-weight: 650;
    line-height: 1.1;
    margin: 0;
    letter-spacing: -0.03em;
    font-family: var(--font-ui);
}

.version {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1;
    color: var(--muted);
    letter-spacing: 0.02em;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: var(--r-pill);
    background: rgba(255, 255, 255, 0.03);
}

/* ============================================
   CARDS
   ============================================ */

.settings,
.compose,
.result-card {
    position: relative;
    background: var(--surface-1);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow:
        inset 0 1px 0 var(--hairline-top),
        0 1px 2px rgba(0, 0, 0, 0.5),
        0 16px 40px -16px rgba(0, 0, 0, 0.6);
}

.settings {
    padding: var(--pad) var(--pad) var(--pad) var(--padl);
    margin-top: var(--sky);
    margin-bottom: var(--gap);
}

.settings-header { margin-bottom: var(--s4); }

.field-head {
    display: flex;
    align-items: center;
    gap: var(--s2);
}

/* mono step markers */
.step {
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 16px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--accent);
}

.settings-subtitle {
    margin: var(--s2) 0 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--muted);
}

.settings-content {
    display: flex;
    flex-direction: column;
    gap: var(--s3);
}

.passphrase-actions {
    display: flex;
    gap: var(--s2);
}
.passphrase-actions .btn-subtle { flex: 1; }

/* ============================================
   THE THREAD: a dithered line linking 01 -> 02 -> 03
   t1 hangs off the passphrase card and bridges the gap to node 02.
   The 02 -> 03 segment is a pair of pseudo-elements on .message-card
   that span the grid rows from the top of the compose card down to the
   03 row, so it ends where the 03 node is (both derive from --foot-h).
   ============================================ */

.thread,
.message-card::before,
.message-card::after {
    position: absolute;
    left: calc(var(--tx) - 2px);
    width: 4px;
    pointer-events: none;
}
.thread,
.message-card::before {
    background: repeating-conic-gradient(rgba(255, 255, 255, 0.16) 0% 25%, transparent 0% 50%) 0 0 / 4px 4px;
}
.message-card::after {
    background: repeating-conic-gradient(var(--accent) 0% 25%, color-mix(in srgb, var(--accent) 45%, transparent) 0% 50%) 0 0 / 4px 4px;
    clip-path: inset(0 0 100% 0);
    transition: clip-path var(--dur-3) var(--ease-out);
}
.thread i {
    position: absolute;
    left: 0; top: 0;
    width: 100%;
    height: 0;
    background: repeating-conic-gradient(var(--accent) 0% 25%, color-mix(in srgb, var(--accent) 45%, transparent) 0% 50%) 0 0 / 4px 4px;
    transition: height var(--dur-3) var(--ease-out);
}
.t1 { top: calc(var(--pad) + 8px); bottom: calc(-1 * (var(--gap) + 2px)); }   /* ends at the compose card's top edge */

/* 02 -> 03: grid items spanning field-head..foot-row */
.message-card {
    display: grid;
    grid-template-columns: 0 minmax(0, 1fr);
}
.message-card > * { grid-column: 2; }
.message-card > .field-head { grid-row: 1; }
.message-card > textarea    { grid-row: 2; }
.message-card > .foot-row   { grid-row: 3; }
.message-card > .action-btn { grid-row: 4; }
.message-card > .hint       { grid-row: 5; }
.message-card::before,
.message-card::after {
    content: '';
    position: static;
    grid-column: 1;
    grid-row: 1 / 4;
    align-self: stretch;
    justify-self: start;
    /* starts at the top edge of the compose card (where t1 ends), ends at the 03 node */
    margin-left: calc(var(--tx) - 2px - var(--padl));
    margin-top: calc(-1 * (var(--tabs-h) + var(--pad)));
    margin-bottom: calc((var(--foot-h) - 1px) / 2);
}

/* nodes: 01 / 02 sit level with their step labels, 03 with the foot row */
.settings::before,
.message-card .field-head::before,
.foot-row::before {
    content: '';
    position: absolute;
    left: calc(var(--tx) - 5px);
    width: 10px;
    height: 10px;
    border-radius: 3px;
    background: var(--ink);
    border: 1px solid var(--border-strong);
    box-shadow: 0 0 0 3px var(--ink);
    transition: background-color var(--dur-2) var(--ease-out), border-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
    z-index: 1;
}
.settings::before { top: calc(var(--pad) + 3px); }
.message-card .field-head { position: relative; }
.message-card .field-head::before { top: 3px; left: calc(var(--tx) - 5px - var(--padl)); }
.foot-row::before { top: calc((var(--foot-h) - 1px) / 2 - 5px); left: calc(var(--tx) - 5px - var(--padl)); }

main:has(#pass:not(:placeholder-shown)) .settings::before,
main:has(#pass:not(:placeholder-shown)) .message-card .field-head::before,
main:has(.tab-content.active textarea:not(:placeholder-shown)) .foot-row::before {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--ink), 0 0 12px var(--accent-glow);
}

main:has(#pass:not(:placeholder-shown)) .t1 i { height: 100%; }
main:has(.tab-content.active textarea:not(:placeholder-shown)) .message-card::after { clip-path: inset(0); }

/* ============================================
   COMPOSE: mode switch docked into the message card
   ============================================ */

.compose {
    z-index: 1;
    margin-bottom: 0;
}

.tabs-nav {
    --tpl: var(--s1);
    --tpr: var(--s1);
    height: var(--tabs-h);
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    padding: var(--s1) var(--tpr) var(--s1) var(--tpl);
    background: var(--surface-0);
    border-bottom: 1px solid var(--border);
    border-radius: calc(var(--r-lg) - 1px) calc(var(--r-lg) - 1px) 0 0;
}

.tab-indicator {
    position: absolute;
    z-index: 0;
    top: var(--s1);
    bottom: var(--s1);
    left: var(--tpl);
    width: calc((100% - var(--tpl) - var(--tpr)) / 2);
    border-radius: calc(var(--r-lg) - 5px);
    background-color: color-mix(in srgb, var(--accent) 20%, var(--ink));
    background-image: var(--dither);
    background-size: 4px 4px;
    box-shadow:
        inset 0 0 0 1px var(--accent-line),
        inset 0 1px 0 rgba(255, 255, 255, 0.12),
        0 0 20px -6px var(--accent-glow);
    transform: translateX(0);
    transition: transform var(--dur-3) var(--ease-out);
}
/* soften dither under the label so the text stays crisp */
.tab-indicator::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 14%, var(--ink)) 0%, color-mix(in srgb, var(--accent) 24%, var(--ink)) 100%);
    opacity: 0.78;
}
html[data-mode="decrypt"] .tab-indicator { transform: translateX(100%); }

.tab-btn {
    position: relative;
    z-index: 1;
    appearance: none;
    background: transparent;
    border: 0;
    border-radius: calc(var(--r-lg) - 5px);
    color: var(--muted);
    padding: var(--s3);
    min-height: 44px;
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    cursor: pointer;
    transition: color var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-spring);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: #ffffff; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45); }
.tab-btn:active { transform: scale(0.97); }

/* ----- panels cross-fade inside a single grid cell ----- */
.stage {
    display: grid;
}
.tab-content {
    grid-area: 1 / 1;
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
    transform: translateX(20px);
    transition:
        opacity var(--dur-2) var(--ease-out),
        transform var(--dur-3) var(--ease-out),
        visibility 0s linear var(--dur-2);
}
html[data-mode="decrypt"] .tab-content:not(.active) { transform: translateX(-20px); }
.tab-content.active {
    visibility: visible;
    pointer-events: auto;
    opacity: 1;
    transform: none;
    transition:
        opacity var(--dur-3) var(--ease-out) 60ms,
        transform var(--dur-3) var(--ease-out),
        visibility 0s;
}

.message-card {
    position: relative;
    padding: var(--pad) var(--pad) var(--pad) var(--padl);
}

.message-card .field-head { margin-bottom: var(--s3); }

textarea {
    display: block;
    width: 100%;
    min-height: 148px;
    resize: vertical;
    background: transparent;
    color: var(--text);
    border: 0;
    padding: 0;
    font-size: 16px;
    font-family: var(--font-mono);
    line-height: 1.65;
    outline: none;
}
textarea::placeholder {
    color: var(--dim);
    font-family: var(--font-ui);
    transition: opacity var(--dur-2) var(--ease-out);
}
textarea:focus::placeholder { opacity: 0.45; }

/* a soft accent glow on the whole compose card when typing */
.compose {
    transition: border-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
}
.compose:focus-within {
    border-color: var(--accent-line);
    box-shadow:
        inset 0 1px 0 var(--hairline-top),
        0 0 0 3px var(--accent-soft),
        0 16px 40px -16px rgba(0, 0, 0, 0.6);
}

.foot-row {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s3);
    margin-top: var(--s3);
    height: var(--foot-h);
    border-top: 1px dashed var(--border);
}
.char-count {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--dim);
    letter-spacing: 0.02em;
}

/* ============================================
   INPUTS
   ============================================ */

.form-group { position: relative; }

input {
    display: block;
    width: 100%;
    height: 48px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 0 52px 0 var(--s4);
    font-size: 16px;
    font-family: var(--font-mono);
    outline: none;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
    transition: border-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out), background-color var(--dur-2) var(--ease-out);
}
input::placeholder { color: var(--dim); font-family: var(--font-ui); }
input:hover { border-color: var(--border-strong); }
input:focus {
    border-color: var(--accent-line);
    background: var(--surface-3);
    box-shadow: 0 0 0 3px var(--accent-soft), 0 0 24px -6px var(--accent-glow);
}

/* Pixel-eye toggle: 40px hit area, 24px crisp icon */
.pass-toggle {
    position: absolute;
    right: var(--s1);
    top: var(--s1);
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    background: transparent;
    border: 0;
    border-radius: var(--r-sm);
    color: var(--muted);
    cursor: pointer;
    transition: color var(--dur-1) var(--ease-out), background-color var(--dur-1) var(--ease-out), transform var(--dur-2) var(--ease-spring);
}
.pass-toggle:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.pass-toggle:active { transform: scale(0.9); }
.pass-toggle.showing { color: var(--accent); }
.pass-toggle svg { width: 24px; height: 24px; image-rendering: pixelated; }
.pass-toggle svg rect { fill: currentColor; }
.pass-toggle .eye-open { display: block; }
.pass-toggle .eye-closed { display: none; }
.pass-toggle.showing .eye-open { display: none; }
.pass-toggle.showing .eye-closed { display: block; }

/* --- Strength: three dithered cells (coral -> amber -> mint) --- */
#strength {
    --p: 0%;
    --c: var(--coral);
    display: flex;
    align-items: center;
    gap: var(--s3);
    margin-top: var(--s3);
    height: 16px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--dim);
    /* tween here, where the class changes; ::before inherits each step */
    transition: --p var(--dur-3) var(--ease-out), --c var(--dur-3) var(--ease-out);
}
#strength::before {
    content: '';
    flex: 0 0 auto;
    width: 116px;
    height: 8px;
    background:
        repeating-conic-gradient(rgba(0, 0, 0, 0.34) 0% 25%, transparent 0% 50%) 0 0 / 2px 2px,
        linear-gradient(90deg, var(--c) var(--p), transparent var(--p)),
        color-mix(in srgb, var(--accent) 16%, rgba(255, 255, 255, 0.07));
    -webkit-mask-image: repeating-linear-gradient(90deg, #000 0 36px, transparent 36px 40px);
    mask-image: repeating-linear-gradient(90deg, #000 0 36px, transparent 36px 40px);
    box-shadow: 0 0 14px -2px var(--accent-glow);
}
#strength::after { content: ''; transition: color var(--dur-2) var(--ease-out); }

#strength.weak   { --p: 31%;  --c: var(--coral); }
#strength.medium { --p: 69%;  --c: var(--amber); }
#strength.strong { --p: 100%; --c: var(--mint); }
#strength.weak::after   { content: 'Weak';   color: var(--coral); }
#strength.medium::after { content: 'Medium'; color: var(--amber); }
#strength.strong::after { content: 'Strong'; color: var(--mint); }

/* ============================================
   BUTTONS
   ============================================ */

.action-btn {
    position: relative;
    display: block;
    width: 100%;
    margin-top: var(--s3);
    min-height: 52px;
    padding: var(--s4);
    appearance: none;
    border: 0;
    border-radius: var(--r-md);
    background: var(--accent);
    color: var(--on-accent);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.38),
        0 8px 24px -8px var(--accent-glow);
    transition:
        transform var(--dur-2) var(--ease-spring),
        box-shadow var(--dur-2) var(--ease-out),
        filter var(--dur-2) var(--ease-out);
}
/* dither shimmer: a moving dithered band, masked */
.action-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: repeating-conic-gradient(rgba(255, 255, 255, 0.6) 0% 25%, transparent 0% 50%) 0 0 / 3px 3px;
    -webkit-mask-image: linear-gradient(100deg, transparent 38%, #000 50%, transparent 62%);
    mask-image: linear-gradient(100deg, transparent 38%, #000 50%, transparent 62%);
    -webkit-mask-size: 260% 100%;
    mask-size: 260% 100%;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: 130% 0;
    mask-position: 130% 0;
    transition: -webkit-mask-position 900ms var(--ease-out), mask-position 900ms var(--ease-out);
}
.action-btn:hover::after {
    -webkit-mask-position: -30% 0;
    mask-position: -30% 0;
}
.action-btn:hover {
    filter: brightness(1.06);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.42),
        0 10px 30px -8px var(--accent-glow);
}
.action-btn:active {
    transform: scale(0.972);
    filter: brightness(0.96);
}

/* step node 03 sits on the thread, level with the foot row */
.action-btn:disabled { cursor: wait; }

/* processing: a dithered scan band sweeps; text stays for a11y */
@keyframes scan {
    from { -webkit-mask-position: 130% 0; mask-position: 130% 0; }
    to   { -webkit-mask-position: -30% 0;  mask-position: -30% 0; }
}
/* the fill drains into a marching dither while the KDF runs; the label stays
   crisp on top and a brighter band sweeps across */
@keyframes march {
    from { background-position: 0 0; }
    to   { background-position: 8px 0; }
}
@keyframes busy-glow {
    0%, 100% { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 0 0 1px var(--accent-line), 0 6px 22px -8px var(--accent-glow); }
    50%      { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 0 0 1px var(--accent-line), 0 6px 30px -4px var(--accent-glow); }
}
.action-btn.processing {
    cursor: wait;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
    background-color: color-mix(in srgb, var(--accent) 34%, var(--ink));
    background-image: var(--dither);
    background-size: 4px 4px;
    filter: none;
    transform: none;
    animation: march 520ms steps(2) infinite, busy-glow 1.05s var(--ease-out) infinite;
    transition: color var(--dur-2) var(--ease-out), background-color var(--dur-2) var(--ease-out);
}
.action-btn.processing::after {
    animation: scan 1.05s linear infinite;
    transition: none;
}

.hint {
    display: block;
    height: 16px;
    margin-top: var(--s2);
    text-align: center;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 16px;
    color: var(--dim);
    opacity: 0;
    transition: opacity var(--dur-2) var(--ease-out);
}
.compose:hover .hint,
.compose:focus-within .hint { opacity: 1; }

.btn {
    appearance: none;
    min-height: 48px;
    padding: var(--s3) var(--s4);
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    transition:
        color var(--dur-1) var(--ease-out),
        background-color var(--dur-2) var(--ease-out),
        border-color var(--dur-2) var(--ease-out),
        box-shadow var(--dur-2) var(--ease-out),
        transform var(--dur-2) var(--ease-spring);
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-3); }
.btn:active { transform: scale(0.97); }

.btn-subtle {
    min-height: 44px;
    padding: var(--s2) var(--s4);
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    box-shadow: none;
}
.btn-subtle:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }

/* Clear All armed: calm pulse of the glow only */
.btn-subtle.confirm {
    color: var(--accent);
    border-color: var(--accent-line);
    background: var(--accent-soft);
    animation: arm 1.2s var(--ease-out) infinite;
}
@keyframes arm {
    0%, 100% { box-shadow: 0 0 0 0 var(--accent-soft); }
    50%      { box-shadow: 0 0 0 4px var(--accent-soft); }
}

@media (hover: hover) {
    .settings:hover,
    .compose:hover { border-color: var(--border-strong); }
}

/* ============================================
   FOCUS RINGS: soft accent glows, never hard boxes
   ============================================ */

:focus { outline: none; }
:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--accent), 0 0 18px var(--accent-glow);
}
.btn:focus-visible,
.footer-link:focus-visible,
.pass-toggle:focus-visible,
.tab-btn:focus-visible {
    box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--accent-line), 0 0 18px var(--accent-glow);
}
input:focus-visible {
    box-shadow: 0 0 0 3px var(--accent-soft), 0 0 24px -6px var(--accent-glow);
}
textarea:focus-visible { box-shadow: none; }

/* ============================================
   STATUS: a chip that rises from under the button
   ============================================ */

.status {
    --dot: var(--muted);
    position: relative;
    z-index: 0;
    display: flex;
    align-items: center;
    gap: var(--s2);
    width: fit-content;
    max-width: 100%;
    margin: -12px 0 0 var(--padl);
    padding: var(--s5) var(--s3) var(--s2) var(--s3);
    min-height: 0;
    border: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 var(--r-md) var(--r-md);
    background: var(--surface-0);
    color: var(--muted);
    font-size: 13px;
    line-height: 20px;
    visibility: hidden;
    opacity: 0;
    transform: translateY(-16px);
    transition:
        transform var(--dur-3) var(--ease-out),
        opacity var(--dur-2) var(--ease-out),
        visibility 0s linear var(--dur-3);
}
.status:empty { display: none; }
.status::before {
    content: '';
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background:
        repeating-conic-gradient(rgba(0, 0, 0, 0.4) 0% 25%, transparent 0% 50%) 0 0 / 4px 4px,
        var(--dot);
    box-shadow: 0 0 8px -1px var(--dot);
}
.status.visible {
    visibility: visible;
    opacity: 1;
    transform: none;
    transition:
        transform var(--dur-3) var(--ease-spring),
        opacity var(--dur-2) var(--ease-out),
        visibility 0s;
}
.status.success { --dot: var(--mint); color: var(--text); }
.status.danger  { --dot: var(--coral); color: #ffb4aa; border-color: rgba(255, 107, 90, 0.3); }
/* an error also tints the card it came from, then settles with the chip */
main:has(.status.danger.visible) .compose {
    border-color: rgba(255, 107, 90, 0.45);
    box-shadow:
        inset 0 1px 0 var(--hairline-top),
        0 0 0 3px rgba(255, 107, 90, 0.12),
        0 16px 40px -16px rgba(0, 0, 0, 0.6);
}
/* the status chip reserves its own height only when shown; keep
   a little air above the footer either way */
.status.visible + .footer { margin-top: var(--s6); }

/* ============================================
   RESULT MODAL: grows out of the button
   ============================================ */

.result-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: var(--s6) var(--s4) calc(var(--s6) + var(--safe-bottom));
    background: rgba(5, 5, 8, 0.82);
    visibility: hidden;
    opacity: 0;
    clip-path: circle(0px at var(--ox, 50%) var(--oy, 80%));
    transition:
        clip-path var(--dur-3) var(--ease-out),
        opacity var(--dur-2) var(--ease-out) var(--dur-1),
        visibility 0s linear var(--dur-3);
}
.result-overlay.active {
    visibility: visible;
    opacity: 1;
    clip-path: circle(150vmax at var(--ox, 50%) var(--oy, 80%));
    transition:
        clip-path 760ms var(--ease-out),
        opacity var(--dur-1) linear,
        visibility 0s;
}

.result-card {
    width: 100%;
    max-width: 520px;
    margin: auto;
    padding: var(--s6);
    background: var(--surface-1);
    transform: translateY(32px) scale(0.95);
    opacity: 0;
    transition: transform var(--dur-2) var(--ease-out), opacity var(--dur-1) var(--ease-out);
}
.result-overlay.active .result-card {
    transform: none;
    opacity: 1;
    transition: transform var(--dur-3) var(--ease-spring) 90ms, opacity var(--dur-2) var(--ease-out) 90ms;
}
/* dithered top edge */
.result-card::before {
    content: '';
    position: absolute;
    top: 0; left: var(--s6); right: var(--s6);
    height: 2px;
    background: repeating-conic-gradient(var(--accent) 0% 25%, transparent 0% 50%) 0 0 / 2px 2px;
}

.result-card h2 {
    display: flex;
    align-items: center;
    gap: var(--s2);
    margin: 0 0 var(--s4);
    font-size: 11px;
    line-height: 16px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
}
.result-card h2::before {
    content: '';
    width: 8px; height: 8px;
    border-radius: 2px;
    background:
        repeating-conic-gradient(rgba(0, 0, 0, 0.4) 0% 25%, transparent 0% 50%) 0 0 / 4px 4px,
        var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
}

.result-card textarea {
    min-height: 130px;
    max-height: 42vh;
    overflow-y: auto;
    padding: var(--s3) var(--s4);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-size: 13px;
    resize: vertical;
    transition: border-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out);
}
.result-card textarea:focus {
    border-color: var(--accent-line);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* intentional selection: accent wash, white text */
::selection {
    background: color-mix(in srgb, var(--accent) 42%, var(--ink));
    color: #ffffff;
}
.result-card textarea::selection {
    background: color-mix(in srgb, var(--accent) 30%, var(--surface-2));
    color: #ffffff;
}

.result-footer {
    display: flex;
    flex-direction: column;
    gap: var(--s2);
    margin-top: var(--s4);
}
.result-actions { display: flex; gap: var(--s2); }
.result-actions .btn { flex: 1; padding-inline: var(--s2); }

.result-footer .btn.primary {
    position: relative;
    background: var(--accent);
    color: var(--on-accent);
    border-color: transparent;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.38), 0 8px 24px -10px var(--accent-glow);
}
.result-footer .btn.primary:hover { filter: brightness(1.07); background: var(--accent); }
.result-footer .btn.primary.copied,
#resultLinkBtn.copied {
    background: var(--mint);
    color: #04140c;
    border-color: transparent;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 8px 24px -10px rgba(94, 242, 176, 0.5);
}

.share-btn { color: var(--muted); }
.share-btn:hover { color: var(--text); }

.btn-close {
    width: 100%;
    min-height: 44px;
    background: transparent;
    color: var(--muted);
    box-shadow: none;
    font-size: 11px;
}
.btn-close:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }

.no-share-api .share-btn { display: none; }

.result-qr-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s3);
    margin-top: var(--s4);
    padding: var(--s4);
    background: #ffffff;
    border-radius: var(--r-md);
}
.result-qr-wrap canvas {
    display: block;
    max-width: 100%;
    height: auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}
.qr-btn { color: var(--dim); font-size: 11px; letter-spacing: 0.04em; }
.qr-btn:hover { color: var(--text); }
.result-qr-caption {
    margin: 0;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #07070a;
    opacity: 0.75;
}
.result-hint {
    margin: var(--s4) 0 0;
    font-size: 13px;
    line-height: 1.55;
    color: var(--muted);
}
.result-hint strong { color: var(--text); font-weight: 650; }

/* ============================================
   FOOTER
   ============================================ */

.footer {
    position: relative;
    margin-top: var(--s8);
    text-align: center;
}

/* dithered divider: echoes the thread, fades by density */
.footer-line {
    height: 4px;
    margin: 0 0 var(--s5);
    background: repeating-conic-gradient(var(--accent) 0% 25%, transparent 0% 50%) 0 0 / 4px 4px;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 30%, #000 70%, transparent);
    mask-image: linear-gradient(90deg, transparent, #000 30%, #000 70%, transparent);
    opacity: 0.55;
}

.dedication {
    display: inline-flex;
    align-items: center;
    gap: var(--s2);
    margin: 0 0 var(--s1);
    font-size: 15px;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--text);
}
/* pixel heart, built from box-shadows (no images, CSP-safe) */
.dedication::after {
    content: '';
    width: 2px;
    height: 2px;
    margin: 0 8px 8px 4px;
    background: var(--accent);
    box-shadow:
        2px 0 var(--accent), 8px 0 var(--accent), 10px 0 var(--accent),
        -2px 2px var(--accent), 0 2px var(--accent), 2px 2px var(--accent), 4px 2px var(--accent), 6px 2px var(--accent), 8px 2px var(--accent), 10px 2px var(--accent), 12px 2px var(--accent),
        -2px 4px var(--accent), 0 4px var(--accent), 2px 4px var(--accent), 4px 4px var(--accent), 6px 4px var(--accent), 8px 4px var(--accent), 10px 4px var(--accent), 12px 4px var(--accent),
        0 6px var(--accent), 2px 6px var(--accent), 4px 6px var(--accent), 6px 6px var(--accent), 8px 6px var(--accent), 10px 6px var(--accent),
        2px 8px var(--accent), 4px 8px var(--accent), 6px 8px var(--accent), 8px 8px var(--accent),
        4px 10px var(--accent), 6px 10px var(--accent);
}

.tech-info {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    color: var(--dim);
}

.footer-link {
    margin-top: var(--s2);
    min-height: 44px;
    padding: var(--s2) var(--s3);
    background: none;
    border: 0;
    border-radius: var(--r-sm);
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.04em;
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: var(--border-strong);
    cursor: pointer;
    transition: color var(--dur-1) var(--ease-out), text-decoration-color var(--dur-1) var(--ease-out);
}
.footer-link:hover { color: var(--text); text-decoration-color: var(--accent); }

/* ============================================
   SCROLLBAR
   ============================================ */

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: var(--r-pill);
    border: 2px solid transparent;
    background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: padding-box; }

/* ============================================
   RESPONSIVE
   ============================================ */

@media (min-width: 900px) {
    :root { --gutter: 36px; --rail: 22px; --pad: 24px; }
    main { max-width: 580px; padding-right: var(--gutter); }
    body { padding-top: calc(var(--safe-top) + var(--s6)); }
    textarea { min-height: 176px; }
}

/* Phones: the passphrase card is the ground the sun sets behind. Open a sky
   window above it, and move the thread inside the cards' left padding. */
@media (max-width: 480px) {
    :root {
        --gutter: 16px;
        --tx: 13px;
        --padl: 30px;
        --gap: var(--s3);
        /* tall phones get a big sky; short ones keep both inputs on screen */
        --sky: 40px;
        --sky: clamp(40px, calc(55vh - 320px), 180px);
        --sky: clamp(40px, calc(55dvh - 320px), 180px);
    }
    main { padding-right: var(--gutter); }
    /* the mode switch lines up with the inputs; the rail runs down its left margin */
    .tabs-nav { --tpl: var(--padl); --tpr: var(--pad); }
    header { padding: var(--s3) 0; }
    .settings-header { margin-bottom: var(--s3); }
    textarea { min-height: 112px; }
    .message-card .field-head { margin-bottom: var(--s2); }
    .foot-row { margin-top: var(--s2); }
    .hint { display: none; }
    .footer { margin-top: var(--s6); }
}
@media (hover: none) { .hint { display: none; } }

@media (max-width: 380px) {
    :root { --gutter: 12px; --rail: 15px; --pad: 16px; --padl: 28px; --tx: 12px; }
    h1 { font-size: 18px; }
    .tab-btn { padding-inline: var(--s2); }
    #strength::before { width: 96px; -webkit-mask-image: repeating-linear-gradient(90deg, #000 0 28px, transparent 28px 32px); mask-image: repeating-linear-gradient(90deg, #000 0 28px, transparent 28px 32px); }
    .result-card { padding: var(--s5); }
}

@media (max-height: 500px) and (orientation: landscape) {
    :root { --sky: 0px; }
    header { padding: var(--s3) 0; }
    .settings { margin-bottom: var(--s3); }
    textarea { min-height: 96px; }
    .footer { margin-top: var(--s4); }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition-duration: 0.01ms !important;
        transition-delay: 0s !important;
    }
    .action-btn.processing::after {
        -webkit-mask-position: 50% 0;
        mask-position: 50% 0;
    }
}

@media (prefers-contrast: more) {
    :root {
        --border: rgba(255, 255, 255, 0.4);
        --border-strong: rgba(255, 255, 255, 0.7);
        --muted: #d0d4dc;
        --dim: #b4b9c4;
        --surface-1: #0d0d12;
        --surface-0: #09090d;
    }
    .settings, .compose, .result-card { -webkit-backdrop-filter: none; backdrop-filter: none; }
    .tab-indicator, .logo-icon { background-image: none; background-color: color-mix(in srgb, var(--accent) 35%, var(--ink)); }
    .tab-indicator::after { display: none; }
    .action-btn::after, .footer-line { display: none; }
    .result-overlay { background: #050508; }
    .thread, .message-card::before { background: rgba(255, 255, 255, 0.35); }
    .thread i, .message-card::after { background: var(--accent); }
}

@media (forced-colors: active) {
    .tab-indicator { border: 2px solid Highlight; }
    .tab-btn.active { color: HighlightText; }
}
