/* =============================================================================
   KOTOVA BOOKS · "AI accounting" section (non-German /books pages, 2nd section)
   -----------------------------------------------------------------------------
   Load AFTER /books/books.css and /books/product.css (it uses the app kit of
   books.css §16 and the AI sheet of product.css §6/§6b: .bk-app, .mtop,
   .rvm-h, .ai-chat, .ai-prop, .abtn, .chip, .scrim) and only on the pages that
   carry the <!--AI-SECTION:START--> block. Every class of its own is bkai-;
   nothing styles a bare element, html or body; :root is untouched. The paper
   receipt and the phone shell are declared here (not borrowed from the German
   hero's bkp-rc / bkp-phone rules), so this file stands on its own.

   What the block shows: a paper receipt of a fictional American business
   meal beside the app on a phone with the "AI suggestion" bottom sheet. Blue
   marks sit over the receipt lines the AI used (name, date, subtotal + sales
   tax, tip, total); each has a blue dot in the proposal. No numbering.

   Layout is by the width of the visual's own column (container query "bkai"),
   not the viewport, so the same markup works in every split:
     >= 604  side by side: the receipt left, the phone right, the receipt's
             right margin tucked under the phone's edge (6 px, plus what the
             tilt moves its lower right).
     < 604   stacked: the receipt on top, the phone over its lower edge.
     < 390   (phones) the phone loses its bezel and is as wide as the column.
   Below 1170 px the split is one column (copy, then the visual); from 1170
   the visual sits left and the copy right.
   Nothing is scaled: the phone screen is 350 px (or the column) so the app
   lays itself out in its phone layout (container bkapp <= 600); all text is
   >= 11 px.

   Reveal (inline script in the block): receipt (step 0) -> phone (1) -> sheet
   (2) -> explanation (3) -> proposal (4) -> question (5) -> "Fill in" (6); the
   blue marks and the dots ride on step 4 and fade in after it, one by one.
   Only opacity and transform move. No JS, reduced motion, print: the complete
   static state with every mark shown.
   ========================================================================== */

.bkai {
    --bkai-blue: #5AA8F7;                          /* the app's AI azure (--m-exchange) */
    --bkai-mark: rgba(52, 140, 246, 0.3);          /* highlighter on the paper */
    --bkai-mark-edge: rgba(36, 118, 232, 0.8);
    overflow-x: clip;                              /* the tilted paper never makes the page scroll sideways */
}

/* --- split: one column below 1170 (the shared .bk-split collapses at 1024,
   which would leave a 525 px column for the composition, which needs 604:
   the visual is 1.15fr of the container minus a 64 px gap, so 604 px from a
   1163 px viewport) --- */
@media (max-width: 1169.98px) {
    .bkai .bk-split,
    .bkai .bk-split--wide-visual,
    .bkai .bk-split--reverse.bk-split--wide-visual {
        grid-template-columns: minmax(0, 1fr);
        gap: var(--spacing-2xl);
    }

    .bkai .bk-split--reverse > .bk-split-visual {
        order: 0;
    }

    .bkai .bk-split-copy {
        max-width: 44rem;
        margin-inline: auto;
    }
}

/* =============================================================================
   The visual: figure + caption in a container
   ========================================================================== */

.bkai-stage {
    container: bkai / inline-size;
}

.bkai-fig {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0 auto;
    padding-top: 8px;
}

/* soft light behind the phone: the app's AI azure into the page's gold */
.bkai-glow {
    position: absolute;
    z-index: 0;
    top: 10%;
    right: -6%;
    width: 70%;
    height: 80%;
    border-radius: 50%;
    background:
        radial-gradient(closest-side, rgba(90, 168, 247, 0.17), transparent 72%),
        radial-gradient(closest-side at 65% 60%, rgba(197, 165, 114, 0.12), transparent 80%);
    filter: blur(10px);
    pointer-events: none;
}

/* --- the paper receipt: thermal paper, mono print, a serrated tear.
   Decorative (aria-hidden); the figure's label names it. --- */
.bkai-rc-wrap {
    --rc-w: 244px;
    --rc-rot: -2.5deg;
    position: relative;
    z-index: 1;
    flex: none;
    width: var(--rc-w);
    transform: rotate(var(--rc-rot));
    filter: drop-shadow(0 30px 30px rgba(0, 0, 0, 0.55)) drop-shadow(0 6px 10px rgba(0, 0, 0, 0.4));
}

