/* essay-typing-surface.css — the typing surface both hosts of Essay Typing's
   engine draw on (ADR-0109).

   These rules were the second section of `essay-typing.html`'s inline
   <style>, back when that page was the engine's only host. Write Essay now
   hosts the same engine over its own textarea, so the surface the Essay
   Painter writes into — the box, the invisible input above it, the `.char`
   spans, the `.wgrp` runs the annotation overlay measures, the annotation
   layer itself and the Inline Choice clusters — is shared, and lives here.

   What did NOT move stayed for a reason: the standalone page's own layout,
   its question header and picker, its tweaks panel, its rail readouts, and
   the pacing states (`.warning`, `.danger`) that Write Essay deliberately
   does not paint (ADR-0109: the countdown already says what they say).

   Two hosts, one way in. The display and the annotation layer are the Essay
   Typing Surface's furniture (ADR-0121), built inside `.typing-area-wrapper`
   on either page and carrying `.typing-display` and `.annotation-layer`, so
   every rule here keys off those classes with the wrapper in front. The one
   id left is the standalone page's textarea, which is still that page's own;
   Write Essay's carries `.typing-input`.

   Colours come from the `--typing-*` tokens in `css/main.css`, which are the
   values this block used to declare in a page-local `:root`. The Devanagari
   gloss face below is the one face outside `--font-ui`/`--font-passage`/
   `--font-mono` that docs/STYLE_GUIDE.md sanctions by name, and it is
   self-hosted like the other three: its `@font-face` is in `css/main.css`, so
   the gloss draws the same on a machine with no Devanagari installed as on one
   that has it. The names after it are a fallback that should never be reached. */

/*
    The essay scrolls inside this box rather than pushing the page down. That
    is a reading choice, not a layout constraint: the annotation overlay is
    positioned in this element's *content* coordinates
    (rect.top - wrapperRect.top + scrollTop), which is correct whether the box
    scrolls or the page does.

    `flex: 1` is the standalone page's height chain reaching this element; in
    Write Essay's grid it means nothing and the box takes the height the
    textarea declares (Writing/Write_Essay.css).
*/
.typing-area-wrapper {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
    flex: 1;
    min-height: 220px;
    overflow-y: auto;
    cursor: text;
    transition: border-color 0.3s, box-shadow 0.3s, background 0.3s;
}

.typing-area-wrapper.focused {
    border-color: var(--typing-accent);
    background: var(--surface);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--typing-accent) 15%, transparent);
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0; }
}

/* ─── Keystroke feedback flourishes (paired with the typing earcons) ───
   These speak the same vocabulary as the pacing states above (the warning
   amber and the danger red/tint) but under their own class names. Sharing
   `warning`/`danger` was tempting and wrong: those belong to the timer and
   persist for minutes, while these are keystroke-driven and transient, so a
   typo could cancel a pacing cue (or a pacing cue swallow a typo pulse).
   The sustained error-run tint is a colour change, not motion, so it stays
   outside the reduced-motion gate; the two animations do not. */
.typing-area-wrapper.typo-run {
    border-color: var(--typing-incorrect);
    background: var(--typing-error-tint);
}
@media (prefers-reduced-motion: no-preference) {
    /* One-shot cousin of pulse-warning: same amber, but it fires once per
       slip instead of looping, mirroring the single low thud it pairs with. */
    .typing-area-wrapper.typo-slip {
        animation: pulse-typo 0.45s 1;
    }
    /* The just-typed correct char glints and fades, a visual echo of the
       tick. Colour only: `.char` is display:inline, so transforms would
       silently no-op here anyway. */
    .char.tick-flash {
        animation: tick-flash 0.35s 1;
        border-radius: 2px;
    }
}
@keyframes pulse-typo {
    0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--typing-typo-pulse) 45%, transparent); }
    100% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--typing-typo-pulse) 0%, transparent); }
}
@keyframes tick-flash {
    0%   { background: var(--typing-accent-soft); }
    100% { background: transparent; }
}

/* Every declaration from `margin` down neutralises main.css's bare-`textarea`
   rule (main.css:224). `min-height: 250px` in particular would push this
   invisible, z-index-10 element past the wrapper on short viewports and
   swallow clicks meant for the content below it. */
#hidden-input,
.typing-area-wrapper .typing-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    color: transparent;
    caret-color: transparent;
    -webkit-text-fill-color: transparent;
    background: transparent;
    border: 0;
    outline: 0;
    z-index: 10;
    cursor: text;
    resize: none;
    width: 100%; height: 100%;
    margin: 0;
    padding: 0;
    min-height: 0;
    font: inherit;
}

