:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f6f6f7;
  --surface-strong: #ececee;
  --raised: #ffffff;
  --ink: #1d1d1f;
  --muted: #5b5b61;
  --faint: #707076;
  --line: #e7e7ea;
  --line-strong: #d5d5da;
  --accent: #b3262f;
  --focus: var(--accent);
  --accent-hover: #9a1f27;
  --accent-soft: #fbeced;
  --accent-ink: #a8232c;
  --on-accent: #ffffff;
  --shadow: 0 1px 2px rgba(20, 20, 30, .06), 0 12px 32px -8px rgba(20, 20, 30, .18);
  --stroke-ghost: #e3e3e6;
  --logo: #111111;
  --row-hover: #ececee;
  --backdrop: rgba(0, 0, 0, .16);
  --row-selected: var(--accent-soft);
  --track: #e9e9ec;
  --thumb: #ffffff;
  --thumb-shadow: 0 1px 3px rgba(20, 20, 30, .16), 0 0 0 .5px rgba(20, 20, 30, .1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --cjk: "PingFang SC", "PingFang TC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --fast: .15s;
  --slow: .2s;
  /* things that come and go: slow enough to see on a 60 Hz phone */
  --ease-move: cubic-bezier(.32, .72, 0, 1);
  --move: .28s;
  --move-out: .2s;
  --radius: 10px;
  /* Rows split --row into padding and sit --attach apart, leaving --group between their text. */
  --block: 4px;
  --attach: 8px;
  --item: 12px;
  --row: 16px;
  --group: 24px;
  --section: 32px;
}
:root:is([data-theme="dark"], [data-system-theme="dark"]:not([data-theme="light"])) {
  color-scheme: dark;
  --bg: #161618;
  --surface: #1c1c1f;
  --surface-strong: #2a2a2e;
  --raised: #232326;
  --ink: #ececee;
  --muted: #a3a3a9;
  --faint: #8b8b92;
  --line: #2b2b2f;
  --line-strong: #3a3a3f;
  --accent: #e5545b;
  --focus: var(--accent-ink);
  --accent-hover: #f06a70;
  --accent-soft: rgba(229, 84, 91, .14);
  --accent-ink: #ff8a8f;
  --on-accent: var(--bg);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 16px 40px -8px rgba(0, 0, 0, .6);
  --stroke-ghost: #333338;
  --logo: #f4f4f2;
  --row-hover: #232327;
  --backdrop: rgba(0, 0, 0, .4);
  --track: #131315;
  --thumb: #46464c;
  --thumb-shadow: 0 1px 2px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; -webkit-font-smoothing: antialiased; }
body { height: 100dvh; overflow: hidden; }
[lang="zh"] { font-family: var(--cjk); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; opacity: .4; }
button[aria-disabled="true"] { cursor: progress; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
a:focus-visible, summary:focus-visible { border-radius: 6px; }
a { color: var(--accent-ink); text-decoration: none; }
@media (hover: hover) { a:hover { text-decoration: underline; text-underline-offset: 3px; } }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon-definitions { position: absolute; width: 0; height: 0; overflow: hidden; }
[hidden]:not(.leaving) { display: none !important; }
.faint { color: var(--faint); }
.hint { margin: var(--attach) 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.icon-button { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; color: var(--muted); transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease); }
.icon-button[aria-expanded="true"] { background: var(--surface-strong); color: var(--ink); }
@media (hover: hover) { .icon-button:hover { background: var(--surface-strong); color: var(--ink); } }
.icon-button.small { width: 32px; height: 32px; }
.icon-button.small svg { width: 17px; height: 17px; }
.quiet-button { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 10px; border-radius: 6px; color: var(--muted); font-size: 13px; transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease); }
.quiet-button svg { width: 16px; height: 16px; }
@media (hover: hover) { .quiet-button:not(:disabled):hover { background: var(--surface-strong); color: var(--ink); } }
.text-link { color: var(--accent-ink); font-size: 13px; line-height: 1.5; display: inline-flex; align-items: center; gap: 4px; }
a.text-link { text-decoration: underline; text-underline-offset: 3px; }
@media (hover: hover) { .text-link:hover { text-decoration: underline; text-underline-offset: 3px; } }
.text-link svg { width: 14px; height: 14px; }

