:root {
    --paper: #F7F2E9;
    --paper-2: #EFE8DB;
    --paper-edge: #E4DBC7;
    --ink: #1A1613;
    --ink-2: #3A332C;
    --ink-3: #5F554A;
    --ink-4: #9B8E80;
    --cinnabar: #B23A2C;
    --cinnabar-deep: #8E2A1E;
    --card-bg: #FFFDF8;
    --card-edge: #E2D7C0;
    --control-bg: #FFFDF8;
    --control-border: #D9CDB6;
    --button-primary-bg: #B23A2C;
    --button-primary-fg: #FFF9EE;
    /* One fill on every page and in every state; hover and press only
       darken it a step. */
    --button-primary-hover: #9E3326;
    --button-primary-active: #8E2A1E;
    --page-warmth: rgba(178, 58, 44, 0.055);
    --radius: 3px;
    --radius-lg: 6px;
    --shadow-soft: 0 2px 8px rgba(26, 22, 19, 0.07);
    --shadow-hover: 0 6px 16px rgba(26, 22, 19, 0.10);
    /* The type system, used everywhere:
       --font-cjk   Song, for every hanzi.
       --font-text  the text serif: roman for English meanings; italic for
                    the lit. gloss, example translations, the results
                    header, rank numerals, spark prompts and headings.
       --pinyin     every pinyin (hero ruby, headwords, cards, the 逐字
                    strip, similar chips, the popover): the roman text
                    serif, tracked --pinyin-tracking, in the muted ink.
       --font-sans  only buttons, chips, tags and the tracked eyebrows. */
    --font-cjk: "Songti SC", "STSong", "SimSun", "Noto Serif CJK SC", "Source Han Serif SC", serif;
    --font-text: Georgia, "Times New Roman", serif;
    --font-sans: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
    --pinyin: Georgia, "Times New Roman", serif;
    --pinyin-tracking: 0.02em;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;
    --max-hero: 920px;
    --max-results: 1100px;
    --page-pad: 40px;
    /* Compact result rows share one grid: rank | headword | meaning | actions. */
    --row-rank-col: 28px;
    /* Room for eight glyphs at 26px, or four at 36px, with their pinyin. */
    --row-headword-col: 13.5rem;
    /* Rank numerals: the display serif in the accent. */
    --rank-fg: #B23A2C;
    /* Non-interactive tags: a paper tint inside a hairline. */
    --tag-bg: #F1EADC;
    --tag-line: #E2D7C0;
    /* Chinese example text on rows and cards: about 80% of the body ink. */
    --ink-zh: #463D35;
    --chip-radius: 4px;
    --focus-ring: 0 0 0 3px rgba(178, 58, 44, 0.28);
    --surface-sunk: #F3EDE2;
    --sunk-edge: #E8DFCD;
    --chip-bg: #F3EDE2;
    --chip-border: #E2D7C0;
    --tag-border: #CDBFA4;
    --control-hover-border: #A89A85;
    --highlight-bg: rgba(178, 58, 44, 0.12);
    --highlight-edge: rgba(178, 58, 44, 0.28);
    --highlight-fg: #8E2A1E;
    --scrim: rgba(26, 22, 19, 0.28);
}

/* Scrollbars and native controls match the theme. */
:root { color-scheme: light; }
:root:has(> body[data-theme="dark"]) { color-scheme: dark; }

