:root {
  color-scheme: light;
  --ink: #1c3730; --muted: #52665b; --pine: #163e35; --paper: #fbfaf4;
  --cream: #f3f2e8; --line: #c5cbbd; --gold: #f0c977; --focus: #b36a03;
  font-family: "Atkinson Hyperlegible Next", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink); background: var(--cream);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; color: inherit; }
button:disabled { cursor: default; opacity: .58; }
button, textarea, input, select { accent-color: var(--pine); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }
.masthead { background: var(--paper); border-bottom: 1px solid var(--line); }
.masthead-inner, #board, #library, .app-footer { width: min(1392px, calc(100% - clamp(28px, 7vw, 116px))); margin: auto; }
.masthead-inner { display: flex; align-items: stretch; justify-content: space-between; gap: 16px; min-height: 68px; }
.identity, .primary-nav, .board-actions, .board-tools, .mode-row, .related-row, .button-row { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
.identity { gap: 12px; }
.identity h1 { font-size: clamp(19px, 2vw, 25px); font-weight: 750; letter-spacing: .04em; margin: 0; }
.brand-mark { width: 36px; height: 38px; display: grid; place-items: center; border-radius: 8px 2px 8px 2px; background: var(--pine); color: var(--gold); font: 700 24px/1.2 "Songti SC","Noto Serif CJK SC",serif; }
.primary-nav { align-items: stretch; flex-wrap: nowrap; }
.primary-nav button { background: transparent; border: 0; border-bottom: 3px solid transparent; padding: 4px 12px 0; font-size: 14px; font-weight: 620; }
.primary-nav button[aria-current="page"] { border-color: var(--pine); color: var(--pine); }
#board, #library { padding-block: clamp(18px, 3.4vh, 36px) 16px; }
.query-pane { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 18px clamp(16px, 2.3vw, 30px); background: var(--paper); border: 1px solid var(--line); border-radius: 14px; }
.input-top, .board-head, .board-bottom, .dialog-title { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.query-title, .panel-title { margin: 0; font-size: 19px; }
.mode-row { gap: 3px; padding: 3px; border-radius: 8px; background: #eaece3; }
.mode-row button { background: transparent; border: 0; border-radius: 5px; padding: 5px 14px; font-size: 14px; font-weight: 600; }
.mode-row button[aria-pressed="true"] { background: var(--pine); color: #fff; }
.input-line { display: flex; align-items: stretch; gap: 10px; }
#query-input { flex: 1 1 0%; min-width: 0; height: 46px; max-height: 12rem; resize: vertical; border: 1px solid #9ba99c; border-radius: 7px; padding: 9px 12px; background: #fffefa; color: var(--ink); line-height: 1.5; }
#query-input::placeholder { color: #617066; opacity: 1; }
.action-solid, .action-light, .dialog-action { border: 1px solid var(--pine); border-radius: 7px; padding: 8px 16px; font-weight: 650; background: var(--pine); color: white; }
#submit-query { flex: 0 0 auto; white-space: nowrap; }
.action-light { background: var(--paper); color: var(--pine); border-color: var(--line); }
.query-help, .status-line { margin: 0; font-size: 14px; color: var(--muted); }
.status-line:not(:empty) { padding-block: 4px; }
.lecture { --large: clamp(42px, 3.3vw, 54px); --detail: clamp(19px, 1.5vw, 24px); background: var(--pine); border: 1px solid #13362e; color: #fffbed; border-radius: 14px; margin-top: 16px; overflow: hidden; }
.lecture[data-size="1"] { --large: clamp(32px, 2.5vw, 40px); --detail: clamp(16px, 1.25vw, 20px); }
.lecture[data-size="2"] { --large: clamp(38px, 3vw, 47px); --detail: clamp(18px, 1.4vw, 22px); }
.lecture[data-size="4"] { --large: clamp(52px, 4.1vw, 65px); --detail: clamp(22px, 1.72vw, 27px); }
.lecture[data-size="5"] { --large: clamp(64px, 5vw, 80px); --detail: clamp(26px, 2vw, 32px); }
.lecture.contrast { background: #071711; color: #fff; --gold:#ffe68d; }
.board-head, .board-bottom { padding: 12px clamp(16px, 2.5vw, 36px); }
.board-head { border-bottom: 1px solid #ffffff35; }
.board-head h2 { margin: 0; font: 600 19px/1.4 "Songti SC","Noto Serif CJK SC",serif; letter-spacing: .08em; }
.board-head h2::before { content: ""; display: inline-block; width: 7px; height: 7px; margin: 0 10px 3px 0; border-radius: 50%; background: var(--gold); }
.board-tools { gap: 6px; }
.lecture button:not(.glyph), .board-tools select { background: transparent; color: #fffbeb; border: 1px solid #8aa498; padding: 6px 11px; border-radius: 7px; font-size: 14px; }
.lecture button[aria-pressed="true"]:not(.glyph), .lecture .related-chip:hover { color: #183c32; background: #e4e9d7; border-color: #e4e9d7; }
.lecture :focus-visible { outline-color: var(--gold); }
.board-content { padding: clamp(18px, 3vw, 46px) clamp(16px, 3.4vw, 50px); min-height: clamp(220px, 32vh, 420px); display: flex; flex-direction: column; justify-content: center; overflow-wrap: anywhere; }
.empty-title { font-size: clamp(28px, 3.2vw, 45px); font-family: "Songti SC","Noto Serif CJK SC",serif; margin: 0 0 10px; font-weight: 600; letter-spacing: .04em; }
.empty-caption { margin: 0 0 22px; color: #d4e0d1; font-size: 16px; }
.board-bottom { border-top: 1px solid #ffffff35; }
.board-bottom label { display: flex; align-items: center; gap: 7px; font-size: 14px; }
.board-bottom input { width: 82px; accent-color: var(--gold); }
.word-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 16px; }
.ruby-line { color: inherit; white-space: pre-wrap; overflow-wrap: anywhere; font-family: "Songti SC","Noto Serif CJK SC",serif; font-size: var(--large); font-weight: 600; line-height: 1.95; }
.glyph { display: inline; vertical-align: baseline; padding: 0 .035em; margin: 0; border: 0; background: transparent; color: inherit; line-height: inherit; font: inherit; }
.glyph:hover { border-radius: 5px; background: #ffffff1b; }
.glyph rt { color: var(--gold); font-family: "Atkinson Hyperlegible Next",Arial,sans-serif; font-size: .36em; font-weight: 500; line-height: 1.15; }
.hide-pinyin rt { visibility: hidden; }
.related-row { margin-top: 14px; gap: 8px; color: #e0e6d7; font-size: 14px; }
.result-note { color: #d8e4d5; margin: 12px 0; }
.lesson-detail { font-size: var(--detail); line-height: 1.55; }
.lesson-detail h3 { font-size: 1.02em; margin: 1em 0 .45em; color: var(--gold); }
.lesson-detail h4 { margin: 0 0 6px; font-size: 1.2em; }
.lesson-detail p,.lesson-detail ul,.lesson-detail ol { margin: .4em 0; }
.lesson-detail ul, .lesson-detail ol { padding-inline-start: 1.35em; }
.card-translation { font-size: 1.22em; }
.entry-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%, 330px),1fr)); gap: 12px; margin-top: 15px; }
.entry-detail, .deep-detail { border-top: 1px solid #ffffff45; padding-top: 10px; }
.entry-detail .type, .example-en { color: #dae4d7; }
.lecture.contrast .example-en, .lecture.contrast .type, .lecture.contrast .result-note { color: #fff; }
.app-footer { border-top: 1px solid var(--line); padding: 10px 0 18px; font-size: 12px; color: var(--muted); line-height: 1.65; }
.footer-row { display: flex; align-items: baseline; gap: 8px 20px; flex-wrap: wrap; }
#backup-status button { padding: 1px 0; border: 0; background: transparent; color: var(--pine); text-decoration: underline; text-underline-offset: .2em; }
#app-version { margin-left: auto; font-variant-numeric: tabular-nums; }
.board-dialog { max-width: min(430px, 94vw); width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 22px; background: var(--paper); color: var(--ink); }
.board-dialog::backdrop { background: #07171185; }
.board-dialog h2 { font-size: 20px; margin: 0; }
.board-dialog p { margin: 10px 0; }
.board-dialog label { display: grid; gap: 6px; margin: 14px 0; }
.board-dialog input, .board-dialog textarea { color: var(--ink); padding: 8px 10px; border-radius: 6px; border: 1px solid #9ba99c; width: 100%; background: #fff; }
.board-dialog .button-row { margin-top: 12px; }
.dialog-message { color: #923d17; font-size: 14px; }
@media (max-width: 650px) {
  .masthead-inner { min-height: 56px; gap: 4px; }
  .identity { gap: 6px; } .primary-nav { gap: 0; } .primary-nav button { padding-inline: 6px; font-size: 13px; }
  .brand-mark { width: 29px; height: 30px; font-size: 21px; }
  .query-pane { padding: 12px; } .mode-row button { padding: 4px 8px; }
  .board-head, .board-bottom { align-items: flex-start; } .board-content { min-height: 225px; }
}
@media (min-width: 900px) and (max-height: 780px) { .board-content { padding-block: 23px; } }
@media print { .masthead, .query-pane, .board-tools, .board-bottom, .app-footer { display: none; } }
.lecture { --phonetic:24px; }
.lecture[data-pinyin="1"] { --phonetic:14px; }
.lecture[data-pinyin="2"] { --phonetic:19px; }
.lecture[data-pinyin="4"] { --phonetic:30px; }
.lecture[data-pinyin="5"] { --phonetic:38px; }
.glyph rt {font-size:var(--phonetic);ruby-align:center;}
.lecture .glyph { display:inline-grid; vertical-align:baseline; }
.lecture ruby {ruby-overhang:none;}
.student {background:var(--pine);color:#fffbed;}
.student main {max-width:100%;margin:0;}
.student .lecture {padding:3vw;margin:0;border:0;border-radius:0;}
.student article,.board-entry {padding:1rem 0;border-bottom:1px solid #ffffff42;}
.student article p {font-size:var(--detail);}
.board-entry .board-actions,.board-entry .related-row {display:flex;flex-wrap:wrap;gap:.4rem;margin-top:.5rem;}
#entries {justify-content:flex-start;}
#ask-dialog {max-width:min(680px,95vw);max-height:90vh;overflow:auto;}
#ask-review {max-height:30vh;overflow:auto;}
.student:has(#screen:empty) { min-height:100vh; }

/* Comparison headwords share a line when there is room; normal sentences keep their block layout. */
.student article:has(> .ruby-line + .ruby-line) > .ruby-line {
  display: inline-block;
  max-width: 100%;
  margin-inline-end: 16px;
  vertical-align: baseline;
}