.search-form { position: relative; display: flex; align-items: center; gap: 4px; height: 44px; padding: 0 4px 0 14px; border: 1px solid transparent; border-radius: 10px; background: var(--surface); transition: background-color var(--slow) var(--ease), border-color var(--slow) var(--ease), box-shadow var(--slow) var(--ease); }
.search-form:focus-within { background: var(--bg); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.search-icon { width: 18px; height: 18px; color: var(--faint); margin-right: 6px; }
#query { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; font-size: 17px; font-family: var(--font), var(--cjk); }
#query::placeholder { color: var(--faint); }
/* webkit still draws its own clear button after appearance: none */
#query::-webkit-search-cancel-button, #query::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.field-button { display: grid; place-items: center; flex-shrink: 0; width: 36px; height: 36px; border-radius: 6px; color: var(--muted); transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease); }
.field-button svg { width: 18px; height: 18px; }
#clear-query svg { width: 15px; height: 15px; }
.field-button[aria-expanded="true"] { background-color: var(--surface-strong); color: var(--accent-ink); }
@media (hover: hover) { .field-button:not(:disabled):hover { background-color: var(--surface-strong); color: var(--accent-ink); } }

.app-shell { display: flex; flex-direction: column; height: 100%; }
.app-header { position: relative; z-index: 21; display: grid; grid-template-columns: minmax(max-content, 1fr) minmax(0, 680px) minmax(max-content, 1fr); align-items: center; gap: 20px; height: 64px; padding: 0 18px; flex-shrink: 0; border-bottom: 1px solid var(--line); }
/* light and dark logos are drawn at different weights */
.logo { display: block; width: auto; flex-shrink: 0; fill: var(--logo); stroke: none; }
.logo-dark { display: none; }
:root:is([data-theme="dark"], [data-system-theme="dark"]:not([data-theme="light"])) .logo-light { display: none; }
:root:is([data-theme="dark"], [data-system-theme="dark"]:not([data-theme="light"])) .logo-dark { display: block; }
.brand { display: inline-flex; justify-self: start; padding: 6px 4px; flex-shrink: 0; }
@media (hover: hover) { .brand:hover { text-decoration: none; } }
.brand .logo { height: 18px; }
.app-header .search-form { width: 100%; }
.header-tools { display: flex; align-items: center; gap: 2px; justify-self: end; }
.dictionary-layout { display: grid; grid-template-columns: 360px minmax(0, 1fr); flex: 1; min-height: 0; }
.results-pane { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; overscroll-behavior: contain; border-right: 1px solid var(--line); background: var(--bg); scrollbar-width: thin; }
.visually-hidden { position: absolute; top: 0; left: 0; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.results-list { display: flex; flex-direction: column; padding: var(--attach) 12px; }
.result-row, .word-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; column-gap: 12px; width: 100%; border-radius: var(--radius); text-align: left; transition: background-color var(--fast) var(--ease); }
.result-row { padding: calc(var(--row) / 2) 14px; }
.result-row + .result-row, .word-row + .word-row, .word-row + .more-words { margin-top: var(--attach); }
@media (hover: hover) { .result-row:hover { background: var(--row-hover); } }
.result-row.selected { background: var(--row-selected); }
.result-row:focus-visible, .word-row:focus-visible { outline-offset: 0; }
.result-row.selected .result-word { color: var(--accent-ink); }
.row-head { display: flex; align-items: baseline; gap: 12px; min-width: 0; white-space: nowrap; }
.result-word, .result-pinyin, .result-gloss { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-word { flex: 0 1 auto; min-width: 0; font-size: 20px; line-height: 1.3; font-weight: 400; transition: color var(--fast) var(--ease); }
.result-word.long { font-size: 18px; }
.result-pinyin { flex: 1 1 0; min-width: 5em; color: var(--muted); font-size: 14px; line-height: 1.4; }
.result-gloss { grid-column: 1 / -1; margin-top: var(--block); color: var(--muted); font-size: 14px; line-height: 1.4; }
/* the dot trails each meaning so a wrapped line never starts with it */
.gloss-sense:not(:last-child)::after { content: " \00B7"; color: var(--faint); }
.phrase-note { margin: var(--attach) 14px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.phrase-note .text-link, .character-error .text-link { display: inline; font-size: inherit; }
/* room for the focus ring between the sentence and its link */
.phrase-note .text-link { margin-left: 3px; }
.phrase-note .note-word { display: inline; padding: 0 4px; font: inherit; color: var(--ink); background: none; border: 0; cursor: pointer; }
@media (hover: hover) { .phrase-note .note-word:hover { text-decoration: underline; text-underline-offset: 3px; } }
.segment-label { display: flex; align-items: center; gap: 10px; width: fit-content; margin: var(--group) 14px 0; color: var(--muted); font-size: 13px; font-weight: 600; line-height: 1.5; }
button.segment-label { min-height: 24px; }
.segment-label svg { width: 13px; height: 13px; margin-left: -6px; color: var(--faint); }
@media (hover: hover) { button.segment-label:hover { color: var(--ink); } }
.segment-label:first-child { margin-top: var(--attach); }
.segment-label + .result-row { padding-top: var(--block); }
.segment-label [lang="zh"] { font-size: 15px; }
.segment-label .faint { font-weight: 400; }
@media (min-width: 681px) { .list-state { display: none; } }
.load-more { margin: 0 12px var(--row); min-height: 44px; border-radius: var(--radius); color: var(--accent-ink); font-size: 13px; font-weight: 500; transition: background-color var(--fast) var(--ease); }
@media (hover: hover) { .load-more:not([aria-disabled="true"]):hover { background: var(--row-hover); } }
.entry-pane { min-width: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; }
.entry-pane:has(:focus-visible) { scroll-behavior: auto; }
#entry-content { display: flex; flex-direction: column; min-height: 100%; width: 100%; max-width: 880px; margin-inline: auto; padding: calc(var(--section) + var(--attach)) 48px calc(2 * var(--section)); }

.back-button { display: none; }
.entry-header { flex-shrink: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.entry-heading { min-width: 0; }
.entry-wordline { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--block) 12px; }
.entry-word { margin: 0; font-size: 48px; line-height: 1.15; font-weight: 500; letter-spacing: .02em; overflow-wrap: anywhere; text-wrap: balance; outline: 0; }
.entry-word.long { font-size: 38px; }
.entry-word.long + .alternate-word { font-size: 17px; }
.entry-word .clause { display: inline-block; }
.alternate-word { padding: 0 6px; margin-inline: -6px; border-radius: 6px; color: var(--faint); font-size: 24px; line-height: 1.3; font-weight: 400; text-align: left; transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease); }
@media (hover: hover) { .alternate-word:hover { background: var(--surface); color: var(--ink); } }
.entry-sound { display: flex; flex-wrap: wrap; align-items: center; gap: var(--block) 10px; margin-top: var(--block); }
/* Reserve height so wrapped controls keep separate tap targets. */
.listen-button { position: relative; display: grid; place-items: center; align-self: center; flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%; color: var(--muted); transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease); }
.listen-button svg { width: 19px; height: 19px; }
@media (hover: hover) { .listen-button:hover { background: var(--surface); color: var(--ink); } }
.listen-button.playing { color: var(--accent-ink); background: var(--accent-soft); }
.listen-button:focus-visible { outline-offset: -2px; }
:root:not(.has-voice) .listen-button { display: none; }
.entry-pinyin { color: var(--muted); font-size: 20px; line-height: 1.4; }
.other-readings { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--attach); color: var(--faint); font-size: 13px; }
.reading-link { padding: 0 4px; border-radius: 6px; color: var(--muted); font-size: 15px; text-decoration: underline 1px var(--line-strong); text-underline-offset: 4px; transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease); }
@media (hover: hover) { .reading-link:hover { background: var(--surface); color: var(--ink); } }
.reading-choice { min-height: 32px; padding: 3px 12px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--muted); font-size: 15px; transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease), border-color var(--fast) var(--ease); }
@media (hover: hover) { .reading-choice:hover { color: var(--ink); border-color: var(--faint); } }