.bkai-rc {
    --z: 6px;
    position: relative;
    padding: 22px 19px calc(20px + var(--z));
    color: #2D2A25;
    font: 500 11px/1.55 "JetBrains Mono", ui-monospace, Menlo, monospace;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    text-align: left;
    filter: brightness(0.92);
    background:
        linear-gradient(180deg, transparent 56%, rgba(70, 58, 40, 0.1) 56.3%, rgba(255, 255, 255, 0.55) 56.8%, transparent 58.5%),
        linear-gradient(90deg, rgba(80, 64, 40, 0.16), transparent 7%, transparent 91%, rgba(80, 64, 40, 0.18)),
        radial-gradient(130% 55% at 25% 0%, rgba(255, 255, 255, 0.6), transparent 62%),
        linear-gradient(180deg, transparent 70%, rgba(80, 64, 40, 0.08)),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .32  0 0 0 0 .27  0 0 0 0 .2  0 0 0 .55 -.18'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
        #F1EDE3;
    -webkit-mask:
        conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) bottom / calc(2 * var(--z)) var(--z) repeat-x,
        linear-gradient(#000 0 0) top / 100% calc(100% - var(--z)) no-repeat;
    mask:
        conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) bottom / calc(2 * var(--z)) var(--z) repeat-x,
        linear-gradient(#000 0 0) top / 100% calc(100% - var(--z)) no-repeat;
}

/* light falls off towards the top, so the lower half (the marked totals) is the brightest zone */
.bkai-rc::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(180deg, rgba(10, 14, 25, 0.3), transparent 38%);
    pointer-events: none;
}

.bkai-rc * {
    -webkit-hyphens: manual;
    hyphens: manual;
    word-break: normal;
    overflow-wrap: normal;
}

.bkai-rc-mark { display: block; width: 46px; height: 16px; margin: 0 auto 8px; }
.bkai-rc-name { font: 700 17px/1.1 "JetBrains Mono", ui-monospace, monospace; letter-spacing: 0.16em; text-align: center; text-shadow: 0 0 0.5px rgba(45, 42, 37, 0.8); }
.bkai-rc-sub { margin-top: 5px; text-align: center; letter-spacing: 0.1em; }
.bkai-rc-addr { margin-top: 3px; text-align: center; opacity: 0.75; }

.bkai-rc-row { display: flex; justify-content: space-between; gap: 10px; white-space: nowrap; }
.bkai-rc-row > span:last-child { text-align: right; }
.bkai-rc-items { opacity: 0.62; }

.bkai-rc hr { height: 0; margin: 7px 0; border: 0; border-top: 1px dashed rgba(45, 42, 37, 0.5); }
.bkai-rc hr.dbl { height: 3px; border-top: 1px solid rgba(45, 42, 37, 0.55); border-bottom: 1px solid rgba(45, 42, 37, 0.55); }
.bkai-rc-gap { margin-top: 8px; }
.bkai-rc-total { font-weight: 700; font-size: 12.5px; letter-spacing: 0.02em; }
.bkai-rc-pay { opacity: 0.72; }
.bkai-rc-foot { margin-top: 2px; text-align: center; opacity: 0.72; }

/* --- the blue marks: a highlighter pen under the print (z-index -1 inside
   the paper's own stacking context, so the text stays crisp). The mark
   belongs to the line that carries .bkai-mk; the proposal's dots are the
   same blue. Hidden only while the reveal waits (js-reveal), shown in every
   static state. --- */
.bkai-mk {
    position: relative;
}

.bkai-mk::before {
    content: "";
    position: absolute;
    inset: -2px -5px;
    z-index: -1;
    border: 1px solid var(--bkai-mark-edge);
    border-radius: 4px;
    background: var(--bkai-mark);
    transform-origin: 0 50%;
    pointer-events: none;
}

span.bkai-mk {
    display: inline-block;
}

.bkai-mk--name::before {
    inset: -3px -4px -3px -7px;     /* the letter-spacing trails the last glyph (2.7 px) */
}

/* =============================================================================
   The phone: a plain bezel, the screen is the app's phone layout
   ========================================================================== */

