:root {
  --bg: #eef5ea;
  --bg-soft: #f8fbf5;
  --paper: #ffffff;
  --ink: #1f2a1f;
  --muted: #63705f;
  --line: #d9e4d2;
  --green: #228b4e;
  --blue: #2368c4;
  --orange: #d97a1c;
  --slate: #5c6572;
  --shadow: 0 18px 42px rgba(85, 110, 79, 0.13);
  --radius: 22px;
  --print-columns: 2;
  --sheet-print-width: 18cm;
  --problem-grid-gap-row: 12px;
  --problem-grid-gap-col: 18px;
  --problem-font-size: 18pt;
  --answer-font-size: 12pt;
  --problem-line-height: 1.5;
  --answer-line-height: 1.5;
  --serial-gap: 0.35em;
  --serial-pad-y: 0.03em;
  --serial-pad-x: 0.28em;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Trebuchet MS", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255, 239, 178, 0.75), transparent 22%),
    radial-gradient(circle at top right, rgba(192, 235, 214, 0.85), transparent 28%),
    linear-gradient(180deg, #f8fcf4 0%, #edf5e9 100%);
}

.page-shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 16px 16px 36px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(217, 228, 210, 0.92);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.brand-block h1 {
  margin: 0;
  font-size: clamp(26px, 3vw, 36px);
}

.panel,
.sheet {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(217, 228, 210, 0.92);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--green);
}

.quick-menu {
  display: flex;
  gap: 10px;
}

.quick-menu a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  padding: 10px 12px;
  border-radius: 999px;
  background: #f5f9f2;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.quick-menu a.is-active {
  background: #e8f5ea;
  color: #1d7b45;
  border-color: #bfe0c9;
}

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.left-column {
  display: grid;
  gap: 16px;
  align-self: start;
  position: sticky;
  top: 16px;
}

.panel {
  padding: 18px 18px 20px;
}

.workspace-hidden {
  display: none;
}

.section-group {
  display: grid;
  gap: 12px;
}

.section-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--ink);
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
}

.section-toggle-mark {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #f3f8f0;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 18px;
}

.section-group:not(.is-open) .section-body {
  display: none;
}

.panel-head h2,
.sheet-head h2 {
  margin: 0;
  font-size: 22px;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 14px;
}

.field label {
  display: block;
  margin-bottom: 8px;
  font-size: 16px;
  font-weight: 800;
}

.field select,
.field input[type="number"] {
  width: 100%;
  border: 1px solid #bfd0b7;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 16px;
  background: #fcfffb;
  color: var(--ink);
}

.subsection {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}

.subsection.is-hidden {
  display: none;
}

.subsection-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f5f9f2;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.toggle-pill input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.toggle-pill.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.button-row-tight {
  margin-top: 0;
}

.btn {
  border: 0;
  border-radius: 14px;
  padding: 13px 18px;
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.12);
}

.btn-green {
  background: var(--green);
}

.btn-blue {
  background: var(--blue);
}

.btn-orange {
  background: var(--orange);
}

.btn-slate {
  background: var(--slate);
}

.status-box {
  margin-top: 14px;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.history-status,
.sheet-meta {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.history-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  max-height: 680px;
  overflow: auto;
  padding-right: 4px;
}

.history-list-shell {
  margin-top: 12px;
}

.history-filters {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: 14px;
  border-radius: 18px;
  background: #f8fbf5;
  border: 1px solid var(--line);
}

.history-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.history-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.history-pagination span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.history-check-all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.history-list-table {
  gap: 8px;
  margin-top: 0;
  max-height: 540px;
}

.history-card {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 72px 88px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 16px;
  background: #f9fbf7;
  border: 1px solid var(--line);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.history-card.is-active {
  border-color: #6eb38b;
  background: #f4fbf4;
  box-shadow: 0 12px 22px rgba(54, 126, 74, 0.12);
  transform: translateY(-1px);
}

.history-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 15px;
}

.history-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.history-select {
  width: 18px;
  height: 18px;
}

.history-summary {
  min-width: 0;
}

.history-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 8px;
  border-radius: 999px;
  background: #eaf6ed;
  color: #1f7a46;
  font-size: 12px;
  font-weight: 800;
}

