:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.65;
  color: #243936;
  background: #f4f7f6;
  --accent: #17665d;
  --accent-hover: #105249;
  --surface: #fff;
  --border: #d8e2de;
  --muted: #536c65;
  --focus: #245ca6;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, input, select { font: inherit; }
button, .button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  padding: .55rem 1rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  transition: background-color 140ms ease, border-color 140ms ease;
}
.quiet { background: var(--surface); color: #334e46; border-color: #8a9f97; }
button:disabled { background: #edf1ef; color: #66786f; border-color: var(--border); cursor: not-allowed; }
button:not(:disabled):active, .button:active { background: var(--accent-hover); }
.quiet:not(:disabled):active { background: #dbeae3; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 1320px;
  margin: auto;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
}
.brand { text-decoration: none; font-weight: 700; color: #234a41; font-size: 1.1rem; }
#account-tools { display: flex; align-items: center; gap: 1rem; min-width: 0; }
#account-name { overflow-wrap: anywhere; font-size: .9rem; color: var(--muted); }
#logout { flex-shrink: 0; }
main { max-width: 1320px; margin: 0 auto; padding: 1.75rem 2rem 2.5rem; }
h1, h2, h3 { line-height: 1.4; margin: 0 0 .85rem; overflow-wrap: anywhere; }
h1 { font-size: 1.6rem; font-weight: 650; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: 1rem; }
p { margin: .6rem 0; }
.card { padding: 1.5rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 1rem; min-width: 0; }
.auth { max-width: 448px; margin: 4vh auto; padding: 2rem; border-top: 3px solid var(--accent); }
.auth form { display: grid; gap: 1.1rem; margin-top: 1.5rem; }
.auth label, .filters > label { display: grid; gap: .4rem; font-size: .9rem; font-weight: 600; }
.auth input, #word-filename, select { width: 100%; min-width: 0; min-height: 44px; padding: .6rem .75rem; border: 1px solid #7c968c; border-radius: 7px; background: white; color: inherit; font-size: 1rem; font-weight: 400; }
.auth .quiet { margin-top: .85rem; width: 100%; }
.auth .small { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.eyebrow { font-size: .8rem; color: var(--accent); font-weight: 700; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.tabs { display: flex; gap: .3rem; margin-bottom: 1.75rem; flex-wrap: wrap; padding-bottom: .65rem; border-bottom: 1px solid var(--border); }
.tabs button { background: transparent; color: #4b655b; border-color: transparent; }
.tabs button[aria-current=page] { background: #deeee6; color: #14584d; border-color: #76a18f; }
.tabs button:not(:disabled):active { background: #d4e7dd; color: #14584d; }
/* Keep the existing basket destination reachable while reading long questions. */
.floating-basket {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right, 0px));
  bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  z-index: 20;
  min-height: 56px;
  gap: .5rem;
  padding: .75rem 1rem;
  border-radius: 999px;
  border-color: var(--accent-hover);
  box-shadow: 0 3px 12px #24393626;
}
.floating-basket svg { flex-shrink: 0; }
.floating-basket[aria-current=page] { border-color: #fff; outline: 2px solid var(--accent); }
.floating-basket:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.floating-basket #basket-count { margin: 0; padding: .1rem .35rem; border-radius: 999px; background: #fff; color: var(--accent); }
body:has(#workspace:not([hidden])) footer { padding-bottom: calc(6rem + env(safe-area-inset-bottom, 0px)); }
#basket-count { display: inline-block; min-width: 1.35rem; font-size: .85rem; margin-left: .35rem; font-variant-numeric: tabular-nums; }
.question-layout { display: grid; grid-template-columns: 272px minmax(0, 1fr); gap: 1.75rem; }
.question-layout > div { min-width: 0; }
.filters { align-self: start; position: sticky; top: 1rem; padding: 1.25rem; background: #edf4f0; }
.filters h2 { margin-bottom: 1.1rem; }
.filters input[type=checkbox], .choice input { accent-color: var(--accent); width: 20px; height: 20px; flex-shrink: 0; }
.tag-choice { display: flex; align-items: start; gap: .6rem; font-size: .9rem; min-height: 38px; padding: .45rem .25rem; border-radius: 5px; cursor: pointer; }
.tag-choice input { margin: .15rem 0 0; }
.tag-choice:has(input:checked) { background: #dcebe2; color: #164f40; font-weight: 600; }
.tag-choice:focus-within { outline: 2px solid var(--focus); outline-offset: 1px; }
.tag-children { padding-left: .7rem; border-left: 1px solid #b8cec3; margin-left: .6rem; }
details summary { cursor: pointer; font-weight: 600; padding: .5rem 0; }
#tag-tree { max-height: 45vh; overflow: auto; margin: .85rem 0; padding: .25rem; scrollbar-gutter: stable; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .75rem 0 1rem; }
.chips:empty { margin: 0; }
.chip { font-size: .8rem; background: #dcebe2; color: #234f40; padding: .25rem .5rem; border-radius: 5px; overflow-wrap: anywhere; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.section-head h1 { margin-bottom: .25rem; }
#question-summary { font-size: .875rem; font-variant-numeric: tabular-nums; }
.question { padding: 1.5rem 1.75rem; }
.question-head { display: flex; justify-content: space-between; gap: 1rem; align-items: center; padding-bottom: .9rem; margin-bottom: .9rem; border-bottom: 1px solid #e6ede9; }
.question-head h2 { margin: 0; color: #305b4d; }
.question-head label { display: flex; align-items: center; gap: .5rem; min-height: 44px; padding: .4rem .65rem; border-radius: 6px; font-size: .9rem; cursor: pointer; }
.question-head label:has(input:checked) { background: #deeee6; color: #14584d; font-weight: 600; }
.question-head input { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; margin: 0; }
.question-body { min-width: 0; line-height: 1.8; }
.question-body p { margin: .7rem 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.question-body img { display: inline-block; max-width: 100%; height: auto; vertical-align: middle; margin: .25rem 0; }
.table-scroll { max-width: 100%; overflow-x: auto; padding-bottom: .25rem; }
.question-body table { border-collapse: collapse; margin: 1rem 0; min-width: 12rem; }
.question-body td { border: 1px solid #8fa69b; padding: .5rem .7rem; vertical-align: top; }
.question-body mjx-container { max-width: 100%; overflow-x: auto; overflow-y: hidden; vertical-align: middle; }
.question-body mjx-container[jax=SVG][display=true] { margin: .7rem 0; }
.math { white-space: normal; }
.metadata { font-size: .8rem; color: #5a7067; border-top: 1px solid #e6ede9; padding-top: .8rem; margin-top: 1rem; overflow-wrap: anywhere; }
.solutions { margin-top: 1rem; padding-top: .25rem; border-top: 1px solid var(--border); }
.solutions > summary { color: #315e4d; min-height: 44px; }
.solutions[open] > .question-body { margin: .25rem 0 .75rem; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1.5rem; font-variant-numeric: tabular-nums; }
.basket-buttons { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.basket-buttons button { font-size: .875rem; padding: .45rem .8rem; }
#basket-state { color: #315e4d; padding: .65rem 0; margin-bottom: 1rem; }
fieldset { border: 1px solid #95aca0; border-radius: 8px; margin: 1.25rem 0; padding: .7rem 1rem; min-width: 0; }
legend { padding: 0 .35rem; font-size: .9rem; color: var(--muted); }
.choice { display: flex; align-items: start; gap: .65rem; min-height: 44px; padding: .55rem 0; cursor: pointer; }
.choice input { margin: .2rem 0 0; }
#notice { max-width: 1256px; margin: 1rem auto 0; background: #e3f1e9; border: 1px solid #87b29c; padding: .85rem 1rem; border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; color: #244f3b; }
#notice.error, .error { color: #a12c26; }
#notice.error { background: #fff1ee; border-color: #c99087; }
#batch-error, #reset-result { white-space: pre-wrap; overflow-wrap: anywhere; }
#reset-result:not(:empty) { background: #edf4f0; padding: 1rem; border-radius: 7px; margin-top: 1rem; }
#reset-login { display: inline-block; padding: .6rem 0; min-height: 44px; color: var(--accent); font-weight: 600; }
.history-item { display: flex; justify-content: space-between; align-items: center; gap: 1.5rem; }
.history-item > div { min-width: 0; }
.history-item .button { flex-shrink: 0; }
.history-item p { margin: .3rem 0; }
.empty { padding: 2rem 1.25rem; text-align: center; color: var(--muted); border: 1px dashed #a6bdb0; border-radius: var(--radius); background: #f9fbfa; }
.warning { color: #855418; overflow-wrap: anywhere; }
footer { max-width: 1320px; margin: 0 auto; padding: 1rem 2rem max(1.25rem, env(safe-area-inset-bottom, 0px)); color: #5f756b; font-size: .8rem; }
input[type=radio] { accent-color: var(--accent); }
@media (hover: hover) and (pointer: fine) {
  button:not(:disabled):hover, .button:hover { background: var(--accent-hover); }
  .quiet:not(:disabled):hover { background: #edf4f0; border-color: #567d69; }
  .tabs button:not(:disabled):hover { background: #e7f0ea; color: #14584d; }
  .tag-choice:hover, .question-head label:hover { background: #e7f0ea; }
}
@media (max-width: 900px) {
  .question-layout { grid-template-columns: 1fr; gap: 1rem; }
  .filters { position: static; }
  #tag-tree { max-height: 16rem; }
  .section-head { align-items: start; flex-wrap: wrap; }
}
@media (max-width: 600px) {
  .topbar { padding: .85rem max(1rem, env(safe-area-inset-left, 0px)) .85rem max(1rem, env(safe-area-inset-right, 0px)); flex-wrap: wrap; gap: .5rem; }
  .brand { font-size: 1rem; }
  #account-tools { width: 100%; justify-content: space-between; gap: .5rem; }
  main { padding: 1.1rem max(1rem, env(safe-area-inset-left, 0px)) 1.75rem max(1rem, env(safe-area-inset-right, 0px)); }
  h1 { font-size: 1.4rem; }
  .card { padding: 1.1rem; }
  .auth { margin: .75rem auto; padding: 1.4rem; }
  .tabs { gap: .25rem; margin-bottom: 1.1rem; padding-bottom: .6rem; }
  .tabs button { flex: 1 1 auto; padding: .55rem .6rem; font-size: .9rem; }
  .filters { padding: 1rem; }
  .filters h2 { margin-bottom: .75rem; }
  .tag-choice { min-height: 44px; }
  .question-head { gap: .4rem; flex-wrap: wrap; margin-bottom: .75rem; padding-bottom: .6rem; }
  .question-head label { padding: .4rem .25rem; }
  .question-body { line-height: 1.8; }
  .question-body td { padding: .4rem .6rem; min-width: 5rem; }
  .section-head > button { width: 100%; }
  .history-item { flex-wrap: wrap; gap: .8rem; }
  .history-item .button { width: 100%; }
  .pagination { gap: .5rem; font-size: .9rem; flex-wrap: wrap; }
  .pagination button { padding: .55rem .75rem; }
  #notice { margin: 1rem; }
  footer { padding-left: max(1rem, env(safe-area-inset-left, 0px)); padding-right: max(1rem, env(safe-area-inset-right, 0px)); }
}
@media (prefers-reduced-motion: reduce) {
  button, .button { transition: none; }
}
@media (forced-colors: active) {
  button, .button, input, select { border-color: ButtonText; }
  button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline-color: Highlight; }
}
/* One continuous paper: content, ordering controls, then generation in document flow. */
.single-paper-workspace { max-width: 960px; margin: 0 auto; }
.single-paper-workspace .paper-controls { display: block; position: static; max-height: none; overflow: visible; padding: 0; margin-top: 1.5rem; min-width: 0; }
.paper-caption { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .85rem; }
.paper-caption h2 { margin: 0; }
.paper-sheet { background: var(--surface); border: 1px solid var(--border); padding: clamp(1.1rem, 4vw, 3rem); min-width: 0; scroll-margin-top: 1rem; }
.paper-heading { text-align: center; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); margin-bottom: 1.75rem; }
.paper-heading h2 { font-size: 1.5rem; }
.paper-item { position: relative; padding-bottom: 1.25rem; margin-bottom: 1.5rem; border-bottom: 1px solid #e6ede9; }
.paper-item:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.paper-question { margin-bottom: 1.5rem; }
.paper-question h3, .paper-solution h3 { font-size: 1rem; color: #305b4d; }
.paper-solution { margin-bottom: 1.5rem; }
.paper-solution h4 { margin: 1rem 0 .3rem; font-size: .9rem; color: var(--muted); }
.paper-option > p:first-child { margin-bottom: .15rem; font-weight: 600; }
.paper-option > p:nth-child(2) { margin-top: .15rem; }
.paper-divider { padding-top: 1.75rem; margin-top: 2rem; border-top: 2px solid var(--border); }
.paper-question-tools { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; padding: .5rem 0; margin-bottom: .7rem; }
.paper-question-tools h3 { margin: 0 auto 0 0; color: #305b4d; }
.paper-question-tools button { font-size: .875rem; min-width: 44px; padding: .5rem .65rem; }
.drag-handle { touch-action: none; cursor: grab; user-select: none; font-size: 1.3rem !important; }
.drag-handle:active { cursor: grabbing; }
.paper-sortable.dragging { outline: 2px dashed var(--accent); outline-offset: .4rem; }
.paper-sortable.drop-before::before, .paper-sortable.drop-after::after { content: ''; position: absolute; left: 0; right: 0; height: 4px; border-radius: 2px; background: var(--accent); }
.paper-sortable.drop-before::before { top: -.8rem; }
.paper-sortable.drop-after::after { bottom: -.8rem; }
#basket-state { margin: .5rem 0 1rem; color: #315e4d; }
.export-settings fieldset { margin: .7rem 0 1rem; }
#generate-word { width: 100%; }
.paper-controls #batch-panel button, .paper-controls #batch-panel .button { margin: .5rem .5rem 0 0; }
.paper-controls:focus, .paper-sheet:focus { outline: none; }
.paper-controls:focus-visible, .paper-sheet:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.filters > details > summary { font-size: 1.05rem; min-height: 44px; margin-bottom: .65rem; }
#history-view > h1 { margin-bottom: .35rem; }
#history-list { margin-top: 1.5rem; }
@media (max-width: 600px) {
  .floating-basket { min-height: 52px; padding: .65rem .9rem; }
  .paper-caption { flex-wrap: wrap; gap: .25rem; }
  .paper-sheet { padding: 1.1rem; }
  .paper-heading { padding-bottom: 1rem; margin-bottom: 1.25rem; }
  .paper-heading h2 { font-size: 1.3rem; }
  .paper-question-tools h3 { flex-basis: 100%; margin-bottom: .15rem; }
  .paper-question-tools button { flex: 1; }
  .paper-controls #batch-panel button, .paper-controls #batch-panel .button { width: 100%; }
}

.word-filename-label { display: block; margin: 1rem 0 .4rem; font-size: .9rem; font-weight: 600; }