/* Tab labels and Listen already carry spare tap room. */
.entry-tabs { flex-shrink: 0; display: flex; gap: 26px; margin-top: var(--item); border-bottom: 1px solid var(--line); }
.entry-tab { position: relative; min-height: 44px; padding: 0 1px; white-space: nowrap; color: var(--muted); font-size: 15px; font-weight: 500; transition: color var(--fast) var(--ease); }
@media (hover: hover) { .entry-tab:hover { color: var(--ink); } }
.entry-tab[aria-selected="true"] { color: var(--ink); }
.tab-mark { position: absolute; bottom: -1px; left: 0; right: 0; height: 2px; background: var(--accent); transform-origin: left; }
.entry-tab small { margin-left: 1px; color: var(--faint); font-size: 12px; font-weight: 500; }
.tab-content { flex: 1; padding-top: var(--group); }

.sense-group + .sense-group { margin-top: var(--item); }
.sense-group + .sense-group:has(> h3) { margin-top: var(--group); }
.pos, .tag { margin: 0; color: var(--faint); font-size: 14px; font-style: normal; font-weight: 400; line-height: 1.5; }
h3.pos { margin-bottom: var(--block); }
.sense-text > :is(.pos, .tag) { margin-right: .2em; -webkit-user-select: none; user-select: none; }
.senses { display: flex; flex-direction: column; gap: var(--item); margin: 0; padding: 0; list-style: none; }
.sense { display: grid; grid-template-columns: 22px minmax(0, 1fr); align-items: baseline; gap: 8px; font-size: 17px; line-height: 1.6; overflow-wrap: anywhere; }
.sense-number { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.senses.lone .sense { grid-template-columns: minmax(0, 1fr); }
.senses.lone .sense-number { display: none; }
.sense-body { max-width: 72ch; text-wrap: pretty; }
.sense-text { margin: 0; }
.note { color: var(--muted); }
.ref-pinyin { color: var(--faint); font-size: .88em; }
.usage-notes { display: flex; flex-direction: column; align-items: flex-start; gap: var(--block); margin: var(--group) 0 0 30px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.usage-notes.lone { margin-left: 0; }
.usage-notes .word-link { font-size: 15px; }
.sense-note { margin: var(--block) 0 0; color: var(--muted); font-size: 15px; line-height: 1.55; }
.sense-examples { margin-top: var(--attach); }
.sense-examples > summary, .added-meanings > summary { display: flex; align-items: center; gap: 4px; width: fit-content; color: var(--muted); font-size: 13px; line-height: 1.5; cursor: pointer; list-style: none; }
.sense-examples > summary::-webkit-details-marker, .added-meanings > summary::-webkit-details-marker { display: none; }
summary > svg { width: 14px; height: 14px; translate: 0 -1px; transition: transform var(--fast) var(--ease); }
details[open]:not(.closing) > summary > svg { transform: rotate(90deg); }
@media (hover: hover) { summary:hover { color: var(--accent-ink); } }
/* Flex contains margins for height measurement; a lead-in margin vanishes on closing. */
.disclosure-body { display: flex; flex-direction: column; }
.disclosure-body > :first-child { margin-top: var(--lead); }
.sense-examples .disclosure-body { gap: var(--attach); --lead: var(--attach); }
.sense-examples .example { padding-left: 14px; border-left: 2px solid var(--line); }
.sense-examples .example-chinese { font-size: 17px; }
.sense-examples .example-english { font-size: 15px; }
.sense-source { margin-left: 8px; color: var(--faint); font-size: 12px; white-space: nowrap; }
.added-meanings { margin-top: var(--section); }
.added-meanings .disclosure-body { gap: var(--item); --lead: var(--attach); }
.added-meanings .sense { font-size: 15px; color: var(--ink); }
.no-break { white-space: nowrap; }
.word-link { display: inline; padding: 0; margin: 0; border-radius: 6px; color: inherit; font: inherit; font-family: var(--cjk); line-height: inherit; background-image: linear-gradient(var(--line-strong), var(--line-strong)); background-size: 0 1px; background-position: 0 100%; background-repeat: no-repeat; transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease); }
.word-link:active, .word-link.looked-up { background-color: var(--surface-strong); }
@media (hover: hover) { .word-link:hover { background-size: 100% 1px; background-color: var(--accent-soft); color: var(--accent-ink); } }
@media (hover: none) {
  .word-link { background-size: 100% 1px; }
  .example-chinese .word-link { background-size: 0 1px; }
}

.examples { margin-top: var(--section); }
.section-title { margin: 0; color: var(--faint); font-size: 13px; font-weight: 400; line-height: 1.5; }
.section-title + .example { margin-top: var(--attach); }
.examples > .example + .example, .more-examples { margin-top: var(--item); }
.example p { margin: 0; overflow-wrap: anywhere; text-wrap: pretty; }
.example p + p { margin-top: var(--block); }
.example-chinese { font-size: 20px; line-height: 1.7; }
.example-pinyin { color: var(--faint); font-size: 13px; line-height: 1.45; }
.example-english { color: var(--muted); font-size: 15px; line-height: 1.55; }
.source-credit { margin: 4px 0 0; color: var(--faint); font-size: 12px; line-height: 1.5; }
.source-credit a { color: inherit; text-decoration: underline 1px var(--line-strong); text-underline-offset: 2px; }
.example-chinese b { font-weight: 600; }
.example-pinyin b { color: var(--ink); font-weight: 400; }
.more-examples summary { display: inline-flex; align-items: center; gap: 6px; color: var(--accent-ink); font-size: 13px; line-height: 1.5; cursor: pointer; list-style: none; }
.more-examples summary::-webkit-details-marker { display: none; }
.more-examples summary svg { width: 14px; height: 14px; transition: transform var(--slow) var(--ease); }
.more-examples[open]:not(.closing) summary svg { transform: rotate(90deg); }
.more-examples .disclosure-body { gap: var(--item); --lead: var(--item); }

.word-row { padding: calc(var(--row) / 2) 12px; margin: 0 -12px; width: calc(100% + 24px); }
.tab-content > .word-row:first-child { margin-top: calc(var(--row) / -2); }
@media (hover: hover) { .word-row:hover { background: var(--surface); } }
.word-row .result-word.long { font-size: 17px; }
.more-words { display: flex; width: fit-content; }
.character-rows { display: flex; flex-direction: column; gap: var(--group); margin: 0; padding: 0; list-style: none; }
.character-row { --stroke-size: 92px; display: grid; grid-template-columns: var(--stroke-size) minmax(0, 1fr); align-items: start; gap: 20px; }
.character-senses { grid-column: 1 / -1; display: flex; flex-direction: column; gap: var(--block); margin-top: var(--block); color: var(--muted); font-size: 15px; line-height: 1.45; text-wrap: pretty; }
.skeleton { display: inline-block; width: 11em; max-width: 100%; height: 10px; border-radius: 5px; background: var(--surface-strong); vertical-align: middle; }
/* keeps repaints inside the box while strokes play */
.stroke-picture { position: relative; display: block; width: var(--stroke-size); height: var(--stroke-size); border-radius: 10px; background: var(--surface); overflow: hidden; contain: strict; touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; transition: background-color var(--fast) var(--ease); }
@media (hover: hover) { button.stroke-picture:hover { background: var(--surface-strong); } }
.stroke-picture::before, .stroke-picture::after { content: ""; position: absolute; pointer-events: none; border: 0 dashed var(--line-strong); }
.stroke-picture::before { left: 50%; top: 6px; bottom: 6px; border-left-width: 1px; }
.stroke-picture::after { top: 50%; left: 6px; right: 6px; border-top-width: 1px; }
.stroke-art { position: absolute; inset: 10%; z-index: 1; }
.stroke-art svg { width: 100%; height: 100%; stroke: none; fill: var(--ink); }
.stroke-picture .stroke-background { fill: var(--stroke-ghost); }
.stroke-picture .stroke-median { fill: none; stroke: var(--ink); stroke-width: 140; stroke-linecap: round; stroke-linejoin: round; }
.stroke-picture > svg { position: absolute; z-index: 2; right: 3px; bottom: 3px; width: 10px; height: 10px; color: var(--faint); fill: currentColor; stroke: none; transition: opacity var(--fast) var(--ease); }
.stroke-picture.playing > svg { opacity: 0; }
.character-rows.single .character-row { --stroke-size: 168px; }
.character-rows.single .stroke-picture > svg { right: 6px; bottom: 6px; width: 12px; height: 12px; }
.stroke-placeholder { display: grid; place-items: center; font-size: 48px; color: var(--faint); }
.character-error { margin: var(--group) 0 0; color: var(--muted); line-height: 1.6; }
.character-text { min-width: 0; display: grid; grid-template-rows: minmax(var(--stroke-size), auto); }
.character-text .word-row { margin-block: 0; padding-block: var(--block); align-content: center; }

.empty-entry { display: grid; place-items: center; min-height: 50vh; padding: 0 8px; text-align: center; color: var(--muted); }
.empty-entry [lang="zh"] { display: block; font-size: 48px; color: var(--line-strong); }
.empty-entry > div { min-width: 0; }
.empty-entry h1, .empty-entry h2 { overflow-wrap: anywhere; margin: 16px 0 6px; color: var(--ink); font-size: 20px; font-weight: 600; }
.empty-entry p { overflow-wrap: anywhere; margin: 0; font-size: 15px; line-height: 1.6; text-wrap: balance; }
.empty-entry .text-link { margin-top: var(--attach); font-size: 15px; }

.panel-layer { position: relative; z-index: 20; }
.panel-surface { display: block; padding: var(--row) 18px; border-radius: 16px; border: 1px solid var(--line); background: var(--raised); box-shadow: var(--shadow); }
.utility-panel { position: absolute; top: 8px; right: 16px; width: 360px; max-height: calc(100dvh - 88px); overflow-y: auto; overscroll-behavior: contain; transform-origin: top right; --away: translateY(-8px) scale(.98); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: var(--item); }
.panel-heading h2 { margin: 0; font-size: 15px; font-weight: 600; }
.panel-heading .icon-button { margin-right: -8px; }
#handwriting-panel, #handwriting-panel * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.canvas-wrap { position: relative; aspect-ratio: 1; border-radius: 10px; background: var(--surface); overflow: hidden; }
@media (max-height: 600px) {
  .canvas-wrap { width: min(100%, max(64px, calc(100dvh - 240px))); margin-inline: auto; }
}
.canvas-wrap::before, .canvas-wrap::after { content: ""; position: absolute; pointer-events: none; border: 0 dashed var(--line-strong); }
.canvas-wrap::before { left: 50%; top: 10px; bottom: 10px; border-left-width: 1px; }
.canvas-wrap::after { top: 50%; left: 10px; right: 10px; border-top-width: 1px; }
#handwriting-canvas { position: relative; z-index: 1; display: block; width: 100%; height: 100%; border-radius: 10px; touch-action: none; -webkit-tap-highlight-color: transparent; cursor: crosshair; }
#handwriting-canvas:focus-visible { outline-offset: -2px; }
.drawing-actions { display: flex; align-items: center; gap: 2px; margin: 8px -6px 0; }
.drawing-actions .faint { margin-left: auto; padding-right: 6px; font-size: 12px; }
/* Share the slot so no empty space waits below the hint. */
.handwriting-result { display: grid; min-height: 52px; margin-top: var(--attach); }
.handwriting-result > * { grid-area: 1 / 1; }
.handwriting-result > .hint { margin: 0; }
.candidates { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.candidate-button { display: grid; place-items: center; width: 100%; height: 52px; border-radius: 10px; background: var(--surface); font-family: var(--cjk); font-size: 32px; animation: content-in var(--fast) var(--ease); transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease); }
@media (hover: hover) { .candidate-button:hover { background: var(--accent-soft); color: var(--accent-ink); } }
.settings-panel { width: 380px; padding: var(--row) 22px 0; }
.settings-panel .panel-heading { margin-bottom: var(--attach); }
.setting { display: grid; gap: var(--attach); margin: 0 0 var(--group); }
.setting-label { color: var(--muted); font-size: 13px; font-weight: 500; line-height: 1.5; }
.setting-hint { margin: 0; color: var(--faint); font-size: 12px; line-height: 1.5; }
.setting-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); column-gap: 14px; }
.segmented { display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--track); }
.segmented button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: 1; min-height: 34px; padding: 0 8px; border-radius: 6px; color: var(--muted); font-size: 13px; white-space: nowrap; transition: background-color var(--slow) var(--ease), color var(--slow) var(--ease), box-shadow var(--slow) var(--ease); }
@media (hover: hover) { .segmented button:hover { color: var(--ink); } }
.segmented button[aria-checked="true"] { background: var(--thumb); color: var(--ink); font-weight: 600; box-shadow: var(--thumb-shadow); }
.segmented button:focus-visible, .quiet-button:focus-visible, .field-button:focus-visible { outline-offset: -2px; }
.segmented button[lang="zh"] { font-size: 15px; }
.segmented svg { width: 16px; height: 16px; }
.panel-footer { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--attach) 16px; margin: 0 -22px; padding: var(--item) 22px; border-top: 1px solid var(--line); }
.panel-link { color: var(--muted); font-size: 13px; line-height: 1.5; }
@media (hover: hover) { .panel-link:hover { color: var(--ink); } }