.bkai-phone {
    position: relative;
    z-index: 2;
    flex: none;
    width: min(100%, 366px);        /* the 350 px screen + 2 x 8 px bezel */
    margin-top: -72px;              /* stacked: over the receipt's lower edge (its card line stays, the rest of the foot hides) */
    padding: 8px;
    border-radius: 44px;
    background: linear-gradient(160deg, #2A3348, #0B0F18 40%, #1A2131);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.08) inset,
        0 0 0 2px #05070C,
        0 50px 90px -30px rgba(0, 0, 0, 0.9),
        0 20px 40px -12px rgba(0, 0, 0, 0.6);
}

.bkai-phone-screen {
    position: relative;
    overflow: hidden;
    border-radius: 36px;
    background: #0A0F1C;
}

/* side by side: 244 - 6 + 366 = 604 */
@container bkai (min-width: 604px) {
    .bkai-fig {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
    }

    .bkai-rc-wrap {
        margin: 40px -6px 0 0;
    }

    .bkai-phone {
        margin-top: 0;
    }
}

/* phones: no phone in a phone. The screen is the column's width. */
@container bkai (max-width: 389.98px) {
    .bkai-phone {
        width: 100%;
        padding: 0;
        border: 1px solid rgba(255, 255, 255, 0.16);
        border-radius: 24px;
        background: #0A0F1C;
        box-shadow: 0 -20px 40px -10px rgba(0, 0, 0, 0.55);
    }

    .bkai-phone-screen {
        border-radius: 23px;
    }

    .bkai-glow {
        display: none;
    }
}

/* --- the app on the screen (kit: books.css §16, product.css §6/§6b) --- */

/* a window onto the item card: the eyebrow and one whole line of the title
   show above the sheet; the window ends on the card's bottom padding, which
   the sheet's 20 px overlap covers, so no line of text is cut through. */
.bk-app.bkai-app .content {
    padding-bottom: 0;
    overflow: hidden;
}

.bk-app.bkai-app .rvm-h {
    position: relative;
    min-height: 96px;       /* the photo (10 + 54 px) + 12 px, above the sheet's overlap */
    padding-right: 64px;    /* room for the photo */
    padding-bottom: 22px;   /* the sheet's 20 px overlap + 2 px under the title line */
}

.bk-app.bkai-app .rvm-t {
    max-height: 1.25em;     /* one line */
    max-height: 1lh;
    overflow: hidden;
}

.bk-app.bkai-app .ai-chat {
    margin-top: -20px;
}

.bk-app.bkai-app .ai-chat .dlg-b {
    padding-top: 10px;
    padding-bottom: 12px;
}

/* a screen as narrow as a 320 px phone's: the app bar drops its search
   button so the title stays whole */
@container bkapp (max-width: 340px) {
    .bk-app.bkai-app .mtop .icon-btn {
        display: none;
    }

    .bk-app.bkai-app .ai-chat .dlg-h .eyebrow {
        white-space: normal;
    }
}

/* --- the proposal: the category lines, each with its blue dot --- */
.bk-app.bkai-app .ai-prop {
    gap: 8px;
}

.bkai-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 2px 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--hairline);
    font-size: 12.5px;
    line-height: 1.4;
    color: var(--ink-2);
}

.bkai-ln {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
}

.bkai-dot {
    display: block;
    flex: none;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--bkai-blue);
    box-shadow: 0 0 0 3px rgba(90, 168, 247, 0.2);
}

.bkai-lines {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    list-style: none;
}

.bkai-lines li,
.bkai-total {
    display: grid;
    grid-template-columns: 7px minmax(0, 1fr) auto;
    align-items: start;
    column-gap: 9px;
}

.bkai-lines li {
    padding: 7px 0;
    border-bottom: 1px solid var(--hairline);
}

.bkai-lines .bkai-dot {
    margin-top: 6px;
}

.bkai-cat {
    min-width: 0;
    font-size: 13px;
    line-height: 1.35;
    font-weight: 500;
    color: var(--ink);
}

.bkai-cat small {
    display: block;
    font-size: 11.5px;
    font-weight: 400;
    color: var(--ink-3);
}

.bkai-amt {
    padding-top: 1px;
    font: 500 12.5px/1.4 var(--f-mono);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: var(--ink);
}

.bkai-total {
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
}

.bkai-total .bkai-amt {
    font-weight: 600;
}

