/* ============================================================
   ACE Grammar Engine — ND Entity Table
   Clean consolidated stylesheet
   ============================================================ */

:root {
    --ace-prepend-color: #2563eb;
    --ace-stem-color: #111827;
    --ace-append-color: #b91c1c;
    --ace-muted-color: #6b7280;

    --ace-bg: #f5f7fa;
    --ace-card-bg: #ffffff;
    --ace-border: #d9dee5;
    --ace-control-border: #bfc7d1;
    --ace-text: #20242a;
    --ace-meta: #5b6470;
}

/* ------------------------------------------------------------
   Base
   ------------------------------------------------------------ */

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--ace-bg);
    color: var(--ace-text);
}

.ace-wrap {
    width: min(1180px, calc(100% - 24px));
    margin: 16px auto 32px;
}

h1 {
    margin: 0 0 6px;
    font-size: 1.45rem;
}

.ace-meta {
    margin: 4px 0;
    color: var(--ace-meta);
    font-size: 0.92rem;
}

.notice {
    text-align: center;
}


/* ------------------------------------------------------------
   Controls
   ------------------------------------------------------------ */

.ace-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 10px;
    align-items: end;

    margin: 12px 0;
    padding: 10px;

    background: var(--ace-card-bg);
    border: 1px solid var(--ace-border);
    border-radius: 10px;
}

.ace-controls label {
    display: flex;
    flex-direction: column;
    gap: 4px;

    font-size: 0.82rem;
    font-weight: 700;
}

.ace-controls select {
    min-width: 145px;
    max-width: 300px;

    padding: 6px 8px;

    background: #fff;
    border: 1px solid var(--ace-control-border);
    border-radius: 6px;
}


/* ------------------------------------------------------------
   Flashcard
   ------------------------------------------------------------ */