.lookup-popover { display: flex; flex-direction: column; max-height: min(360px, calc(100dvh - 24px)); position: fixed; z-index: 30; width: 380px; overflow-y: auto; overscroll-behavior: contain; padding: var(--row) 18px var(--item); --away: translateY(-8px) scale(.98); border-radius: 16px; border: 1px solid var(--line); background: var(--raised); box-shadow: var(--shadow); }
.peek-heading { flex-shrink: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.peek-heading h2 { margin: 0; font-size: 32px; font-weight: 500; line-height: 1.25; overflow-wrap: anywhere; }
.peek-heading .icon-button { margin: -4px -8px 0 0; }
.peek-pinyin { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 10px; margin-top: var(--block); color: var(--muted); font-size: 15px; }
/* Fade scrolling lines to avoid a hard cut at the edges. */
.peek-body { flex: 1; min-height: 0; overflow-y: auto; margin-top: var(--group); --above: 0px; --below: 0px; -webkit-mask-image: linear-gradient(transparent, #000 var(--above), #000 calc(100% - var(--below)), transparent); mask-image: linear-gradient(transparent, #000 var(--above), #000 calc(100% - var(--below)), transparent); }
.peek-body:focus-visible { outline-offset: -2px; -webkit-mask-image: none; mask-image: none; }
.peek-body.more-above { --above: 28px; }
.peek-body.more-below { --below: 28px; }
.peek-body .sense { font-size: 15px; line-height: 1.55; }
.peek-alternatives { display: flex; flex-wrap: wrap; gap: var(--attach); margin-top: var(--attach); }
.peek-open { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 44px; margin-top: var(--item); border-top: 1px solid var(--line); color: var(--accent-ink); font-size: 13px; font-weight: 500; }
.peek-open svg { width: 15px; height: 15px; transition: transform var(--slow) var(--ease); }
@media (hover: hover) { .peek-open:hover svg { transform: translateX(3px); } }

.toast { position: fixed; z-index: 40; left: 50%; bottom: 24px; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--bg); font-size: 13px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: opacity var(--slow) var(--ease), transform var(--slow) var(--ease); }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

.loading-bar { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; overflow: hidden; pointer-events: none; opacity: 0; transition: opacity var(--slow) var(--ease); }
.loading-bar.active { opacity: 1; }
.loading-bar::before { content: ""; position: absolute; top: 0; bottom: 0; width: 36%; background: linear-gradient(90deg, transparent, var(--accent) 35%, var(--accent) 65%, transparent); transform: translateX(-80%); animation: loading-dash 1.1s cubic-bezier(.4, 0, .6, 1) infinite paused; }
.loading-bar.active::before { animation-play-state: running; }
@keyframes loading-dash { to { transform: translateX(280%); } }
.home .loading-bar { display: none; }
.theme-change, .theme-change *, .theme-change *::before, .theme-change *::after { transition: none !important; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .24s; animation-timing-function: ease; }
@keyframes settle { from { transform: translateY(3px); } }
.entry-enter .entry-header, .entry-enter .tab-content, .content-enter { animation: content-in var(--fast) var(--ease); }
.lookup-popover.content-enter { animation-name: settle; }
@keyframes content-in { from { opacity: .8; } }
.tab-enter { animation: arrive var(--move) var(--ease-move) backwards; }
.result-row.arriving { animation: settle var(--move) var(--ease-move) backwards; }
@keyframes arrive { from { opacity: 0; transform: translateY(4px); } }
.script-swap .entry-word, .script-swap .alternate-word { animation: settle var(--fast) var(--ease); }

@media (min-width: 1600px) {
  .dictionary-layout { grid-template-columns: 380px minmax(0, 1fr); }
  #entry-content { padding-top: calc(var(--section) + var(--row)); }
}

@media (max-width: 900px) {
  .dictionary-layout { grid-template-columns: 280px minmax(0, 1fr); }
  #entry-content { padding: var(--group) 28px calc(2 * var(--group)); }
  .entry-word { font-size: 44px; }
}

.backdrop { display: none; }

@media (max-width: 680px) {
  body { font-size: 15px; }
  .app-header { display: flex; flex-wrap: wrap; gap: 6px; height: auto; padding: 8px 12px 10px; padding-top: max(8px, env(safe-area-inset-top)); }
  .brand .logo { height: 16px; }
  .results-list { padding: var(--attach) 8px; }
  .result-row { padding-inline: 10px; }
  .phrase-note, .segment-label { margin-inline: 10px; }
  .app-header .search-form { order: 3; flex-basis: 100%; }
  .header-tools { margin-left: auto; }
  #query { font-size: 16px; }
  .dictionary-layout { position: relative; display: block; overflow: hidden; }
  .results-pane, .entry-pane { position: absolute; inset: 0; }
  .results-pane { border-right: 0; transition: transform var(--slow) var(--ease), opacity var(--slow) var(--ease); }
  .entry-pane { background: var(--bg); transform: translateX(100%); visibility: hidden; transition: transform var(--slow) var(--ease), visibility 0s linear var(--slow); }
  .detail-open .entry-pane { transform: none; visibility: visible; transition: transform var(--slow) var(--ease), visibility 0s; }
  .detail-open .results-pane { transform: translateX(-24%); opacity: .4; }
  .no-slide .results-pane, .no-slide .entry-pane { transition: none; }
  #entry-content { padding: var(--row) 18px calc(2 * var(--group)); padding-bottom: max(calc(2 * var(--group)), env(safe-area-inset-bottom)); }
  .detail-open .brand { display: none; }
  .detail-open .back-button { display: inline-flex; align-items: center; gap: 2px; min-height: 40px; margin-left: -8px; padding: 0 10px 0 4px; border-radius: 6px; color: var(--muted); font-size: 15px; animation: content-in var(--fast) var(--ease); }
  .back-button svg { width: 18px; height: 18px; }
  @media (hover: hover) { .back-button:hover { background: var(--surface); color: var(--ink); } }
  .entry-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--block) 14px; }
  .entry-word { font-size: 40px; }
  .entry-word.long { font-size: 30px; }
  .entry-word.long + .alternate-word { font-size: 15px; }
  .alternate-word { font-size: 20px; }
  .entry-pinyin { font-size: 17px; }
  .entry-sound { margin-top: 0; }
  .entry-tabs { gap: 20px; }
  .example-chinese { font-size: 17px; }
  .character-row { --stroke-size: 84px; }
  .character-rows.single .character-row { --stroke-size: 116px; }
  .canvas-wrap { width: min(100%, max(140px, calc(100dvh - 380px))); margin-inline: auto; }
  .utility-panel { left: 10px; right: 10px; width: auto; max-height: calc(100dvh - 130px); }
  .settings-panel { padding-inline: 18px; }
  .panel-footer { margin-inline: -18px; padding-inline: 18px; }
  .backdrop { display: block; position: fixed; inset: 0; background: var(--backdrop); --away: none; }
}

