/* Layout: one 46rem working column under a sticky tab strip; every tool repeats the same dictionary row (Han headword left, English gloss right). */
:root {
  --paper: #F2F5F1;
  --card: #FFFFFF;
  --soft: #E7EDE8;
  --ink: #17212A;
  --muted: #55616B;
  --line: #D6DDD7;
  --jade: #0B6A59;
  --on-jade: #FFFFFF;
  --jade-soft: #DCEEE7;
  --price: #CF2F1C;
  --warn-bg: #FFF2D6;
  --warn-ink: #6E4407;
  --err: #B0261C;
  --display: "Bricolage Grotesque", "Hanken Grotesk", -apple-system, "Segoe UI", Roboto, Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  --body: "Hanken Grotesk", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --han: "Noto Serif SC", Georgia, "Times New Roman", "Songti SC", "STSong", "SimSun", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 14px;
  color-scheme: light;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0E1417; --card: #162027; --soft: #1D2930; --ink: #E4EBE6; --muted: #98A5AC; --line: #29363D;
    --jade: #52C4A6; --on-jade: #05211A; --jade-soft: #12362F; --price: #FF6B57;
    --warn-bg: #36290F; --warn-ink: #F0C46C; --err: #FF8A7F;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--body); font-size: 16px; line-height: 1.5; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--paper); }
h1, h2, h3, p, ul, ol, figure { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }
a { color: var(--jade); font-weight: 600; }
code { font-family: var(--mono); font-size: .9em; background: var(--soft); padding: 1px 6px; border-radius: 5px; }
[lang="zh-CN"] { font-family: var(--han); }
:focus-visible { outline: 2px solid var(--jade); outline-offset: 2px; border-radius: 4px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap {
  max-width: 46rem; margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* Header */
.top .wrap { padding-block: 28px 18px; display: grid; gap: 12px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
h1 {
  font-family: var(--display); font-weight: 800; font-size: clamp(2.1rem, 7vw, 3.1rem);
  line-height: 1; letter-spacing: -0.025em; display: flex; align-items: center; gap: .3em; flex-wrap: wrap;
}
.seal {
  display: inline-grid; place-items: center; width: 1.1em; height: 1.1em; flex: none;
  border: 3px solid var(--jade); border-radius: .18em; color: var(--jade);
  font-family: var(--han); font-weight: 700; font-size: .78em; line-height: 1; transform: rotate(-5deg);
}
.lede { color: var(--muted); max-width: 36rem; font-size: 1.04rem; text-wrap: pretty; }

/* API key */
.keybar { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.keystate { font-size: 14px; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; min-width: 0; overflow-wrap: anywhere; }
.keystate::before { content: ""; flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.keystate[data-on="true"] { color: var(--ink); }
.keystate[data-on="true"]::before { background: var(--jade); }
.key-panel { max-width: 40rem; }
.key-panel h2 { font-family: var(--display); font-weight: 800; font-size: 1.3rem; line-height: 1.2; }
.steps { padding-left: 20px; display: grid; gap: 6px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; font-weight: 600; }
.check input { width: 18px; height: 18px; accent-color: var(--jade); }
.key-input { font-family: var(--mono); }

/* Tabs */
.tabs { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--paper); border-bottom: 1px solid var(--line); }
.tabrow { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabrow::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; appearance: none; background: none; border: 0; border-bottom: 3px solid transparent;
  padding: 10px 10px 7px; color: var(--muted); font: 600 14px/1.2 var(--body); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; white-space: nowrap;
}
.tab .tzh { font-size: 12px; font-weight: 500; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--jade); }

/* Panels */
main .wrap { padding-block: 22px 36px; }
.panel { display: grid; gap: 18px; min-width: 0; }
.intro { display: grid; gap: 6px; }
.intro h2 { font-family: var(--display); font-weight: 800; font-size: 1.6rem; line-height: 1.15; letter-spacing: -0.01em; text-wrap: balance; }
.intro p { color: var(--muted); max-width: 40rem; text-wrap: pretty; }
.stack { display: grid; gap: 18px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr)); gap: 18px; }
.slot:empty { display: none; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; min-width: 0; align-content: start; }
.card h3 { font-family: var(--display); font-weight: 800; font-size: 1.15rem; line-height: 1.2; }
.gzh { font-family: var(--han); font-weight: 500; font-size: .85em; color: var(--muted); margin-left: .25em; }
.hint { color: var(--muted); font-size: 14px; }
.sub { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

/* Controls */
.field { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.opt { font-weight: 500; color: var(--muted); }
textarea, input[type="text"], input[type="password"], input[type="number"], input[type="search"], select {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--paper);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 3.2em; line-height: 1.45; }
textarea:focus, input:focus, select:focus { border-color: var(--jade); outline: none; box-shadow: 0 0 0 3px var(--jade-soft); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn {
  appearance: none; border: 1px solid var(--jade); background: var(--jade); color: var(--on-jade);
  font: 700 15px/1 var(--body); padding: 12px 18px; border-radius: 10px; cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--jade); }
.btn.small { padding: 9px 14px; font-size: 14px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.linkish { appearance: none; background: none; border: 0; padding: 0; color: var(--jade); font: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.copy {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: 600 13px/1 var(--body); padding: 8px 13px; border-radius: 999px; cursor: pointer; white-space: nowrap; justify-self: start;
}
.copy:hover { border-color: var(--jade); }
.copy.done { background: var(--jade); border-color: var(--jade); color: var(--on-jade); }

.status { font-size: 14px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.status[data-kind="busy"]::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--jade); animation: pulse 1.1s ease-in-out infinite; }
.status[data-kind="err"] { color: var(--err); font-weight: 600; }
@keyframes pulse { 50% { opacity: .2; transform: scale(.7); } }

.notice { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 12px 14px; font-size: 14px; }
.notice .linkish { color: inherit; }

/* Screenshot drop zone */
.drop { background: var(--card); border: 2px dashed var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; }
.drop.over { border-color: var(--jade); background: var(--jade-soft); }
.drop strong { font-family: var(--display); font-size: 1.1rem; display: block; }
.drop span { color: var(--muted); font-size: 14px; }
.thumbs { display: flex; gap: 10px; flex-wrap: wrap; }
.thumbs:empty { display: none; }
.thumb { position: relative; width: 72px; height: 128px; border-radius: 9px; overflow: hidden; border: 1px solid var(--line); background: var(--soft); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0;
  background: var(--ink); color: var(--card); cursor: pointer; font: 700 15px/1 var(--body);
}

/* Results */
.result { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 16px; min-width: 0; }
.result.example { border-style: dashed; border-width: 2px; }
.result-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.result-head h3 { font-family: var(--display); font-weight: 800; font-size: 1.3rem; line-height: 1.2; }
.pill { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 4px 9px; border-radius: 999px; background: var(--soft); color: var(--muted); }
.summary { font-size: 1.04rem; max-width: 40rem; }
.prices { display: flex; flex-wrap: wrap; gap: 12px 28px; }
.price { display: grid; gap: 1px; min-width: 0; }
.price .cny { font-family: var(--display); font-weight: 800; font-size: 1.75rem; line-height: 1.1; color: var(--price); font-variant-numeric: tabular-nums; }
.price .conv { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.price .plabel { font-size: 14px; max-width: 16rem; }
.rate-line { font-size: 13px; color: var(--muted); }
.box { border-radius: 10px; padding: 12px 14px; display: grid; gap: 4px; }
.box .sub { color: inherit; opacity: .8; }
.box ul { padding-left: 18px; display: grid; gap: 4px; }
.warn { background: var(--warn-bg); color: var(--warn-ink); }
.next { background: var(--jade-soft); }
.answer { background: var(--soft); }

/* Dictionary rows */
.terms { list-style: none; padding: 0; display: grid; }
.term { display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr); gap: 4px 18px; padding: 11px 0; border-top: 1px solid var(--line); }
.term .head, .term .gloss { display: grid; gap: 1px; align-content: start; min-width: 0; }
.zh { font-family: var(--han); font-weight: 500; font-size: 1.2rem; line-height: 1.35; overflow-wrap: anywhere; }
.py { font-style: italic; color: var(--muted); font-size: 13px; }
.en { font-weight: 600; }
.note { color: var(--muted); font-size: 14px; }
@media (max-width: 480px) { .term { grid-template-columns: minmax(0, 8.5rem) minmax(0, 1fr); gap: 4px 12px; } }

.queries { list-style: none; padding: 0; display: grid; }
.query { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 14px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.query .q-main { display: grid; gap: 2px; min-width: 0; }
.query .zh { font-size: 1.3rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: grid; border: 1px solid var(--line); border-radius: 10px; padding: 6px 11px; background: var(--paper); min-width: 0; }
.chip .zh { font-size: 1.05rem; }
.chip small { color: var(--muted); font-size: 12.5px; }

.say { background: var(--soft); border-radius: 10px; padding: 12px 14px; display: grid; gap: 6px; min-width: 0; }
.big-zh { font-size: 1.35rem; user-select: all; }
.en-plain { font-size: 1.02rem; }

.phrase-list { list-style: none; padding: 0; display: grid; }
.phrase { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 14px; align-items: center; padding: 11px 0; border-top: 1px solid var(--line); }
.phrase .ptext { display: grid; gap: 1px; min-width: 0; }
.phrase .zh { font-size: 1.12rem; }
.phrase .en { font-weight: 500; color: var(--muted); font-size: 14px; }
.pgroup { display: grid; gap: 4px; }
.pgroup + .pgroup { margin-top: 10px; }

/* Words tab */
.facts { padding-left: 18px; display: grid; gap: 8px; max-width: 42rem; }
.facts strong { font-weight: 700; }
.searchbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.count { color: var(--muted); font-size: 14px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Convert tab */
.trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.duo { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mini { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); min-width: 0; }
.mini input, .mini select { font-variant-numeric: tabular-nums; }
.out { display: grid; gap: 4px; }
.big { font-family: var(--display); font-weight: 800; font-size: 2.1rem; line-height: 1.05; font-variant-numeric: tabular-nums; }
.wide { grid-column: 1 / -1; }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td .zh { font-size: 1.05rem; white-space: nowrap; }
details summary { cursor: pointer; color: var(--jade); font-weight: 700; font-size: 14px; }
details[open] summary { margin-bottom: 8px; }

.foot .wrap { padding-block: 8px 40px; display: grid; gap: 6px; color: var(--muted); font-size: 13px; }

@media (prefers-reduced-motion: reduce) {
  .status[data-kind="busy"]::before { animation: none; }
}