/* The essay is the page's reading text, so it is set in the body ink rather
   than the muted grey it used to wear: what the learner has not typed yet is
   the thing they are reading, and reading it should not feel like reading a
   placeholder. Progress is carried by the colour the typed characters take
   instead (below). */
.typing-area-wrapper .typing-display {
    font-size: 18px;
    line-height: 2.2;            /* generous so annotations have headroom above */
    color: var(--ink);
    white-space: pre-wrap;
    position: relative;
    z-index: 1;
    pointer-events: none;
    user-select: none;
    font-feature-settings: "liga" 1, "calt" 1;
}

/* Per-character spans */
.char {
    display: inline;
}
/*
    Typed-and-correct text turns the rail arrows' blue, so the learner reads
    their own progress as a coloured trail through black text. The token is
    --accent, not the raw brand blue those buttons are tinted from: this is
    small body text on white, and --accent is the AA-safe darkening of it.

    Written with the wrapper and the display in front of it for the
    specificity alone (three classes). Bold vocabulary targets and sense-group
    words carry their own colour rule later in this file, and typing state has
    to outrank both; otherwise the trail would break wherever it crossed the
    words the learner is here to learn.
*/
.typing-area-wrapper .typing-display .char.correct {
    color: var(--typing-accent);
}
.char.incorrect {
    color: var(--typing-incorrect);
    background: var(--incorrect-bg);
    border-radius: 2px;
}
.char.cursor {
    position: relative;
    animation: blink 1.05s infinite;
}
.char.cursor::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.08em;
    bottom: 0.08em;
    border-left: 2px solid var(--typing-cursor);
}
.char.cursor-space {
    position: relative;
    animation: blink 1.05s infinite;
}
.char.cursor-space::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 0.08em;
    width: 0.7em;
    transform: translateX(-50%);
    border-bottom: 2px solid var(--typing-cursor);
}
.char.cursor-enter {
    position: relative;
    animation: blink 1.05s infinite;
}
.char.cursor-enter::after {
    content: "";
    position: absolute;
    left: calc(100% + 0.12em);
    bottom: 0.08em;
    width: 0.7em;
    border-bottom: 2px solid var(--typing-cursor);
}
.char.target-bold,
.wgrp.target-sense .char {
    font-weight: 600;
    color: var(--ink);
}
.wgrp.target-sense {
    background: color-mix(in srgb, var(--typing-accent-soft) 35%, transparent);
    border-radius: 3px;
}
.char.sense-gap {
    background: color-mix(in srgb, var(--typing-accent-soft) 35%, transparent);
}
.char.target-italic { font-style: italic; }

/* Word grouping wrapper: receives syntax-tint underline + annotation anchors */
.wgrp {
    position: relative;
    display: inline;
    text-decoration-thickness: 2px;
    text-underline-offset: 5px;
}

/* ── Syntax tinting: sentence parts (subject/verb/object/modifier/connector) ──
   Keyed off the wrapper, which the Essay Typing Surface writes `data-syntax`
   on from the view's tweak (ADR-0121), so the prose's styling depends only on
   the element the Surface owns. Nothing writes the attribute on <body>. */
.typing-area-wrapper[data-syntax="parts"] .wgrp[data-role="subj"] { text-decoration: underline; text-decoration-color: var(--typing-role-subj); text-decoration-thickness: 2px; }
.typing-area-wrapper[data-syntax="parts"] .wgrp[data-role="pred"] { text-decoration: underline; text-decoration-color: var(--typing-role-pred); text-decoration-thickness: 2px; }
.typing-area-wrapper[data-syntax="parts"] .wgrp[data-role="obj"]  { text-decoration: underline; text-decoration-color: var(--typing-role-obj);  text-decoration-thickness: 2px; }
.typing-area-wrapper[data-syntax="parts"] .wgrp[data-role="mod"]  { text-decoration: underline; text-decoration-color: var(--typing-role-mod);  text-decoration-thickness: 2px; text-decoration-style: dotted; }
.typing-area-wrapper[data-syntax="parts"] .wgrp[data-role="conn"] { text-decoration: underline; text-decoration-color: var(--typing-role-conn); text-decoration-thickness: 2px; text-decoration-style: dotted; }

