@font-face { font-family: "Atkinson Hyperlegible"; font-weight: 400; font-display: swap; src: url(../fonts/atkinson-hyperlegible-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Atkinson Hyperlegible"; font-weight: 700; font-display: swap; src: url(../fonts/atkinson-hyperlegible-latin-700-normal.woff2) format("woff2"); }
@font-face { font-family: "Bricolage Grotesque"; font-weight: 800; font-display: swap; src: url(../fonts/bricolage-grotesque-latin-800-normal.woff2) format("woff2"); }

/* Layout concept: a squared-paper desk with real sheets on it, settings in a rail beside them.
   Pencil yellow is the single action colour; correcting-pen red is reserved for answers. */
:root {
  --desk: #dbe4ee;
  --desk-line: #cbd7e4;
  --panel: #f7f9fc;
  --raised: #ffffff;
  --ink: #18202b;
  --mute: #566274;
  --line: #c5d0dd;
  --pencil: #f8c630;
  --pencil-ink: #2b2200;
  --pen: #c4122f;
  --focus: #1f5fbf;
  --shadow: 0 1px 2px rgb(24 32 43 / 0.16), 0 10px 26px rgb(24 32 43 / 0.14);
  --display: "Bricolage Grotesque", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Trebuchet MS", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --desk: #141a22;
    --desk-line: #1c242f;
    --panel: #1b222c;
    --raised: #252e3a;
    --ink: #e9eef5;
    --mute: #a0adbe;
    --line: #38444f;
    --pencil: #f8c630;
    --pencil-ink: #2b2200;
    --pen: #ff7d8f;
    --focus: #79aefc;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.5), 0 12px 30px rgb(0 0 0 / 0.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --desk: #141a22;
  --desk-line: #1c242f;
  --panel: #1b222c;
  --raised: #252e3a;
  --ink: #e9eef5;
  --mute: #a0adbe;
  --line: #38444f;
  --pencil: #f8c630;
  --pencil-ink: #2b2200;
  --pen: #ff7d8f;
  --focus: #79aefc;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.5), 0 12px 30px rgb(0 0 0 / 0.45);
  color-scheme: dark;
}

/* In Chinese, plain digits from the system font read better than Atkinson's slashed zero */
html[lang="zh-CN"] {
  --display: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", system-ui, sans-serif;
  --body: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font: 15px/1.4 var(--body);
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding-block: 9px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand-word { font: 800 24px/1.1 var(--display); letter-spacing: -0.01em; white-space: nowrap; }
.brand-one { position: relative; display: inline-block; }
.brand-one sup {
  position: absolute;
  left: 0.12em;
  top: -0.42em;
  font-size: 0.48em;
  color: var(--pen);
  line-height: 1;
}
.lang-buttons { display: flex; gap: 4px; }
.lang-buttons button {
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  background: var(--raised);
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
}
.lang-buttons button:hover { border-color: var(--ink); }
.lang-buttons button[aria-pressed="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); }

.btn {
  border: 1px solid var(--line);
  background: var(--raised);
  border-radius: 6px;
  padding: 9px 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not([disabled]) { border-color: var(--ink); }
.btn-primary { background: var(--pencil); border-color: var(--pencil); color: var(--pencil-ink); }
.btn-primary:hover:not([disabled]) { border-color: var(--pencil-ink); }
.btn[disabled] { opacity: 0.45; cursor: default; }
.btn-small { padding: 5px 10px; font-size: 13px; font-weight: 400; }

/* Two panes */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(330px, 390px) minmax(0, 1fr);
}
.rail {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.rail-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 16px 14px 20px;
  padding-left: max(14px, env(safe-area-inset-left, 0px));
}
.rail-foot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px 14px;
  padding-left: max(14px, env(safe-area-inset-left, 0px));
  background: var(--raised);
  border-top: 1px solid var(--line);
}
.foot-actions { display: flex; gap: 8px; }
.foot-actions .btn-primary { flex: 1; font-size: 16px; padding-block: 11px; }

/* Numbered steps */
.step { display: flex; flex-direction: column; gap: 10px; }
.step h2, .foot-title {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font: 800 16px/1.2 var(--display);
}
.step-no {
  width: 22px;
  height: 22px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--ink);
  color: var(--panel);
  font: 700 13px/1 var(--body);
}
.grade-buttons { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
.term-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.grade-buttons button, .term-buttons button {
  min-height: 38px;
  padding: 0 2px;
  border: 1px solid var(--line);
  background: var(--raised);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.grade-buttons button:hover, .term-buttons button:hover { border-color: var(--ink); }
.grade-buttons button[aria-pressed="true"], .term-buttons button[aria-pressed="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); }

/* The paper */
.desk {
  overflow-y: auto;
  min-width: 0;
  background-color: var(--desk);
  background-image:
    linear-gradient(var(--desk-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--desk-line) 1px, transparent 1px);
  background-size: 22px 22px;
}
.desk-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: center;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.summary { margin: 0; color: var(--mute); font-size: 13px; font-variant-numeric: tabular-nums; }
.view-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.view-toggle button { border: 0; background: var(--raised); padding: 6px 16px; font-weight: 700; cursor: pointer; }
.view-toggle button + button { border-left: 1px solid var(--line); }
.view-toggle button[aria-pressed="true"] { background: var(--ink); color: var(--panel); }
.view-toggle button[disabled] { opacity: 0.45; cursor: default; }
#view-key[aria-pressed="true"] { background: var(--pen); color: var(--panel); }
.pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 24px 20px 48px;
}
.sheet { width: 100%; max-width: 760px; box-shadow: var(--shadow); background: #ffffff; line-height: 0; }
.sheet svg { width: 100%; height: auto; display: block; }

/* Problem rows */
.sections { display: flex; flex-direction: column; gap: 8px; }
.card {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.card-title { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.35; min-width: 0; }
.card-main { display: flex; align-items: flex-end; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.icon-btn {
  width: 28px;
  height: 28px;
  flex: none;
  margin: -3px -4px 0 0;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 5px;
  cursor: pointer;
  color: var(--mute);
  font-size: 14px;
  line-height: 1;
}
.icon-btn:hover:not([disabled]) { border-color: var(--line); color: var(--ink); }
.icon-btn[disabled] { opacity: 0.3; cursor: default; }
.stepper { display: flex; }
.stepper button {
  width: 32px;
  height: 36px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.stepper button:first-child { border-radius: 5px 0 0 5px; }
.stepper button:last-child { border-radius: 0 5px 5px 0; }
.stepper button:hover { border-color: var(--ink); }
.stepper input {
  width: 46px;
  min-height: 36px;
  border-width: 1px 0;
  border-radius: 0;
  text-align: center;
  padding: 0 2px;
  appearance: textfield;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { appearance: none; margin: 0; }

label, .field-label, legend {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--mute);
}
input[type="text"], input[type="number"], select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  padding: 5px 8px;
}
input[type="number"] { font-variant-numeric: tabular-nums; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.range-row { display: flex; align-items: center; gap: 6px; }
.range-row span { color: var(--mute); font-size: 13px; flex: none; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button {
  flex: 1 1 auto;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 5px;
  padding: 5px 8px;
  min-height: 32px;
  cursor: pointer;
  font-size: 14px;
}
.seg button:hover { border-color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); font-weight: 700; }
.check-line { display: flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 400; color: var(--ink); }
.check-line input, .checks input { width: 16px; height: 16px; margin: 0; flex: none; accent-color: var(--ink); }
.format-hint { font-size: 13px; color: var(--mute); margin: 0; }
.note { margin: 0; font-size: 13px; color: var(--pen); }
.move-row { display: flex; gap: 6px; }

/* Things kept out of the way until asked for */
details > summary {
  cursor: pointer;
  color: var(--mute);
  font-size: 13px;
  font-weight: 700;
  padding-block: 2px;
}
details > summary:hover { color: var(--ink); }
.more-body { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; }
.setup { border-top: 1px solid var(--line); padding-top: 12px; }
.setup > summary { font-size: 14px; }
.setup-body { display: flex; flex-direction: column; gap: 12px; padding-top: 12px; }
.standard-note { margin: 0; font-size: 12.5px; color: var(--mute); }

.add-row { display: flex; flex-direction: column; gap: 4px; }
.add-controls { display: flex; gap: 6px; }
.add-controls select { flex: 1; min-width: 0; }

.checks { border: 0; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; }
.checks legend { margin-bottom: 6px; padding: 0; }
.checks label { display: flex; align-items: center; gap: 7px; font-weight: 400; font-size: 14px; color: var(--ink); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: calc(100vw - 32px);
  background: var(--ink);
  color: var(--panel);
  border-radius: 7px;
  padding: 9px 14px;
  box-shadow: var(--shadow);
}
.toast button { border: 0; background: transparent; color: var(--pencil); font-weight: 700; cursor: pointer; padding: 2px 4px; text-decoration: underline; flex: none; }

@media (max-width: 900px) {
  html, body { height: auto; }
  body { padding-bottom: calc(112px + env(safe-area-inset-bottom, 0px)); }
  .workspace { display: flex; flex-direction: column; }
  .rail { border-right: 0; border-bottom: 1px solid var(--line); }
  .rail-scroll {
    overflow: visible;
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  /* Export stays within thumb reach while scrolling down to the preview */
  .rail-foot {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 4;
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 14px rgb(24 32 43 / 0.12);
  }
  .foot-title { display: none; }
  .desk { overflow: visible; }
  .desk-bar { position: static; }
  .pages { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .toast { bottom: calc(124px + env(safe-area-inset-bottom, 0px)); }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .seg button, .grade-buttons button, .term-buttons button { transition: border-color 120ms, background-color 120ms; }
}
