@font-face {
  font-family: "Notebook Libertine";
  src: url("/fonts/LinLibertine_R.otf") format("opentype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Notebook Libertine";
  src: url("/fonts/LinLibertine_RB.otf") format("opentype");
  font-style: normal;
  font-weight: 600 900;
  font-display: swap;
}

:root {
  --font: "Notebook Libertine", "Times New Roman", serif;
  --bg: #ffffff;
  --paper: #ffffff;
  --ink: #171717;
  --muted: #686868;
  --accent: #0033cc;
  --accent-hover: #002699;
  --line: #dddddd;
  --answer-bg: #ededff;
  --answer-border: #3333ff;
  --answer-title: #0000cc;
  --hint-bg: #fff4eb;
  --hint-border: #fa7d00;
  --hint-title: #a34d00;
  --solution-bg: #f0fff0;
  --solution-border: #00b300;
  --solution-title: #006600;
  color-scheme: light;
  font-family: var(--font);
  font-size: 100%;
}

:root[data-theme="dark"] {
  --bg: #151515;
  --paper: #1c1c1c;
  --ink: #ededed;
  --muted: #b0b0b0;
  --accent: #a7b7ff;
  --accent-hover: #c3ceff;
  --line: #3b3b3b;
  --answer-bg: #232338;
  --answer-border: #7d88ff;
  --answer-title: #bbc2ff;
  --hint-bg: #33281c;
  --hint-border: #dd984d;
  --hint-title: #efb677;
  --solution-bg: #1c2c1c;
  --solution-border: #73bc73;
  --solution-title: #9dd89d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input { font: inherit; }
button, a, input { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; color: inherit; }
button:disabled { opacity: .55; cursor: wait; }
button, a { transition: background .15s, color .15s; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
svg { flex-shrink: 0; }
.icon { width: 18px; height: 18px; vertical-align: middle; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: -80px; left: 20px; z-index: 99; background: var(--accent); color: var(--bg); padding: 12px 20px; }
.skip-link:focus { top: 12px; }
.loading { text-align: center; margin: 100px auto; color: var(--muted); }

.app-shell { width: min(100% - 80px, 1040px); margin: 0 auto; }
.site-header { display: flex; align-items: center; justify-content: space-between; gap: 24px; min-height: 96px; border-bottom: 1px solid var(--line); }
.brand { text-decoration: none; font-size: 1.6875rem; line-height: 1.2; font-weight: 700; }
.brand-mark { font: italic 32px var(--font); }
.header-tools { display: flex; flex-shrink: 0; align-items: center; gap: 8px; }
.icon-button, .settings-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 44px; min-height: 44px; padding: 10px; border: 0; background: transparent; color: var(--muted); }
.settings-button { font-size: 0.875rem; }
.icon-button:hover, .settings-button:hover { background: var(--answer-bg); color: var(--accent); }
.content-shell { max-width: 740px; margin: 0 auto; }
#main { min-height: calc(100dvh - 188px); outline: none; }
.lookup-section { padding-top: 88px; max-width: 600px; margin: 0 auto; }
h1 { font-size: 2.5rem; line-height: 1.2; font-weight: 700; }
#lookup-form { margin-top: 32px; }
#lookup-form > label { display: block; margin-bottom: 10px; font-size: 1rem; font-weight: 700; }
.lookup-controls { display: flex; gap: 10px; }
#question-search { flex: 1; min-width: 0; padding: 14px 15px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); font-size: 1.125rem; border-radius: 0; }
input::placeholder { color: var(--muted); opacity: 1; }
.primary-button, .secondary-button { display: inline-flex; align-items: center; justify-content: center; gap: 12px; min-width: 0; min-height: 46px; padding: 12px 18px; border: 1px solid transparent; border-radius: 0; font-size: 0.9375rem; font-weight: 700; white-space: normal; }
.primary-button { background: var(--accent); color: var(--bg); }
.primary-button:hover { background: var(--accent-hover); }
.secondary-button { background: transparent; color: var(--accent); border-color: var(--line); }
.secondary-button:hover { background: var(--answer-bg); }
.primary-button .icon, .secondary-button .icon { width: 16px; height: 16px; }
.notebook-line { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 12px; color: var(--muted); font-size: 0.875rem; line-height: 1.7; }
.text-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-width: 44px; min-height: 44px; border: 0; padding: 8px 4px; background: transparent; color: var(--accent); font-size: inherit; }
.text-button:hover { text-decoration: underline; text-underline-offset: 3px; }
footer { display: flex; justify-content: space-between; gap: 18px; padding: 30px 0; color: var(--muted); font-size: 0.75rem; line-height: 1.6; }

.question-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 32px; margin-bottom: 30px; }
.back-button { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 0; border: 0; background: transparent; color: var(--muted); font-size: 0.875rem; }
.back-button:hover { color: var(--accent); }
.back-button .icon { width: 16px; height: 16px; }
.edition-label { font-size: 0.8125rem; color: var(--muted); }
.question-tools { display: flex; align-items: center; gap: 16px; font-size: .875rem; }
.question-top, .panel-heading { flex-wrap: wrap; }
.recovery-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 16px; margin-top: 24px; }
.study-content, .problem-panel, .rich-text, .question-parts > div { min-width: 0; }
[tabindex="-1"] { scroll-margin: 24px; }
.math-scroll, .math-inline .katex { overscroll-behavior-x: contain; }
.math-scroll:focus-visible, .math-inline .katex:focus-visible { outline-offset: -2px; }
.question-title { font-size: 2.25rem; }
.study-content { padding-bottom: 8px; }
.problem-panel { margin-top: 27px; margin-bottom: 24px; }
.problem-panel p { font-size: 1.125rem; line-height: 1.8; }
.question-parts { display: flex; flex-direction: column; gap: 15px; margin-top: 18px; margin-bottom: 26px; }
.question-parts strong { margin-right: 4px; }
.part-label { display: block; font-size: 1.0625rem; margin-bottom: 3px; }
.rich-text { font-size: 1.125rem; line-height: 1.8; overflow-wrap: break-word; }
.rich-text p + p { margin-top: 12px; }
.rich-text .math-inline .katex { display: inline-block; max-width: 100%; overflow-x: auto; overflow-y: hidden; vertical-align: middle; line-height: normal; padding: 3px 1px 4px; scrollbar-width: thin; }
.rich-text .math-inline math { font-size: 1em; }
.rich-display { display: block; margin: 8px 0; font-size: 1.4375rem; padding: 14px 3px; }
.rich-display .katex { display: block; width: max-content; min-width: 100%; }
.answer-rich, .hint-panel > .rich-text { margin-top: 12px; }
.answer-rich { font-size: 1.125rem; }
.solution-steps .rich-text { margin-top: 8px; }
.solution-steps li > div > .rich-text:first-child { margin-top: 0; }
.notebook-figures { margin: 22px 0; }
.notebook-figures.multiple { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }
.notebook-figure { margin: 0; padding: 14px; background: #fff; color: #171717; border: 1px solid var(--line); }
.notebook-figure img { display: block; width: 100%; height: auto; max-width: 560px; max-height: 540px; object-fit: contain; margin: 0 auto; }
.notebook-figures.multiple img { max-width: 340px; }
.notebook-figure figcaption { text-align: center; font-size: 0.875rem; line-height: 1.6; margin-top: 10px; }
.question-parts .math-scroll { margin: 0; font-size: 1.5rem; padding: 14px 6px; }
.math-scroll { max-width: 100%; overflow-x: auto; padding: 18px 6px; font-size: 1.5625rem; scrollbar-width: thin; }
.math-scroll math { min-width: max-content; margin: 0 auto; }
.problem-panel .math-scroll { margin: 11px 0 21px; padding: 25px 6px; font-size: 1.75rem; }
.answer-panel, .hint-panel, .solution-panel { padding: 19px 22px; border-left: 3px solid; }
.answer-panel { background: var(--answer-bg); border-color: var(--answer-border); }
.answer-panel h2, .panel-heading h2 { font-size: 1.1875rem; font-weight: 700; }
.answer-panel h2 { color: var(--answer-title); }
.answer-panel .math-scroll { margin-top: 9px; }
.answer-note { font-size: 1rem; line-height: 1.8; text-align: center; margin-top: 4px; }
.answer-parts { margin-top: 20px; display: flex; flex-direction: column; gap: 22px; }
.answer-parts > section { display: flex; gap: 12px; }
.answer-parts h3 { font-size: 1.0625rem; line-height: 1.6; font-weight: 700; padding-top: 12px; }
.answer-parts section > div { flex: 1; min-width: 0; }
.answer-parts .math-scroll { margin-top: 0; padding: 12px 2px; }
.reveal-row { padding-top: 24px; }
.hint-panel { margin-top: 24px; background: var(--hint-bg); border-color: var(--hint-border); }
.hint-panel h2 { color: var(--hint-title); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.panel-heading .text-button { font-size: 0.875rem; }
.hint-panel > p { font-size: 1.125rem; line-height: 1.8; margin-top: 10px; }
.solution-panel { margin-top: 24px; background: var(--solution-bg); border-color: var(--solution-border); }
.solution-panel h2 { color: var(--solution-title); }
.solution-steps { list-style: none; padding: 0; margin: 24px 0 0; display: flex; flex-direction: column; gap: 25px; }
.solution-steps > li { display: flex; gap: 15px; }
.step-number { flex-shrink: 0; width: 19px; font-size: 1rem; line-height: 1.7; }
.solution-steps li > div { min-width: 0; flex: 1; }
.solution-steps h3 { font-size: 1.0625rem; line-height: 1.7; font-weight: 700; }
.solution-steps p { font-size: 1.125rem; line-height: 1.8; margin-top: 8px; }
.step-math { margin-top: 8px; font-size: 1.4375rem; }
.bottom-back { margin-top: 29px; }
.video-panel { margin-top: 28px; }
.video-panel h3 { display: flex; align-items: center; gap: 8px; font-size: 1.0625rem; }
.video-panel video { display: block; width: 100%; background: #101010; margin: 16px 0; }
.video-panel p { font-size: 1.0625rem; line-height: 1.8; }

dialog { width: min(440px, calc(100% - 32px)); max-width: calc(100% - 32px); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 30px; background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: 0; box-shadow: 0 15px 60px #0002; }
dialog::backdrop { background: #10101070; }
.dialog-top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.dialog-top .icon-button { flex-shrink: 0; }
dialog h2 { min-width: 0; overflow-wrap: anywhere; font-size: 1.75rem; line-height: 1.3; font-weight: 700; }
.dialog-description { color: var(--muted); font-size: 1rem; line-height: 1.8; margin: 15px 0 24px; }
#version-form > label { display: block; font-size: 0.9375rem; font-weight: 700; margin-bottom: 9px; }
#version-input { width: 100%; padding: 13px; color: var(--ink); font-size: 1.0625rem; background: var(--bg); border: 1px solid var(--line); border-radius: 0; }
.field-help { font-size: 0.8125rem; line-height: 1.8; color: var(--muted); margin: 13px 0 8px; }
.version-options { display: flex; flex-wrap: wrap; gap: 8px; }
.version-option { padding: 10px; min-height: 44px; background: transparent; color: var(--accent); border: 1px solid var(--line); font-size: 0.8125rem; }
.version-option:hover { background: var(--answer-bg); }
.form-error { color: #a62620; font-size: 0.9375rem; line-height: 1.7; margin-top: 10px; }
.form-error:empty { margin-top: 0; }
[data-theme="dark"] .form-error { color: #ffaaa2; }
.theme-fieldset { border: 0; padding: 0; margin: 25px 0; }
.theme-fieldset legend { font-size: 0.9375rem; font-weight: 700; margin-bottom: 11px; padding: 0; }
.theme-options { display: flex; gap: 8px; }
.theme-options label { flex: 1; position: relative; cursor: pointer; }
.theme-options input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.theme-options span { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; padding: 11px 8px; min-height: 44px; border: 1px solid var(--line); font-size: 0.875rem; }
.theme-options .icon { width: 16px; height: 16px; }
.theme-options input:checked + span { border-color: var(--accent); color: var(--accent); background: var(--answer-bg); }
.theme-options input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }
.dialog-submit { width: 100%; justify-content: space-between; }
#toast { position: fixed; bottom: 24px; left: 50%; z-index: 10; transform: translateX(-50%); max-width: calc(100% - 32px); background: var(--ink); color: var(--paper); padding: 12px 18px; font-size: 0.9375rem; line-height: 1.7; opacity: 0; pointer-events: none; transition: opacity .15s; }
#toast.visible { opacity: 1; }
.error-page { max-width: 600px; margin: auto; padding: 60px 25px; }
.error-page h1 { font-size: 2.125rem; margin: 25px 0 15px; }
.error-page p { color: var(--muted); line-height: 1.8; }

@media (max-width: 760px) {
  .app-shell { width: calc(100% - 48px); }
  .site-header { min-height: 82px; }
  .lookup-section { padding-top: 62px; }
  #main { min-height: calc(100dvh - 174px); }
  h1 { font-size: 2.25rem; }
}
@media (max-width: 460px) {
  .app-shell { width: calc(100% - 36px); }
  .site-header { gap: 10px; }
  .brand { font-size: 1.375rem; }
  .header-tools { gap: 0; }
  .settings-button > span { display: none; }
  .lookup-section { padding-top: 46px; }
  h1 { font-size: 2rem; }
  #lookup-form { margin-top: 26px; }
  .lookup-controls { flex-direction: column; gap: 9px; }
  #question-search { width: 100%; }
  #lookup-form .primary-button { justify-content: space-between; min-height: 46px; }
  .notebook-line { font-size: 0.8125rem; }
  footer { font-size: 0.6875rem; padding: 27px 0; gap: 12px; }
  .question-top { padding-top: 22px; margin-bottom: 24px; }
  .edition-label { font-size: 0.75rem; }
  .question-tools { gap: 10px; }
  .question-title { font-size: 2rem; }
  .problem-panel { margin-top: 24px; }
  .problem-panel p { font-size: 1.0625rem; }
  .rich-text, .answer-rich { font-size: 1.0625rem; }
  .rich-display { font-size: 1.25rem; }
  .notebook-figure { padding: 8px; }
  .notebook-figures.multiple { grid-template-columns: 1fr; }
  .problem-panel .math-scroll { font-size: 1.5625rem; }
  .answer-panel, .hint-panel, .solution-panel { padding: 16px 14px; }
  .answer-panel .math-scroll { font-size: 1.375rem; }
  .answer-note { font-size: 0.9375rem; }
  .hint-panel > p, .solution-steps p { font-size: 1.0625rem; }
  .solution-steps > li { gap: 10px; }
  .step-math { font-size: 1.25rem; }
  dialog { padding: 24px; }
  dialog h2 { font-size: 1.625rem; }
}
@media (max-width: 360px) {
  .site-header { flex-wrap: wrap; gap: 0; padding: 12px 0; }
  .brand { flex: 1 1 180px; }
  .theme-options { flex-wrap: wrap; }
  .theme-options label { flex: 1 1 80px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