body.page { height: auto; min-height: 100dvh; overflow: auto; }
.page-content { max-width: 560px; margin: 0 auto; padding: calc(var(--section) + var(--attach)) 20px calc(2 * var(--section)); }
.page-back { display: inline-flex; align-items: center; gap: 2px; min-height: 40px; margin-left: -8px; padding: 0 10px 0 4px; border-radius: 6px; color: var(--muted); font-size: 15px; transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease); }
.page-back svg { width: 18px; height: 18px; }
@media (hover: hover) { .page-back:hover { background: var(--surface); color: var(--ink); text-decoration: none; } }
.page-content h1 { margin: var(--group) 0; font-size: 24px; font-weight: 600; line-height: 1.3; }
.page-content p { margin: var(--group) 0 0; color: var(--muted); line-height: 1.6; }
.source-list { margin: var(--group) 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.source-list li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0 12px; padding: var(--item) 0; line-height: 1.5; border-bottom: 1px solid var(--line); }
.page-content p a, .page-content li a { color: var(--ink); text-decoration: underline 1px var(--line-strong); text-underline-offset: 3px; transition: text-decoration-color var(--fast) var(--ease); }
@media (hover: hover) { .page-content p a:hover, .page-content li a:hover { text-decoration-color: currentColor; } }
.source-list a { font-weight: 500; }
.source-list small { margin-left: auto; color: var(--faint); font-size: 12px; text-align: right; }
.page-content small a { color: var(--faint); font-weight: 400; }
.notices { margin-top: var(--group); color: var(--muted); font-size: 13px; line-height: 1.5; }
.notices > summary { display: flex; align-items: center; gap: 4px; width: fit-content; cursor: pointer; list-style: none; }
.notices > summary::-webkit-details-marker { display: none; }
.notices ul { gap: var(--item); margin: 0; padding: 0; list-style: none; --lead: var(--item); }
.notices li > a { display: inline-flex; align-items: center; min-height: 44px; }
.page-content .notices a { color: var(--muted); }

