:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #64748b;
  --line: #e5e7eb;
  --strong-line: #cbd5e1;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --coral: #2563eb;
  --coral-soft: #eff6ff;
  --mint: #10b981;
  --mint-soft: #d1fae5;
  --sun: #f59e0b;
  --sun-soft: #fff7ed;
  --green: #15803d;
  --red: #b42318;
  --red-soft: #fee4e2;
  --paper: #fffef9;
  --print-mizi-size: 15mm;
  --preview-mizi-size: 57px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 240px minmax(220px, 1fr) auto;
  align-items: center;
  gap: 18px;
  height: 58px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  padding: 0 24px;
  backdrop-filter: blur(16px);
}

.header-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #111827;
  font-size: 15px;
  font-weight: 900;
  text-decoration: none;
}

.header-logo {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #111827;
  color: #ffffff;
  font-size: 12px;
  letter-spacing: 0;
}

.header-search {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 8px 12px;
  color: #94a3b8;
  font-size: 13px;
}

.header-links {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.header-links a {
  border-radius: 8px;
  padding: 8px 10px;
  color: #475569;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.header-links a.active,
.header-links a:hover {
  background: var(--blue-soft);
  color: var(--blue);
}

.app-shell {
  display: grid;
  grid-template-columns: 240px minmax(420px, var(--workspace-width, 660px)) 16px minmax(360px, 1fr);
  gap: 20px;
  align-items: start;
  min-height: calc(100vh - 58px);
  padding: 20px 24px 28px;
}

.site-sidebar {
  position: sticky;
  top: 78px;
  min-height: calc(100vh - 98px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 14px;
  box-shadow: none;
}

.brand-block {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid #111827;
  border-radius: 8px;
  background: #111827;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
}

.brand-title {
  color: #111827;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.2;
}

.brand-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.side-nav {
  display: grid;
  gap: 3px;
  margin-top: 14px;
}

.side-section-title {
  margin: 16px 8px 6px;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 900;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 10px;
  color: #475569;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.nav-item.active {
  border-color: #dbeafe;
  background: var(--blue-soft);
  color: var(--blue);
}

.nav-item.disabled {
  opacity: 0.58;
  cursor: default;
}

.nav-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #cbd5e1;
  flex: 0 0 auto;
}

.nav-item.active .nav-dot {
  background: var(--blue);
}

.workspace {
  min-width: 0;
}

.resize-handle {
  position: sticky;
  top: 78px;
  display: flex;
  align-items: stretch;
  justify-content: center;
  width: 16px;
  min-height: calc(100vh - 98px);
  border-radius: 8px;
  cursor: col-resize;
  touch-action: none;
}

.resize-handle span {
  width: 6px;
  min-height: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(#94a3b8, #94a3b8) center 45% / 2px 26px no-repeat,
    linear-gradient(#94a3b8, #94a3b8) center 55% / 2px 26px no-repeat,
    #ffffff;
  box-shadow: none;
}

.resize-handle:hover span,
.resize-handle.dragging span,
.resize-handle:focus-visible span {
  border-color: var(--blue);
  background:
    linear-gradient(#ffffff, #ffffff) center 45% / 2px 26px no-repeat,
    linear-gradient(#ffffff, #ffffff) center 55% / 2px 26px no-repeat,
    var(--blue);
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 18px;
  box-shadow: none;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: #111827;
  font-size: 32px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  letter-spacing: 0;
}

.topbar p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.toolbar,
.field-row,
.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.grid-layout {
  display: grid;
  gap: 16px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
  box-shadow: none;
}

.input-panel {
  border-color: var(--line);
  background: #ffffff;
}

.library-panel {
  border-color: var(--line);
  background: #ffffff;
}

.worksheet-panel {
  border-color: var(--line);
  background: #ffffff;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 8px;
  background: #eef2f7;
  padding: 0 10px;
  color: #475569;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

textarea {
  width: 100%;
  min-height: 118px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  line-height: 1.55;
}

.pronunciation-panel {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.pronunciation-row {
  display: grid;
  grid-template-columns: 54px 1fr;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.pronunciation-char {
  width: 42px;
  height: 42px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e3a8a;
  font-family: "KaiTi", "STKaiti", serif;
  font-size: 28px;
  line-height: 42px;
  text-align: center;
}

.pronunciation-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pronunciation-option {
  min-height: 32px;
  border: 1px solid #d8dee9;
  border-radius: 8px;
  background: #ffffff;
  padding: 0 10px;
  color: #475569;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.pronunciation-option.active {
  border-color: #bfdbfe;
  background: var(--blue-soft);
  color: var(--blue);
}

.pronunciation-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
}

label {
  display: grid;
  gap: 7px;
  flex: 1 1 190px;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 8px 10px;
}

.compact-input {
  max-width: 210px;
}

.button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
}

.button.primary {
  background: var(--blue);
  color: #ffffff;
}

.button.secondary {
  background: var(--blue-soft);
  color: #1e3a8a;
}

.button.ghost {
  background: #f8fafc;
  color: #334155;
  border: 1px solid var(--line);
}

.button.danger {
  background: var(--red-soft);
  color: var(--red);
}

.button.full {
  width: 100%;
  margin-top: 12px;
}

.worksheet-actions {
  margin-top: 12px;
}

.worksheet-actions .button {
  flex: 1 1 160px;
}

.tag-filter {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.tag-chip {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 0 10px;
  color: #475569;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.tag-chip.active {
  border-color: #bfdbfe;
  background: var(--blue-soft);
  color: var(--blue);
}

.word-list {
  display: grid;
  max-height: 420px;
  overflow: auto;
  border-top: 1px solid #edf2f7;
}

.word-row {
  display: grid;
  grid-template-columns: 30px 54px minmax(96px, 160px) 1fr 44px;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  border-bottom: 1px solid #edf2f7;
}

.select-box {
  width: 24px;
  height: 24px;
  border: 1px solid var(--strong-line);
  border-radius: 6px;
  background: #ffffff;
  cursor: pointer;
}

.select-box.selected {
  border-color: var(--blue);
  background: var(--blue);
}

.select-box.selected::after {
  content: "";
  display: block;
  width: 10px;
  height: 6px;
  margin: 6px auto 0;
  border-bottom: 2px solid #ffffff;
  border-left: 2px solid #ffffff;
  transform: rotate(-45deg);
}

.hanzi-cell {
  width: 48px;
  height: 48px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e3a8a;
  font-family: "KaiTi", "STKaiti", serif;
  font-size: 32px;
  line-height: 48px;
  text-align: center;
}

.pinyin-input {
  min-height: 34px;
}

.tag-cell {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.word-tag {
  border: 0;
  border-radius: 6px;
  background: #eef2f7;
  padding: 3px 7px;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.word-tag.active {
  background: var(--blue-soft);
  color: var(--blue);
}

.mini {
  border: 0;
  background: transparent;
  padding: 0;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.danger-text {
  color: var(--red);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.wide {
  grid-column: 1 / -1;
}

.option-group {
  display: grid;
  gap: 8px;
}

.option-title {
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.check-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.check-card {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 0 10px;
  color: #475569;
  font-size: 13px;
  font-weight: 800;
}

.check-card input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--blue);
}

.check-card:has(input:disabled) {
  opacity: 0.48;
}

.inline-value {
  color: var(--blue);
  font-style: normal;
}

.print-stage {
  min-width: 0;
}

.sheet {
  width: min(100%, 794px);
  min-height: 1123px;
  margin: 0 auto;
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 36px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 2px solid #111827;
  padding-bottom: 16px;
}

.sheet-header h2 {
  font-size: 28px;
}

.sheet-header p,
.sheet-score {
  color: #475569;
  font-size: 14px;
}

.sheet-score {
  padding-top: 10px;
  white-space: nowrap;
}

.sheet-body {
  display: grid;
  grid-template-columns: repeat(var(--sheet-columns, 2), minmax(0, 1fr));
  gap: 23px 30px;
  margin-top: 26px;
}

.exercise {
  break-inside: avoid;
}

.exercise-prompt {
  min-height: 27px;
  color: #111827;
  font-size: 16px;
  font-weight: 900;
}

.answer-line {
  height: var(--preview-mizi-size);
  border-bottom: 2px solid #111827;
}

.mizi {
  position: relative;
  width: var(--preview-mizi-size);
  min-width: var(--preview-mizi-size);
  max-width: var(--preview-mizi-size);
  height: var(--preview-mizi-size);
  min-height: var(--preview-mizi-size);
  max-height: var(--preview-mizi-size);
  border: 2px solid #d14343;
  background:
    linear-gradient(45deg, transparent 49.4%, #ef9a9a 49.8%, #ef9a9a 50.2%, transparent 50.6%),
    linear-gradient(-45deg, transparent 49.4%, #ef9a9a 49.8%, #ef9a9a 50.2%, transparent 50.6%),
    linear-gradient(90deg, transparent 49.4%, #ef9a9a 49.8%, #ef9a9a 50.2%, transparent 50.6%),
    linear-gradient(0deg, transparent 49.4%, #ef9a9a 49.8%, #ef9a9a 50.2%, transparent 50.6%);
}

.mizi .ghost-char {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(17, 24, 39, 0.16);
  font-family: "KaiTi", "STKaiti", serif;
  font-size: 40px;
  line-height: 1;
}

.copy-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.hint-list {
  display: grid;
  gap: 12px;
}

.hint-item {
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  background: #ffffff;
  padding: 14px;
}

.hint-item strong {
  display: block;
  color: #065f46;
  font-size: 15px;
  margin-bottom: 6px;
}

.hint-item span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.math-sheet {
  background: #fffef9;
}

.math-body {
  display: grid;
  grid-template-columns: repeat(var(--math-columns, 4), minmax(0, 1fr));
  gap: 18px 20px;
  margin-top: 26px;
}

.math-problem {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-height: 42px;
  border-bottom: 1px dashed #cbd5e1;
  color: #111827;
  font-size: var(--math-font-size, 22px);
  font-weight: 800;
  line-height: 1.2;
  break-inside: avoid;
}

.problem-index {
  width: 28px;
  color: #64748b;
  font-size: 14px;
  font-weight: 800;
  flex: 0 0 auto;
}

.problem-equation {
  white-space: nowrap;
}

.empty-state {
  grid-column: 1 / -1;
  border: 1px dashed var(--strong-line);
  border-radius: 8px;
  padding: 36px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1100px) {
  .site-header {
    grid-template-columns: 200px 1fr;
  }

  .header-links {
    display: none;
  }

  .app-shell {
    grid-template-columns: 200px 1fr;
  }

  .resize-handle {
    display: none;
  }

  .print-stage {
    grid-column: 2;
  }
}

@media (max-width: 860px) {
  .site-header {
    grid-template-columns: 1fr;
    height: auto;
    padding: 12px 14px;
  }

  .header-search {
    display: none;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .site-sidebar {
    position: static;
    min-height: auto;
  }

  .brand-block {
    grid-template-columns: auto 1fr;
    align-items: center;
  }

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

  .print-stage {
    grid-column: auto;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .sheet-header {
    display: grid;
  }

  .settings-grid,
  .sheet-body,
  .math-body {
    grid-template-columns: 1fr;
  }

  .word-row {
    grid-template-columns: 30px 48px 1fr 44px;
  }

  .tag-cell {
    grid-column: 3 / 5;
  }
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  body {
    background: #ffffff;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  .site-header,
  .site-sidebar,
  .resize-handle,
  .workspace {
    display: none;
  }

  .app-shell {
    display: block;
    min-height: auto;
    padding: 0;
  }

  .print-stage {
    display: block;
  }

  .sheet {
    width: auto;
    min-height: auto;
    border: 0;
    padding: 0;
    box-shadow: none;
  }

  .sheet-header {
    padding-bottom: 5mm;
  }

  .sheet-header h2 {
    font-size: 20pt;
  }

  .sheet-body {
    grid-template-columns: repeat(var(--sheet-columns, 2), minmax(0, 1fr));
    gap: 6mm 8mm;
    margin-top: 7mm;
  }

  .math-body {
    grid-template-columns: repeat(var(--math-columns, 4), minmax(0, 1fr));
    gap: 7mm 8mm;
    margin-top: 8mm;
  }

  .math-problem {
    min-height: 10mm;
    border-bottom: 0.25mm dashed #94a3b8;
    font-size: var(--math-print-font-size, 13pt);
  }

  .problem-index {
    width: 7mm;
    font-size: 9pt;
  }

  .exercise {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .exercise-prompt {
    min-height: 7mm;
    margin-bottom: 2mm;
    font-size: 12pt;
  }

  .answer-line {
    height: var(--print-mizi-size);
  }

  .mizi {
    width: var(--print-mizi-size);
    min-width: var(--print-mizi-size);
    max-width: var(--print-mizi-size);
    height: var(--print-mizi-size);
    min-height: var(--print-mizi-size);
    max-height: var(--print-mizi-size);
    border-width: 0.35mm;
  }

  .mizi .ghost-char {
    font-size: 10.5mm;
  }

  .copy-row {
    gap: 2mm;
  }
}