.history-meta-line {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-card button {
  border: 0;
  border-radius: 12px;
  padding: 9px 10px;
  background: #eef4ff;
  color: #245eb1;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.history-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.history-card .btn-delete {
  background: #fff3f0;
  color: #b84a22;
}

.worksheet-panel {
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.sheet-tabs {
  display: inline-flex;
  gap: 8px;
  margin-bottom: 10px;
}

.sheet-tab {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.sheet-tab.is-active {
  background: #e8f5ea;
  color: #1d7b45;
  border-color: #bfe0c9;
}

.sheet {
  padding: 20px 20px 26px;
  margin-bottom: 16px;
}

.sheet-pane {
  display: none;
}

.sheet-pane.is-active {
  display: block;
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.sheet-tags {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.sheet-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.archive-badge {
  padding: 10px 12px;
  border-radius: 999px;
  background: #e8f6ea;
  color: #1f7a46;
  border: 1px solid #b9dfc4;
  font-size: 13px;
  font-weight: 800;
}

.archive-badge.is-hidden {
  display: none;
}

.archive-meta {
  padding: 10px 12px;
  border-radius: 14px;
  background: #f5faf2;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.worksheet-panel.is-history-mode .sheet {
  border-color: #c7e3cf;
  box-shadow: 0 18px 42px rgba(56, 122, 74, 0.14);
}

.worksheet-panel.is-review-mode .problem-item {
  letter-spacing: 0.04em;
}

.worksheet-panel.is-review-mode .answer-item {
  color: #a3acb3;
}

.problem-grid,
.answer-grid {
  display: grid;
  grid-template-columns: repeat(var(--print-columns), minmax(0, 1fr));
  gap: var(--problem-grid-gap-row) var(--problem-grid-gap-col);
}

.problem-item,
.answer-item {
  min-height: 2.2em;
  page-break-inside: avoid;
  break-inside: avoid;
  font-variant-numeric: tabular-nums;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  column-gap: var(--serial-gap);
  align-items: start;
}

.problem-item {
  font-size: var(--problem-font-size);
  line-height: var(--problem-line-height);
  text-align: left;
}

.answer-item {
  font-size: var(--answer-font-size);
  line-height: var(--answer-line-height);
  color: #7a838c;
  text-align: left;
}

.problem-no,
.answer-no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-width: 0;
  padding: var(--serial-pad-y) var(--serial-pad-x);
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.problem-no {
  background: #edf5e7;
  color: #365538;
}

.answer-no {
  background: #f1f3f5;
  color: #6f7780;
}

.problem-text,
.answer-text {
  display: block;
}

.answer-sheet.is-hidden {
  display: none;
}

@media screen and (max-width: 1180px) {
  .layout {
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .left-column {
    position: static;
  }
}

@media screen and (max-width: 860px) {
  .topbar,
  .layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .left-column {
    position: static;
  }

  .problem-grid,
  .answer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-card {
    grid-template-columns: 24px minmax(0, 1fr);
  }

  .history-state {
    grid-column: 2 / 3;
    justify-self: start;
  }

  .history-actions {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 84px;
  }
}

@media screen and (max-width: 560px) {
  .page-shell {
    padding: 10px 10px 24px;
  }

  .topbar,
  .panel,
  .sheet {
    padding: 16px 14px 18px;
  }

  .problem-grid,
  .answer-grid {
    grid-template-columns: 1fr;
  }

  .problem-item {
    font-size: 17pt;
  }
}

@media print {
  @page {
    size: A4;
    margin: 1.5cm;
  }

  body {
    background: #fff;
  }

  .topbar,
  .left-column {
    display: none !important;
  }

  .page-shell {
    max-width: none;
    padding: 0;
  }

  .layout {
    display: block;
  }

  .sheet-tabs,
  .sheet-tags,
  .archive-badge,
  .archive-meta,
  .sheet-tools,
  #questionMeta,
  #answerSheet {
    display: none !important;
  }

  .sheet {
    box-shadow: none;
    border: 0;
    padding: 0;
    margin: 0;
    background: #fff;
    width: var(--sheet-print-width);
    max-width: var(--sheet-print-width);
  }

  .problem-grid,
  .answer-grid {
    grid-template-columns: repeat(var(--print-columns), minmax(0, 1fr)) !important;
  }

  .problem-no {
    background: transparent;
    border: 1px solid #cfd8cf;
  }
}
