:root {
  color-scheme: light;
  --text: #37352f;
  --muted: #69675f;
  --line: #e9e7e4;
  --surface: #f7f6f3;
  --hover: #efedea;
  --accent: #2eaadc;
  --error: #eb5757;
  --focus: #24739a;
  --accent-light: #eaf3f7;
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; background: #f7f6f3; }
button { border: 0; border-radius: 4px; background: transparent; transition: background-color 150ms; color: inherit; cursor: pointer; font: inherit; padding: 6px 9px; }
button:hover { background: var(--hover); }
button:active:not(:disabled) { background: #e3e1db; }
button:disabled { opacity: .4; cursor: default; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
header { background: var(--surface); flex: none; padding-inline: clamp(14px, 3vw, 38px); height: 52px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.brand { font-size: 18px; font-weight: 600; text-decoration: none; color: inherit; }
nav { display: flex; gap: 4px; font-size: .875rem; }
nav button { min-height: 40px; }
nav button.active { background: var(--surface); font-weight: 600; }
nav span { color: var(--muted); font-variant-numeric: tabular-nums; }
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 218px minmax(0, 1fr); }
.library-panel { overflow: auto; border-right: 1px solid var(--line); background: var(--surface); padding: 23px 13px; }
.library-panel h2 { margin: 0 9px 8px; color: var(--muted); font-size: .875rem; font-weight: 600; }
.set { display: flex; width: 100%; text-align: left; justify-content: space-between; align-items: center; gap: 8px; font-size: .875rem; padding: 10px 9px; }
.set.current { background: var(--hover); font-weight: 600; }
.set small { font-size: .8125rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.sidefoot { display: flex; justify-content: space-between; margin: 26px 9px 6px; color: var(--muted); font-size: .8125rem; }
progress { display: block; width: calc(100% - 18px); height: 4px; margin: 0 9px; accent-color: var(--accent); }
main { min-height: 0; height: 100%; }
#practice { height: 100%; max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; }
.reading { min-height: 75px; flex: 1 1 auto; overflow: auto; padding: clamp(14px, 4vh, 42px) clamp(18px, 5vw, 58px) 14px; }
.context, .toolbar, .pager, .article-meta, .modalhead, .result { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.context { margin-bottom: 9px; font-size: .875rem; color: var(--muted); }
#mobileSets { margin-left: -8px; color: var(--text); font-weight: 600; }
.toolbar { border-bottom: 1px solid var(--line); font-size: .875rem; color: var(--muted); }
.toolbar button:first-child, .article-bottom button:first-child { margin-left: -8px; }
.pager button { font-size: 1.35rem; line-height: 1; min-width: 44px; min-height: 44px; }
.pager button:first-child { margin: 0; }
#pageNo { white-space: nowrap; font-variant-numeric: tabular-nums; }
.article-meta { margin-top: 14px; font-size: .8125rem; color: var(--muted); }
article h1, .records h1 { font-size: clamp(1.375rem, 2.6vw, 2rem); line-height: 1.25; margin: 4px 0 16px; letter-spacing: -.01em; }
#lines { font-size: 1.0625rem; line-height: 1.6; max-width: 76ch; overflow-wrap: anywhere; }
#lines p { margin: 0 0 .5em; }
#lines .source-heading { color: var(--muted); font-size: .87em; font-style: italic; }
.term { cursor: pointer; color: inherit; text-decoration: underline; text-underline-offset: .19em; text-decoration-thickness: .08em; text-decoration-color: var(--accent); border-radius: 2px; box-decoration-break: clone; }
.term.sel, .term:hover { background: var(--accent-light); }
.term.done { text-decoration-color: #8d9c91; }
.article-bottom { display: flex; gap: 4px; margin-top: 4px; color: var(--muted); font-size: .875rem; }
#translation { border-top: 1px solid var(--line); margin-top: 8px; line-height: 1.7; }
.answer-panel { flex: none; min-width: 0; }
.answer-panel > h2 { display: none; }
#answer { margin-inline: clamp(18px, 5vw, 58px); border-top: 1px solid var(--line); padding: 12px 0 max(12px, env(safe-area-inset-bottom)); background: #f7f6f3; }
#answer.empty { color: var(--muted); font-size: .875rem; }
.question { font-size: 1rem; font-weight: 600; line-height: 1.4; margin: 0 0 9px; overflow-wrap: anywhere; }
.opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.option { display: flex; align-items: center; text-align: left; gap: 8px; min-height: 48px; border: 1px solid var(--line); padding: 8px 12px; font-size: 1rem; overflow-wrap: anywhere; }
.choice-number { color: var(--muted); font-size: .8125rem; line-height: 1; flex: 0 0 1ch; }
.choice-text { min-width: 0; overflow-wrap: anywhere; }
.option:disabled { opacity: 1; }
.option.correct { background: var(--accent-light); border-color: var(--line); }
.option.incorrect { background: #f9eeee; border-color: var(--line); box-shadow: inset 2px 0 var(--error); }
.result { margin-top: 7px; font-size: .875rem; }
.result > div { display: flex; gap: 8px; flex: none; }
.result button { min-height: 44px; padding-inline: 12px; }
.primary { background: var(--text); color: white; }
.primary:hover { background: #555149; }
.retry, .muted { color: var(--muted); }
.records { height: 100%; overflow: auto; max-width: 860px; margin: 0 auto; padding: clamp(22px, 5vw, 58px); }
.records h2 { font-size: .875rem; color: var(--muted); margin: 22px 0 4px; }
.jump { width: 100%; display: flex; justify-content: space-between; align-items: center; text-align: left; gap: 10px; padding: 10px 8px; border-bottom: 1px solid var(--line); border-radius: 0; }
.jump span { overflow-wrap: anywhere; }
.jump small { color: var(--muted); font-size: .8125rem; flex: none; }
.attempt { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.attempt strong, .attempt em { display: block; font-style: normal; }
.attempt em { margin-top: 2px; color: var(--muted); font-size: .875rem; }
.more { margin-top: 12px; }
dialog { width: min(94vw, 560px); max-height: 85dvh; padding: 0; border: 1px solid var(--line); border-radius: 4px; }
dialog::backdrop { background: #25242155; }
.modalhead { position: sticky; top: 0; background: #f7f6f3; border-bottom: 1px solid var(--line); padding: 10px 16px; }
.modalhead h2 { font-size: 1.0625rem; margin: 0; }
#close { font-size: 1.3rem; }
#modalBody { padding: 8px 16px 18px; }
#modalBody img { display: block; width: 100%; height: auto; }
@media (max-width: 760px) {
  .layout { display: block; }
  .library-panel { display: none; }
  header { height: 46px; }
  .reading { padding: 9px 16px; }
  .answer-panel { background: var(--surface); }
  #answer { margin-inline: 0; padding: 8px 16px max(8px, env(safe-area-inset-bottom)); }
  nav button, #mobileSets, #catalog, .article-bottom button { min-height: 44px; }
  .result button { padding-inline: 10px; }
  .reading.focused .context { margin-bottom: 0; }
  .context { margin-bottom: 1px; }
  article h1 { margin-bottom: 9px; }
  .article-meta { margin-top: 5px; }
  .option { gap: 8px; padding-inline: 8px; font-size: .9375rem; }
  .reading.focused .article-meta, .reading.focused h1 { display: none; }
  .reading.focused #lines { margin-top: 8px; }
}
/* The desktop workspace owns the only scrollbar, shared by all three columns. */
@media (min-width: 980px) {
  header { height: 48px; padding-inline: 22px; }
  .layout {
    align-items: start;
    grid-template-columns: clamp(192px, 17vw, 240px) minmax(0, 1fr);
    overflow: auto;
    scrollbar-gutter: stable;
  }
  .library-panel {
    overflow: visible;
    min-height: calc(100dvh - 48px);
    padding: 27px 12px;
  }
  .library-panel h2 { font-size: .8125rem; margin-bottom: 11px; }
  .set { padding-block: 8px; border-radius: 4px; }
  main { min-width: 0; height: auto; }
  #practice {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(246px, 24vw, 340px);
    gap: clamp(18px, 2.4vw, 40px);
    align-items: start;
    max-width: 1390px;
    height: auto;
    padding: 28px clamp(18px, 2.5vw, 46px) 40px;
  }
  .reading {
    width: 100%;
    max-width: 708px;
    justify-self: center;
    min-height: 0;
    overflow: visible;
    padding: 0;
  }
  .context { margin-bottom: 4px; }
  .toolbar { margin-bottom: clamp(18px, 4vh, 42px); }
  article h1 { font-size: clamp(1.5rem, 2.6vw, 2rem); }
  .article-meta { margin-top: 0; }
  #lines p { margin-bottom: .72em; }
  .answer-panel {
    margin-top: 0;
    padding: 13px 14px 15px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 4px;
  }
  .answer-panel > h2 { display: block; color: var(--muted); margin: 0 0 10px; font-size: .8125rem; font-weight: 600; }
  #answer { margin: 0; border: 0; padding: 0; background: transparent; }
  .option { border-color: transparent; background: var(--surface); }
  .option:hover:not(:disabled) { background: var(--hover); }
  .option.correct { background: var(--accent-light); }
  .option.incorrect { background: #f9eeee; }
  .opts { grid-template-columns: minmax(0, 1fr); }


  .choice-number {
    display: grid;
    place-items: center;
    flex: 0 0 22px;
    height: 22px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--surface);
  }
  .result { align-items: flex-start; flex-direction: column; margin-top: 9px; }
  .result > div { align-self: flex-end; }
  .records { height: auto; overflow: visible; }
}
@media (min-width: 980px) and (min-height: 620px) {
  .library-panel, .answer-panel { position: sticky; }
  .library-panel { top: 0; }
  .answer-panel { top: 20px; }
}
@media (max-width: 979px) and (max-height: 520px) and (orientation: landscape) {
  #practice { flex-direction: row; overflow: auto; }
  .reading, .answer-panel { flex: 1 1 50%; }
  .reading { overflow: visible; }
  #answer { margin: 0; padding: 10px 14px; border-top: 0; border-left: 1px solid var(--line); }
}
dialog { background: #fff; color: var(--text); }
.modalhead { background: #fff; }
@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}
