/* ==========================================================================
   Tactile buttons (KAN-766): every button on the website presses like the app's
   (KAN-750: mobile `Tactile`, AGENTS.md rule 8) and like its Start your wishlist.

   A button opts in with the class `tactile`:
     <button class="my-button tactile">Save</button>
     <a class="hero-1b-action tactile tactile--deep" href="...">Start your wishlist</a>

   - A hard block sits behind the face, 3px right and 4px down (the app's RETRO_CTA inset).
   - While pressed (mouse down, finger down, Space on a <button>) the face sinks 2px right and 3px down
     into it: 1px short, so an edge of the block stays in view. The block itself never moves.
   - With a mouse, hover lifts the face 1px up-left and the block keeps its place (KAN-397's hover lift,
     made to fit the block). Phones have no hover: block at rest, sink on tap.
   - A disabled button has no block and no sink: nothing to press into.

   How it is drawn:
   - The block is an outer box-shadow. An outer shadow is never painted under the face, so a see-through
     outlined face shows only the L of block at its right and bottom, never a block through it.
   - The face moves with `translate`, not `transform`, so a button placed with a transform (centred,
     floating) keeps its place, and the page's own transform animations keep running.
   - box-shadow and translate carry !important: each page's stylesheet styles its own buttons, often with
     a soft shadow, a scale on :active or a hover lift; on a tactile button the press belongs here.
     A face that draws its border with an inset shadow keeps it through --tactile-inset.
   - Phones: iOS Safari only applies :active when the page listens for touches; components/tactile_head.html
     adds an empty passive touchstart listener next to this file.
   - The hold (KAN-767, static/js/tactile.js): a tapped button keeps its face sunk (class `tactile-held`) and
     acts 0.2 s later, so the press is seen before a sheet opens or the page changes.

   Block colour: maroon unless a modifier (section 3) or the button's own rule sets --tactile-block.
   Not buttons in this sense (they keep their own pressed look): bare icon taps (close ✕, chevrons, ⓘ,
   share icons), text links, chips and pills, tabs and segmented choices, selectable cards, gift / wishlist
   cards, list and menu rows, toggles and checkboxes, form fields.
   Rule for agents: .agents/rules/tactile_buttons.md
   ========================================================================== */

/* ---- 1. The numbers and the block colours ------------------------------- */
:root {
    /* The app's TACTILE / RETRO_CTA: block 3 right, 4 down; the face sinks 1px short of it */
    --tactile-x: 3px;
    --tactile-y: 4px;
    --tactile-sink-x: 2px;
    --tactile-sink-y: 3px;
    --tactile-lift: 1px;

    /* Block colours: the app's tactileBlock (src/constants/colors.ts) plus KAN-397's coral under maroon */
    --tactile-maroon: #561023;      /* under coral, mustard, cream and white faces on light pages */
    --tactile-coral: #e45558;       /* under maroon faces (KAN-397) */
    --tactile-maroon-deep: #2a0811; /* under coral or cream faces on a maroon page or sheet */
    --tactile-forest-deep: #0b1c16; /* under forest / green faces, and anything on a green sheet */
    --tactile-coral-edge: #8c2426;  /* under a coral face on a coral surface */
    --tactile-soft: rgba(0, 0, 0, 0.12); /* a darker shade of whatever colour the button sits on */
}

/* ---- 2. The press ------------------------------------------------------- */
.tactile {
    -webkit-tap-highlight-color: transparent;
    /* A press that drifts off the face would otherwise select its label (the app's Tactile does the same) */
    -webkit-user-select: none;
    user-select: none;
    box-shadow: var(--tactile-x) var(--tactile-y) 0 0 var(--tactile-block, var(--tactile-maroon)),
        var(--tactile-inset, 0 0 #0000) !important;
    /* The face and the block's visible edge move together (a box-shadow transition left on its own would slide
       the block while the face jumps). Colour fades stay. */
    transition: translate 70ms ease-out, box-shadow 70ms ease-out, background-color 0.15s ease,
        border-color 0.15s ease, color 0.15s ease, filter 0.2s ease, opacity 0.2s ease !important;
}

@media (prefers-reduced-motion: reduce) {
    .tactile {
        transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease !important;
    }
}

@media (hover: hover) and (pointer: fine) {
    .tactile:hover:not(:disabled, [aria-disabled="true"], .button-disabled, .is-disabled, .disabled) {
        translate: calc(-1 * var(--tactile-lift)) calc(-1 * var(--tactile-lift)) !important;
        box-shadow: calc(var(--tactile-x) + var(--tactile-lift)) calc(var(--tactile-y) + var(--tactile-lift)) 0 0
                var(--tactile-block, var(--tactile-maroon)),
            var(--tactile-inset, 0 0 #0000) !important;
    }
}

/* Pressed: while a finger or mouse button is on it, and while static/js/tactile.js holds the click (KAN-767:
   the face stays sunk after finger up, then springs back, and the button acts 0.2 s after the tap) */
.tactile:active:not(:disabled, [aria-disabled="true"], .button-disabled, .is-disabled, .disabled),
.tactile.tactile-held:not(:disabled, [aria-disabled="true"], .button-disabled, .is-disabled, .disabled) {
    translate: var(--tactile-sink-x) var(--tactile-sink-y) !important;
    box-shadow: calc(var(--tactile-x) - var(--tactile-sink-x)) calc(var(--tactile-y) - var(--tactile-sink-y)) 0 0
            var(--tactile-block, var(--tactile-maroon)),
        var(--tactile-inset, 0 0 #0000) !important;
}

.tactile:is(:disabled, [aria-disabled="true"], .button-disabled, .is-disabled, .disabled) {
    translate: none !important;
    box-shadow: var(--tactile-inset, none) !important;
}

/* ---- 3. Block colours other than maroon --------------------------------- */
.tactile--coral { --tactile-block: var(--tactile-coral); }             /* maroon face */
.tactile--deep { --tactile-block: var(--tactile-maroon-deep); }        /* on a maroon page or sheet */
.tactile--forest { --tactile-block: var(--tactile-forest-deep); }      /* green face, or on a green sheet */
.tactile--coral-edge { --tactile-block: var(--tactile-coral-edge); }   /* coral face on a coral surface */
.tactile--soft { --tactile-block: var(--tactile-soft); }               /* shade of the surface it sits on */
.tactile--edge { --tactile-block: currentColor; }                      /* outlined see-through face, outline = text colour */