/* ── Annotation overlay (lives inside the typing area, above the text) ── */
.annotation-layer {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    pointer-events: none;
    z-index: 5;
}
.ann {
    position: absolute;
    transform: translateY(-100%);
    margin-top: 1px;
    font-size: 9.5px;
    letter-spacing: 0.4px;
    color: var(--ink-muted);
    line-height: 1;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.25s, color 0.25s;
}
.ann.is-visible    { opacity: 1; color: var(--ink-muted); } /* full opacity: translucency can't reach AA at this size; the active state still dominates via accent+bold */
.ann.is-active     { opacity: 1; color: var(--typing-accent); font-weight: 700; }
.ann.kind-bold     { color: var(--ink-secondary); font-weight: 700; }
.ann.kind-bold.is-active { color: var(--typing-accent); }
.ann.kind-italic {
    color: var(--typing-accent);
    text-transform: uppercase;
    font-weight: 700;
    font-size: 9px;
    letter-spacing: 0.9px;
    background: var(--typing-accent-soft);
    padding: 1px 5px;
    border-radius: 999px;
    line-height: 1.2;
    /* Lifted a little further off its line than the other annotations: this
       one is a section heading sitting above a paragraph, and it reads as
       labelling that paragraph only if there is air between the two. */
    transform: translateY(-130%);
}

/* Nepali gloss appears below the contextual sense group */
.gloss {
    position: absolute;
    transform: translateY(38%);
    font-size: 13px;
    line-height: 1;
    color: var(--typing-accent);
    letter-spacing: 0;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.25s;
    /* Mangal and Arial were a machine's fonts, not ours: the Noto face is
       unicode-range scoped to U+0900-097F, so the Latin inside a gloss fell
       through to whatever the box had and the same gloss was two pictures
       (#1011, ADR-0051). --font-ui is the shipped answer behind it. */
    font-family: "Noto Sans Devanagari", var(--font-ui);
    font-style: normal;
    font-weight: 400;
}
.gloss.is-visible { opacity: 0.85; }
.gloss.is-muted {
    /* de-emphasis kept via colour, not translucency; AA needs 4.5:1 */
    color: var(--ink-muted);
    opacity: 1;
}
.gloss.is-active {
    color: var(--typing-accent);
    opacity: 0.9;
}

/* ─── Inline Choice (bracketed vertical stack of alternatives) ─── */
.choice-block {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    position: relative;
    padding: 2px 14px;
    margin: 0 8px;
    line-height: 1.15;
}
.choice-options {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
}
.choice-preview {
    display: none;
    color: var(--ink-muted);
    font-style: italic;
    white-space: nowrap;
}
.choice-block.is-preview {
    padding: 0 2px;
    margin: 0;
}
.choice-block.is-preview::before,
.choice-block.is-preview::after,
.choice-block.is-preview .choice-options,
.choice-block.is-preview .choice-confirm-hint,
.choice-block.is-preview .choice-hint {
    display: none;
}
.choice-block.is-preview .choice-preview {
    display: inline;
}
.choice-block::before,
.choice-block::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 5px;
    border-color: var(--ink-secondary);
    border-style: solid;
}
.choice-block::before {
    left: 0;
    border-width: 1.5px 0 1.5px 1.5px;
    border-top-left-radius: 3px;
    border-bottom-left-radius: 3px;
}
.choice-block::after {
    right: 0;
    border-width: 1.5px 1.5px 1.5px 0;
    border-top-right-radius: 3px;
    border-bottom-right-radius: 3px;
}
.choice-row {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    padding: 0 2px;
    border-radius: 3px;
    min-height: 1.65em;
    transition: opacity 180ms ease, color 180ms ease, background-color 180ms ease;
}
.choice-row.is-distractor {
    color: var(--ink-muted);
}
.choice-row.is-correct {
    color: var(--ink-muted);
}
.choice-row.is-accepted-option {
    color: var(--ink-muted);
}
/* Chars on a row whose alternative starts with the typed prefix get this class
   so the learner can see what they've typed echoed onto the matching row. */
/* The prefix typed inside a cluster wears the same progress blue as the essay
   around it; it used to be `--ink`, which distinguished it from muted body
   text, and no longer would now that the body text is ink too. */
.choice-row .dchar.is-typed,
.choice-row .char.is-typed {
    color: var(--typing-accent);
    font-weight: 500;
}
.choice-row .dchar.incorrect,
.choice-row .char.incorrect {
    color: var(--typing-incorrect);
    background: var(--incorrect-bg);
    border-radius: 2px;
}
/* The cursor inside an Inline Choice also lands on `.dchar` spans, not just
   the engine's `.char` spans, so the styling needs to apply to both. */