.ace-card {
    margin-top: 12px;
    padding: 16px;

    background: var(--ace-card-bg);
    border: 1px solid var(--ace-border);
    border-radius: 12px;

    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.ace-address {
    margin-bottom: 6px;
    font-weight: 700;
}


/* ------------------------------------------------------------
   Latin / transliteration
   ------------------------------------------------------------ */

.ace-latin {
    margin-top: 16px;
    text-align: center;
    font-size: 1.25rem;
}

.ace-prepend-text {
    color: var(--ace-prepend-color);
}

.ace-append-text {
    color: var(--ace-append-color);
}


/* ------------------------------------------------------------
   Shared component colors
   Arabic + English + Urdu
   ------------------------------------------------------------ */

.ace-prepend,
.ace-meaning-prepend {
    color: var(--ace-prepend-color);
    font-weight: 700;
}

.ace-stem,
.ace-meaning-stem {
    color: var(--ace-stem-color);
    font-weight: 700;
}

.ace-append,
.ace-meaning-append {
    color: var(--ace-append-color);
    font-weight: 700;
}

.ace-meaning-plus {
    color: var(--ace-muted-color);
    font-weight: 400;
}


/* ------------------------------------------------------------
   Arabic construction
   ------------------------------------------------------------ */

/*
   IMPORTANT:
   Arabic prepend/stem/append spans must remain inline.

   Do NOT apply:
   - flex
   - inline-block
   - transform
   - margin
   - gap
   - letter-spacing

   directly to these Arabic spans.

   Those properties can visually separate joined Arabic letters.
*/

.ace-arabic {
    margin: 18px 0 12px;

    direction: rtl;
    unicode-bidi: plaintext;
    text-align: center;

    font-family:
        "Amiri",
        "Noto Naskh Arabic",
        "Scheherazade New",
        "Traditional Arabic",
        serif;

    font-size: clamp(3.2rem, 7vw, 5.6rem);
    line-height: 1.5;

    white-space: nowrap;
}

.ace-arabic-word {
    display: inline;

    direction: rtl;
    unicode-bidi: embed;

    letter-spacing: 0;
    word-spacing: 0;
}

.ace-prepend,
.ace-stem,
.ace-append,
.ace-joiner {
    display: inline;

    margin: 0;
    padding: 0;
    border: 0;

    letter-spacing: 0;
    word-spacing: 0;
}

/*
   Invisible ZWJ helper.
   Used only to preserve contextual joining across span boundaries.
*/
.ace-joiner {
    font-size: 0;
    line-height: 0;
}


/* ------------------------------------------------------------
   Arabic relay animation
   ------------------------------------------------------------ */

/*
   Arabic uses relative "top" animation instead of transform.

   This keeps each Arabic component inline and prevents the
   prepend/stem/append from appearing detached.
*/

.ace-drop {
    position: relative;
    top: -1.15em;
    opacity: 0;

    animation:
        aceArabicRelayDrop
        900ms
        cubic-bezier(.2, .75, .2, 1)
        forwards;
}

.ace-prepend.ace-drop {
    animation-delay: 350ms;
}

.ace-append.ace-drop {
    animation-delay: 1250ms;
}

@keyframes aceArabicRelayDrop {
    0% {
        top: -1.15em;
        opacity: 0;
    }

    60% {
        top: 0.10em;
        opacity: 1;
    }

    82% {
        top: -0.035em;
        opacity: 1;
    }

    100% {
        top: 0;
        opacity: 1;
    }
}


/* ------------------------------------------------------------
   English / Urdu translations
   ------------------------------------------------------------ */

.ace-translation {
    margin: 0.55rem 0;

    text-align: center;

    font-size: 1.15rem;
    line-height: 1.7;
}

.ace-translation-en {
    direction: ltr;
    text-align: center;
}

.ace-translation-ur {
    direction: rtl;
    text-align: center;
    font-size: 1.25rem;
}


/* ------------------------------------------------------------
   Translation relay
   ------------------------------------------------------------ */

/*
   English and Urdu do not require Arabic contextual joining,
   so transform-based animation is safe here.

   Relay order:
   1. stem
   2. prepend
   3. append
*/

.ace-translation .ace-relay-stem,
.ace-translation .ace-relay-prepend,
.ace-translation .ace-relay-append {
    display: inline-block;
    will-change: opacity, transform;
}

.ace-translation .ace-relay-stem {
    animation: aceStemSettle 550ms ease-out both;
}

.ace-translation .ace-relay-prepend {
    animation:
        aceTranslationRelayDrop
        850ms
        cubic-bezier(.22, .8, .25, 1)
        450ms
        both;
}

.ace-translation .ace-relay-append {
    animation:
        aceTranslationRelayDrop
        950ms
        cubic-bezier(.22, .8, .25, 1)
        1150ms
        both;
}

@keyframes aceStemSettle {
    0% {
        opacity: 0;
        transform: scale(0.96);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes aceTranslationRelayDrop {
    0% {
        opacity: 0;
        transform: translateY(-1.1em);
    }

    65% {
        opacity: 1;
        transform: translateY(0.12em);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}


/* ------------------------------------------------------------
   Refresh countdown
   ------------------------------------------------------------ */

.ace-countdown {
    display: inline-block;

    min-width: 4.6rem;

    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.ace-countdown.is-off {
    color: #777;
    opacity: 0.6;
}

.ace-countdown.is-refreshing {
    animation:
        aceCountdownPulse
        650ms
        ease-in-out
        infinite
        alternate;
}

@keyframes aceCountdownPulse {
    from {
        opacity: 0.45;
    }

    to {
        opacity: 1;
    }
}


/* ------------------------------------------------------------
   Accessibility
   ------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {

    .ace-drop {
        top: 0;
        opacity: 1;
        animation: none !important;
    }

    .ace-translation .ace-relay-stem,
    .ace-translation .ace-relay-prepend,
    .ace-translation .ace-relay-append,
    .ace-countdown.is-refreshing {
        animation: none !important;
        transform: none !important;
        opacity: 1 !important;
    }
}