:root {
  color-scheme: light;
  --paper: #f8f5ed;
  --rule: #e9e1d1;
  --cover-rule: #d9cbb1;
  --rail: #f7f2e7;
  --display: "Songti SC", "Noto Serif CJK SC", STSong, "SimSun", serif;
  --surface: #fffefa;
  --ink: #293c2e;
  --muted: #606c5f;
  --green: #526b50;
  --green-hover: #40573f;
  --sage: #e9ecdf;
  --border: #e0d8c9;
  --danger: #a44738;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(ellipse 90% 36rem at 50% 0, #f1e8d9 0, transparent 75%), var(--paper);
}
button, input, textarea, select { font: inherit; }
button, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 44px; padding: 11px 19px; border: 1px solid transparent; border-radius: 11px; color: var(--ink); background: #eeeee5; font-size: 15px; font-weight: 550; line-height: 1.4; cursor: pointer; transition: background .18s, border-color .18s, transform .18s, box-shadow .18s; }
button:hover { background: #e3e6d9; }
button:active { transform: translateY(1px); }
button.primary { background: var(--green); color: #fffefa; }
button.primary:hover { background: var(--green-hover); box-shadow: 0 4px 12px #37493d14; }
button.secondary { background: #dce3d2; color: #374c35; }
button.secondary:hover { background: #ced9c3; }
button.quiet { background: transparent; border-color: var(--border); }
button.quiet:hover { background: var(--sage); }
button:disabled { opacity: .55; cursor: wait; transform: none; }
:focus-visible { outline: 3px solid #8caa79; outline-offset: 4px; }
input, textarea, select { border: 1px solid #d8d9ca; border-radius: 10px; background: var(--surface); color: var(--ink); padding: 12px 14px; font-size: 16px; min-height: 46px; transition: border-color .18s, box-shadow .18s; }
input:hover, textarea:hover, select:hover { border-color: #a8b29b; }
input:focus, textarea:focus, select:focus { border-color: var(--green); }
input::placeholder, textarea::placeholder { color: #687061; opacity: 1; }
textarea { width: 100%; min-height: 108px; resize: vertical; line-height: 1.8; }
select { cursor: pointer; }
label { display: block; margin: 0 0 10px; font-size: 14px; font-weight: 600; line-height: 1.6; }
p { line-height: 1.8; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-weight: 650; }
h1 { font-size: clamp(27px, 2.8vw, 38px); line-height: 1.5; letter-spacing: -.035em; margin-bottom: 12px; }
h2 { font-size: 25px; line-height: 1.5; letter-spacing: -.025em; margin-bottom: 10px; }
h3 { font-size: 19px; line-height: 1.6; margin-bottom: 12px; }
.icon { display: inline-block; width: 21px; height: 21px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.svg-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.app-shell { width: min(1184px, 100%); min-height: 100svh; margin: auto; padding: 0 32px; display: flex; flex-direction: column; }
.site-header { min-height: 106px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 14px; font-size: 25px; font-weight: 650; letter-spacing: .015em; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 45px; height: 45px; border-radius: 13px; background: var(--green); color: #f8f6f0; }
.brand-mark .icon { width: 28px; height: 28px; stroke-width: 1.6; }
nav { display: flex; gap: 8px; }
nav button { background: transparent; padding: 12px 22px; font-size: 16px; min-height: 46px; }
main { flex: 1; }
.page-intro { padding: 46px 0 33px; }
.panel {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 18px;
  padding: 32px;
  box-shadow: 0 4px 0 -2px #f2ebde, 0 6px 0 -3px #e4d9c5, 0 16px 38px -27px #6153385c;
}
.section-description { color: #6b7466; font-size: 15px; margin-bottom: 27px; }
.notebook-input {
  --notebook-gutter: 31px;
  display: block;
  min-height: 144px;
  height: 180px;
  padding: 8px 16px 8px calc(var(--notebook-gutter) + 15px);
  border-color: #d8cdb9;
  background-color: #fcf8ee;
  background-image:
    linear-gradient(to right, transparent var(--notebook-gutter), #e0c7a5 var(--notebook-gutter), #e0c7a5 calc(var(--notebook-gutter) + 1px), transparent calc(var(--notebook-gutter) + 1px)),
    repeating-linear-gradient(to bottom, transparent 0 35px, #e8e0d0 35px 36px);
  background-attachment: local;
  line-height: 36px;
  font-size: 17px;
}
.field-hint { margin: 10px 0 23px; color: var(--muted); font-size: 13px; }
#prepareToday, #startLesson { min-height: 49px; padding-inline: 22px; }
#prepareToday .icon { width: 19px; }
.notice { font-size: 14px; line-height: 1.7; color: #5e7355; margin: 15px 0 0; overflow-wrap: anywhere; }
.notice:empty { display: none; }
.site-footer { display: flex; justify-content: space-between; align-items: center; gap: 20px; border-top: 1px solid var(--border); min-height: 75px; margin-top: 15px; color: #7c8374; font-size: 12px; }
.site-footer p { margin: 0; max-width: 75%; font-size: 12px; }
#connection { display: flex; align-items: baseline; gap: 9px; }
#connection::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.status-ok { color: #627957; }
.status-error { color: var(--danger); }
.muted { color: var(--muted); font-size: 14px; }
.bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 120px; }
#progress { margin-bottom: 0; font-variant-numeric: tabular-nums; }
progress { display: block; appearance: none; width: 100%; height: 6px; border: 0; border-radius: 8px; overflow: hidden; background: #eaece3; color: #8ba279; margin: 23px 0; }
progress::-webkit-progress-bar { background: #eaece3; border-radius: 8px; }
progress::-webkit-progress-value { background: #8ba279; border-radius: 8px; transition: width .25s ease; }
progress::-moz-progress-bar { background: #8ba279; border-radius: 8px; }
.practice-hint { color: var(--muted); font-size: 14px; margin-bottom: 22px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 16px; }
.word { position: relative; display: flex; flex-direction: column; gap: 18px; min-height: 150px; background: #f8f4e9; border: 1px solid #e8e2d2; border-radius: 15px; font-size: 25px; font-weight: 550; padding: 20px; overflow-wrap: anywhere; }
.word:hover { transform: translateY(-3px); box-shadow: 0 7px 16px #525b4410; border-color: #aab799; }
.word small { align-self: flex-start; color: #828875; font-size: 12px; font-weight: 400; letter-spacing: .05em; }
.word.seen { background: #e9efdf; border-color: #cddbbf; }
.word.seen small { color: #5c7650; }
#quizNote { text-align: center; margin: 24px 0 0; }
.fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 14px; }
.fields input, .fields select { width: 100%; min-width: 0; }
.library-panel, .history-panel { margin-bottom: 34px; }
.bulk-section textarea { display: block; margin-bottom: 14px; }
.bulk-section label { color: var(--muted); font-weight: 400; }
#search { width: 100%; background: #faf9f4; margin-bottom: 10px; }
.entry { display: grid; grid-template-columns: 1fr 1fr 1.2fr auto; gap: 16px; align-items: center; padding: 19px 3px; border-bottom: 1px solid #eeede5; overflow-wrap: anywhere; }
.entry strong { font-weight: 550; }
.entry .actions { display: flex; gap: 7px; }
.entry button { min-height: 36px; padding: 7px 12px; font-size: 13px; }
.danger { color: var(--danger); background: #f7eee8; }
#entries > p, #historyList > p { padding: 45px 16px; margin: 8px 0 0; text-align: center; color: var(--muted); font-size: 15px; background: #f9f8f2; border-radius: 12px; line-height: 1.9; }
.history-row { position: relative; padding: 25px 0 25px 24px; border-bottom: 1px solid #e9e8df; }
.history-row::before { content: ''; position: absolute; left: 0; top: 34px; width: 8px; height: 8px; background: #a8b895; border-radius: 50%; }
.history-row:last-child { border: 0; }
.history-row strong { font-size: 16px; font-weight: 550; }
.history-row p { margin: 7px 0; }
.history-row > span { display: block; margin-top: 8px; line-height: 1.9; }
.resolve-form { border-top: 1px solid var(--border); margin-top: 25px; padding-top: 24px; }
.resolve { padding: 16px 0; border-bottom: 1px solid #eae9df; }
.resolve:last-child { border: 0; }
.resolve strong { display: block; font-size: 16px; margin-bottom: 12px; }
.resolve .fields { grid-template-columns: 1fr 1fr; gap: 12px; }
.resolve .fields select { grid-column: 1 / -1; }
.resolve .fields button { justify-self: start; }
dialog { border: 1px solid var(--border); border-radius: 25px; padding: 42px 35px 27px; width: min(440px, calc(100vw - 32px)); max-height: calc(100svh - 32px); background: var(--surface); color: var(--ink); text-align: center; box-shadow: 0 24px 90px #26332230; }
dialog[open] { animation: arrive .22s ease-out; }
dialog::backdrop { background: #28302559; backdrop-filter: blur(5px); }
.close { position: absolute; top: 12px; right: 12px; width: 36px; min-height: 36px; padding: 7px; border-radius: 50%; background: transparent; color: #7b8372; }
.english { font-family: Georgia, "Times New Roman", serif; font-size: clamp(36px, 8vw, 56px); line-height: 1.2; font-weight: 500; color: #425c40; overflow-wrap: anywhere; margin: 8px 0 15px; }
.ipa { font-size: 21px; color: #7b826e; overflow-wrap: anywhere; }
#audioNote { margin: 15px 0 0; font-size: 12px; }
#audioNote:empty { display: none; }
#audioNote.status-error, #quizNote.status-error { color: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
[hidden], .hidden { display: none !important; }
@keyframes arrive { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
@media (min-width: 1500px) { .app-shell { max-width: 1280px; } }
@media (max-width: 900px) {
  .app-shell { padding-inline: 24px; }
  .site-header { min-height: 92px; }
  .brand { font-size: 22px; }
  nav button { padding-inline: 14px; font-size: 15px; }
  .panel { padding: 24px; }
}
@media (max-width: 650px) {
  .app-shell { padding: 0 20px; }
  .site-header { flex-direction: column; align-items: flex-start; gap: 22px; padding: 24px 0 18px; }
  .brand { font-size: 23px; gap: 12px; }
  .brand-mark { width: 40px; height: 40px; border-radius: 12px; }
  .brand-mark .icon { width: 25px; height: 25px; }
  nav { width: 100%; gap: 4px; }
  nav button { flex: 1; padding: 11px 7px; font-size: 14px; }
  .page-intro { padding: 29px 2px 25px; }
  h1 { font-size: 27px; line-height: 1.55; letter-spacing: -.04em; max-width: 340px; }
  h2 { font-size: 23px; }
  .panel { padding: 23px 20px; border-radius: 16px; }
  .section-description { font-size: 14px; margin-bottom: 22px; }
  .notebook-input { --notebook-gutter: 21px; height: 164px; font-size: 16px; }
  .field-hint { font-size: 12px; }
  #prepareToday { width: 100%; }
  .site-footer { align-items: flex-start; flex-direction: column; gap: 7px; padding: 19px 2px 23px; }
  .site-footer p { max-width: 100%; font-size: 11px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .word { min-height: 136px; font-size: 23px; padding: 15px; gap: 16px; }
  .word small { font-size: 10px; }
  .practice-hint { font-size: 12px; }
  .fields { grid-template-columns: 1fr; gap: 16px; }
  .entry { grid-template-columns: 1fr 1fr; gap: 12px; font-size: 15px; }
  .entry .actions { justify-content: flex-end; }
  .entry .muted { font-size: 13px; }
  .history-row { padding-left: 18px; }
  .history-row .grow { flex-basis: 100%; }
  .history-row strong { font-size: 14px; }
  .history-row button { font-size: 13px; min-height: 38px; }
  .resolve .fields { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

.app-shell {
  width: min(960px, 100%);
  padding-bottom: 48px;
}
.site-header {
  position: sticky;
  top: 0;
  z-index: 3;
  min-height: 82px;
  border-color: var(--cover-rule);
  background: rgb(248 245 237 / 94%);
  backdrop-filter: blur(12px);
}
.brand { padding: 0; background: transparent; font-family: var(--display); font-size: 24px; font-weight: 750; letter-spacing: .025em; }
.brand:hover { background: transparent; color: var(--green-hover); }
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(145deg, #526b50, #3b543e);
  box-shadow: inset 0 0 0 1px #ffffff26, 0 3px 8px #32442b26;
}
.brand-mark .icon { width: 24px; height: 24px; }
.site-header nav button { padding-inline: 22px; }
nav button[aria-current] { background: #e1e7d5; color: #354a33; }
.page-intro { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 42px 0 23px; }
.page-intro h1 {
  margin: 0;
  font: 800 clamp(32px, 3.5vw, 46px)/1.25 var(--display);
  letter-spacing: -.025em;
}
[tabindex="-1"]:focus { outline: none; }
.manual-setup > label, #lessonSetup > label { font-size: 16px; font-weight: 650; margin-bottom: 14px; }
.home-start {
  padding-block: clamp(34px, 6vw, 60px);
  text-align: center;
  background: radial-gradient(ellipse at 50% 0%, #f8f0e1, transparent 75%), var(--surface);
}
.home-study {
  width: min(100%, 288px);
  min-height: 60px;
  gap: 14px;
  font-size: 19px;
  font-weight: 650;
  box-shadow: 0 7px 16px -9px #354a33;
}
.home-study .icon { width: 20px; height: 20px; }
.home-hint { margin: 12px 0 0; font-size: 14px; font-variant-numeric: tabular-nums; }
.home-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  width: min(100%, 288px);
  margin: 23px auto 0;
  padding-top: 18px;
  border-top: 1px solid var(--rule);
}
.home-options button { flex: 1 0 auto; }
.home-options button[aria-expanded="true"] { background: var(--sage); }
#manualSetup { margin-top: 16px; }
.lesson-actions { display: flex; align-items: stretch; gap: 12px; max-width: 580px; }
.lesson-actions select { flex: 1; min-width: 0; }
#startLesson { flex: none; }
.setup-actions { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 16px; }
.setup-actions .field-hint { margin: 0; }
.setup-actions button { flex: none; }
.quick-review {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 25px;
  padding: 12px 15px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--rail);
}
.quick-review h2 { margin: 0; font: 700 17px/1.5 var(--display); }
.quick-review select { background-color: #fffcf5; }
.quick-review .notice { flex-basis: 100%; margin: 0; }
.review-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.review-controls :is(button, select) { min-height: 44px; font-size: 14px; }
.review-controls select { padding: 8px 10px; }
progress { margin: 10px 0 17px; }
.practice-options { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 15px; }
.practice-choice { display: flex; gap: 3px; padding: 3px; border: 1px solid var(--rule); border-radius: 13px; background: var(--rail); }
.practice-choice button { padding: 8px 16px; border-radius: 9px; background: transparent; white-space: nowrap; }
.practice-choice button:hover { background: #eeeadd; }
.practice-choice button[aria-pressed="true"] { background: var(--sage); color: #354a33; border-color: #d7dfca; }
.practice-hint { margin-bottom: 16px; }
.grid { grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); }
.word {
  background: linear-gradient(#fefcf7, #f7f1e5);
  border-color: #e5dbca;
  box-shadow: 0 2px 0 #e9e0d35e;
  font-family: var(--display);
  font-weight: 700;
  gap: 8px;
  min-width: 0;
  min-height: 120px;
}
.word:hover { border-color: #aab799; }
.word.seen { background: #e9efdf; border-color: #cddbbf; }
.word:active { transform: translateY(1px); }
.word small { align-self: auto; color: #5f6a53; font-family: system-ui, sans-serif; letter-spacing: 0; }
.card-prompt { max-width: 100%; overflow-wrap: anywhere; }
.card-prompt[lang="en"] { font-family: Georgia, "Times New Roman", serif; font-weight: 500; }
.english-prompts .word { font-size: 22px; padding-inline: 12px; }
.draw { width: min(100%, 480px); margin-inline: auto; }
.draw .draw-card, .draw-answer, .draw-complete { min-height: 290px; border-radius: 20px; }
.draw .draw-card {
  display: grid;
  grid-template: auto 1fr auto / minmax(0, 1fr);
  width: 100%;
  justify-items: center;
  align-items: center;
  padding: 22px 25px;
  box-shadow: 0 4px 0 -2px #e9dfca, 0 18px 35px -26px #61533870;
}
.draw-card .card-prompt { font-size: clamp(30px, 6vw, 50px); line-height: 1.35; }
.draw-position, .draw-cue { color: var(--muted); font: 500 14px/1.5 system-ui, sans-serif; }
.draw-position { font-variant-numeric: tabular-nums; }
.draw-cue { display: flex; align-items: center; gap: 7px; color: #425c40; }
.draw-cue .icon { width: 17px; height: 17px; }
.draw-answer, .draw-complete {
  border: 1px solid #e4d8c0;
  background: linear-gradient(#fcf8ef, var(--surface) 45%);
  text-align: center;
  box-shadow: inset 0 2px 0 #ebdfc7, 0 12px 26px -21px #61533868;
  padding: 16px 25px 24px;
}
.draw-complete { display: grid; align-content: center; justify-items: center; gap: 10px; }
.draw-complete h2 { font-family: var(--display); }
#quizNote { margin: 18px 0 0; }
#quizNote:empty { display: none; }
.text-action { background: transparent; color: #425c40; }
.text-action:hover { background: var(--sage); }
.text-action.danger { color: var(--danger); }
.site-footer { display: block; padding: 14px 0 0; min-height: 0; }
.site-footer p { max-width: none; color: var(--danger); }
.resolve-form h2 { font-size: 19px; }

.library-panel, .collection-panel { margin-bottom: 0; }
.library-tools, .collection-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.collection-search { flex: 1; min-width: 160px; }
#search, #collectionSearch { width: 100%; margin: 0; background: #fcfbf7; }
.library-utilities { margin: 10px 0 6px; }
summary { cursor: pointer; }
.library-utilities > summary, .word-tools > summary { color: #425c40; font-size: 14px; padding: 12px 8px; }
.library-utilities[open], #entryForm { padding: 16px; margin: 16px 0; border: 1px solid var(--border); border-radius: 12px; background: #faf9f4; }
.library-utilities[open] > summary { padding: 0 0 14px; }
.utility-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
#entryChoices:not(:empty) { margin-bottom: 12px; }
#ipaLookup .secondary { background: transparent; }
.list-count { margin: 17px 0 1px; font-size: 13px; font-variant-numeric: tabular-nums; }
.list-count:empty { display: none; }
.entry { grid-template-columns: minmax(0, .95fr) minmax(0, 1.2fr) minmax(0, 1fr) auto; padding: 9px 0; gap: 8px 16px; min-height: 60px; border-color: #efe9dc; }
.entry-english { font-family: Georgia, "Times New Roman", serif; font-size: 1.12em; line-height: 1.35; }
.entry:last-child { border-bottom: 0; }
.entry-marks { grid-column: 1 / 4; grid-row: 2; font-size: 12px; padding-bottom: 3px; }
.word-tools { position: relative; }
.word-tools .actions { position: absolute; right: 0; top: 100%; z-index: 2; flex-direction: column; gap: 2px; min-width: 116px; border: 1px solid var(--border); border-radius: 12px; padding: 6px; background: var(--surface); box-shadow: 0 8px 24px #37493d20; }
.word-tools .actions button { justify-content: flex-start; white-space: nowrap; }
.review-tabs { border-bottom: 1px solid var(--rule); padding-bottom: 14px; margin-bottom: 20px; gap: 5px; }
.review-tabs button { flex: 0 1 auto; font-size: 14px; padding-inline: 15px; }
.empty-state { text-align: center; padding: 36px 14px; margin: 0; border-radius: 12px; color: var(--muted); font-size: 15px; }
.history-row { padding: 14px 0 14px 18px; }
.history-row::before { top: 22px; width: 6px; height: 6px; background: #9e8a62; }

dialog {
  padding: 16px 26px 25px;
  border-color: #e4d8c0;
  background: linear-gradient(#fcf8ef, var(--surface) 32%);
  box-shadow: inset 0 2px 0 #ebdfc7, 0 24px 90px #26332230;
}
.answer-top { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: center; min-height: 44px; margin-bottom: 19px; padding-bottom: 5px; border-bottom: 1px solid var(--rule); }
.answer-top .close { position: static; justify-self: end; width: 44px; min-height: 44px; }
.favorite-button { justify-self: start; gap: 6px; min-height: 44px; padding: 6px 8px; font-size: 13px; white-space: nowrap; }
.favorite-button[aria-pressed="true"] { color: #76531e; }
#favoriteIcon { font-size: 22px; line-height: 1; }
#answerPosition { grid-column: 2; margin: 0; font-variant-numeric: tabular-nums; }
#answerPrompt { margin-bottom: 0; font: 700 21px/1.55 var(--display); overflow-wrap: anywhere; }
#answerPrompt > [lang="en"] { font-family: Georgia, "Times New Roman", serif; font-weight: 500; }
.answer-title:not(.english) { margin: 7px 0; font: 750 clamp(28px, 6vw, 38px)/1.4 var(--display); overflow-wrap: anywhere; }
.english { margin: 7px 0; letter-spacing: -.03em; }
.ipa:empty { display: none; }
.pronunciation-controls { display: flex; align-items: center; justify-content: center; gap: 4px; margin: 16px 0; }
.pronunciation-controls button { padding: 8px 12px; font-size: 14px; gap: 7px; }
.pronunciation-controls select { padding: 8px; font-size: 13px; min-height: 44px; }
.answer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; padding-top: 16px; margin-top: 13px; border-top: 1px solid var(--rule); }
.answer-actions button { font-size: 14px; padding-inline: 8px; }
.answer-unavailable .answer-actions { grid-template-columns: 1fr; }
.mark-note { margin: 0; font-size: 13px; color: #526b50; }
.mark-note:empty { display: none; }
.mark-note.status-error { color: var(--danger); }

@media (max-width: 650px) {
  .site-header { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; padding: 18px 0 10px; }
  .site-header nav { width: auto; }
  .site-header nav button { padding-inline: 10px; min-height: 44px; }
  .brand { gap: 8px; font-size: 19px; }
  .brand-mark { width: 33px; height: 33px; border-radius: 9px; }
  .brand-mark .icon { width: 21px; height: 21px; }
  .page-intro { padding: 27px 0 17px; }
  .page-intro h1 { font-size: 32px; }
  .setup-actions { align-items: stretch; flex-direction: column; gap: 10px; }
  .lesson-actions { display: grid; gap: 10px; }
  .lesson-actions select, #startLesson { width: 100%; min-width: 0; }
  .home-options button { padding-inline: 12px; }
  .quick-review { margin-top: 20px; padding: 12px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .word { min-height: 96px; }
  .review-tabs { padding-bottom: 10px; margin-bottom: 14px; }
  .review-tabs button { flex: 1; padding-inline: 6px; font-size: 13px; }
  .library-tools .collection-search { min-width: 100px; }
  .library-tools > button { padding-inline: 10px; font-size: 13px; }
  .entry { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 4px 10px; }
  .entry-ipa { grid-column: 2; grid-row: 2; }
  .entry-marks { grid-row: 3; }
  .entry-ipa:empty { display: none; }
  .entry > :last-child { grid-column: 3; grid-row: 1 / 3; align-self: center; }
  .entry button, .word-tools > summary { padding-inline: 7px; font-size: 12px; }
  dialog, .draw-answer { padding-inline: 18px; }
}

@media (max-width: 500px) {
  .practice-choice { flex: 1 1 190px; }
  .practice-choice button { flex: 1; }
  .english-prompts .word { font-size: clamp(18px, 5.6vw, 22px); padding-inline: 10px; }
  .draw .draw-card, .draw-answer, .draw-complete { min-height: 250px; }
}

@media (max-width: 360px) {
  .site-header nav { width: 100%; }
  .page-intro h1 { font-size: 30px; }
  .site-header nav button { flex: 1; }
  .collection-toolbar .review-controls { width: 100%; }
  .collection-toolbar .review-controls button { flex: 1; }
}

/* Keep the reading area inside the visible screen when a device rotates. */
.app-shell {
  --page-gutter: 32px;
  padding-inline: max(var(--page-gutter), env(safe-area-inset-left)) max(var(--page-gutter), env(safe-area-inset-right));
  padding-bottom: max(48px, env(safe-area-inset-bottom));
}
.site-header { padding-top: env(safe-area-inset-top); }

@media (max-width: 900px) {
  .app-shell { --page-gutter: 24px; }
}

@media (any-pointer: coarse) {
  .site-header { background: var(--paper); backdrop-filter: none; }
  .app-shell:has(#home:not([hidden]), #lesson:not([hidden]), #study:not([hidden])) .site-header { position: relative; }
  .library-utilities > summary, .word-tools > summary, .entry button, .history-row button { min-height: 44px; }
  .review-controls select, .pronunciation-controls select { font-size: 16px; }
}

/* Keep the settings beside the card when there is room for both. */
@media (min-width: 740px) and (any-pointer: coarse) {
  .app-shell { width: min(1080px, 100%); --page-gutter: clamp(24px, 4vw, 48px); }
  .home-start {
    display: grid;
    grid-template-columns: minmax(240px, 330px) minmax(180px, 230px);
    align-content: center;
    justify-content: center;
    column-gap: clamp(24px, 6vw, 72px);
    min-height: 260px;
  }
  .home-study { grid-column: 1; width: 100%; }
  .home-hint, #homeStudyNote { grid-column: 1; }
  .home-options {
    grid-column: 2;
    grid-row: 1 / span 3;
    flex-direction: column;
    justify-content: center;
    width: 100%;
    margin: 0;
    padding: 0 0 0 clamp(24px, 4vw, 48px);
    border: 0;
    border-left: 1px solid var(--rule);
  }
  .home-options button { flex: none; }
  #practice:has(.draw:not([hidden])) {
    display: grid;
    grid-template-columns: minmax(210px, .8fr) minmax(0, 1.65fr);
    align-items: center;
    gap: 14px clamp(24px, 4vw, 48px);
  }
  #practice:has(.draw:not([hidden])) .practice-options { flex-direction: column; }
  #practice:has(.draw:not([hidden])) .practice-choice button { flex: 1; }
  #practice:has(.draw:not([hidden])) .practice-hint { margin-bottom: 0; }
  #practice:has(.draw:not([hidden])) #quizNote { grid-column: 1 / -1; }
  .draw { width: 100%; }
  .draw .draw-card, .draw-answer, .draw-complete { min-height: clamp(290px, 37vw, 365px); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

@media (max-width: 650px) {
  .app-shell { --page-gutter: clamp(12px, 4vw, 20px); }
  .site-header { min-height: 64px; padding-block: max(8px, env(safe-area-inset-top)) 8px; gap: 6px; }
  .site-header nav { width: auto; }
  .site-header nav button { min-width: 44px; padding-inline: 7px; }
  .home-study, .home-options { width: min(100%, 340px); }
  .practice-choice { min-width: 0; }
  .library-tools { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
  .library-tools .collection-search { grid-column: 1 / -1; min-width: 0; }
  #libraryLesson { width: 100%; }
  #addWord { grid-column: 2; min-width: 92px; font-size: 14px; }
}
@media (max-width: 500px) {
  .panel { padding-inline: clamp(14px, 4vw, 20px); }
  .draw .draw-card, .draw-answer, .draw-complete { min-height: clamp(250px, 36svh, 330px); }
  .draw-answer { padding-inline: 12px; }
  .practice-options { gap: 8px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .site-header { position: static; min-height: 56px; }
  .page-intro { padding-block: 14px 12px; }
  .draw .draw-card, .draw-answer, .draw-complete { min-height: 200px; }
  .home-start { min-height: 0; padding-block: 24px; }
}