.choice-row .dchar.cursor,
.choice-row .char.cursor {
    position: relative;
    animation: blink 1.05s infinite;
}
.choice-row .dchar.cursor::before,
.choice-row .char.cursor::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.08em;
    bottom: 0.08em;
    border-left: 2px solid var(--typing-cursor);
}
.choice-row.is-struck {
    text-decoration: line-through;
    text-decoration-color: var(--typing-incorrect);
    text-decoration-thickness: 1.5px;
    color: var(--ink-muted);
    opacity: 0.6;
}
.choice-row.is-struck .dchar,
.choice-row.is-struck .char {
    text-decoration: line-through;
    text-decoration-color: var(--typing-incorrect);
    text-decoration-thickness: 1.5px;
}
.choice-row.is-struck .dchar.is-typed,
.choice-row.is-struck .dchar.cursor { display: none; }
/* The tick is a picture now, not a ✓ (#832): `--nav-icon-size` restates the
   12px the glyph was set to and the artwork takes the correct-ink through
   `currentColor`, so the hold animation below is untouched. */
.choice-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 5px;
    color: var(--typing-correct);
    --nav-icon-size: 12px;
    line-height: 1;
    opacity: 0;
    transform: translateY(2px) scale(0.65);
}
/* Multi-accepted choices stay expanded until the active sentence advances.
   Their checks should remain visible instead of using the one-shot pop. */
.choice-block.is-accepted-hold .choice-row.is-accepted-choice .choice-check {
    opacity: 1;
    transform: none;
    animation: none;
}
.choice-hint {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    align-self: center;
    font-size: 12px;
    line-height: 1.65;
    color: var(--typing-accent);
    background: color-mix(in srgb, var(--typing-accent-soft) 38%, transparent);
    border-radius: 0 4px 4px 0;
    padding: 5px 8px 5px 10px;
    margin-left: 10px;
    gap: 3px;
    font-style: normal;
    white-space: normal;
    width: max-content;
    max-width: min(220px, calc(100% - 16px));
    z-index: 5;
    pointer-events: none;
}
.choice-hint::after {
    display: none;
}
/* Wrong-answer hints are a column of marks alone. Empty rows are kept in the
   layout so each symbol lines up with the matching alternative row.

   The marks are the icon set's now, not ✅ ❌ • (#832): `.nav-icon` in
   main.css says how one sits, `--nav-icon-size` restates the 15px the glyphs
   were set to, and each takes `currentColor` — so the verdict's colour is
   this stylesheet's to say, which is what the two rules below finally do. A
   colour emoji ignored `.is-incorrect-choice` entirely. */
.choice-hint-row {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.4em;
    min-height: 1.9em;
    padding: 0;
    font-size: 15px;
    line-height: 1;
}
.choice-hint-row.is-empty {
    opacity: 0;
}
.choice-hint-row.is-incorrect-choice {
    color: var(--typing-incorrect);
}
.choice-hint-row.is-correct-choice {
    color: var(--typing-correct);
}
.choice-hint-emoji {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    --nav-icon-size: 15px;
}
.choice-hint-note {
    display: inline-flex;
    align-items: center;
    min-height: 1.65em;
    margin-top: 4px;
    padding: 0 2px;
    color: var(--ink);
    font-weight: 700;
    font-size: 10.5px;
}
.choice-hint[hidden] {
    display: none;
}
.choice-confirm-hint {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    align-self: center;
    font-size: 11.5px;
    line-height: 1.65;
    color: var(--typing-accent);
    background: color-mix(in srgb, var(--typing-accent-soft) 38%, transparent);
    border-left: 2px solid var(--typing-accent);
    border-radius: 0 4px 4px 0;
    padding: 5px 10px 5px 12px;
    margin-left: 12px;
    white-space: nowrap;
    z-index: 5;
    pointer-events: none;
}
.choice-confirm-hint[hidden] {
    display: none;
}
.choice-confirm-row {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    min-height: 1.65em;
    padding: 0 2px;
}
.choice-confirm-key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.9em;
    padding: 1px 6px 2px;
    border: 1px solid var(--control-border);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: var(--surface-sunken);
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.08);
    font-weight: 700;
    color: var(--ink);
    font-size: 10.5px;
    line-height: 1.25;
    font-style: normal;
    letter-spacing: 0.02em;
}
.choice-row.is-hidden {
    opacity: 0;
    pointer-events: none;
    height: 0;
    overflow: hidden;
    padding-top: 0;
    padding-bottom: 0;
}
.choice-block.is-resolved {
    padding: 0;
    margin: 0;
}
.choice-block.is-resolved::before,
.choice-block.is-resolved::after {
    display: none;
}
.dchar {
    display: inline-block;
    font: inherit;
    color: inherit;
}

/* ── Choice ghost: non-selected accepted alternative after sentence exit ── */
.choice-resolved {
    position: relative;
    display: inline;
}
.choice-ghost {
    position: absolute;
    top: calc(100% + 1px);
    left: 0;
    font-size: 0.68em;
    color: var(--ink-secondary);
    opacity: 0.38;
    line-height: 1;
    white-space: nowrap;
    pointer-events: none;
}
