:root {
  --ink: #171717;
  --muted: #68707d;
  --line: #d9dde3;
  --accent: #1f5b47;
  --accent-soft: #e8f2ed;
  --panel: #ffffff;
  --page-shadow: 0 20px 48px rgb(35 46 60 / 16%);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: #1b2430;
  background: #eef1f4;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(circle at top right, rgb(222 234 228 / 80%), transparent 32rem),
    #eef1f4;
}

button,
textarea,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  min-height: 74px;
  padding: 14px clamp(20px, 3vw, 48px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: #fff;
  background: #1c2b30;
  box-shadow: 0 2px 12px rgb(20 33 36 / 20%);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-brand strong,
.app-brand small {
  display: block;
}

.app-brand strong {
  letter-spacing: 0.04em;
  font-size: 18px;
}

.app-brand small {
  margin-top: 3px;
  color: rgb(255 255 255 / 68%);
  font-size: 12px;
}

.brand-seal {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgb(255 255 255 / 84%);
  color: #fff;
  font-family: "STKaiti", "KaiTi", "SimKai", serif;
  font-size: 30px;
  line-height: 1;
}

.local-badge {
  padding: 7px 10px;
  border: 1px solid rgb(255 255 255 / 24%);
  border-radius: 999px;
  color: rgb(255 255 255 / 80%);
  font-size: 12px;
  white-space: nowrap;
}

.app-layout {
  min-height: calc(100vh - 74px);
  display: grid;
  grid-template-columns: minmax(290px, 350px) minmax(0, 1fr);
}

.control-panel {
  padding: 24px;
  border-right: 1px solid #dce1e5;
  background: rgb(255 255 255 / 88%);
}

.panel-section + .panel-section {
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid #e7e9ed;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-heading h1,
.section-heading h2,
.preview-toolbar h2 {
  margin: 0;
  color: #202832;
  font-size: 16px;
}

.count-badge {
  padding: 3px 8px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.help-text,
.print-tip,
.status-message {
  margin: 8px 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.status-message[data-state="error"] {
  color: #ba3838;
}

.status-message[data-state="success"] {
  color: #28734e;
}

#nameInput {
  width: 100%;
  min-height: 150px;
  padding: 11px;
  resize: vertical;
  border: 1px solid #cad2d9;
  border-radius: 8px;
  outline: none;
  color: #202832;
  background: #fff;
  font-size: 15px;
  line-height: 1.65;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

#nameInput:focus,
.setting-row select:focus {
  border-color: #5b967e;
  box-shadow: 0 0 0 3px rgb(81 146 119 / 16%);
}

.file-drop {
  margin-top: 10px;
  padding: 11px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px dashed #8ba598;
  border-radius: 8px;
  color: #315e4b;
  background: #f6fbf8;
  cursor: pointer;
}

.file-drop:hover {
  background: #eff8f2;
}

.file-drop input {
  display: none;
}

.file-drop strong,
.file-drop small {
  display: block;
}

.file-drop strong {
  font-size: 13px;
}

.file-drop small {
  margin-top: 2px;
  color: #71827a;
  font-size: 11px;
}

.file-icon {
  width: 28px;
  height: 28px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #4a8970;
  font-size: 18px;
  font-weight: 700;
}

.setting-row,
.check-row {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #39434e;
  font-size: 13px;
}

.setting-row + .setting-row {
  margin-top: 7px;
}

.setting-row select {
  min-width: 112px;
  padding: 7px 26px 7px 8px;
  border: 1px solid #cbd3da;
  border-radius: 6px;
  outline: none;
  color: #26323b;
  background: #fff;
}

.check-row {
  justify-content: flex-start;
  margin-top: 10px;
  cursor: pointer;
}

.check-row input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.actions {
  display: grid;
  gap: 9px;
}

.button {
  min-height: 39px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-weight: 700;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button.primary {
  color: #fff;
  background: #246449;
  box-shadow: 0 5px 13px rgb(36 100 73 / 22%);
}

.button.primary:hover {
  background: #195239;
}

.button.secondary {
  color: #315846;
  border-color: #b9d0c2;
  background: #f8fcf9;
}

.print-tip {
  margin: 2px 0 0;
}

.preview-area {
  min-width: 0;
  padding: 24px clamp(16px, 3vw, 44px) 48px;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 210mm;
  margin: 0 auto 12px;
}

.preview-toolbar h2 {
  font-size: 18px;
}

.preview-toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.preview-actions {
  display: flex;
  gap: 7px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid #ccd4da;
  border-radius: 7px;
  color: #2d4954;
  background: #fff;
  font-size: 25px;
  line-height: 1;
}

.icon-button:hover:not(:disabled) {
  border-color: #7d9b8b;
  color: #1b5d44;
}

.icon-button:disabled {
  cursor: default;
  opacity: 0.42;
}

.student-list {
  max-width: 210mm;
  margin: 0 auto 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.student-chip {
  min-width: 40px;
  padding: 6px 10px;
  border: 1px solid #cfd6dc;
  border-radius: 999px;
  color: #53606d;
  background: #fff;
  font-size: 13px;
}

.student-chip[aria-current="true"] {
  border-color: #418365;
  color: #fff;
  background: #327458;
}

.preview-message {
  max-width: 210mm;
  margin: 0 auto 16px;
  padding: 10px 12px;
  border-radius: 7px;
  color: #946000;
  background: #fff5dc;
  font-size: 13px;
}

.pages {
  display: grid;
  justify-items: center;
}

.copybook-page {
  --writing-font: "STKaiti", "KaiTi", "SimKai", "DFKai-SB", serif;
  width: 210mm;
  min-height: 297mm;
  padding: 7mm 14mm 5mm;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--ink);
  background: #fff;
  box-shadow: var(--page-shadow);
  font-family: "SimSun", "Songti SC", serif;
}

.copybook-page.font-songti {
  --writing-font: "SimSun", "Songti SC", serif;
}

.copybook-page.font-huawenkaiti {
  --writing-font: "STKaiti", "华文楷体", "KaiTi", "SimKai", serif;
}

.copybook-page.font-xingkai {
  --writing-font: "STXingkai", "华文行楷", "FZXingKai-S04", "KaiTi", serif;
}

.copybook-page.font-fangsong {
  --writing-font: "FangSong", "仿宋", "STFangsong", serif;
}

.copybook-page.font-lishu {
  --writing-font: "LiSu", "隶书", "STLiti", serif;
}

.copybook-page.font-yuanti {
  --writing-font: "YouYuan", "幼圆", "STYuanti", sans-serif;
}

.copybook-page.font-heiti {
  --writing-font: "SimHei", "Microsoft YaHei", sans-serif;
}

.copybook-page:not(.active) {
  display: none;
}

.copybook-header {
  position: relative;
  min-height: 21mm;
}

.copybook-mark {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: flex-start;
  gap: 2mm;
}

.copybook-mark .mark-seal {
  width: 11mm;
  height: 11mm;
  display: grid;
  place-items: center;
  border: 0.35mm solid #3b3b3b;
  color: #111;
  font-family: var(--writing-font);
  font-size: 8mm;
  line-height: 1;
}

.copybook-mark strong,
.copybook-mark small {
  display: block;
  white-space: nowrap;
}

.copybook-mark strong {
  margin-top: 0.5mm;
  font-family: var(--writing-font);
  font-size: 6.5mm;
  font-weight: 400;
  line-height: 1;
}

.copybook-mark small {
  margin-top: 1.4mm;
  color: #333;
  font-family: var(--writing-font);
  font-size: 3.1mm;
}

.copybook-title {
  position: absolute;
  top: 1.2mm;
  left: 50%;
  margin: 0;
  transform: translateX(-50%);
  color: #060606;
  font-size: 13mm;
  font-weight: 500;
  letter-spacing: 1.2mm;
  line-height: 1;
  white-space: nowrap;
}

.copybook-slogan {
  position: absolute;
  right: 1mm;
  bottom: 1.5mm;
  margin: 0;
  font-family: var(--writing-font);
  font-size: 5.5mm;
  white-space: nowrap;
}

.profile {
  width: min(128mm, 100%);
  height: 47mm;
  /* margin: 0 auto; */
  display: grid;
  grid-template-columns: repeat(var(--card-count), minmax(0, 1fr));
  border-top: 0.35mm solid #141414;
  border-left: 0.35mm solid #141414;
}

.profile-card {
  min-width: 0;
  display: grid;
  grid-template-rows: 9mm 22mm 8mm 8mm;
  border-right: 0.35mm solid #141414;
  border-bottom: 0.35mm solid #141414;
}

.profile-card > * + * {
  border-top: 0.25mm solid #161616;
}

.pinyin {
  display: grid;
  place-items: center;
  overflow: hidden;
  font-family: "Times New Roman", "Microsoft YaHei", sans-serif;
  font-size: 5.5mm;
  line-height: 1;
}

.featured-grid {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.featured-grid::before,
.featured-grid::after,
.tian-cell::before,
.tian-cell::after {
  position: absolute;
  content: "";
  pointer-events: none;
}

.featured-grid::before {
  top: 0;
  bottom: 0;
  left: 50%;
  border-left: 0.26mm dashed #5d5d5d;
}

.featured-grid::after {
  top: 50%;
  right: 0;
  left: 0;
  border-top: 0.26mm dashed #5d5d5d;
}

.featured-grid span {
  position: relative;
  z-index: 1;
  font-family: var(--writing-font);
  font-size: 19mm;
  line-height: 1;
}

.character-data {
  padding: 1.5mm 1.8mm;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2mm;
  font-family: var(--writing-font);
  font-size: 3.8mm;
  white-space: nowrap;
}

.character-data .structure {
  color: #686868;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 2.3mm;
}

.without-profile .profile {
  display: none;
}

.character-drills {
  height: var(--drill-height, 75mm);
  margin-top: 4mm;
  display: grid;
  grid-template-rows: repeat(var(--drill-count), minmax(0, 1fr));
}

.practice-strip {
  min-height: 0;
  display: grid;
  grid-template-rows: 5mm minmax(0, 1fr);
}

.strip-note {
  padding: 0 2mm;
  display: flex;
  align-items: center;
  gap: 2mm;
  border: 0.32mm solid #181818;
  border-bottom: 0;
  font-family: var(--writing-font);
  font-size: 3.4mm;
  line-height: 1;
}

.strip-note strong {
  font-family: var(--writing-font);
  font-size: 4.2mm;
  font-weight: 400;
}

.strip-note .guide-data {
  color: #555;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 2.55mm;
}

.grid-line {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  border: 0.32mm solid #181818;
}

.tian-cell {
  position: relative;
  min-width: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  font-family: var(--writing-font);
  font-size: 13mm;
  line-height: 1;
}

.tian-cell + .tian-cell {
  border-left: 0.28mm solid #181818;
}

.tian-cell::before {
  top: 50%;
  right: 0;
  left: 0;
  border-top: 0.25mm dashed #555;
}

.tian-cell::after {
  top: 0;
  bottom: 0;
  left: 50%;
  border-left: 0.25mm dashed #555;
}

.tian-cell > span {
  position: relative;
  z-index: 1;
  transform: translateY(-0.3mm);
}

.tian-cell.trace > span,
.phrase-trace {
  color: #c9c9c9;
}

.compact-drills .practice-strip {
  grid-template-rows: 4mm minmax(0, 1fr);
}

.compact-drills .strip-note {
  font-size: 2.8mm;
}

.compact-drills .tian-cell {
  font-size: 10.4mm;
}

.name-practice {
  height: 60mm;
  margin-top: 5mm;
  display: grid;
  grid-template-rows: repeat(4, minmax(0, 1fr));
}

.name-practice .grid-line + .grid-line {
  border-top: 0;
}

.name-practice .tian-cell {
  font-size: 12.4mm;
}

.long-name .name-practice .tian-cell {
  font-size: 10.5mm;
}

.phrase-practice {
  height: 38mm;
  margin-top: 5mm;
  display: grid;
  grid-template-rows: repeat(4, minmax(0, 1fr));
  border: 0.32mm solid #181818;
}

.phrase-line {
  padding: 0 4mm;
  display: flex;
  align-items: center;
  gap: 7mm;
  overflow: hidden;
  font-family: var(--writing-font);
  font-size: 7.2mm;
  line-height: 1;
  white-space: nowrap;
}

.phrase-line + .phrase-line {
  border-top: 0.28mm solid #181818;
}

.long-name .phrase-line {
  font-size: 5.8mm;
}

.copybook-footer {
  min-height: 17mm;
  margin-top: auto;
  padding-top: 3mm;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8mm;
}

.footer-quote,
.footer-small {
  margin: 0;
}

.footer-quote {
  font-family: var(--writing-font);
  font-size: 4.8mm;
  line-height: 1.2;
}

.footer-quote strong {
  display: block;
  margin-top: 1mm;
  font-family: "Microsoft YaHei", sans-serif;
  font-size: 5.6mm;
  font-weight: 500;
}

.footer-small {
  max-width: 70mm;
  color: #323232;
  font-family: var(--writing-font);
  font-size: 3.4mm;
  line-height: 1.55;
  text-align: right;
}

.footer-seal {
  width: 11mm;
  height: 11mm;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border: 0.35mm solid #1c1c1c;
  font-family: var(--writing-font);
  font-size: 7mm;
}

@media (max-width: 980px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    border-right: 0;
    border-bottom: 1px solid #dce1e5;
  }
}

@media (max-width: 700px) {
  .app-header {
    align-items: flex-start;
  }

  .local-badge {
    display: none;
  }

  .preview-area {
    padding-inline: 10px;
  }

  .pages {
    justify-items: start;
    overflow-x: auto;
  }

  .copybook-page {
    flex: 0 0 auto;
  }
}

@page {
  size: A4 portrait;
  margin: 0;
}

@media print {
  html,
  body {
    width: 210mm;
    margin: 0;
    background: #fff;
  }

  .app-header,
  .control-panel,
  .preview-toolbar,
  .student-list,
  .preview-message {
    display: none !important;
  }

  .app-layout,
  .preview-area,
  .pages {
    display: block;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  .copybook-page,
  .copybook-page:not(.active) {
    width: 210mm;
    min-height: 297mm;
    display: flex !important;
    margin: 0;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
  }

  .copybook-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }
}