/* --- the caption under the figure --- */
.bkai-cap {
    position: relative;
    z-index: 3;
    max-width: 34rem;
    margin: 22px auto 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--color-text-secondary);
    text-align: center;
    text-wrap: balance;
}

.bkai-key {
    display: inline-block;
    width: 18px;
    height: 10px;
    margin-right: 6px;
    border: 1px solid var(--bkai-mark-edge);
    border-radius: 3px;
    background: rgba(52, 140, 246, 0.42);
    vertical-align: -1px;
}

/* =============================================================================
   Reveal. The inline script of the block sets .js-reveal on the figure, then
   .is-in and --d (the step's delay) on each [data-step]. Steps: 0 the receipt
   settles, 1 the phone rises, 2 the sheet slides up over the dimmed app (the
   scrim rides along), 3 the explanation, 4 the proposal (+ the blue marks and
   dots, which ride on it and follow 0.4 s later, one by one), 5 the question,
   6 "Fill in" turns active. Each step plays once, when its top is 40 px inside
   the viewport; a step that comes into view also starts the earlier ones.
   Only opacity and transform move, so nothing shifts.
   ========================================================================== */

.bkai-fig.js-reveal [data-step]:where(:not([data-ride])):not(.is-in) {
    opacity: 0;
}

.bkai-fig.js-reveal [data-step="6"]:not(.is-in) {
    opacity: 0.45;
}

.bkai-fig.js-reveal .scrim[data-ride]:not(.is-in),
.bkai-fig.js-reveal .bkai-dot[data-ride]:not(.is-in) {
    opacity: 0;
}

.bkai-fig.js-reveal .bkai-mk[data-ride]:not(.is-in)::before {
    opacity: 0;
}

.bkai-fig.js-reveal [data-step]:where(:not([data-ride])).is-in {
    animation: bkai-in 380ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
    animation-delay: var(--d, 120ms);
}

.bkai-fig.js-reveal .bkai-rc-wrap.is-in {
    animation-name: bkai-settle;
    animation-duration: 700ms;
}

.bkai-fig.js-reveal .bkai-phone.is-in {
    animation-name: bkai-rise;
    animation-duration: 600ms;
}

.bkai-fig.js-reveal .scrim.is-in {
    animation: bkai-fade 380ms ease both;
    animation-delay: var(--d, 120ms);
}

.bkai-fig.js-reveal .ai-chat.is-in {
    animation-name: bkai-sheet;
    animation-duration: 520ms;
}

/* No translate: in the app "Fill in" is disabled until a proposal exists. */
.bkai-fig.js-reveal [data-step="6"].is-in {
    animation-name: bkai-arm;
}

.bkai-fig.js-reveal .bkai-dot.is-in {
    animation: bkai-fade 420ms ease both;
    animation-delay: calc(var(--d, 120ms) + 420ms + var(--i, 0) * 150ms);
}

.bkai-fig.js-reveal .bkai-mk.is-in::before {
    animation: bkai-mark 520ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
    animation-delay: calc(var(--d, 120ms) + 420ms + var(--i, 0) * 150ms);
}

@keyframes bkai-settle {
    from { opacity: 0; transform: translate(-12px, -18px) rotate(calc(var(--rc-rot) - 5deg)); }
    to { opacity: 1; transform: rotate(var(--rc-rot)); }
}

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

@keyframes bkai-sheet {
    from { opacity: 0; transform: translateY(56px); }
    to { opacity: 1; transform: none; }
}

@keyframes bkai-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

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

@keyframes bkai-arm {
    from { opacity: 0.45; }
    to { opacity: 1; }
}

@keyframes bkai-mark {
    from { opacity: 0; transform: scaleX(0.82); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .bkai-fig [data-step],
    .bkai-fig [data-step]::before {
        opacity: 1 !important;
        animation: none !important;
    }
}

/* Print: the complete static state. The phone's big soft shadow prints as a
   hard block over the paper and the glow as a smudge, so both go; the paper
   (mask, noise) and the app screen need their backgrounds even when
   "background graphics" is off. */
@media print {
    .bkai-fig [data-step],
    .bkai-fig [data-step]::before {
        opacity: 1 !important;
        animation: none !important;
    }

    .bkai-phone {
        box-shadow: none;
    }

    .bkai-glow {
        display: none;
    }

    .bkai,
    .bkai-fig {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
