/* ═══════════════════════════════════════════════════════════════════
   Number Decoder (D106) — /Articles/NumbersInChineseCulture

   One page, one widget. Everything colour-neutral uses Bootstrap's own CSS
   variables so the decoder follows the site's dark mode with no second
   palette to keep in step; only the four verdict accents are stated here,
   and each is given as a translucent tint over the body background rather
   than a flat colour, so it reads on either theme.

   The prefix is "nd", never "ad" — a class or id containing "ad" is what
   content blockers match on, and a blocked widget looks like a broken page.
   ═══════════════════════════════════════════════════════════════════ */

.nd {
    --nd-gold: #f59e0b;
    --nd-red: #dc2626;
    --nd-green: #10b981;
    --nd-slate: #64748b;
    border-radius: 0.75rem;
    overflow: hidden;
}

.nd-hero {
    background: linear-gradient(135deg, #b91c1c 0%, #dc2626 55%, #f59e0b 100%);
    color: #fff;
}

/* ── The box you type a number into ─────────────────────────────── */
.nd-input {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.nd-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.nd-chip {
    border: 1px solid var(--bs-border-color);
    background: var(--bs-tertiary-bg);
    color: var(--bs-body-color);
    border-radius: 999px;
    padding: .2rem .7rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    transition: transform .12s ease, border-color .12s ease, background-color .12s ease;
}

.nd-chip:hover,
.nd-chip:focus-visible {
    transform: translateY(-2px);
    border-color: var(--nd-red);
    background: color-mix(in srgb, var(--nd-red) 12%, var(--bs-body-bg));
}

/* ── The answer's header ────────────────────────────────────────── */
.nd-head {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    border: 1px solid var(--bs-border-color);
    border-left: 5px solid var(--nd-gold);
    border-radius: .6rem;
    padding: .8rem 1rem;
    margin-bottom: .9rem;
    background: var(--bs-tertiary-bg);
}

.nd-head-number {
    font-size: clamp(2rem, 9vw, 3rem);
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: var(--nd-red);
}

.nd-head-body { flex: 1 1 14rem; min-width: 0; }
.nd-head-han { font-size: 1.5rem; line-height: 1.3; }
.nd-head-notes { padding-left: 1.1rem; margin-top: .25rem; }

/* ── A whole number read as a phrase ────────────────────────────── */
.nd-code {
    border: 1px solid var(--bs-border-color);
    border-radius: .6rem;
    padding: .8rem 1rem;
    margin-bottom: .9rem;
    background: var(--bs-body-bg);
}

.nd-code-exact {
    border-color: color-mix(in srgb, var(--nd-red) 45%, var(--bs-border-color));
    background: color-mix(in srgb, var(--nd-red) 7%, var(--bs-body-bg));
}

.nd-code-kicker { text-transform: uppercase; letter-spacing: .06em; opacity: .75; }
.nd-code-phrase { font-size: 1.9rem; line-height: 1.25; }
.nd-code-pinyin { opacity: .8; }
.nd-code-meaning { font-weight: 600; }

.nd-map {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
    gap: .5rem;
}

.nd-map-cell {
    display: grid;
    justify-items: center;
    gap: .1rem;
    text-align: center;
    border: 1px dashed var(--bs-border-color);
    border-radius: .5rem;
    padding: .4rem .25rem;
}

.nd-map-digit { font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.nd-map-arrow { opacity: .45; font-size: .8rem; line-height: 1; }
.nd-map-han { font-size: 1.5rem; line-height: 1.2; }
.nd-map-pin { font-size: .85rem; opacity: .8; }
.nd-map-gloss { font-size: .75rem; opacity: .7; }

/* ── One card per digit ─────────────────────────────────────────── */
.nd-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: .7rem;
}

.nd-card {
    border: 1px solid var(--bs-border-color);
    border-left: 5px solid var(--nd-slate);
    border-radius: .6rem;
    padding: .7rem .85rem;
    background: var(--bs-body-bg);
}

.nd-card.nd-lucky { border-left-color: var(--nd-gold); }
.nd-card.nd-avoided { border-left-color: var(--nd-red); }
.nd-card.nd-mixed { border-left-color: var(--nd-slate); }
.nd-card.nd-neutral { border-left-color: var(--bs-border-color); }

.nd-card-top {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: .45rem;
    margin-bottom: .3rem;
}

.nd-card-num {
    font-size: 1.5rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.nd-card-han { font-size: 1.7rem; line-height: 1.1; }
.nd-card-pin { opacity: .8; }

/* "×3" — a repeated digit gets one card that says how often it occurs, rather
   than three identical cards. */
.nd-times {
    font-size: .78rem;
    font-weight: 700;
    border-radius: 999px;
    padding: .05rem .4rem;
    background: var(--bs-tertiary-bg);
    color: var(--bs-secondary-color);
}

.nd-verdict {
    margin-left: auto;
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    border-radius: 999px;
    padding: .1rem .55rem;
    border: 1px solid currentColor;
    white-space: nowrap;
}

.nd-lucky .nd-verdict { color: #a16207; }
.nd-avoided .nd-verdict { color: var(--nd-red); }
.nd-mixed .nd-verdict,
.nd-neutral .nd-verdict { color: var(--nd-slate); }

/* The gold has to lift in dark mode or it reads as brown on near-black. */
@media (prefers-color-scheme: dark) {
    .nd-lucky .nd-verdict { color: var(--nd-gold); }
}

[data-bs-theme="dark"] .nd-lucky .nd-verdict { color: var(--nd-gold); }

.nd-sounds { display: grid; gap: .45rem; }

.nd-sound {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    align-items: baseline;
    gap: .35rem .5rem;
    border-top: 1px solid var(--bs-border-color);
    padding-top: .45rem;
}

.nd-sound-han { font-size: 1.35rem; line-height: 1.2; }
.nd-sound-pin { font-weight: 600; }
.nd-sound-gloss { font-size: .9rem; opacity: .85; min-width: 0; }

.nd-like {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-radius: 999px;
    padding: .05rem .45rem;
    white-space: nowrap;
}

.nd-exact { background: color-mix(in srgb, var(--nd-green) 22%, transparent); color: #047857; }
.nd-tone { background: color-mix(in srgb, var(--nd-gold) 26%, transparent); color: #92400e; }
.nd-near { background: var(--bs-tertiary-bg); color: var(--bs-secondary-color); }

@media (prefers-color-scheme: dark) {
    .nd-exact { color: #6ee7b7; }
    .nd-tone { color: #fcd34d; }
}

[data-bs-theme="dark"] .nd-exact { color: #6ee7b7; }
[data-bs-theme="dark"] .nd-tone { color: #fcd34d; }

.nd-sound-note,
.nd-role {
    grid-column: 1 / -1;
    font-size: .78rem;
    opacity: .72;
}

.nd-role {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    opacity: .55;
}

/* ── The little speaker buttons ─────────────────────────────────── */
.nd-speak {
    border: 1px solid var(--bs-border-color);
    background: transparent;
    color: var(--bs-secondary-color);
    border-radius: 999px;
    line-height: 1;
    padding: .1rem .35rem;
    font-size: .75rem;
    vertical-align: middle;
}

.nd-speak:hover,
.nd-speak:focus-visible { color: var(--nd-red); border-color: var(--nd-red); }

.nd-caveat { opacity: .7; margin-top: .8rem; }

/* ── Entrance ───────────────────────────────────────────────────── */
.nd-in {
    animation: nd-rise .34s cubic-bezier(.21, .95, .36, 1) both;
    animation-delay: calc(var(--nd-i, 0) * 45ms);
}

@keyframes nd-rise {
    from { opacity: 0; transform: translateY(10px) scale(.985); }
    to { opacity: 1; transform: none; }
}

/* A lucky digit gets one pass of a gold sheen, so the answer has a moment of
   life without anything continuing to move beside an ad. */
.nd-card.nd-lucky.nd-in::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(105deg, transparent 35%, color-mix(in srgb, var(--nd-gold) 30%, transparent) 50%, transparent 65%);
    animation: nd-sheen .85s ease-out both;
    animation-delay: calc(var(--nd-i, 0) * 45ms + 180ms);
}

.nd-card { position: relative; overflow: hidden; }

@keyframes nd-sheen {
    from { transform: translateX(-100%); opacity: 0; }
    35% { opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .nd-in,
    .nd-card.nd-lucky.nd-in::after,
    .nd-chip { animation: none; transition: none; }

    .nd-chip:hover,
    .nd-chip:focus-visible { transform: none; }
}
