/* ---------- tokens ---------- */
:root {
  --cover-green: #23694a;      /* classic exercise-book cover */
  --cover-green-deep: #17462f;
  --label-paper: #fbfaf5;
  --grid-red: #c8402a;         /* seal / grid red, used sparingly */
  --ink: #21201c;
  --desk: #e9e7e0;             /* muted desk surface behind pages */
  --page-shadow: 0 2px 6px rgba(30, 40, 34, 0.18), 0 12px 32px rgba(30, 40, 34, 0.12);
  --serif: "Noto Serif SC", "Songti SC", serif;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--desk);
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

/* ---------- the green cover (controls) ---------- */
.cover {
  background:
    linear-gradient(160deg, rgba(255,255,255,0.05), rgba(0,0,0,0.10)),
    var(--cover-green);
  border-right: 6px solid var(--cover-green-deep);
  padding: 28px 22px 32px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

/* the white name-label patch every 作业本 has */
.label-patch {
  background: var(--label-paper);
  border: 1.5px solid var(--grid-red);
  outline: 4px solid var(--label-paper);
  border-radius: 2px;
  padding: 18px 16px 16px;
  text-align: center;
  margin: 6px 4px 28px;
}

.label-title {
  font-family: var(--serif);
  font-weight: 900;
  font-size: 28px;
  letter-spacing: 0.14em;
  margin: 0;
  color: var(--ink);
}

.label-sub {
  margin: 6px 0 14px;
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b675c;
}

.label-rule {
  border-bottom: 1px solid var(--grid-red);
  opacity: 0.55;
  margin: 10px 10px 0;
}
.label-rule.short { margin: 10px 34px 0; }

/* ---------- fields ---------- */
#controls { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1; }
.field-row { display: flex; gap: 12px; }

.field > label, .checks {
  color: #eef0e6;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

textarea, input[type="text"], select {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  background: var(--label-paper);
  border: 1px solid var(--cover-green-deep);
  border-radius: 3px;
  padding: 8px 9px;
  width: 100%;
}

textarea { resize: vertical; font-size: 18px; line-height: 1.5; }

textarea:focus-visible, input:focus-visible, select:focus-visible,
button:focus-visible, .check input:focus-visible {
  outline: 3px solid var(--grid-red);
  outline-offset: 1px;
}

.hint {
  margin: 0;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.75);
  font-weight: 400;
}

.checks {
  border: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  font-size: 13px;
  color: #eef0e6;
  cursor: pointer;
}
.check input { accent-color: var(--grid-red); width: 15px; height: 15px; }

.status {
  margin: 2px 0 0;
  font-size: 12px;
  min-height: 2.4em;
  color: rgba(255, 255, 255, 0.85);
}
.status.warn { color: #ffd9a8; }

.print-btn {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.06em;
  color: var(--label-paper);
  background: var(--grid-red);
  border: none;
  border-radius: 3px;
  padding: 12px;
  cursor: pointer;
  transition: filter 120ms ease;
}
.print-btn:hover { filter: brightness(1.08); }
.print-btn:active { filter: brightness(0.94); }

/* ---------- the desk / preview ---------- */
.desk {
  padding: 36px 40px;
  display: flex;
  justify-content: center;
}

#pages { display: flex; flex-direction: column; gap: 28px; }

/* ---------- the worksheet page itself ---------- */
.sheet {
  width: 216mm;
  min-height: 279mm;
  padding: 10mm 12mm;
  background: #fff;
  box-shadow: var(--page-shadow);
}

.sheet-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: baseline;
  border-bottom: 1.5px solid var(--ink);
  padding-bottom: 2mm;
  margin-bottom: 5mm;
}

.name-slot {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 12pt;
}
.name-slot .name-line {
  display: inline-block;
  width: 30mm;
  border-bottom: 1px solid var(--ink);
}

.sheet-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 14pt;
  text-align: center;
  margin: 0;
  white-space: nowrap;
}

.page-num {
  text-align: right;
  font-size: 8pt;
  color: #888;
}

/* one character's block */
.char-block { margin-bottom: 4mm; }

.guide-row {
  display: flex;
  align-items: flex-end;
  height: 8mm;
  margin-bottom: 0.6mm;
}

.pinyin {
  font-family: var(--sans);
  font-size: 9pt;
  color: var(--ink);
  align-self: flex-start;
  width: var(--cell);
  flex: none;
}

.step { width: 6.5mm; height: 6.5mm; flex: none; }
.step svg { width: 100%; height: 100%; display: block; }

.cell-row { display: flex; }
.cell { width: var(--cell); height: var(--cell); flex: none; }
.cell svg { width: 100%; height: 100%; display: block; }

.empty-note {
  padding: 60px 30px;
  text-align: center;
  color: #8a877d;
  font-size: 14px;
}

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  body { grid-template-columns: 1fr; }
  .cover { position: static; height: auto; border-right: none; border-bottom: 6px solid var(--cover-green-deep); }
  .desk { padding: 20px 8px; overflow-x: auto; justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- print ---------- */
@page { size: letter portrait; margin: 10mm 0; }

@media print {
  body { display: block; background: #fff; }
  .cover { display: none; }
  /* Forced page breaks are ignored on flex items in Chromium —
     print layout must be plain block flow. */
  .desk { display: block; padding: 0; }
  #pages { display: block; }
  .sheet {
    width: auto;
    min-height: 0;
    margin: 0;
    padding: 0 12mm;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
  }
  .sheet:last-child { break-after: auto; page-break-after: auto; }
  .char-block { break-inside: avoid; page-break-inside: avoid; }
}