body[data-theme="dark"] {
    --paper: #16130F;
    --paper-2: #1E1A15;
    --paper-edge: #2A241D;
    --ink: #F2EADB;
    --ink-2: #D9CFBE;
    --ink-3: #B3A792;
    --ink-4: #77695A;
    --card-bg: #1C1814;
    /* Cards separate from the ground: a 24% cream edge. */
    --card-edge: rgba(242, 234, 219, 0.24);
    --control-bg: #211C17;
    --control-border: #54473A;
    /* A deeper coral so the cream label clears 4.5:1 (about 6.4:1). */
    --button-primary-bg: #9E3B2E;
    --button-primary-fg: #FFF8EC;
    --button-primary-hover: #8E3428;
    --button-primary-active: #82302A;
    --page-warmth: rgba(224, 100, 84, 0.025);
    --cinnabar: #E06454;
    --cinnabar-deep: #F07A68;
    --shadow-soft: 0 2px 8px rgba(0, 0, 0, 0.24);
    --shadow-hover: 0 6px 18px rgba(0, 0, 0, 0.30);
    --focus-ring: 0 0 0 3px rgba(224, 100, 84, 0.38);
    --surface-sunk: #2A241D;
    --sunk-edge: #3B3026;
    --chip-bg: #262019;
    --chip-border: #4A3D30;
    --tag-border: #5A4A3A;
    --control-hover-border: #7D6B58;
    --highlight-bg: rgba(240, 122, 104, 0.16);
    --highlight-edge: rgba(240, 122, 104, 0.40);
    --highlight-fg: #F48A79;
    --scrim: rgba(0, 0, 0, 0.45);
    --rank-fg: #D9604F;
    --tag-bg: #42382E;
    --tag-line: #54473A;
    --ink-zh: #D2C9B8;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    font-family: var(--font-sans);
    color: var(--ink);
    background-color: var(--paper);
    background-image:
        radial-gradient(ellipse at 50% -12%, rgba(178, 58, 44, 0.10), transparent 40%),
        radial-gradient(ellipse at 12% 62%, rgba(122, 123, 70, 0.055), transparent 38%),
        radial-gradient(ellipse at 88% 76%, rgba(178, 58, 44, 0.045), transparent 36%);
    background-attachment: fixed;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

::selection {
    color: var(--card-bg);
    background: var(--cinnabar);
}

button,
textarea,
a {
    font: inherit;
    color: inherit;
}

button {
    border: none;
    background: none;
}

/* Chinese is never slanted: no italic Song and no faux oblique, wherever an
   italic voice would otherwise reach it. Only oblique synthesis is turned
   off; a Song face without a bold weight may still embolden its headwords. */
:lang(zh),
[lang|=zh],
.cjk {
    font-style: normal;
    font-synthesis: weight;
}

button:focus-visible,
a:focus-visible,
textarea:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.noise {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.18;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.1 0 0 0 0 0.08 0 0 0 0 0.05 0 0 0 0.035 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

body[data-theme="dark"] .noise {
    mix-blend-mode: screen;
    opacity: 0.08;
}

.app {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.site-header,
.hero,
.search-wrap,
.saved-section,
.results-wrap,
.foot {
    width: 100%;
}

.site-header {
    max-width: var(--max-results);
    margin: 0 auto;
    padding: 24px var(--page-pad) 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.wordmark {
    display: flex;
    align-items: center;
    gap: 14px;
    text-decoration: none;
}

.seal {
    width: 44px;
    height: 44px;
    border-radius: 2px;
    background: var(--cinnabar);
    color: #FDF6E8;
    display: grid;
    place-items: center;
    font-family: var(--font-cjk);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    transform: rotate(-2deg);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.15), 0 1px 0 rgba(0, 0, 0, 0.15);
    position: relative;
}

.seal::after {
    content: "";
    position: absolute;
    inset: 3px;
    border: 1.5px solid rgba(255, 255, 255, 0.3);
    border-radius: 1px;
}

.titles {
    line-height: 1.1;
}

.titles .cn {
    font-family: var(--font-cjk);
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.titles .en {
    font-family: var(--font-text);
    font-size: 13px;
    color: var(--ink-3);
    font-style: italic;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.script-toggle {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--control-border);
    background: var(--control-bg);
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

@media (hover: hover) {
    .script-toggle:hover {
        border-color: var(--control-hover-border);
    }
}

.script-toggle-option {
    color: var(--ink-3);
    font-family: var(--font-cjk);
    font-size: 14px;
    line-height: 1;
    transition: color 0.15s ease;
}

/* The script on show carries the accent and an underline, not weight alone. */
.script-toggle-option.active {
    color: var(--cinnabar);
    font-weight: 700;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 5px;
}

.script-toggle-divider {
    color: var(--ink-4);
    font-size: 10px;
    line-height: 1;
}

/* A fixed minimum width with room for the count, so the header controls
   never shift when the count appears or the script changes. */
.saved-pill {
    min-width: 92px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 7px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--control-border);
    background: var(--control-bg);
    color: var(--ink-3);
    font-size: 12px;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

@media (hover: hover) {
    .saved-pill:hover {
        border-color: var(--control-hover-border);
        color: var(--ink);
    }
}

.saved-pill.active {
    background: var(--highlight-bg);
    border-color: var(--highlight-edge);
    color: var(--highlight-fg);
}

.saved-pill svg {
    width: 16px;
    height: 16px;
}

.saved-count {
    min-width: 1.3em;
    color: var(--ink-2);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    display: grid;
    place-items: center;
    cursor: pointer;
    color: var(--ink-2);
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

@media (hover: hover) {
    .icon-btn:hover {
        background: var(--paper-2);
        border-color: var(--paper-edge);
        color: var(--ink);
    }
}

.icon-btn.active {
    background: var(--paper-2);
    border-color: var(--control-hover-border);
    color: var(--ink);
}

.icon-btn.is-success {
    background: var(--paper-2);
    border-color: var(--control-hover-border);
    color: var(--cinnabar);
}

/* Header theme toggle: the same bordered control as the script toggle and
   the saved pill, in both themes. */
.theme-toggle {
    border-color: var(--control-border);
    background: var(--control-bg);
}

@media (hover: hover) {
    .theme-toggle:hover {
        border-color: var(--control-hover-border);
        background: var(--control-bg);
    }
}

.icon-btn svg {
    width: 18px;
    height: 18px;
}

/* Both icons are always rendered so the header markup does not depend on the
   theme; the prerendered page then matches the first render in either theme. */
.theme-icon {
    display: inline-flex;
}

body[data-theme="dark"] .theme-icon-light,
body:not([data-theme="dark"]) .theme-icon-dark {
    display: none;
}

.hero {
    position: relative;
    isolation: isolate;
    max-width: var(--max-hero);
    margin: 0 auto;
    padding: 22px var(--page-pad) 8px;
    text-align: center;
}

/* Eyebrows: small, letter-spaced capitals in the accent. The one label
   voice ("Your collection", "Example · 例句", exact-match
   sections). */
.saved-kicker,
.field-label,
.exact-label,
.preview-open-label {
    color: var(--cinnabar);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.12em;
    line-height: 1.4;
    text-transform: uppercase;
}

.hero-chars {
    margin: 0 0 24px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: clamp(4px, 1.5vw, 16px);
    font-family: var(--font-cjk);
    font-size: clamp(64px, 7.5vw, 92px);
    font-weight: 700;
    line-height: 0.95;
}

.hero-character {
    position: relative;
    display: inline-flex;
    padding-top: 22px;
    transition: color 0.2s ease;
}

@media (hover: hover) {
    .hero-character:hover {
        color: var(--cinnabar);
    }
}

.hero-character.accent {
    color: var(--cinnabar);
}

.hero-character.accent::after {
    content: "";
    position: absolute;
    right: 3%;
    bottom: -10px;
    left: 3%;
    height: 3px;
    border-radius: 999px;
    background: var(--cinnabar);
    transform: rotate(-3deg);
    opacity: 0.75;
}

.hero-chars .ch {
    display: inline-block;
    min-width: auto;
    margin: 0;
}

/* The pinyin token, at a fixed share of the hero glyphs (17px over 92px),
   never under 13px. */
.hero-pinyin {
    position: absolute;
    top: 0;
    left: 50%;
    font-size: max(13px, 0.19em);
    line-height: 1.2;
    white-space: nowrap;
    transform: translateX(-50%);
}

/* Page headings and the brand speak in the display serif; Chinese in Song;
   everything else in the UI sans. */
.hero-sub {
    margin: 0 0 8px;
    color: var(--ink);
    font-family: var(--font-text);
    font-size: clamp(26px, 3vw, 34px);
    font-weight: 400;
    letter-spacing: -0.01em;
    line-height: 1.25;
    text-wrap: balance;
}

.hero-copy {
    max-width: 600px;
    margin: 0 auto;
    color: var(--ink-3);
    font-family: var(--font-text);
    font-size: 18px;
    font-style: italic;
    line-height: 1.5;
    text-wrap: balance;
}

.hero-copy .cn {
    font-family: var(--font-cjk);
    font-style: normal;
}

.search-wrap {
    max-width: var(--max-hero);
    margin: 0 auto;
    padding: 18px var(--page-pad) 24px;
}

.search-wrap-landing {
    padding-bottom: 44px;
}

/* On results the box shares one left edge with the logo, header and cards. */
.search-wrap:not(.search-wrap-landing) {
    max-width: var(--max-results);
}

.search-box {
    position: relative;
    overflow: hidden;
    background: var(--card-bg);
    border: 1px solid var(--card-edge);
    border-radius: 14px;
    box-shadow: 0 2px 0 rgba(26, 22, 19, 0.03), 0 18px 54px -24px rgba(64, 43, 24, 0.28);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.25s ease;
}

.search-box:focus-within {
    border-color: rgba(178, 58, 44, 0.42);
    box-shadow: 0 2px 0 rgba(26, 22, 19, 0.03), 0 24px 62px -24px rgba(178, 58, 44, 0.28), var(--focus-ring);
    transform: translateY(-2px);
}

.search-row {
    display: flex;
    align-items: stretch;
    min-width: 0;
}

.search-input-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
}

.magnifier {
    position: absolute;
    left: 22px;
    top: 27px;
    width: 19px;
    height: 19px;
    color: var(--ink-3);
}

.search-input {
    width: 100%;
    min-height: 74px;
    max-height: 176px;
    padding: 24px 20px 22px 56px;
    resize: none;
    field-sizing: content;
    overflow-y: auto;
    border: none;
    background: transparent;
    color: var(--ink);
    line-height: 1.5;
    /* Upright, in the roman text serif: typed Chinese stays an upright Song
       glyph, never a slanted one. */
    font-family: var(--font-text);
    font-size: 19px;
    font-style: normal;
    font-synthesis: none;
}

.search-input::placeholder {
    color: var(--ink-3);
    font-family: var(--font-text);
    font-style: normal;
    opacity: 1;
}

/* The whole search box shows focus (focus-within), so the field itself
   does not draw a second ring inside it. */
.search-input:focus-visible {
    box-shadow: none;
}

.search-btn {
    margin: 9px;
    padding: 0 24px;
    border-radius: 8px;
    background: var(--button-primary-bg);
    color: var(--button-primary-fg);
    min-width: 164px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.02em;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 8px 20px -12px rgba(142, 42, 30, 0.75);
    transition: background-color 0.15s ease, transform 0.2s ease, box-shadow 0.2s ease;
    white-space: nowrap;
}

@media (hover: hover) {
    .search-btn:hover:not(:disabled) {
        background: var(--button-primary-hover);
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 12px 24px -12px rgba(142, 42, 30, 0.9);
        transform: translateY(-1px);
    }
}

.search-btn:active:not(:disabled) {
    background: var(--button-primary-active);
}

/* Searching keeps the same fill; only the label and cursor change. */
.search-btn:disabled {
    cursor: wait;
}

/* On results the button sits flat, like the cards beneath it. */
.search-wrap:not(.search-wrap-landing) .search-btn,
.search-wrap:not(.search-wrap-landing) .search-btn:hover:not(:disabled) {
    box-shadow: none;
    transform: none;
}

.search-btn .cn {
    font-family: var(--font-cjk);
    font-weight: 500;
}

.examples-intro {
    padding: 24px 2px 10px;
}

/* Editorial voice: the display serif, as in the tagline. */
.examples-label {
    color: var(--ink-2);
    font-family: var(--font-text);
    font-size: 19px;
    font-style: italic;
    font-weight: 400;
}

/* One uniform grid of six equal cards: three by two on wide screens, two
   by three on mid-width ones, one column on phones. No orphan row. */
.examples {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

@media (max-width: 900px) {
    .examples {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.chip {
    min-width: 0;
    border-radius: 10px;
    border: 1px solid var(--control-border);
    background: color-mix(in srgb, var(--card-bg) 82%, transparent);
    padding: 14px 15px;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: start;
    gap: 12px;
    cursor: pointer;
    text-align: left;
    box-shadow: 0 1px 0 rgba(26, 22, 19, 0.03);
    transition: border-color 0.15s ease, color 0.15s ease, transform 0.25s ease, box-shadow 0.25s ease, background-color 0.2s ease;
}

@media (hover: hover) {
    .chip:hover {
        background: var(--card-bg);
        transform: translateY(-3px);
        border-color: var(--control-hover-border);
        box-shadow: var(--shadow-hover);
    }
}

.chip-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chip-label {
    overflow: hidden;
    color: var(--ink-2);
    font-family: var(--font-text);
    font-size: 15px;
    font-style: italic;
    line-height: 1.35;
    text-overflow: ellipsis;
}

/* Each card previews its result: the idiom in ink, with its pinyin. */
.chip-idiom {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.chip .cn {
    color: var(--ink);
    font-family: var(--font-cjk);
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.06em;
}

.chip-pinyin {
    font-size: 13.5px;
}

.chip-arrow {
    color: var(--ink-3);
    font-size: 14px;
    transition: color 0.15s ease, transform 0.2s ease;
}

@media (hover: hover) {
    .chip:hover .chip-arrow {
        color: var(--ink);
    }
}

@media (hover: hover) {
    .chip:hover .chip-arrow {
        transform: translate(2px, -2px);
    }
}

.message-card {
    margin-top: 16px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--card-edge);
    background: var(--card-bg);
    padding: 22px 24px;
    box-shadow: var(--shadow-soft);
    color: var(--ink-2);
}

.error-card {
    border-color: rgba(178, 58, 44, 0.22);
    color: var(--cinnabar-deep);
}

.loading-card,
.no-results-card {
    max-width: var(--max-hero);
}

.message-title {
    margin: 0 0 8px;
    font-family: var(--font-text);
    font-size: 22px;
    font-weight: 400;
    color: var(--ink);
}

.saved-section {
    max-width: var(--max-results);
    min-height: calc(100vh - 180px);
    margin: 0 auto;
    padding: 40px var(--page-pad) 48px;
}

.saved-head {
    margin-bottom: 24px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--paper-edge);
}

/* One compact toolbar row above the heading: the way back on the left,
   the collection label and its count on the right. */
.saved-bar {
    margin: -8px 0 6px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    column-gap: 16px;
}

.saved-bar-meta {
    margin: 0;
    display: inline-flex;
    align-items: baseline;
    gap: 10px;
}

.saved-kicker {
    margin: 0;
}

/* A quiet way back to the page Saved was opened over: small muted sans,
   lighter than the heading and the Export action. Its text sits on the
   heading's left edge; the hit area is 44px tall. */
.saved-back {
    min-height: 44px;
    margin: 0 0 0 -8px;
    padding: 0 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: var(--radius);
    color: var(--ink-3);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    transition: background-color 0.15s ease, color 0.15s ease;
}

@media (hover: hover) {
    .saved-back:hover {
        background: var(--paper-2);
        color: var(--ink);
    }
}

.saved-title {
    margin: 0;
    font-family: var(--font-text);
    font-size: clamp(30px, 4vw, 42px);
    font-weight: 400;
    letter-spacing: -0.01em;
}

.saved-title span {
    color: var(--ink-3);
    font-family: var(--font-cjk);
    font-size: 0.58em;
    font-weight: 500;
}

.saved-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 16px;
}

.saved-meta {
    color: var(--ink-3);
    font-size: 13px;
}

.saved-export-btn {
    flex: none;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 13px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid var(--control-border);
    border-radius: var(--radius);
    background: var(--control-bg);
    color: var(--ink-2);
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
}

@media (hover: hover) {
    .saved-export-btn:hover {
        border-color: var(--control-hover-border);
        color: var(--ink);
    }
}

.saved-export-btn svg {
    width: 16px;
    height: 16px;
}

/* Three cards across on wide screens: room for a four-glyph idiom beside
   the corner actions, and a long one on one line beneath them. */
.saved-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(288px, 1fr));
    gap: 16px;
}

.saved-card {
    position: relative;
    border-radius: var(--radius-lg);
    border: 1px solid var(--card-edge);
    background: var(--card-bg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* The idiom's actions: a footer row pinned to the card's foot, so the
   idiom above has the card's full width. */
.saved-card-foot {
    margin-top: auto;
    padding: 0 6px;
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid var(--paper-edge);
}

.saved-card-main {
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    flex: 1;
    padding: 18px 18px 14px;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

@media (hover: hover) {
    .saved-card-main:hover {
        background: color-mix(in srgb, var(--paper-2) 45%, transparent);
    }
}

.saved-card .saved-card-chars {
    --hw: 34px;
    --pin: 14px;
    max-width: 100%;
    margin-bottom: 2px;
    font-family: var(--font-cjk);
    font-weight: 600;
    line-height: 1.1;
}

.saved-card.hw-8 .saved-card-chars {
    --hw: 30px;
    --pin: 13px;
}

.saved-ruby {
    display: contents;
}

/* Read by screen readers in place of the ruby, which would otherwise be
   announced syllable, glyph, syllable, glyph. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.saved-card-meaning {
    color: var(--ink);
    font-family: var(--font-text);
    font-size: 18px;
    line-height: 1.4;
}

.saved-card-literal {
    color: var(--ink-3);
    font-family: var(--font-text);
    font-size: 15px;
    font-style: italic;
    line-height: 1.45;
}

/* Above the footer: the same example preview as result rows. */
.saved-card-preview {
    min-width: 0;
    padding: 0 18px 14px;
}

.saved-card-preview .example-preview {
    margin: -6px -6px -10px;
}

.saved-details {
    margin: 0 18px 18px;
    padding-top: 14px;
}

.saved-details[hidden] {
    display: none;
}

/* Cards in a row share row tracks (idiom | preview | details | footer), so
   their preview lines and footers align. */
@supports (grid-template-rows: subgrid) {
    .saved-grid {
        row-gap: 0;
    }

    .saved-card {
        grid-row: span 4;
        display: grid;
        grid-template-rows: subgrid;
        margin-bottom: 16px;
    }

    .saved-details-slot {
        align-self: start;
    }

    .saved-card-foot {
        margin-top: 0;
        align-self: end;
    }
}

.featured {
    max-width: var(--max-hero);
    margin: 0 auto;
    padding: 8px var(--page-pad) 28px;
}

.section-rule {
    margin-bottom: 14px;
    color: var(--ink-3);
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-text);
    font-size: 14px;
    font-style: italic;
}

.section-rule::before,
.section-rule::after {
    content: "";
    height: 1px;
    background: var(--paper-edge);
    flex: 1;
}

.featured-card {
    border-radius: var(--radius-lg);
    border: 1px solid var(--card-edge);
    background: var(--card-bg);
    box-shadow: var(--shadow-soft);
    padding: 28px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 22px;
    align-items: center;
}

.featured-chars {
    font-family: var(--font-cjk);
    font-size: 72px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.04em;
}

.featured-label {
    margin-bottom: 8px;
    color: var(--ink-3);
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 11px;
}

.featured-pinyin {
    margin-bottom: 10px;
    font-family: var(--font-text);
    font-size: 18px;
    font-style: italic;
    color: var(--ink-3);
}

.featured-literal {
    margin-bottom: 10px;
    font-family: var(--font-text);
    font-size: 20px;
    color: var(--ink-2);
}

.featured-desc {
    color: var(--ink-2);
    line-height: 1.75;
}

.results-wrap {
    max-width: var(--max-results);
    margin: 0 auto;
    padding: 4px var(--page-pad) 32px;
}

.results-head {
    padding-bottom: 12px;
    margin-bottom: 14px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px 24px;
    border-bottom: 1px solid var(--paper-edge);
}

.results-head .results-title {
    flex: 1 1 auto;
    min-width: 0;
}

/* One quiet, upright line in the text serif (an italic heading read as
   slanted and restless). The first words carry a faint, level stroke. A long query wraps to a
   second line, then ends in an ellipsis. */
.results-title {
    margin: 0;
    padding-bottom: 4px;
    display: -webkit-box;
    overflow: hidden;
    color: var(--ink-3);
    font-family: var(--font-text);
    font-size: 21px;
    font-style: normal;
    font-weight: 400;
    line-height: 1.35;
    overflow-wrap: anywhere;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

.results-title .count {
    position: relative;
    color: var(--ink);
}

.results-title .count::after {
    content: "";
    position: absolute;
    right: 4%;
    bottom: -3px;
    left: 1px;
    height: 2px;
    border-radius: 999px;
    background: var(--ink-4);
    opacity: 0.45;
}

/* The heading stays upright; only the searcher's own words lean, as a
   quotation would in print (a Chinese query stays upright, below). */
.results-query {
    color: var(--ink-2);
    font-style: italic;
}

.results-query.is-cjk {
    font-family: var(--font-cjk);
    font-size: 0.92em;
    font-style: normal;
}

/* Weak meaning search: a plain "no close match" block leads, with what to
   try next; the distant guesses wait behind one disclosure. */
.weak-hint {
    margin: 4px 0 14px;
    padding: 22px 24px 20px;
    border: 1px solid var(--card-edge);
    border-radius: var(--radius-lg);
    background: var(--card-bg);
}

.weak-title {
    margin: 0 0 6px;
    color: var(--ink);
    font-family: var(--font-text);
    font-size: 21px;
    font-style: normal;
    font-weight: 400;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.weak-hint-copy {
    margin: 0;
    color: var(--ink-2);
    font-family: var(--font-text);
    font-size: 17px;
    line-height: 1.5;
}

/* "Show 10 loose guesses" and "Show more close idioms": one centred
   button with a chevron, wherever more results wait. */
.reveal-toggle,
.load-more-btn {
    min-height: 44px;
    padding: 0 14px 0 18px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--control-border);
    border-radius: var(--radius);
    background: var(--control-bg);
    color: var(--ink-2);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.reveal-toggle:focus-visible,
.load-more-btn:focus-visible {
    border-color: var(--control-hover-border);
    color: var(--ink);
}

@media (hover: hover) {
    .reveal-toggle:hover,
    .load-more-btn:hover:not(:disabled) {
        border-color: var(--control-hover-border);
        color: var(--ink);
    }
}

.reveal-toggle svg,
.load-more-btn svg {
    flex: none;
    width: 14px;
    height: 14px;
    transform: rotate(90deg);
    transition: transform 0.2s ease;
}

.reveal-toggle[aria-expanded="true"] svg {
    transform: rotate(-90deg);
}

.load-more-btn:disabled {
    cursor: wait;
}

/* No chevron: the button starts something over rather than revealing more. */
.load-more-btn.is-plain {
    padding: 0 18px;
}

.results-grid.is-weak {
    margin-top: 12px;
}

.results-grid.is-weak[hidden] {
    display: none;
}

.results-reveal {
    display: flex;
    justify-content: center;
    margin-top: 6px;
}

/* The same spark grid as on the landing page, on the same left and right
   edges as the "no close match" block above it. */
.results-sparks {
    margin: 12px 0 0;
}

/* Revealed guesses stay visibly secondary: no card fill. */
.results-grid.is-weak .result-card {
    background: transparent;
}

.results-meta {
    color: var(--ink-3);
    font-size: 12px;
    white-space: nowrap;
}

.results-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

/* --card-pad-x is the one right inset shared by every entry's content and
   action cluster: the first entry's corner actions and the rows' action
   column end on the same edge. */
.result-card {
    --card-pad-x: 28px;
    position: relative;
    border-radius: var(--radius-lg);
    border: 1px solid var(--card-edge);
    background: var(--card-bg);
    padding: 24px var(--card-pad-x);
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

/* Only an exact match, where the answer is known, sits in a card. Meaning
   searches are ranked guesses, so they read as one open list of entries on
   the paper, divided by hairlines: no result claims to be the answer. */
.results-grid:not(.is-exact) {
    gap: 0;
}

.results-grid:not(.is-exact) > .result-card {
    border: 0;
    border-top: 1px solid var(--card-edge);
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.results-grid:not(.is-exact) > .result-card:first-child {
    border-top: 0;
}

.results-grid:not(.is-exact) > .result-card:last-child {
    border-bottom: 1px solid var(--card-edge);
}

@media (hover: hover) {
    .results-grid:not(.is-exact) > .result-card:hover {
        background: color-mix(in srgb, var(--card-bg) 60%, transparent);
    }
}

/* Card layout: rank gutter | headword, then the gloss under the headword.
   The idiom's actions sit in the first card's top-right corner and, on
   compact rows, in a fixed column right after the meaning. */
.hero-row {
    display: grid;
    grid-template-columns: var(--row-rank-col) minmax(0, 1fr);
    grid-template-areas:
        "rank head"
        ".    gloss";
    column-gap: 20px;
    align-items: start;
}

/* Rank numerals speak in the display serif, italic, in the accent, and sit
   on the glyph line rather than the pinyin line. */
.rank-badge {
    grid-area: rank;
    align-self: end;
    padding-bottom: 24px;
    color: var(--rank-fg);
    font-family: var(--font-text);
    font-size: 19px;
    font-style: italic;
    font-weight: 400;
    line-height: 1.1;
    white-space: nowrap;
}

.headword-block {
    grid-area: head;
    min-width: 0;
}

.gloss-block {
    grid-area: gloss;
    min-width: 0;
}

.rank-1 .hero-row > .card-actions {
    position: absolute;
    top: 14px;
    right: var(--card-pad-x);
}

/* The first result's other script and tags, under its meaning. */
.hero-extra {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.hero-extra .tags-row {
    margin-top: 2px;
}

/* Phones only: "Details ›", a small inline text disclosure right after the
   first result's example, for its other script and tags. Its hit area is
   44px tall; the text sits on the example's left edge. */
.hero-more {
    display: none;
    justify-self: start;
    min-height: 44px;
    margin: -12px 0 -8px -8px;
    padding: 0 8px;
    align-items: center;
    gap: 3px;
    border-radius: var(--radius);
    color: var(--ink-3);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.01em;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.hero-more svg {
    flex: none;
    width: 12px;
    height: 12px;
    transition: transform 0.2s ease;
}

.hero-more[aria-expanded="true"] svg {
    transform: rotate(90deg);
}

@media (hover: hover) {
    .hero-more:hover {
        background: var(--paper-2);
        color: var(--ink);
    }
}

/* Every glyph in an idiom is one size: --hw, set per layout and stepped
   down for a long idiom (.hw-6: five or six glyphs on a line; .hw-8: seven
   or eight). Ruby pinyin is one size per layout (--pin) and never shrinks.
   An idiom with a full-width comma, or of more than eight glyphs
   (.hw-split), always breaks at its .hw-break; other idioms stay on one
   line wherever their layout has room (phones break .hw-8 rows, below). */
.result-chars,
.saved-card-chars {
    --hw: 64px;
    --pin: 15px;
    font-size: var(--hw);
    letter-spacing: 0;
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-end;
    gap: 0.08em;
}

/* A headword on two lines keeps its second line's pinyin clear of the
   first line's glyphs. */
.hw-split .result-chars,
.hw-split .saved-card-chars {
    flex-wrap: wrap;
    row-gap: 0.35em;
}

.result-chars {
    margin: 0;
    font-family: var(--font-cjk);
    font-weight: 600;
    line-height: 1.12;
}

.rank-1.hw-6 .result-chars {
    --hw: 54px;
}

.rank-1.hw-8 .result-chars {
    --hw: 46px;
}

.hw-break {
    display: none;
    flex-basis: 100%;
    height: 0;
}

.hw-split .hw-break {
    display: block;
}

/* Each character is a small ruby column: pinyin above the glyph. */
.ch {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    min-width: 1em;
}

.ch.punct,
.punct {
    min-width: auto;
}

/* Every glyph sits in a cell exactly 1em wide, with one constant 0.08em
   gap between cells, so an idiom's glyphs are evenly spaced whatever their
   pinyin. A syllable is centred over its cell and may overflow evenly into
   the gaps; it never widens the cell. A full-width comma ends its line as a
   narrow cell with no ruby slot. */
.result-chars .ch,
.saved-card-chars .ch {
    flex: none;
    width: 1em;
    min-width: 1em;
    max-width: 1em;
}

.result-chars .ch.punct,
.saved-card-chars .ch.punct {
    width: 0.4em;
    min-width: 0;
    align-items: flex-start;
}

.ch-word {
    display: inline-flex;
    align-items: flex-end;
    gap: 0.08em;
    border-radius: 4px;
    transition: background 0.15s ease;
}

/* Every pinyin on the site is one style: the --pinyin token, the roman
   text serif, lightly tracked, in the muted ink. */
.pin,
.hero-pinyin,
.chip-pinyin,
.char-cell-pin,
.similar-pin,
.dict-pop-pinyin {
    color: var(--ink-3);
    font-family: var(--pinyin);
    font-style: normal;
    font-weight: 400;
    font-synthesis: none;
    letter-spacing: var(--pinyin-tracking);
}

/* Ruby pinyin at its layout's one size (--pin), with one constant gap to
   the glyph. */
.pin {
    margin-bottom: 0.08em;
    font-size: var(--pin, 14px);
    line-height: 1.2;
    white-space: nowrap;
    pointer-events: none;
}

/* Only a syllable wider than 1.35 of its glyph, or one that would run into
   its neighbour's pinyin (keeping 0.3em of the pinyin between them), is
   tightened: first its tracking (down to -0.03em), then its size, by at
   most 12%. --pw is the syllable's natural width in ems of the pinyin face,
   --pn its letter count and --pwn its narrower neighbour's width, all set
   in the markup. */
.result-chars .pin,
.saved-card-chars .pin {
    --pin-limit: min(1.35 * var(--hw), 2 * (1.08 * var(--hw) - 0.3 * var(--pin)) - var(--pwn, 0) * var(--pin));
    --pin-over: calc(var(--pw, 0) * var(--pin) - var(--pin-limit));
    --pin-track: clamp(-0.03 * var(--pin), 0.02 * var(--pin) - var(--pin-over) / var(--pn, 1), 0.02 * var(--pin));
    letter-spacing: var(--pin-track);
    font-size: clamp(
        0.88 * var(--pin),
        var(--pin) - max(0px, var(--pin-over) - var(--pn, 1) * (0.02 * var(--pin) - var(--pin-track))) / (var(--pw, 1) - 0.02 * var(--pn, 1)),
        var(--pin)
    );
}

/* In the results heading row, one quiet note says the headword's glyphs
   open the dictionary: small muted sans after a small 字 mark, right-aligned
   on the heading's line (on phones, its own line under it). "Tap" on touch
   screens, "Select" where the pointer hovers. It is gone for good once a
   popover has been opened. */
.char-hint {
    flex: none;
    margin: 0;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--ink-3);
    font-family: var(--font-sans);
    font-size: 12.5px;
    font-weight: 400;
    letter-spacing: 0.01em;
    line-height: 1.4;
    white-space: nowrap;
}

.char-hint-mark {
    flex: none;
    width: 18px;
    height: 18px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--tag-border);
    border-radius: 2px;
    color: var(--ink-3);
    font-family: var(--font-cjk);
    font-size: 11.5px;
    line-height: 1;
}

.char-hint-pointer {
    display: none;
}

@media (hover: hover) and (pointer: fine) {
    .char-hint-touch {
        display: none;
    }

    .char-hint-pointer {
        display: inline;
    }
}

/* The idiomatic meaning, the most-read line: the roman text serif, large
   and in full ink. */
.result-meaning {
    max-width: 60ch;
    margin: 0;
    color: var(--ink);
    font-family: var(--font-text);
    font-size: 21px;
    font-weight: 400;
    line-height: 1.38;
}

.rank-1 .gloss-block {
    padding-top: 10px;
}

/* The literal gloss and the example's translation are the editorial voice:
   the display serif in italic, muted, on a short measure. */
.literal-line {
    max-width: 60ch;
    margin: 6px 0 0;
    color: var(--ink-3);
    font-family: var(--font-text);
    font-size: 15px;
    font-style: italic;
    line-height: 1.45;
}

/* Other forms of the idiom, folded into this result by the server, and on
   the first result its other script: one block under the lit. gloss, one
   line per relation. Labels are the bilingual UI voice (sans, small, muted);
   each form is an accent link that searches it. */
.variant-line {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin: 10px 0 0;
    color: var(--ink-3);
    font-family: var(--font-text);
    font-size: 14px;
    line-height: 1.5;
}

.result-row .variant-line {
    margin-top: 6px;
}

/* In a row every kind of form shares one line, wrapping only when it must. */
.result-row .variant-line {
    flex-direction: row;
    flex-wrap: wrap;
    column-gap: 18px;
}

.result-row .variant-group {
    display: inline-grid;
}

/* Label, then the forms; a wrapped form hangs under the first one. */
.variant-group {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: baseline;
    column-gap: 10px;
}

.variant-forms {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 14px;
    row-gap: 2px;
}

.variant-label {
    color: var(--ink-3);
    font-family: var(--font-sans);
    font-size: 12px;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.variant-label-zh {
    margin-right: 2px;
    color: var(--ink-3);
    font-family: var(--font-cjk);
}

/* A form is one unit (characters, usual-form mark, pinyin) that wraps as a
   whole; only a unit wider than the line lets its pinyin drop under it. */
.variant-item {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 6px;
    max-width: 100%;
}

.variant-form,
.variant-common {
    white-space: nowrap;
}

.variant-form,
.variant-more {
    position: relative;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
}

.variant-form {
    color: var(--cinnabar-deep);
    font-family: var(--font-cjk);
    font-size: 15px;
    letter-spacing: 0.04em;
    /* A dotted rule says "link"; the solid red rule stays the example's highlight. */
    text-decoration: underline dotted;
    text-decoration-color: color-mix(in srgb, var(--cinnabar-deep) 45%, transparent);
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
}

/* The hit area grows past the glyphs without moving the line. */
.variant-form::after,
.variant-more::after {
    position: absolute;
    inset: -10px -4px;
    content: "";
}

.variant-form:hover,
.variant-more:hover {
    text-decoration: underline solid;
    text-decoration-color: currentColor;
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
}

.variant-form:focus-visible,
.variant-more:focus-visible {
    border-radius: 3px;
    outline: 2px solid var(--cinnabar);
    outline-offset: 2px;
}

.variant-pin {
    color: var(--ink-3);
    font-family: var(--font-text);
    font-size: 13px;
}

/* Meta text in the label's voice, not a chip: it can't be read as a tag. */
.variant-common {
    color: var(--ink-3);
    font-family: var(--font-sans);
    font-size: 10.5px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.variant-more {
    color: var(--ink-3);
    font-family: var(--font-sans);
    font-size: 12px;
    text-decoration: none;
}

.variant-script {
    color: var(--ink-2);
    font-family: var(--font-cjk);
    font-size: 15px;
    letter-spacing: 0.04em;
}

/* "lit." is part of its gloss: the same italic text serif, muted and a
   touch smaller. */
/* A dictionary note lifted out of the meaning ("from Analects"): upright,
   a step quieter than the literal gloss it follows. */
.meaning-note {
    color: var(--ink-3);
    font-style: normal;
    font-size: 0.92em;
}

.lit-label {
    margin-right: 1px;
    color: var(--ink-3);
    font-family: var(--font-text);
    font-size: 0.92em;
    font-style: italic;
    font-weight: 400;
    letter-spacing: 0;
}

.card-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Pronounce, save and copy are one icon-only ghost button everywhere (top
   card, rows, saved cards): a border appears only under a hovering pointer
   or keyboard focus, never as a leftover of a click. */
.card-action {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-color: transparent;
    background: transparent;
    color: var(--ink-2);
}

@media (hover: hover) {
    .card-action:hover {
        border-color: var(--control-border);
        background: var(--control-bg);
        color: var(--ink);
    }
}

.card-action:focus-visible {
    border-color: var(--control-hover-border);
    color: var(--ink);
}

/* Saved: the bookmark fills in the accent (aria-pressed); no tinted box. */
.card-action.save-action.active {
    border-color: transparent;
    background: transparent;
    color: var(--cinnabar);
}

.card-action.save-action.active:focus-visible {
    border-color: var(--control-hover-border);
}

@media (hover: hover) {
    .card-action.save-action.active:hover {
        border-color: var(--control-border);
        background: var(--control-bg);
        color: var(--cinnabar);
    }
}

.card-action svg {
    width: 17px;
    height: 17px;
}

/* The lead entry's save action names itself: "Save", or "Saved" beside
   the filled accent bookmark, in the small button sans. */
.card-action.save-action.has-label {
    width: auto;
    padding: 0 10px 0 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.save-text {
    display: inline-grid;
    justify-items: start;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.01em;
    line-height: 1;
}

.save-text > span {
    grid-area: 1 / 1;
}

.save-text-sizer {
    visibility: hidden;
}

.result-body {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--paper-edge);
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-label {
    display: block;
}

.field-value {
    color: var(--ink-2);
    line-height: 1.72;
}

.example-block {
    grid-column: 1 / -1;
}

/* The Chinese sentence and its translation share one left rule and one
   measure; no filled bar competes with the meaning above. */
.example-quote {
    max-width: 46rem;
    padding: 2px 0 2px 16px;
    border-left: 2px solid var(--tag-border);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* No orphaned last glyph or line-initial punctuation. */
.example-zh {
    font-family: var(--font-cjk);
    font-size: 17px;
    line-height: 1.75;
    line-break: strict;
    text-wrap: pretty;
}

/* The idiom inside its example, everywhere: normal ink over a 2px
   cinnabar underline, no tint. */
.highlight,
.dict-token.highlight {
    color: var(--ink);
    background: none;
    padding: 0;
    border-radius: 0;
    text-decoration-line: underline;
    text-decoration-color: var(--cinnabar);
    text-decoration-thickness: 2px;
    text-underline-offset: 0.3em;
    text-decoration-skip-ink: none;
}

.example-en {
    max-width: 60ch;
    color: var(--ink-3);
    font-family: var(--font-text);
    font-size: 15px;
    font-style: italic;
    line-height: 1.5;
}

/* Dark: the translation takes the secondary body text's ink. */
body[data-theme="dark"] .example-en {
    color: var(--ink-2);
}

.tags-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* Tags are labels, not controls: a paper tint inside a hairline, so they
   separate from the card. */
.tag {
    border: 1px solid var(--tag-line);
    border-radius: var(--chip-radius);
    background: var(--tag-bg);
    color: var(--ink-2);
    padding: 3px 8px;
    font-size: 13px;
    line-height: 1.35;
    text-transform: lowercase;
}

/* The first result between phone and wide layouts: the headword and gloss,
   then the gloss, example and tags under one rule, all on the gloss's left
   edge. A lone exact match has no rank numeral and no rank gutter. */
.rank-1 .hero-body {
    margin-left: calc(var(--row-rank-col) + 20px);
}

.rank-1 .hero-row:not(:has(.rank-badge)) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
        "head"
        "gloss";
}

.rank-1:not(:has(.rank-badge)) .hero-body {
    margin-left: 0;
}

/* Wide screens: the first result is two balanced columns. The idiom,
   meaning and lit. read down the left (52%); the right holds the 释义
   (exact matches), the example and its translation, then the other script
   and the tags. Both columns start on the pinyin line; the corner actions
   sit level with the right column's first label, well clear of it. Top and
   bottom padding match. */
@media (min-width: 1024px) {
    .result-card.rank-1 {
        display: grid;
        grid-template-columns: minmax(0, 52fr) minmax(0, 48fr);
        column-gap: 40px;
        align-items: start;
        padding-top: 24px;
        padding-bottom: 24px;
    }

    .rank-1 .hero-row > .card-actions {
        top: 16px;
    }

    .rank-1 .gloss-block {
        padding-top: 14px;
    }

    .rank-1 .literal-line {
        margin-top: 8px;
    }

    .rank-1 .gloss-block > .gloss-zh-block {
        margin-top: 12px;
    }

    .rank-1 .hero-body {
        display: flex;
        flex-direction: column;
        gap: 12px;
        margin: 0;
        padding: 2px 0 0;
        border-top: none;
    }

    .rank-1 .hero-body .field {
        gap: 10px;
    }

    .rank-1 .hero-body .example-en {
        line-height: 1.45;
    }

    .rank-1 .example-block,
    .rank-1 .tags-row {
        margin: 0;
        padding: 0;
        border-top: none;
    }

    .rank-1 .hero-body > .hero-extra {
        margin-top: -4px;
        gap: 8px;
    }

    .rank-1 .example-quote {
        max-width: none;
    }

    .rank-1 .example-zh {
        font-size: 16px;
        line-height: 1.65;
    }
}

/* Compact rows: results 2..N. Every row shares one set of columns,
   rank | idiom | meaning | actions, so every meaning starts at the same x;
   the meaning takes all the room up to the actions, which stay at the
   row's right edge, centred on it. The idiom column fits four glyphs at
   36px with their pinyin; a longer idiom wraps and its row grows taller. */
.result-card.result-row {
    padding-top: 14px;
    padding-bottom: 14px;
}

.result-row .hero-row {
    grid-template-columns: var(--row-rank-col) var(--row-headword-col) minmax(0, 1fr) auto;
    grid-template-areas: "rank head gloss actions";
    align-items: center;
}

.result-row .rank-badge {
    align-self: center;
    padding-bottom: 0;
}

.result-row .hero-row > .card-actions {
    grid-area: actions;
}

.result-row .result-chars {
    --hw: 36px;
    --pin: 14px;
    line-height: 1.1;
}

.result-row.hw-6 .result-chars {
    --hw: 30px;
    --pin: 13px;
}

.result-row.hw-8 .result-chars {
    --hw: 26px;
    --pin: 12px;
}

.result-row .result-meaning {
    max-width: none;
    font-size: 18.5px;
    line-height: 1.38;
}

.result-row .literal-line {
    max-width: none;
}

/* Senses past the second wait behind the example disclosure. */
.result-row:not(.is-expanded) .meaning-more {
    display: none;
}

.result-row .literal-line {
    margin-top: 2px;
}

/* A compact row's example disclosure: a one-line preview of the Chinese
   example in Song, muted, the idiom marked in the accent, cut with an
   ellipsis and ending in a chevron. Open, it becomes the example's eyebrow
   and the panel beneath holds the whole example, translation and tags. */
/* The whole line is the toggle: full width, at least 44px tall, with a
   visible hover and focus state. Negative margins keep the row compact. */
.example-preview {
    width: calc(100% + 12px);
    max-width: none;
    min-height: 44px;
    margin: -2px -6px -12px;
    padding: 0 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: var(--radius);
    color: var(--ink-zh);
    cursor: pointer;
    text-align: left;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.preview-zh {
    min-width: 0;
    overflow: hidden;
    font-family: var(--font-cjk);
    font-size: 15px;
    line-height: 1.6;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-narrow {
    display: none;
}

/* The example's English translation, under its Chinese preview: one muted
   italic line in the text serif, cut with an ellipsis. Wide screens only;
   open, the panel beneath holds it in full. */
.preview-en {
    display: none;
}

@media (min-width: 721px) {
    .example-preview:has(.preview-en) {
        flex-wrap: wrap;
        row-gap: 0;
        padding-top: 6px;
        padding-bottom: 6px;
    }

    /* The Chinese line takes the first line whole; the chevron follows the
       English line, which is the one the ellipsis cuts. */
    .example-preview:has(.preview-en) .preview-zh {
        flex: 1 0 100%;
        max-width: 100%;
    }

    .example-preview:has(.preview-en):not([aria-expanded="true"]) svg {
        order: 3;
    }

    .preview-en {
        display: block;
        flex: 0 1 auto;
        order: 2;
        min-width: 0;
        max-width: calc(100% - 20px);
        overflow: hidden;
        color: var(--ink-3);
        font-family: var(--font-text);
        font-size: 14.5px;
        font-style: italic;
        line-height: 1.45;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .example-preview[aria-expanded="true"] .preview-en {
        display: none;
    }
}

@media (max-width: 720px) {
    .preview-wide {
        display: none;
    }

    .preview-narrow {
        display: block;
    }
}

.preview-tags {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
}

.preview-open-label {
    display: none;
}

.example-preview[aria-expanded="true"] .preview-zh,
.example-preview[aria-expanded="true"] .preview-prefix {
    display: none;
}

.example-preview[aria-expanded="true"] .preview-open-label {
    display: inline;
}

.example-preview svg {
    flex: none;
    width: 14px;
    height: 14px;
    transform: rotate(90deg);
    transition: transform 0.2s ease;
}

.example-preview[aria-expanded="true"] svg {
    transform: rotate(-90deg);
}

@media (hover: hover) {
    .example-preview:hover {
        background: var(--paper-2);
        color: var(--ink);
    }
}

.result-details {
    margin: 12px 0 4px calc(var(--row-rank-col) + var(--row-headword-col) + 40px);
    padding-top: 14px;
}

.result-details[hidden] {
    display: none;
}

/* Where subgrid is supported, every compact row in a list shares one set of
   columns, and the idiom column is as wide as the list's widest headword
   (at least --row-headword-col). An idiom of up to eight glyphs then stays
   on one line at its full pinyin size, and every meaning still starts at
   the same x. The card's padding becomes the outer tracks' margin. */
@supports (grid-template-columns: subgrid) {
    @media (min-width: 721px) {
        .results-grid {
            /* rank | idiom | meaning | actions. Items that span the flexible
               meaning track (the first result, an open example) never widen
               the content-sized columns. */
            grid-template-columns: auto minmax(var(--row-headword-col), max-content) minmax(0, 1fr) auto;
            column-gap: 20px;
        }

        .results-grid > .rank-1 {
            grid-column: 1 / -1;
        }

        .result-card.result-row,
        .result-row .hero-row {
            display: grid;
            grid-column: 1 / -1;
            grid-template-columns: subgrid;
        }

        .result-row .hero-row {
            grid-template-areas: none;
        }

        .result-row .rank-badge {
            grid-area: 1 / 1;
            min-width: var(--row-rank-col);
        }

        .result-row .headword-block {
            grid-area: 1 / 2;
        }

        /* A split idiom sizes nothing: it takes the column it is given and
           breaks at its .hw-break, instead of claiming both lines' width. */
        .result-row.hw-split .headword-block {
            contain: inline-size;
        }

        .result-row .gloss-block {
            grid-area: 1 / 3;
        }

        .result-row .hero-row > .card-actions {
            grid-area: 1 / 4;
        }

        .result-row .result-details {
            grid-column: 3 / -1;
            margin-left: 0;
        }
    }
}

/* After an exact match: the idiom's characters one by one, then idioms
   close to it in meaning. */
.exact-extras {
    margin-top: 26px;
    display: flex;
    flex-direction: column;
    gap: 26px;
}

.exact-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.exact-label {
    margin: 0;
}

.char-strip {
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(var(--cells, 4), minmax(0, 1fr));
    gap: 10px;
    list-style: none;
}

.char-cell {
    width: 100%;
    height: 100%;
    min-width: 0;
    padding: 13px 16px 14px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
        "glyph pin"
        "glyph gloss";
    column-gap: 14px;
    align-items: start;
    align-content: start;
    border: 1px solid var(--card-edge);
    border-radius: var(--radius-lg);
    background: var(--card-bg);
    color: var(--ink);
    text-align: left;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

button.char-cell {
    cursor: pointer;
}

@media (hover: hover) {
    button.char-cell:hover {
        border-color: var(--control-hover-border);
    }
}

.char-cell.is-dict-active {
    border-color: var(--highlight-edge);
    background: var(--card-bg);
    box-shadow: inset 0 -2px 0 var(--highlight-edge);
}

.char-cell-glyph {
    grid-area: glyph;
    font-family: var(--font-cjk);
    font-size: 28px;
    font-weight: 600;
    line-height: 1.1;
}

.char-cell-pin {
    grid-area: pin;
    align-self: start;
    font-size: 15px;
    line-height: 1.3;
}

/* A definition wraps to two lines before it ends in an ellipsis. */
.char-cell-gloss {
    grid-area: gloss;
    align-self: start;
    display: -webkit-box;
    overflow: hidden;
    color: var(--ink-2);
    font-family: var(--font-text);
    font-size: 14px;
    line-height: 1.4;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

/* Similar idioms: a grid of chips at least 200px wide (four across the
   results column), each the idiom over its pinyin, then its English gloss
   on up to two lines, so neighbours can be told apart. */
.similar-chips {
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
    gap: 8px;
    list-style: none;
}

.similar-chips > li {
    min-width: 0;
}

.similar-chip {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    text-align: left;
    text-decoration: none;
    min-height: 44px;
    padding: 8px 12px 9px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
    border: 1px solid var(--control-border);
    border-radius: var(--chip-radius);
    background: var(--control-bg);
    color: var(--ink);
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

@media (hover: hover) {
    .similar-chip:hover {
        border-color: var(--control-hover-border);
        background: var(--card-bg);
    }
}

.similar-head {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    text-align: left;
}

.similar-cn {
    flex: none;
    font-family: var(--font-cjk);
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.similar-pin {
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    font-size: 13.5px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.similar-gloss {
    min-width: 0;
    display: -webkit-box;
    overflow: hidden;
    color: var(--ink-2);
    font-family: var(--font-text);
    font-size: 14px;
    line-height: 1.35;
    text-align: left;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

/* The Chinese gloss (释义) in Song, under the lit. gloss. */
.gloss-block > .gloss-zh-block {
    margin-top: 18px;
}

/* The Chinese gloss (释义) in Song. */
.gloss-zh {
    max-width: 46rem;
    margin: 0;
    color: var(--ink);
    font-family: var(--font-cjk);
    font-size: 16px;
    line-height: 1.75;
    line-break: strict;
    text-wrap: pretty;
}

.results-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin: 26px 0 16px;
}

/* A line beside the button about what it will do, or why the last try failed. */
.results-actions-note {
    margin: 0;
    max-width: 46ch;
    color: var(--ink-2);
    font-size: 14px;
    text-align: center;
    text-wrap: pretty;
}

.results-actions-note.is-error {
    color: var(--cinnabar-deep);
}

.message-card .results-actions {
    margin: 16px 0 0;
    align-items: flex-start;
}

.foot {
    width: 100%;
    max-width: var(--max-results);
    margin: auto auto 0;
    padding: 16px var(--page-pad) 24px;
    border-top: 1px solid var(--paper-edge);
    color: var(--ink-3);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.footer-title {
    color: var(--ink-3);
    font-size: 12px;
}

.footer-link {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--ink-3);
    text-decoration-color: var(--paper-edge);
    text-underline-offset: 4px;
    font-size: 12px;
    transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

@media (hover: hover) {
    .footer-link:hover {
        color: var(--ink);
        text-decoration-color: var(--ink-3);
    }
}

.footer-link svg {
    width: 16px;
    height: 16px;
}

@media (max-width: 900px) {
    :root {
        --row-headword-col: 11rem;
    }

    .site-header,
    .hero,
    .search-wrap,
    .featured,
    .results-wrap,
    .foot {
        padding-left: 20px;
        padding-right: 20px;
    }

    .result-card {
        --card-pad-x: 24px;
        padding: 22px var(--card-pad-x);
    }

    .result-chars {
        --hw: 58px;
    }

    .rank-1.hw-6 .result-chars {
        --hw: 50px;
    }

    .rank-1.hw-8 .result-chars {
        --hw: 42px;
    }
}

@media (max-width: 720px) {
    :root {
        --page-pad: 16px;
    }

    .site-header,
    .hero,
    .search-wrap,
    .featured,
    .results-wrap,
    .foot {
        padding-left: var(--page-pad);
        padding-right: var(--page-pad);
    }

    .site-header {
        padding-top: 16px;
        padding-bottom: 14px;
        align-items: center;
        flex-direction: row;
        gap: 12px;
    }

    .wordmark {
        gap: 9px;
        min-width: 0;
    }

    .seal {
        width: 38px;
        height: 38px;
        font-size: 19px;
    }

    .titles .cn {
        font-size: 16px;
    }

    .titles .en {
        font-size: 11px;
    }

    .nav-actions {
        width: auto;
        margin-left: auto;
        justify-content: flex-end;
        flex-wrap: nowrap;
        gap: 4px;
    }

    .saved-label {
        display: none;
    }

    .saved-pill {
        min-width: 62px;
    }

    .script-toggle,
    .saved-pill,
    .icon-btn {
        min-height: 44px;
        height: 44px;
    }

    .icon-btn {
        width: 44px;
    }

    .hero {
        padding-top: 28px;
        padding-bottom: 14px;
    }

    .hero-chars {
        margin-bottom: 22px;
        font-size: clamp(52px, 15vw, 76px);
        gap: 5px;
    }

    .hero-character {
        padding-top: 18px;
    }

    .hero-sub {
        font-size: 22px;
        line-height: 1.25;
    }

    .hero-copy {
        font-size: 17px;
        line-height: 1.5;
    }

    .search-row {
        flex-direction: column;
    }

    /* 16px or more, so iOS does not zoom into the field. */
    .search-input {
        min-height: 56px;
        padding-top: 16px;
        padding-bottom: 16px;
        font-size: 17px;
        line-height: 1.45;
    }

    .magnifier {
        top: 20px;
    }

    .search-btn {
        margin: 0 8px 8px;
        justify-content: center;
        min-height: 52px;
        font-size: 15px;
    }

    .examples-intro {
        padding-top: 24px;
    }

    .examples {
        gap: 8px;
    }

    .examples {
        grid-template-columns: minmax(0, 1fr);
    }

    .chip {
        padding: 12px;
        gap: 8px;
    }

    .saved-section {
        padding-top: 14px;
    }

    .saved-head {
        margin-bottom: 14px;
        padding-bottom: 14px;
    }

    .saved-title {
        font-size: 28px;
    }

    .saved-grid {
        grid-template-columns: 1fr;
    }

    .featured-card {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 24px;
    }

    .featured-chars {
        font-size: 52px;
    }

    .results-meta {
        white-space: normal;
    }

    /* Mobile cards: the rank numeral sits in a narrow left gutter, on the
       glyph line; pinyin, hanzi, meaning, example and actions all share one
       left edge to its right. */
    .result-card,
    .result-card.result-row {
        padding: 12px 12px 12px 10px;
        --gutter: 18px;
        --gutter-gap: 6px;
    }

    .rank-badge,
    .result-row .rank-badge {
        grid-area: rank;
        align-self: end;
        padding: 0 0 0.45em;
        font-size: 15px;
        text-align: left;
    }

    /* A row's headword can wrap (塞翁失马焉知非福 breaks 4 + 4), so its numeral
       and actions hang from the first glyph line, not the last: one pinyin
       line (about 17px) plus one 34px glyph line (37.4px) above the numeral's
       baseline gap. */
    .result-row .rank-badge {
        align-self: start;
        padding: 31px 0 0;
    }

    .result-row .card-actions {
        align-self: start;
        margin-top: 10px;
    }

    .hero-row,
    .result-row .hero-row {
        grid-template-columns: var(--gutter) minmax(0, 1fr) auto;
        grid-template-areas:
            "rank head actions"
            ".    gloss gloss";
        column-gap: var(--gutter-gap);
        align-items: end;
    }

    .rank-1 .hero-row:not(:has(.rank-badge)) {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "head actions"
            "gloss gloss";
    }

    /* Rows keep their actions on the glyph line: 44px targets, no gap. */
    .result-row .hero-row > .card-actions {
        margin-right: -8px;
        gap: 0;
    }

    .result-row .gloss-block {
        padding-top: 4px;
    }

    /* The first result keeps its actions on the glyph line too, as rows
       do: no separate icon row. */
    .rank-1 .hero-row > .card-actions {
        position: static;
        grid-area: actions;
        margin-right: -8px;
        gap: 0;
    }

    .rank-1 .gloss-block {
        padding-top: 6px;
    }

    /* Beside the actions there is no room for seven or eight glyphs with
       their pinyin: those break after the fourth glyph (4 / 3, 4 / 4) at
       the full size instead of shrinking. */
    .hw-8 .result-chars {
        flex-wrap: wrap;
        row-gap: 0.35em;
    }

    .result-card.hw-8 .hw-break {
        display: block;
    }

    .card-action {
        width: 44px;
        height: 44px;
        min-height: 44px;
    }

    .card-action.save-action.has-label {
        width: auto;
        padding: 0 6px 0 2px;
        gap: 4px;
    }

    /* The first result's glyphs fill the room beside the gutter and the
       actions, including the lead's labelled Save (about 230px of the
       viewport): four 1em cells and three gaps
       for a four-glyph line, six for hw-6, and a four-glyph line plus a
       comma cell for a split idiom (with a few px to spare, since that
       line wraps rather than overflowing). */
    .result-chars {
        --hw: clamp(32px, calc((100vw - 230px) / 4.24), 54px);
        --pin: 14px;
    }

    .rank-1.hw-6 .result-chars {
        --hw: clamp(22px, calc((100vw - 230px) / 6.4), 32px);
    }

    .rank-1.hw-8 .result-chars,
    .rank-1.hw-split .result-chars {
        --hw: clamp(30px, calc((100vw - 236px) / 4.8), 50px);
    }

    /* A lone exact match has no gutter: the same sums without it. */
    .rank-1:not(:has(.rank-badge)) .result-chars {
        --hw: clamp(32px, calc((100vw - 208px) / 4.24), 54px);
    }

    .rank-1.hw-6:not(:has(.rank-badge)) .result-chars {
        --hw: clamp(22px, calc((100vw - 208px) / 6.4), 32px);
    }

    .rank-1.hw-8:not(:has(.rank-badge)) .result-chars,
    .rank-1.hw-split:not(:has(.rank-badge)) .result-chars {
        --hw: clamp(30px, calc((100vw - 212px) / 4.8), 50px);
    }

    .result-row .result-chars,
    .result-row.hw-8 .result-chars {
        --hw: 34px;
        --pin: 14px;
    }

    .result-row.hw-6 .result-chars {
        --hw: 26px;
        --pin: 12px;
    }

    /* A slightly tighter pinyin-to-glyph gap on phones. */
    .result-chars .pin {
        margin-bottom: 0.03em;
    }

    .result-meaning {
        font-size: 19px;
    }

    .result-row .result-meaning {
        font-size: 17.5px;
    }

    .example-preview {
        margin-top: 2px;
    }

    /* Details run on the content edge to the gutter's right, like the
       meaning above them. */
    .rank-1 .hero-body,
    .result-details {
        max-width: none;
        margin-left: calc(var(--gutter) + var(--gutter-gap));
    }

    .rank-1:not(:has(.rank-badge)) .hero-body {
        margin-left: 0;
    }

    .result-body {
        margin-top: 12px;
        padding-top: 14px;
        gap: 14px;
    }

    .result-details {
        margin-top: 8px;
        margin-bottom: 2px;
    }

    .example-quote {
        padding-left: 12px;
    }

    .exact-extras {
        margin-top: 22px;
        gap: 22px;
    }

    .char-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .char-cell {
        padding: 12px;
        column-gap: 10px;
    }

    /* Similar idioms, two to a row. */
    .similar-chips {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .similar-chip {
        padding: 8px 10px;
    }

    .similar-cn {
        font-size: 17px;
    }

    .similar-pin {
        font-size: 13px;
    }
    /* The heading drops its echo of the query: it is in the box above. */
    .results-for {
        display: none;
    }

    /* The character note takes its own short line under the heading. */
    .results-head {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .results-head .results-title {
        align-self: stretch;
    }

    /* Results pages keep the search box to one row. */
    .search-wrap:not(.search-wrap-landing) .search-row {
        flex-direction: row;
    }

    /* The same "Search 搜索" label as on the landing page. */
    .search-wrap:not(.search-wrap-landing) .search-btn {
        min-width: 0;
        min-height: 44px;
        margin: 6px;
        padding: 0 14px;
        gap: 6px;
        font-size: 14px;
    }

    .search-wrap:not(.search-wrap-landing) .search-input {
        padding-right: 8px;
    }

    .foot {
        flex-direction: row;
        align-items: center;
    }
}

@media (max-width: 360px) {
    .titles {
        display: none;
    }
}

@media (max-width: 480px) {
    .hero {
        padding-top: 22px;
    }

    .hero-chars {
        font-size: clamp(48px, 14vw, 62px);
    }

    .hero-sub {
        font-size: 20px;
    }

    .hero-copy {
        font-size: 16px;
    }

    .script-toggle {
        padding: 7px 10px;
        gap: 7px;
    }

    .script-toggle-option {
        font-size: 13px;
    }

    .script-toggle-divider {
        font-size: 9px;
    }

    .saved-pill {
        padding: 7px 10px;
        font-size: 11px;
    }

    .search-box,
    .featured-card,
    .message-card,
    .result-card,
    .saved-card {
        border-radius: 6px;
    }

    .search-input {
        min-height: 52px;
        padding-left: 44px;
        padding-right: 16px;
        font-size: 16px;
        line-height: 1.4;
    }

    .magnifier {
        left: 16px;
        width: 17px;
        height: 17px;
    }

    .saved-export-btn {
        width: 100%;
        justify-content: center;
    }

    .saved-card-main {
        padding: 14px 14px 10px;
    }

    .saved-card-preview {
        padding: 0 14px 12px;
    }

    .saved-card-foot {
        padding: 0 4px;
    }

    .saved-card-foot .card-actions {
        gap: 0;
    }


    .example-zh {
        font-size: 16px;
    }

    /* Results: the heading keeps to one line (the full query is in the box
       and the sticky bar), and the box sits a little tighter. */
    .search-wrap:not(.search-wrap-landing) {
        padding-top: 10px;
        padding-bottom: 16px;
    }

    .results-head {
        margin-bottom: 12px;
        padding-bottom: 10px;
    }

    .results-title {
        display: block;
        font-size: 19px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* The rank numeral sits beside the headword only. Everything under the
       headword line (meaning, lit., example preview and details) spans the
       card's full content width from the numeral's x. */
    .hero-row,
    .result-row .hero-row {
        grid-template-columns: var(--gutter) minmax(0, 1fr) auto;
        grid-template-areas:
            "rank head actions"
            "gloss gloss gloss";
    }

    .result-details {
        margin-left: 0;
    }

    /* The first result: rank, headword and actions on one line, then the
       meaning, lit. and the complete example with its translation, all at
       full width. An inline "Details" disclosure after the example holds
       the other script and the tags. */
    .result-card.rank-1 {
        display: grid;
        grid-template-columns: var(--gutter) minmax(0, 1fr) auto;
        grid-template-areas:
            "rank head actions"
            "meaning meaning meaning"
            "lit lit lit"
            "var var var"
            "zh zh zh"
            "body body body";
        column-gap: var(--gutter-gap);
        align-items: end;
    }

    .result-card.rank-1:not(:has(.rank-badge)) {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "head actions"
            "meaning meaning"
            "lit lit"
            "var var"
            "zh zh"
            "body body";
    }

    .rank-1 .hero-row,
    .rank-1 .gloss-block {
        display: contents;
    }

    .rank-1 .headword-block {
        grid-area: head;
    }

    .rank-1 .result-meaning {
        grid-area: meaning;
        margin-top: 6px;
    }

    .rank-1 .literal-line {
        grid-area: lit;
    }

    .rank-1 .variant-line {
        grid-area: var;
    }

    .rank-1 .gloss-block > .gloss-zh-block {
        grid-area: zh;
        margin-top: 14px;
    }

    .rank-1 .hero-body,
    .rank-1:not(:has(.rank-badge)) .hero-body {
        grid-area: body;
        margin: 14px 0 0;
        padding-top: 0;
        border-top: none;
        gap: 12px;
    }

    .rank-1:has(.hero-more):not(.is-expanded) .hero-extra {
        display: none;
    }

    .hero-more {
        display: inline-flex;
    }
}

/* Results pages: once the search box scrolls away, a compact copy of it
   sits at the top: the same bordered field on the content width, the small
   seal, the query on one line and the "Search 搜索" submit. Tapping it
   returns to the box. It rests on a full-width paper band with a bottom
   hairline, so nothing peeks around it. It sits under the dictionary sheet
   and its scrim. */
.sticky-search {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 50;
    padding: max(8px, env(safe-area-inset-top)) var(--page-pad) 8px;
    border-bottom: 1px solid var(--paper-edge);
    background: var(--paper);
    visibility: hidden;
    opacity: 0;
    transform: translateY(-12px);
    transition: transform 0.2s ease, opacity 0.2s ease, visibility 0s linear 0.2s;
}

@supports ((backdrop-filter: blur(8px)) or (-webkit-backdrop-filter: blur(8px))) {
    .sticky-search {
        background: color-mix(in srgb, var(--paper) 96%, transparent);
        -webkit-backdrop-filter: blur(8px);
        backdrop-filter: blur(8px);
    }
}

body.show-sticky-search .sticky-search {
    visibility: visible;
    opacity: 1;
    transform: none;
    transition: transform 0.2s ease, opacity 0.2s ease, visibility 0s;
}

.sticky-search-btn {
    width: 100%;
    max-width: calc(var(--max-results) - 2 * var(--page-pad));
    height: 50px;
    margin: 0 auto;
    padding: 0 6px 0 9px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--card-edge);
    border-radius: 12px;
    background: var(--card-bg);
    box-shadow: 0 1px 2px rgba(26, 22, 19, 0.05);
    color: var(--ink);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s ease;
}

@media (hover: hover) {
    .sticky-search-btn:hover {
        border-color: var(--control-hover-border);
    }
}

.sticky-seal {
    flex: none;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 2px;
    background: var(--cinnabar);
    color: #FDF6E8;
    font-family: var(--font-cjk);
    font-size: 15px;
    font-weight: 700;
    box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.22);
    transform: rotate(-2deg);
}

/* Upright roman, like the search box it stands for. */
.sticky-search-query {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    font-family: var(--font-text);
    font-size: 17px;
    font-style: normal;
    font-synthesis: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sticky-search-chip {
    flex: none;
    min-height: 36px;
    padding: 0 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 8px;
    background: var(--button-primary-bg);
    color: var(--button-primary-fg);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.sticky-search-chip .cn {
    font-family: var(--font-cjk);
    font-weight: 500;
}

.sticky-search-btn:focus-visible {
    box-shadow: var(--focus-ring);
}

/* ---------------------------------------------------------------------------
   Dictionary tooltip styles
--------------------------------------------------------------------------- */

/* Hanzi that open the dictionary: a help cursor and a light paper-tint box
   under a pointer or keyboard focus, with a dotted hairline under each
   glyph, so learners find them. */
.ch[data-dict-char],
.ch-word,
.dict-token {
    cursor: help;
    border-radius: 3px;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

.ch[data-dict-char]::after,
.ch-word .ch::after {
    content: "";
    position: absolute;
    right: 0.1em;
    bottom: 0.02em;
    left: 0.1em;
    border-bottom: 1px dotted var(--ink-4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.ch[data-dict-char]:focus-visible::after,
.ch-word:focus-visible .ch::after {
    opacity: 1;
}

@media (hover: hover) {
    .ch[data-dict-char]:hover::after,
    .ch-word:hover .ch::after {
        opacity: 1;
    }
}

/* The open glyph's accent underline replaces the dotted one. */
.ch[data-dict-char].is-dict-active::after,
.ch-word.is-dict-active .ch::after {
    opacity: 0;
}

.ch[data-dict-char]:focus-visible,
.ch-word:focus-visible,
.dict-token:focus-visible {
    background: var(--tag-bg);
    box-shadow: var(--focus-ring);
    outline: none;
}

.dict-token.highlight:focus-visible {
    background: var(--tag-bg);
}

@media (hover: hover) {
    .ch[data-dict-char]:hover,
    .ch-word:hover,
    .dict-token:hover {
        background: var(--tag-bg);
    }

    .dict-token.highlight:hover {
        background: var(--tag-bg);
    }

    .result-card:hover {
        border-color: var(--control-border);
    }
}

.dict-scrim {
    display: none;
}

.dict-popover {
    position: fixed;
    z-index: 1000;
    max-width: 340px;
    min-width: 220px;
    max-height: min(520px, calc(100vh - 16px));
    overflow: auto;
    background: var(--card-bg);
    border: 1px solid var(--control-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.18);
    padding: 12px 16px 16px;
    font-family: var(--font-cjk);
    font-size: 15px;
    line-height: 1.5;
}

.dict-popover[hidden] {
    display: none;
}

/* The caret sits over the popover's edge, pointing at the glyph or word it
   defines: up when the popover is below, down when it is above. */
.dict-caret {
    position: fixed;
    z-index: 1001;
    width: 12px;
    height: 12px;
    border: 1px solid var(--control-border);
    background: var(--card-bg);
    pointer-events: none;
    transform: rotate(45deg);
}

.dict-caret[data-placement="below"] {
    border-right-color: transparent;
    border-bottom-color: transparent;
}

.dict-caret[data-placement="above"] {
    border-top-color: transparent;
    border-left-color: transparent;
}

.dict-caret[hidden] {
    display: none;
}

/* The glyph or word whose definition is open stays tinted. */
.ch[data-dict-char].is-dict-active,
.ch-word.is-dict-active,
.dict-token.is-dict-active {
    background: var(--highlight-bg);
    color: var(--highlight-fg);
    box-shadow: inset 0 -2px 0 var(--highlight-edge);
}

.dict-pop-handle {
    display: none;
}

.dict-pop-toolbar {
    margin: 0 -4px 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--paper-edge);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    color: var(--ink-3);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.dict-pop-close {
    min-height: 36px;
    padding: 0 6px;
    border-radius: var(--radius);
    color: var(--ink-3);
    cursor: pointer;
    font-size: 13px;
    letter-spacing: 0;
}

@media (hover: hover) {
    .dict-pop-close:hover {
        color: var(--ink);
    }
}

.dict-pop-close span {
    margin-left: 3px;
    font-size: 16px;
}

.dict-pop-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.dict-pop-word {
    font-size: 24px;
    font-weight: 600;
    color: var(--ink);
}

.dict-pop-trad {
    font-size: 24px;
    font-weight: 600;
    color: var(--ink-2);
}

/* 简 屡 · 繁 屢: each form carries its script's name. */
.dict-pop-script {
    margin-right: -2px;
    color: var(--ink-3);
    font-size: 13px;
}

.dict-pop-sep {
    color: var(--ink-4);
    font-size: 15px;
}

.dict-pop-tag {
    font-size: 12px;
    padding: 1px 6px;
    border: 1px solid var(--tag-border);
    border-radius: 3px;
    color: var(--ink-2);
    font-family: var(--font-cjk);
}

.dict-pop-pinyin {
    font-size: 16px;
    margin-bottom: 8px;
}

.dict-pop-literal {
    color: var(--ink-3);
    font-family: var(--font-text);
    font-size: 15px;
    font-style: italic;
    margin-bottom: 8px;
    line-height: 1.45;
}

.dict-pop-defs {
    margin: 0;
    padding-left: 22px;
    list-style: decimal;
    color: var(--ink-3);
    font-family: var(--font-text);
}

.dict-pop-def {
    color: var(--ink);
    font-family: var(--font-text);
    font-size: 16px;
    line-height: 1.5;
    margin-bottom: 4px;
}

/* Runs a search for the word the popover defines. */
.dict-pop-search {
    min-height: 36px;
    margin-top: 10px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid var(--control-border);
    border-radius: var(--radius);
    background: var(--control-bg);
    color: var(--ink-2);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    transition: border-color 0.15s ease, color 0.15s ease;
}

@media (hover: hover) {
    .dict-pop-search:hover {
        border-color: var(--control-hover-border);
        color: var(--ink);
    }
}

.dict-pop-search-word {
    font-family: var(--font-cjk);
    font-size: 15px;
}

@media (max-width: 640px) {
    /* A light scrim behind the bottom sheet; tapping it closes the sheet. */
    .dict-scrim {
        position: fixed;
        inset: 0;
        z-index: 999;
        display: block;
        background: var(--scrim);
    }

    .dict-scrim[hidden] {
        display: none;
    }

    .dict-caret {
        display: none;
    }

    .dict-popover {
        inset: auto 0 0 0 !important;
        width: 100%;
        max-width: none;
        min-width: 0;
        max-height: min(62vh, 520px);
        border-right: none;
        border-bottom: none;
        border-left: none;
        border-radius: 16px 16px 0 0;
        padding: 0 20px max(24px, env(safe-area-inset-bottom));
        box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.22);
    }

    .dict-pop-toolbar {
        position: sticky;
        top: 0;
        z-index: 1;
        margin: 0 -4px 12px;
        padding: 22px 4px 8px;
        background: var(--card-bg);
    }

    .dict-pop-handle {
        position: absolute;
        top: 8px;
        left: 50%;
        display: block;
        width: 40px;
        height: 4px;
        border-radius: 999px;
        background: var(--ink-4);
        opacity: 0.7;
        transform: translateX(-50%);
    }

    .dict-pop-word {
        font-size: 28px;
    }

    .dict-pop-def {
        font-size: 17px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
