/* ==========================================================================
   Black Chest — dark neumorphic keys
   Every control is extruded from the graphite ground (raised) or pressed
   into it (inset). Color lives only in the icon glyphs.
   ========================================================================== */

:root {
    color-scheme: dark;

    /* Ground and extrusion light */
    --bg: #23262e;
    --bg-raised: #262a33;
    --bg-well: #1f2229;
    --shade-hi: #2e323c;
    --shade-lo: #16181d;

    /* Ink */
    --ink: #e9ecf3;
    /* Lifted toward white for legibility on the dark ground (AA on every surface) */
    --ink-soft: #cdd3de;
    --ink-faint: #b4bbca;
    --ink-hint: #a9b0bf; /* placeholders: one step below typed text */

    /* Signal */
    --ok: #3ee0a0;
    --err: #ff7b93;
    --focus: #8f9cff;

    /* Gradients, mirrored from the SVG defs for non-SVG uses */
    --g-save: linear-gradient(135deg, #ff5c8a, #ff9d63);
    --g-get: linear-gradient(135deg, #6f80ff, #a15cf2);
    --g-go: linear-gradient(135deg, #2ee8c6, #2088ff);

    /* Depth */
    --raise-xl: -14px -14px 30px var(--shade-hi), 16px 18px 36px var(--shade-lo);
    --raise: -8px -8px 18px var(--shade-hi), 10px 10px 22px var(--shade-lo);
    --raise-sm: -5px -5px 12px var(--shade-hi), 6px 6px 14px var(--shade-lo);
    --press: inset 6px 6px 14px var(--shade-lo), inset -6px -6px 14px var(--shade-hi);
    --well: inset 5px 5px 12px var(--shade-lo), inset -5px -5px 12px var(--shade-hi);
    --edge: inset 0 1px 0 rgba(255, 255, 255, 0.035);

    /* Shape */
    --r-key: 32%;
    --r-panel: 2.6rem;
    --r-well: 1.4rem;

    /* Motion: few, long, soft */
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-io: cubic-bezier(0.65, 0, 0.35, 1);
    --t-press: 380ms;
    --t-view: 760ms;
    --t-sheet: 820ms;

    --ease-soft: cubic-bezier(0.4, 0, 0.2, 1);

    --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Self-hosted Nunito (variable): rounded terminals echo the soft keys */
@font-face {
    font-family: "Nunito";
    font-style: normal;
    font-weight: 200 1000;
    font-display: swap;
    src: url("fonts/nunito-latin-ext.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: "Nunito";
    font-style: normal;
    font-weight: 200 1000;
    font-display: swap;
    src: url("fonts/nunito-latin.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    background: var(--bg);
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    isolation: isolate;
    display: grid;
    grid-template-rows: auto 1fr;
    font-family: var(--font);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--ink);
    background:
        radial-gradient(120% 80% at 20% 0%, #282c35 0%, transparent 60%),
        var(--bg);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Circuit-board ground: orthogonal traces with 45-degree bends, pads, vias
   and a processor package, drawn as one seamless tile of thin white lines.
   It fades out behind the keys so the ground there stays calm. */
body::before,
.pulse-canvas {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 48%, rgba(0, 0, 0, 0.15) 0%, #000 78%);
    mask-image: radial-gradient(ellipse 70% 60% at 50% 48%, rgba(0, 0, 0, 0.15) 0%, #000 78%);
}

/* Electric pulses (pulses.js): a canvas over the trace lines, under all content. */
.pulse-canvas {
    width: 100%;
    height: 100%;
}

body::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'%3E%3Cg fill='none' stroke='%23fff' stroke-opacity='0.075' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='102,88 102,64 78,40 78,0'/%3E%3Cpolyline points='114,88 114,56 138,32 138,0'/%3E%3Cpolyline points='126,88 126,40 126,0'/%3E%3Cpolyline points='216,0 216,24 192,48'/%3E%3Cpolyline points='30,0 30,30 6,54 0,54'/%3E%3Cpolyline points='152,102 184,102 208,126 240,126'/%3E%3Cpolyline points='152,114 168,114 192,138 192,172 216,196 216,240'/%3E%3Cpolyline points='152,138 176,138'/%3E%3Cpolyline points='102,152 102,176 126,200 126,240'/%3E%3Cpolyline points='114,152 114,164 90,188 90,240'/%3E%3Cpolyline points='138,152 138,190'/%3E%3Cpolyline points='78,240 78,222 54,198'/%3E%3Cpolyline points='138,240 138,226 162,202'/%3E%3Cpolyline points='88,102 60,102 36,78 0,78'/%3E%3Cpolyline points='88,114 70,114 46,138 0,138'/%3E%3Cpolyline points='88,126 0,126'/%3E%3Cpolyline points='240,78 210,78'/%3E%3Cpolyline points='240,138 226,138 202,162'/%3E%3Cpolyline points='30,240 30,214 18,202'/%3E%3Cpolyline points='0,30 24,30'/%3E%3Cpolyline points='240,54 222,54'/%3E%3Cpolyline points='146,240 146,226'/%3E%3Cpolyline points='90,0 90,20'/%3E%3Cpolyline points='240,30 170,30 146,6 146,0'/%3E%3Crect x='96' y='96' width='48' height='48' rx='4'/%3E%3Crect x='108' y='108' width='24' height='24' rx='2' stroke-opacity='0.060'/%3E%3Cpath d='M102 88V96 M102 144V152 M88 102H96 M144 102H152'/%3E%3Cpath d='M114 88V96 M114 144V152 M88 114H96 M144 114H152'/%3E%3Cpath d='M126 88V96 M126 144V152 M88 126H96 M144 126H152'/%3E%3Cpath d='M138 88V96 M138 144V152 M88 138H96 M144 138H152'/%3E%3Crect x='176' y='200' width='14' height='8' rx='1.5'/%3E%3Crect x='22' y='108' width='8' height='14' rx='1.5'/%3E%3Crect x='196' y='70' width='8' height='14' rx='1.5'/%3E%3C/g%3E%3Cg fill='none' stroke='%23fff' stroke-opacity='0.112' stroke-width='1.4'%3E%3Ccircle cx='192' cy='48' r='4.5'/%3E%3Ccircle cx='176' cy='138' r='3'/%3E%3Ccircle cx='138' cy='190' r='4.5'/%3E%3Ccircle cx='54' cy='198' r='4.5'/%3E%3Ccircle cx='162' cy='202' r='3'/%3E%3Ccircle cx='210' cy='78' r='4.5'/%3E%3Ccircle cx='202' cy='162' r='3'/%3E%3Ccircle cx='18' cy='202' r='4.5'/%3E%3Ccircle cx='24' cy='30' r='4.5'/%3E%3Ccircle cx='222' cy='54' r='4.5'/%3E%3Ccircle cx='146' cy='226' r='4.5'/%3E%3Ccircle cx='90' cy='20' r='4.5'/%3E%3C/g%3E%3Cg fill='%23fff' fill-opacity='0.165'%3E%3Ccircle cx='176' cy='138' r='1.4'/%3E%3Ccircle cx='162' cy='202' r='1.4'/%3E%3Ccircle cx='202' cy='162' r='1.4'/%3E%3Ccircle cx='102' cy='102' r='1.8'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 300px 300px;
    background-position: center top;
}

::selection {
    background: rgba(143, 156, 255, 0.35);
    color: #fff;
}

* {
    scrollbar-width: thin;
    scrollbar-color: #3a3f4b transparent;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #3a3f4b; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

.sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.hidden {
    display: none !important;
}

/* --------------------------------------------------------------------------
   Top bar
   -------------------------------------------------------------------------- */

.topbar {
    view-transition-name: topbar;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 1.5rem clamp(1.25rem, 4vw, 2.5rem) 0.5rem;
}

.topbar > .key-chip {
    justify-self: end;
}

/* Left slot: the install key (icon only), hidden until installable */
.topbar-side {
    display: flex;
    justify-self: start;
    align-items: center;
}

.install-key {
    padding: 0;
    width: 3rem;
}

.key.install-key .glyph {
    width: 1.5rem;
    height: 1.5rem;
}

.install-key.show {
    animation: fade-in 700ms var(--ease-soft) both;
}

/* Brand: a link home, centered */
.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0.8rem;
    border-radius: 1.2rem;
    text-decoration: none;
    font-weight: 750;
    font-size: clamp(1.4rem, 5vw, 1.9rem);
    line-height: 1.1;
    letter-spacing: -0.015em;
    color: var(--ink);
    transition: transform var(--t-press) var(--ease), opacity var(--t-press) var(--ease);
}

.brand-mark {
    width: 2.35rem;
    height: 2.35rem;
    flex: none;
    transition: transform var(--t-press) var(--ease);
}

@media (hover: hover) and (pointer: fine) {
    .brand:hover .brand-mark {
        transform: translateY(-2px) scale(1.06);
    }
}

.brand:active {
    transform: scale(0.97);
}

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

/* --------------------------------------------------------------------------
   Keys: the one control
   -------------------------------------------------------------------------- */

.key {
    position: relative;
    display: inline-grid;
    place-items: center;
    border: 0;
    border-radius: var(--r-key);
    background: linear-gradient(145deg, #282c35, #21242b);
    color: var(--ink-soft);
    font: inherit;
    cursor: pointer;
    box-shadow: var(--raise), var(--edge);
    transition:
        box-shadow var(--t-press) var(--ease),
        transform var(--t-press) var(--ease),
        color var(--t-press) var(--ease);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

@supports (corner-shape: squircle) {
    .key {
        --r-key: 44%;
        corner-shape: squircle;
    }
}

.key .glyph {
    width: 42%;
    height: 42%;
    transition: transform var(--t-press) var(--ease), opacity var(--t-press) var(--ease);
}

@media (hover: hover) and (pointer: fine) {
    .key:hover {
        color: var(--ink);
    }
    .key:hover .glyph {
        transform: translateY(-2px) scale(1.04);
    }
}

.key:active,
.key.is-pressed {
    box-shadow: var(--press);
    transform: scale(0.975);
}

.key:active .glyph,
.key.is-pressed .glyph {
    transform: scale(0.92);
}

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

.key:disabled {
    cursor: progress;
}

.key-xl {
    /* Never wider than half the row, so two keys always fit */
    width: min(clamp(8.5rem, 30vw, 10.5rem), calc((100vw - 2rem - var(--home-gap, 1.75rem)) / 2));
    aspect-ratio: 1;
    box-shadow: var(--raise-xl), var(--edge);
}

.key-xl .glyph {
    width: 40%;
    height: 40%;
}

.key-lg {
    width: 5.75rem;
    aspect-ratio: 1;
}

.key-md {
    width: 3.75rem;
    aspect-ratio: 1;
    box-shadow: var(--raise-sm), var(--edge);
}

.key-md .glyph {
    width: 46%;
    height: 46%;
}

.key-sm {
    width: 2.9rem;
    aspect-ratio: 1;
    box-shadow: var(--raise-sm), var(--edge);
}

.key-sm .glyph {
    width: 48%;
    height: 48%;
}

.key-chip {
    min-width: 3rem;
    height: 2.75rem;
    padding: 0 0.85rem;
    border-radius: 1rem;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    box-shadow: var(--raise-sm), var(--edge);
}

@supports (corner-shape: squircle) {
    .key-chip {
        border-radius: 1.4rem;
    }
}

/* Small readout under a control glyph (counter, TTL) */
.key-badge {
    position: absolute;
    bottom: -0.5rem;
    left: 50%;
    translate: -50% 0;
    min-width: 2.1rem;
    padding: 0.08rem 0.45rem;
    border-radius: 0.7rem;
    background: var(--bg);
    box-shadow: var(--raise-sm);
    font-size: 0.72rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.35;
    color: var(--ink);
    white-space: nowrap;
}

.key-badge.bump {
    animation: bump 520ms var(--ease);
}

@keyframes bump {
    0% { transform: translateY(5px); opacity: 0.2; filter: blur(3px); }
    100% { transform: none; opacity: 1; filter: none; }
}

/* Busy: a slow gradient ring orbits the pressed key */
.busy-ring {
    position: absolute;
    inset: -7px;
    border-radius: inherit;
    padding: 2px;
    background: conic-gradient(from var(--spin, 0deg), transparent 0 55%, #2ee8c6 75%, #2088ff 95%, transparent);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0;
    transition: opacity 500ms var(--ease);
    pointer-events: none;
}

@property --spin {
    syntax: "<angle>";
    inherits: false;
    initial-value: 0deg;
}

.key.is-busy {
    box-shadow: var(--press);
}

.key.is-busy .glyph {
    opacity: 0.45;
    transform: scale(0.88);
}

.key.is-busy .busy-ring {
    opacity: 1;
    animation: orbit 1.6s linear infinite;
}

#retrieve-button .busy-ring {
    background: conic-gradient(from var(--spin, 0deg), transparent 0 55%, #6f80ff 75%, #a15cf2 95%, transparent);
}

@keyframes orbit {
    to { --spin: 360deg; }
}

/* --------------------------------------------------------------------------
   Stage and views
   -------------------------------------------------------------------------- */

.stage {
    display: grid;
    /* Panels sit right under the brand so the on-screen keyboard never covers
       them; the home view stretches to the full height and stays centered. */
    place-items: start center;
    padding: 0.75rem clamp(1rem, 4vw, 2rem) 3rem;
}

.view {
    grid-area: 1 / 1;
    width: 100%;
}

/* Home */

.home {
    display: grid;
    place-items: center;
    align-self: stretch;
}

.home-keys {
    --home-gap: clamp(1.25rem, 7vw, 3.5rem);
    display: flex;
    gap: var(--home-gap);
    margin-top: -4vh;
}

.home-item {
    display: grid;
    justify-items: center;
    gap: 1.4rem;
}

.home-label {
    font-size: 0.9rem;
    font-weight: 550;
    letter-spacing: 0.01em;
    color: var(--ink-faint);
    transition: color var(--t-press) var(--ease);
}

.home-item:has(.key:hover) .home-label,
.home-item:has(.key:focus-visible) .home-label {
    color: var(--ink);
}

#go-save { view-transition-name: morph-save; }
#go-retrieve { view-transition-name: morph-retrieve; }
#save-section { view-transition-name: morph-save; }
#retrieve-section { view-transition-name: morph-retrieve; }

/* Panels: one raised surface, everything inside is a well or a key */

.panel {
    width: min(34rem, 100%);
    display: grid;
    gap: 1.5rem;
    padding: clamp(1.25rem, 4vw, 2rem);
    border-radius: var(--r-panel);
    background: linear-gradient(160deg, #272b34, #22252d);
    box-shadow: var(--raise-xl), var(--edge);
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}



/* Wells: pressed into the ground */

.well {
    border-radius: var(--r-well);
    background: var(--bg-well);
    box-shadow: var(--well);
}

.well-text {
    padding: 0.35rem;
}

textarea,
input {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--ink);
    font: inherit;
    caret-color: var(--focus);
    outline: none;
}

textarea {
    display: block;
    min-height: 9.5rem;
    max-height: 45vh;
    padding: 1rem 1.1rem;
    resize: vertical;
    line-height: 1.55;
}

::placeholder {
    color: var(--ink-hint);
    opacity: 1;
}

.well:focus-within {
    box-shadow: var(--well), 0 0 0 2px rgba(143, 156, 255, 0.55);
}

.field {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 3.75rem;
    padding: 0 1rem;
    cursor: text;
}

.field input {
    padding: 0.9rem 0;
    font-size: 1rem;
}

.field-icon {
    flex: none;
    width: 1.3rem;
    height: 1.3rem;
}

.field-lg {
    min-height: 4.1rem;
}

#retrieve-key-input {
    font-size: 1.12rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

#retrieve-key-input::placeholder {
    font-size: 1rem;
    font-weight: 400;
    letter-spacing: 0;
}

/* Controls row */

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

.controls .field {
    flex: 1;
    min-width: 0;
}

.go-row {
    display: grid;
    place-items: center;
    padding-top: 0.5rem;
}

/* Attachments */

.thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem;
}

.thumbnail {
    position: relative;
    width: 4.5rem;
    height: 4.5rem;
    border-radius: 1.15rem;
    background: var(--bg-well);
    box-shadow: var(--well);
    padding: 0.3rem;
    animation: settle 620ms var(--ease) both;
}

@keyframes settle {
    from { opacity: 0; transform: scale(0.86); filter: blur(6px); }
    to { opacity: 1; transform: none; filter: none; }
}

.thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0.85rem;
    display: block;
}

.file-thumb-icon {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 0.15rem;
}

.file-thumb-icon svg {
    width: 1.4rem;
    height: 1.4rem;
}

.file-ext {
    font-size: 0.62rem;
    font-weight: 750;
    letter-spacing: 0.06em;
    color: var(--ink-soft);
}

.remove-btn {
    position: absolute;
    top: -0.45rem;
    right: -0.45rem;
    width: 1.7rem;
    height: 1.7rem;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: var(--bg-raised);
    color: var(--ink-soft);
    box-shadow: var(--raise-sm);
    cursor: pointer;
    transition: color var(--t-press) var(--ease), transform var(--t-press) var(--ease);
}

.remove-btn::after {
    content: "";
    position: absolute;
    inset: -0.5rem;
}

.remove-btn svg {
    width: 0.8rem;
    height: 0.8rem;
}

.remove-btn:hover {
    color: var(--err);
}

.remove-btn:active {
    transform: scale(0.9);
}

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

/* Upload progress */

.progress {
    display: grid;
    gap: 0.6rem;
}

.progress-track {
    height: 0.75rem;
    padding: 0.2rem;
    border-radius: 0.6rem;
}

.progress-fill {
    width: 0%;
    height: 100%;
    border-radius: 0.4rem;
    background: var(--g-go);
    transition: width 900ms var(--ease);
}

.progress-text {
    text-align: center;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    color: var(--ink-faint);
}

/* --------------------------------------------------------------------------
   Entrances (fallback when view transitions are unavailable)
   -------------------------------------------------------------------------- */

.view.entering {
    animation: rise var(--t-view) var(--ease) both;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(28px) scale(0.96); filter: blur(10px); }
    to { opacity: 1; transform: none; filter: none; }
}

.home .home-item {
    animation: float-in 1100ms var(--ease) both;
}

.home .home-item + .home-item {
    animation-delay: 120ms;
}

@keyframes float-in {
    from { opacity: 0.001; transform: translateY(22px); filter: blur(8px); }
    to { opacity: 1; transform: none; filter: none; }
}

/* Shared-element morph: key grows into its panel */

/* The key and its panel share one box that glides between them;
   the two snapshots crossfade together so the screen never dips. */
::view-transition-group(morph-save),
::view-transition-group(morph-retrieve) {
    animation-duration: 820ms;
    animation-timing-function: var(--ease-soft);
}

::view-transition-image-pair(morph-save),
::view-transition-image-pair(morph-retrieve) {
    isolation: isolate;
}

::view-transition-old(morph-save),
::view-transition-old(morph-retrieve),
::view-transition-new(morph-save),
::view-transition-new(morph-retrieve) {
    height: 100%;
    object-fit: cover;
    mix-blend-mode: plus-lighter;
    animation-duration: 820ms;
    animation-timing-function: var(--ease-soft);
    animation-fill-mode: both;
}

::view-transition-old(morph-save),
::view-transition-old(morph-retrieve) {
    animation-name: vt-out;
}

::view-transition-new(morph-save),
::view-transition-new(morph-retrieve) {
    animation-name: vt-in;
}

::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 820ms;
    animation-timing-function: var(--ease-soft);
}

@keyframes vt-out {
    to { opacity: 0; }
}

@keyframes vt-in {
    from { opacity: 0; }
}

/* --------------------------------------------------------------------------
   Result sheet
   -------------------------------------------------------------------------- */

.sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(17, 19, 24, 0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    animation: dim-in 600ms var(--ease) both;
}

.sheet-overlay.closing {
    animation: dim-out 520ms var(--ease-io) both;
}

.sheet-overlay.closing .sheet {
    animation: sheet-out 520ms var(--ease-io) both;
}

@keyframes dim-in {
    from { background: rgba(17, 19, 24, 0); backdrop-filter: blur(0); -webkit-backdrop-filter: blur(0); }
}

@keyframes dim-out {
    to { background: rgba(17, 19, 24, 0); backdrop-filter: blur(0); -webkit-backdrop-filter: blur(0); }
}

.sheet {
    position: relative;
    width: min(32rem, 100%);
    max-height: 86vh;
    max-height: 86dvh;
    overflow-y: auto;
    padding: 2rem clamp(1.25rem, 4vw, 2rem) 2rem;
    border-radius: var(--r-panel);
    background: linear-gradient(160deg, #282c35, #22252d);
    box-shadow: var(--raise-xl), var(--edge);
    animation: sheet-in 950ms var(--ease-soft) both;
    --rise: 90px;
}

@media (max-width: 639px) {
    .sheet {
        --rise: 120px;
    }
}

@keyframes sheet-in {
    from { opacity: 0; transform: translateY(var(--rise)) scale(0.98); }
    to { opacity: 1; transform: none; }
}

@keyframes sheet-out {
    to { opacity: 0; transform: translateY(50px) scale(0.98); filter: blur(8px); }
}

.sheet-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
}

.result-content {
    display: grid;
    gap: 1.25rem;
}

/* Status glyph at the top of a result */
.result-mark {
    justify-self: center;
    width: 5rem;
    height: 5rem;
    display: grid;
    place-items: center;
    border-radius: 34%;
    background: var(--bg-raised);
    box-shadow: var(--raise), var(--edge);
    animation: mark-in 900ms var(--ease-soft) 420ms both;
}

.result-mark svg {
    width: 2.4rem;
    height: 2.4rem;
}

@keyframes mark-in {
    from { opacity: 0; transform: scale(0.7); filter: blur(6px); }
    to { opacity: 1; transform: none; filter: none; }
}

/* --------------------------------------------------------------------------
   The chest: the one signature moment (user-requested, S12)
   Save closes and locks it; retrieve unlocks and opens it. Gentle overshoot
   is allowed here and nowhere else. Only transform, opacity and a static blur
   on the glow are animated. The un-animated state is the END state.
   -------------------------------------------------------------------------- */

.chest {
    justify-self: center;
    width: min(11rem, 62%);
    --d0: 250ms;
    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --soft: cubic-bezier(0.4, 0, 0.2, 1);
}

.chest-svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

.chest-svg g,
.chest-svg ellipse,
.chest-svg rect {
    transform-box: fill-box;
}

.c-floor {
    fill: var(--shade-lo);
    opacity: 0.9;
    filter: blur(4px);
}

.c-sq { transform-origin: 50% 100%; }
.c-lid-open,
.c-lid-closed { transform-origin: 50% 100%; }
.c-key { transform-origin: 0% 50%; }
.c-lock { transform-origin: 50% 50%; }
.c-glint { opacity: 0; transform-origin: 50% 50%; }
.c-glow { filter: blur(5px); transform-origin: 50% 100%; }

/* End states */
.chest.is-save .c-lid-open,
.chest.is-save .c-glow { opacity: 0; }
.chest.is-save .c-key { transform: rotate(90deg); }
.chest.is-get .c-lid-closed,
.chest.is-get .c-key { opacity: 0; }

/* SAVE: lid swings shut, soft squash, key in and turned, one glint (~1.6s) */
.chest.is-save .c-lid-open {
    animation: lid-fold 420ms var(--soft) var(--d0) both;
}
.chest.is-save .c-lid-closed {
    animation:
        lid-shut 560ms var(--spring) calc(var(--d0) + 60ms) both,
        fade-in 140ms linear calc(var(--d0) + 260ms) both;
}
.chest.is-save .c-sq {
    animation: squash 460ms var(--soft) calc(var(--d0) + 500ms) both;
}
.chest.is-save .c-key {
    animation: key-lock 620ms var(--soft) calc(var(--d0) + 800ms) both;
}
.chest.is-save .c-glint {
    animation: glint 480ms var(--soft) calc(var(--d0) + 1330ms) both;
}

/* RETRIEVE: key turns back, lid springs open, light rises (~1.5s) */
.chest.is-get .c-key {
    animation: key-unlock 900ms var(--soft) calc(var(--d0) + 120ms) both;
}
.chest.is-get .c-lid-closed {
    animation: lid-fold-rev 360ms var(--soft) calc(var(--d0) + 560ms) both;
}
.chest.is-get .c-lid-open {
    animation:
        lid-pop 640ms var(--spring) calc(var(--d0) + 600ms) both,
        fade-in 140ms linear calc(var(--d0) + 620ms) both;
}
.chest.is-get .c-glow {
    animation: glow-rise 820ms var(--ease) calc(var(--d0) + 800ms) both;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

@keyframes lid-fold {
    from { opacity: 1; transform: none; }
    60% { opacity: 1; }
    to { opacity: 0; transform: scaleY(0.3); }
}
@keyframes lid-shut {
    from { transform: scaleY(0.3); }
    to { transform: none; }
}
@keyframes lid-fold-rev {
    from { opacity: 1; transform: none; }
    to { opacity: 0; transform: scaleY(0.3); }
}
@keyframes lid-pop {
    from { transform: scaleY(0.3); }
    to { transform: none; }
}
@keyframes squash {
    0% { transform: none; }
    35% { transform: scale(1.025, 0.94); animation-timing-function: var(--spring); }
    75% { transform: scale(0.99, 1.03); }
    100% { transform: none; }
}
@keyframes key-lock {
    0% { opacity: 0; transform: translateX(40px) rotate(0deg); }
    40% { opacity: 1; transform: translateX(0) rotate(0deg); }
    55% { opacity: 1; transform: translateX(0) rotate(0deg); }
    100% { opacity: 1; transform: translateX(0) rotate(90deg); }
}
@keyframes key-unlock {
    0% { opacity: 1; transform: translateX(0) rotate(90deg); }
    38% { opacity: 1; transform: translateX(0) rotate(0deg); }
    55% { opacity: 1; transform: translateX(0) rotate(0deg); }
    100% { opacity: 0; transform: translateX(38px) rotate(0deg); }
}
@keyframes glint {
    0% { opacity: 0; transform: scale(1); }
    40% { opacity: 0.85; transform: scale(1.1); }
    100% { opacity: 0; transform: scale(1); }
}
@keyframes glow-rise {
    from { opacity: 0; transform: translateY(10px) scale(0.9); }
    to { opacity: 1; transform: none; }
}

/* Content rises in after the chest has finished */
.reveal {
    animation: reveal-rise 800ms var(--ease) var(--rd, 0ms) both;
}
@keyframes reveal-rise {
    from { opacity: 0; transform: translateY(18px); }
    to { opacity: 1; transform: none; }
}

.result-note {
    text-align: center;
    font-size: 0.9rem;
    color: var(--ink-soft);
}

.result-note.is-error {
    color: var(--err);
}

/* Keyword: one short word to remember, so it has no copy key */

.keyword {
    min-width: 0;
    padding: 1.25rem 1.1rem;
    text-align: center;
    font-size: clamp(1.4rem, 5vw, 1.9rem);
    font-weight: 700;
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
    overflow-wrap: anywhere;
}

.copy-btn.copied {
    color: var(--ok);
}

/* Retrieved text */

.text-block {
    position: relative;
}

.result-text {
    margin: 0;
    padding: 1.1rem 4.9rem 1.1rem 1.1rem;
    max-height: 46vh;
    overflow: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: inherit;
    font-size: 0.98rem;
    line-height: 1.55;
    color: var(--ink);
}

.text-block .copy-btn {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
}

/* Retrieved images and files */

.result-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
    gap: 0.85rem;
}

.result-image-wrap {
    position: relative;
}

/* Small download key in the corner of each image */
.key-xs {
    width: 2.35rem;
    aspect-ratio: 1;
    box-shadow: var(--raise-sm), var(--edge);
}

.key-xs .glyph {
    width: 50%;
    height: 50%;
}

.image-dl::after {
    content: "";
    position: absolute;
    inset: -0.45rem;
}

.image-dl {
    position: absolute;
    right: 0.65rem;
    bottom: 0.65rem;
    text-decoration: none;
}

.result-image-link {
    display: block;
    border-radius: 1.1rem;
    padding: 0.3rem;
    background: var(--bg-well);
    box-shadow: var(--well);
}

.result-image {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 0.85rem;
}

.result-file-list {
    display: grid;
    gap: 0.75rem;
}

.file-download-btn {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.8rem 1rem;
    border-radius: 1.1rem;
    background: var(--bg-raised);
    box-shadow: var(--raise-sm), var(--edge);
    color: var(--ink);
    text-decoration: none;
    transition: box-shadow var(--t-press) var(--ease), transform var(--t-press) var(--ease);
}

.file-download-btn:active {
    box-shadow: var(--press);
    transform: scale(0.985);
}

.file-download-btn:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 3px;
}

.file-download-btn svg {
    flex: none;
    width: 1.4rem;
    height: 1.4rem;
}

.file-download-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.92rem;
}

/* --------------------------------------------------------------------------
   Toast and update banner
   -------------------------------------------------------------------------- */

.toast {
    position: fixed;
    left: 50%;
    /* Top of the screen: never covers the send key */
    top: calc(4.75rem + env(safe-area-inset-top));
    z-index: 80;
    max-width: min(26rem, calc(100% - 2rem));
    padding: 0.85rem 1.25rem;
    border-radius: 1.2rem;
    background: var(--bg-raised);
    box-shadow: var(--raise), var(--edge);
    color: var(--ink);
    font-size: 0.9rem;
    text-align: center;
    opacity: 0;
    transform: translate(-50%, -24px);
    filter: blur(6px);
    transition: opacity 600ms var(--ease), transform 600ms var(--ease), filter 600ms var(--ease);
    pointer-events: none;
}

.toast.visible {
    opacity: 1;
    transform: translate(-50%, 0);
    filter: none;
}

.update-banner {
    position: fixed;
    left: 50%;
    bottom: calc(1.25rem + env(safe-area-inset-bottom));
    z-index: 70;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 0.6rem 0.6rem 1.2rem;
    border-radius: 1.4rem;
    background: var(--bg-raised);
    box-shadow: var(--raise), var(--edge);
    font-size: 0.88rem;
    color: var(--ink-soft);
    transform: translateX(-50%);
    animation: banner-in 800ms var(--ease) both;
}

.update-btn {
    color: var(--ink);
    letter-spacing: 0.02em;
}

@keyframes banner-in {
    from { opacity: 0; transform: translate(-50%, 30px); filter: blur(6px); }
    to { opacity: 1; transform: translate(-50%, 0); filter: none; }
}

/* Offline pill: a raised chip, bottom center, never over the send key */
.offline-pill {
    position: fixed;
    left: 50%;
    bottom: calc(1.25rem + env(safe-area-inset-bottom));
    z-index: 40;
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.55rem 1.1rem 0.55rem 0.85rem;
    border-radius: 1.2rem;
    background: var(--bg-raised);
    box-shadow: var(--raise-sm), var(--edge);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--ink-soft);
    transform: translateX(-50%);
    animation: pill-in 800ms var(--ease) both;
    pointer-events: none;
}

.offline-pill.leaving {
    animation: pill-out 450ms var(--ease-soft) both;
}

.pill-icon {
    width: 1.3rem;
    height: 1.3rem;
    flex: none;
}

/* The update banner owns the bottom edge: the pill rides above it */
body:has(.update-banner:not(.hidden)) .offline-pill {
    bottom: calc(5.25rem + env(safe-area-inset-bottom));
}

@keyframes pill-in {
    from { opacity: 0; transform: translate(-50%, 22px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes pill-out {
    from { opacity: 1; transform: translate(-50%, 0); }
    to { opacity: 0; transform: translate(-50%, 12px); }
}

/* iOS install guide: two inset wells, glyph first */
.steps {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 1rem;
}

.step {
    display: flex;
    align-items: center;
    gap: 1.1rem;
    padding: 1.15rem 1.4rem;
    font-weight: 700;
    color: var(--ink);
}

.step svg {
    width: 2.4rem;
    height: 2.4rem;
    flex: none;
}

/* --------------------------------------------------------------------------
   Small screens
   -------------------------------------------------------------------------- */

@media (max-width: 420px) {
    .controls {
        flex-wrap: wrap;
    }
    .controls .field {
        flex-basis: 100%;
        order: 3;
    }
    .panel {
        gap: 1.25rem;
    }
}

/* Narrow phones: a slightly smaller brand keeps it truly centered */
@media (max-width: 360px) {
    .brand {
        gap: 0.55rem;
        padding: 0.3rem 0.3rem;
    }
    .brand-mark {
        width: 2rem;
        height: 2rem;
    }
}

/* Short or very narrow phones: keep the send key above the fold */
@media (max-width: 360px), (max-height: 700px) {
    .stage {
        padding-bottom: 1.5rem;
    }
    .panel {
        gap: 1rem;
        padding: 1.1rem;
    }
    textarea {
        min-height: 5.5rem;
    }
    .field,
    .field-lg {
        min-height: 3.25rem;
    }
    .key-lg {
        width: 4.75rem;
    }
    .go-row {
        padding-top: 0;
    }
    .home-keys {
        margin-top: 0;
    }
}

/* --------------------------------------------------------------------------
   Reduced motion: keep fades, drop travel and blur
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 200ms !important;
        animation-delay: 0ms !important;
        transition-duration: 150ms !important;
    }

    @keyframes rise { from { opacity: 0; } }
    @keyframes float-in { from { opacity: 0.001; } }
    @keyframes sheet-in { from { opacity: 0; } }
    @keyframes sheet-out { to { opacity: 0; } }
    @keyframes settle { from { opacity: 0; } }
    @keyframes mark-in { from { opacity: 0; } }
    @keyframes reveal-rise { from { opacity: 0; } }
    @keyframes pill-in { from { opacity: 0; } }
    @keyframes pill-out { to { opacity: 0; } }

    /* Chest: show the end state, closed and locked (save) or open (retrieve) */
    .chest *,
    .chest-svg * {
        animation: none !important;
    }
    .chest {
        animation: fade-in 200ms linear both !important;
    }
    @keyframes bump { from { opacity: 0.2; } }

    .key.is-busy .busy-ring {
        animation: none;
    }

    /* Views still crossfade, without travel or morph */
    ::view-transition-group(*) {
        animation: none !important;
    }
    ::view-transition-old(*),
    ::view-transition-new(*) {
        animation-duration: 200ms !important;
        animation-timing-function: linear !important;
    }
}