body.home { height: auto; min-height: 100dvh; overflow: auto; display: flex; flex-direction: column; }
.dictionary .home-heading, .dictionary .home-examples, .dictionary .home-footer, .dictionary .submit-button { display: none; }
.home .brand, .home .header-tools, .home .dictionary-layout { display: none; }
.home .app-shell { flex: 1; height: auto; }
/* heading is about 180px, so the box sits just above the middle */
.home-content, .home .app-header, .home .panel-layer, .home .home-examples { width: min(620px, calc(100% - 32px)); margin: 0 auto; }
.suggest { display: none; }
.home .suggest:not([hidden]) { display: block; position: relative; isolation: isolate; width: 100%; margin-top: 8px; padding: 6px; background: var(--raised); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.suggest.opening { animation: suggest-open var(--slow) var(--ease); transform-origin: top center; }
.suggest.opening [role="option"] { animation: suggest-row var(--move) var(--ease) backwards; }
.suggest.opening [role="option"]:nth-child(2) { animation-delay: 20ms; }
.suggest.opening [role="option"]:nth-child(3) { animation-delay: 40ms; }
.suggest.opening [role="option"]:nth-child(4) { animation-delay: 60ms; }
.suggest.opening [role="option"]:nth-child(5) { animation-delay: 80ms; }
.suggest.opening [role="option"]:nth-child(6) { animation-delay: 100ms; }
@keyframes suggest-open { from { opacity: 0; transform: translateY(-4px) scale(.99); } }
@keyframes suggest-row { from { opacity: 0; transform: translateY(-3px); } }
.suggest [role="option"] { display: block; width: 100%; text-align: left; border: 0; background-color: transparent; color: inherit; font: inherit; cursor: pointer; border-radius: 10px; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; transition: background-color 120ms linear, color 120ms linear; }
.suggest .result-row { overflow: hidden; }
.suggest .row-head { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.suggest .result-gloss { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest .result-word { font-size: 18px; transition: color 120ms linear; }
.suggest .result-row.active { background-color: var(--accent-soft); }
.suggest .more.active { background-color: var(--accent); color: var(--on-accent); }
.suggest .result-row.active .result-word { color: var(--accent-ink); }
.suggest .more { position: relative; margin-top: 9px; padding: 12px 14px; color: var(--accent-ink); font-size: 15px; font-weight: 500; }
.suggest .more::before { content: ""; position: absolute; left: 8px; right: 8px; top: -5px; border-top: 1px solid var(--line); }
.suggest .more span { display: inline-block; margin-left: 4px; transition: transform var(--fast) var(--ease); }
.suggest .more.active span { transform: translateX(3px); }
.home:has(.suggest:not([hidden])) .home-examples { visibility: hidden; }
.suggest .result-row:not(.active):hover, .suggest .result-row.selected:not(.active) { background-color: transparent; }
.home-content, .home .app-header { display: flex; flex-direction: column; align-items: center; gap: 0; height: auto; padding: max(32px, calc(46dvh - 180px)) 0 0; border: 0; }
.home-content { flex: 1; padding-bottom: 40px; }
.home .panel-layer { display: flex; justify-content: flex-end; }
.home #handwriting-panel { position: static; width: 360px; max-width: 100%; max-height: none; margin-top: 14px; }
.home-heading { max-width: 100%; text-align: center; margin-bottom: 30px; }
.lockup { display: flex; justify-content: center; max-width: 100%; margin: 0; }
.lockup .logo { width: 432px; max-width: 100%; height: auto; }
.home-heading p { margin: 18px 0 0; text-wrap: balance; color: var(--muted); font-size: 17px; animation: settle var(--fast) var(--ease); }
.not-found-mark { display: block; font-size: 48px; line-height: 1.2; color: var(--line-strong); }
.not-found h1 { margin: 12px 0 0; font-size: 24px; font-weight: 600; }
.home-search, .home .app-header .search-form { width: 100%; height: 56px; border-radius: 16px; padding-left: 18px; animation: settle var(--fast) var(--ease); }
.home #query { font-size: 17px; }
.submit-button { display: grid; place-items: center; width: 42px; height: 42px; margin-left: 2px; border-radius: 10px; background: var(--accent); color: var(--on-accent); transition: background-color var(--fast) var(--ease), transform var(--fast) var(--ease); }
@media (hover: hover) { .submit-button:hover { background: var(--accent-hover); } }
.submit-button:active { transform: scale(.96); }
.home-examples { display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-start; gap: 8px; margin-top: 22px; animation: settle var(--fast) var(--ease); }
.home .home-examples { flex: 1; margin-top: 22px; padding-bottom: 40px; }
.home-examples a { padding: 6px 14px; border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 15px; transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease); }
@media (hover: hover) { .home-examples a:hover { background: var(--surface-strong); color: var(--ink); text-decoration: none; } }
.home-footer a { color: var(--muted); }
@media (hover: hover) { .home-footer a:hover { color: var(--ink); text-decoration: none; } }
.home-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 18px; padding: 20px 16px 24px; color: var(--faint); font-size: 12px; line-height: 1.6; text-align: center; }
@media (max-width: 680px) {
  .home-content, .home .app-header { padding-top: max(24px, calc(38dvh - 160px)); }
  .home .app-header .search-form { order: 0; flex-basis: auto; }
  .lockup .logo { width: min(317px, 100%); }
  .home-search, .home .app-header .search-form { padding-left: 14px; }
  .home #query { font-size: 16px; }
  .submit-button { width: 40px; height: 40px; }
}
@media (max-width: 360px) {
  .entry-tabs { gap: 14px; }
}
@media (max-width: 680px), (pointer: coarse) {
  /* Text links borrow tap room without changing layout. */
  :is(button, .brand, .page-back, .home-examples a):not(.word-link, .note-word, .segment-label, .reading-link, .text-link, .alternate-word, .listen-button) { min-height: 44px; }
  .field-button, .icon-button, .submit-button { min-width: 44px; }
  /* Reserve the header's full tap area when controls wrap. */
  .listen-button { width: 44px; height: 44px; }
  .entry-tabs { margin-top: var(--attach); }
  .alternate-word { display: inline-flex; align-items: center; min-width: 44px; min-height: 44px; }
  .alternate-word:focus-visible { outline-offset: -2px; }
  /* Side-by-side measure words need separate real tap boxes. */
  .usage-notes > span:has(.note-links) { display: flex; align-items: baseline; gap: var(--block); max-width: 100%; white-space: nowrap; }
  .note-links { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--block); }
  .usage-notes .word-link { display: inline-block; padding: 11px 14.5px; background-origin: content-box; background-clip: content-box; }
  .usage-notes .word-link:focus-visible { outline-offset: -2px; }
  #query { height: calc(100% + 2px); margin-block: -1px; }
  .field-button { padding: 2px; border-radius: 8px; background-clip: content-box; }
  .brand, .home-examples a { display: inline-flex; align-items: center; }
  /* Sentence links cannot borrow tap height because their lines sit too close. */
  :is(summary, .text-link, .panel-link, .home-footer a, .notices a, .source-list a, .note-word, .segment-label) { position: relative; z-index: 1; }
  :where(summary, .text-link, .panel-link, .home-footer a, .notices a, .source-list a, .note-word, .segment-label)::after { content: ""; position: absolute; inset: min(0px, calc(50% - 22px)) min(-8px, calc(50% - 22px)); }
  /* Side-by-side readings need separate real tap boxes. */
  .other-readings { gap: var(--attach); }
  .reading-link { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; }
  .reading-link:focus-visible { outline-offset: -2px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0s !important; scroll-behavior: auto !important; }
  .loading-bar::before { width: 100%; transform: none; opacity: .25; }
}

.results-list, #entry-content > *, .tab-content { transition: opacity var(--fast) var(--ease); }
.results-list[aria-busy="true"], #entry-content[aria-busy="true"] > *, .lookup-popover[aria-busy="true"], .candidates[aria-busy="true"], .text-link[aria-busy="true"] { opacity: .5; transition-delay: 180ms; }

@media (max-width: 680px) {
  .lookup-popover { inset: auto 0 0; width: auto; max-height: min(440px, 62dvh); padding-top: var(--group); border-radius: 16px 16px 0 0; border-bottom: 0; padding-bottom: max(var(--item), env(safe-area-inset-bottom)); overflow: hidden; touch-action: none; }
  .lookup-popover .peek-body { touch-action: pan-y; }
  .lookup-popover::before { content: ""; position: absolute; top: 8px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--line-strong); }
  .lookup-popover { --away: translateY(100%); }
}
