@font-face {
  font-family: "Tibetan Uchen";
  src: url("./noto-serif-tibetan-regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0F00-0FFF, U+25CC;
}

@font-face {
  font-family: "Tibetan Ume";
  src: url("./Qomolangma-Tsutong.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0F00-0FFF, U+25CC;
}

@font-face {
  font-family: "Pinyin Step";
  src: url("./vendor/pinyin-font/pinyin-step.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "Pinyin Regular";
  src: url("./vendor/pinyin-font/pinyin-regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: light;
  --canvas: #e9e2d5;
  --panel: #f7f3ea;
  --paper: #fffefb;
  --ink: #27231f;
  --muted: #7b7165;
  --soft: #a89c8d;
  --line: #d8ccba;
  --line-soft: #e7ded1;
  --accent: #a54b35;
  --accent-strong: #823724;
  --accent-soft: #f1ddd4;
  --gold: #b08540;
  --shadow: 0 20px 50px rgba(66, 48, 30, 0.14);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

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

button {
  color: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  min-height: 100vh;
}

.controls {
  position: sticky;
  top: 0;
  align-self: start;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 28px 24px 32px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), transparent 26%),
    var(--panel);
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 27px;
}

.brand-mark {
  display: grid;
  width: 49px;
  height: 49px;
  flex: none;
  overflow: hidden;
  background: #ffffff;
  border-radius: 15px 15px 15px 5px;
  box-shadow: 0 8px 18px rgba(165, 75, 53, 0.22);
  place-items: center;
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.kicker {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.kicker[lang="bo"] {
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 12px;
  letter-spacing: 0;
}

.brand h1,
.preview-toolbar h2 {
  margin: 0;
  font-family: "Songti SC", SimSun, serif;
  letter-spacing: 0.035em;
}

.brand h1 {
  font-size: 25px;
}

.subject-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: -6px 0 20px;
  padding: 5px;
  background: rgba(255, 254, 251, 0.62);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.subject-tab {
  display: grid;
  min-width: 0;
  min-height: 54px;
  padding: 6px 3px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  place-items: center;
}

.subject-tab span {
  font-family: "Tibetan Uchen", "Times New Roman", "Microsoft Himalaya", serif;
  font-size: 18px;
  line-height: 1.05;
}

.subject-tab strong {
  margin-top: 3px;
  font-size: 10px;
}

.subject-tab:hover {
  color: var(--accent);
  background: #fffaf5;
}

.subject-tab.is-active {
  color: var(--accent-strong);
  background: #ffffff;
  border-color: #d8b7a8;
  box-shadow: 0 4px 12px rgba(89, 61, 35, 0.08);
}

.subject-tab:focus-visible {
  outline: 3px solid rgba(165, 75, 53, 0.17);
  outline-offset: 1px;
}

.control-group {
  padding: 20px 0;
  border-top: 1px solid var(--line-soft);
}

.control-group--text {
  padding-top: 0;
  border-top: 0;
}

.content-mode-group {
  display: grid;
  gap: 8px;
  padding-top: 0;
  border-top: 0;
}

.content-mode-switch {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
  gap: 4px;
  padding: 4px;
  background: rgba(255, 254, 251, 0.64);
  border: 1px solid var(--line);
  border-radius: 11px;
}

.content-mode-switch button {
  min-height: 34px;
  padding: 4px 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.content-mode-switch button:hover {
  color: var(--accent);
}

.content-mode-switch button.is-active {
  color: var(--accent-strong);
  background: var(--paper);
  border-color: #d8b7a8;
  box-shadow: 0 3px 9px rgba(89, 61, 35, 0.08);
}

.content-mode-switch button:focus-visible {
  outline: 3px solid rgba(165, 75, 53, 0.17);
  outline-offset: 1px;
}

.label-row,
.range-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}

.label-row label,
.range-row label,
.field-label,
fieldset legend {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.label-row span,
.range-row output,
.mini-output {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.mini-output {
  display: block;
  margin-top: 7px;
}

textarea {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  padding: 14px;
  color: var(--ink);
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 26px;
  line-height: 1.7;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: 0;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

textarea:focus,
select:focus-visible,
input[type="range"]:focus-visible,
input[type="color"]:focus-visible,
.choice-card:has(input:focus-visible),
.switch-row:has(input:focus-visible),
.text-button:focus-visible,
.letter-key:focus-visible,
.print-button:focus-visible,
summary:focus-visible {
  border-color: var(--accent);
  outline: 3px solid rgba(165, 75, 53, 0.17);
  outline-offset: 2px;
}

textarea[lang="en"] {
  font-family: "Pinyin Regular", "Times New Roman", Georgia, serif;
  font-size: 30px;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.text-button {
  padding: 6px 9px;
  color: var(--muted);
  font-size: 11px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: 140ms ease;
}

.text-button:hover {
  color: var(--accent);
  background: var(--paper);
  border-color: #caa695;
}

.letter-picker {
  margin-top: 10px;
  background: rgba(255, 254, 251, 0.52);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
}

.letter-picker summary {
  padding: 9px 11px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.letter-picker summary::-webkit-details-marker {
  display: none;
}

.letter-picker summary::after {
  float: right;
  color: var(--accent);
  content: "＋";
}

.letter-picker[open] summary::after {
  content: "－";
}

.letter-picker-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
  padding: 0 9px 10px;
}

.letter-key {
  display: grid;
  aspect-ratio: 1;
  padding: 0;
  color: var(--ink);
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 18px;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  cursor: pointer;
  place-items: center;
}

.letter-key:hover {
  color: var(--accent);
  border-color: #caa695;
}

.study-button {
  display: flex;
  width: 100%;
  min-height: 58px;
  align-items: center;
  gap: 11px;
  margin-top: 10px;
  padding: 9px 12px;
  text-align: left;
  background: #fff9f3;
  border: 1px solid #d9b9aa;
  border-radius: 12px;
  cursor: pointer;
  transition: 150ms ease;
}

.study-button:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.study-button:focus-visible {
  outline: 3px solid rgba(165, 75, 53, 0.17);
  outline-offset: 2px;
}

.study-mark {
  display: grid;
  width: 35px;
  height: 35px;
  flex: none;
  color: #fff9f0;
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 23px;
  line-height: 1;
  background: var(--accent);
  border-radius: 9px;
  place-items: center;
}

.study-button strong,
.study-button small {
  display: block;
}

.study-button strong {
  font-size: 12px;
}

.study-button small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

fieldset legend {
  margin-bottom: 10px;
}

.choice-grid {
  display: grid;
  gap: 8px;
}

.choice-grid--font {
  grid-template-columns: repeat(2, 1fr);
}

.choice-card {
  position: relative;
  cursor: pointer;
}

.choice-card input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.choice-content {
  display: flex;
  min-height: 69px;
  align-items: center;
  gap: 9px;
  padding: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: 140ms ease;
}

.choice-card:hover .choice-content {
  border-color: #c5ad96;
}

.choice-card input:checked + .choice-content {
  background: #fff9f4;
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.choice-card--disabled {
  cursor: not-allowed;
}

.choice-card--disabled .choice-content {
  opacity: 0.58;
}

.font-sample {
  display: grid;
  width: 38px;
  height: 43px;
  flex: none;
  font-size: 33px;
  line-height: 1;
  place-items: center;
}

.font-sample--uchen,
[data-font="uchen"] .tibetan-text,
[data-font="uchen"] .cell-glyph,
[data-font="uchen"] .continuous-glyph {
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
}

.font-sample--ume,
[data-font="ume"] .tibetan-text,
[data-font="ume"] .cell-glyph,
[data-font="ume"] .continuous-glyph {
  font-family: "Tibetan Ume", "Microsoft Himalaya", serif;
  font-weight: 400;
}

.choice-content strong,
.choice-content small {
  display: block;
}

.choice-content strong {
  font-size: 12px;
}

.choice-content small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.35;
}

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

select {
  width: 100%;
  height: 38px;
  margin-top: 7px;
  padding: 0 30px 0 10px;
  color: var(--ink);
  background-color: var(--paper);
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: 0;
  cursor: pointer;
}

input[type="range"] {
  width: 100%;
  height: 5px;
  margin: 4px 0;
  background: #d8cbbb;
  border-radius: 999px;
  outline: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

.field-help {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.color-columns {
  align-items: end;
}

.color-input {
  display: flex;
  height: 38px;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
  padding: 5px 10px 5px 6px;
  color: var(--muted);
  font-size: 11px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 9px;
}

input[type="color"] {
  width: 27px;
  height: 27px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 6px;
}

.switch-group {
  display: grid;
  gap: 10px;
}

.switch-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}

.switch-row input {
  width: 17px;
  height: 17px;
  flex: none;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.switch-row strong,
.switch-row small {
  display: block;
}

.switch-row strong {
  font-size: 12px;
}

.switch-row small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
}

.print-button {
  display: flex;
  width: 100%;
  height: 48px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 4px;
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  background: var(--accent);
  border: 0;
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(165, 75, 53, 0.21);
  cursor: pointer;
  transition: 150ms ease;
}

.print-button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.print-icon {
  position: relative;
  width: 16px;
  height: 13px;
  border: 1.8px solid currentColor;
  border-radius: 2px;
}

.print-icon::before {
  position: absolute;
  top: -5px;
  left: 3px;
  width: 7px;
  height: 5px;
  border: 1.8px solid currentColor;
  border-bottom: 0;
  content: "";
}

.print-icon::after {
  position: absolute;
  right: 3px;
  bottom: 2px;
  width: 2px;
  height: 2px;
  background: currentColor;
  border-radius: 50%;
  content: "";
}

.stroke-note {
  margin: 14px 0 0;
  color: var(--soft);
  font-size: 9px;
  line-height: 1.65;
}

.writing-standard {
  margin-top: 12px;
  color: var(--muted);
  background: rgba(255, 254, 251, 0.58);
  border: 1px solid var(--line-soft);
  border-radius: 11px;
}

.writing-standard summary {
  padding: 10px 12px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}

.writing-standard summary::-webkit-details-marker {
  display: none;
}

.writing-standard summary::after {
  float: right;
  color: var(--accent);
  content: "＋";
}

.writing-standard[open] summary::after {
  content: "－";
}

.writing-standard-body {
  padding: 0 12px 11px;
  font-size: 10px;
  line-height: 1.55;
}

.writing-standard-body p {
  margin: 7px 0;
}

.writing-standard-body strong {
  color: var(--accent-strong);
}

.standard-source {
  padding-top: 7px;
  border-top: 1px dashed var(--line);
}

.standard-source a {
  color: var(--accent);
  text-underline-offset: 2px;
}

body:has(dialog[open]) {
  overflow: hidden;
}

.stroke-dialog,
.image-dialog {
  width: min(980px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 26px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 30px 90px rgba(46, 34, 22, 0.28);
}

.stroke-dialog::backdrop,
.image-dialog::backdrop {
  background: rgba(35, 28, 21, 0.62);
  backdrop-filter: blur(4px);
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.dialog-heading h2 {
  margin: 0;
  font-family: "Songti SC", SimSun, serif;
  font-size: 25px;
}

.dialog-subtitle {
  margin: 5px 0 0;
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 21px;
  line-height: 1.4;
}

.dialog-close {
  display: grid;
  width: 34px;
  height: 34px;
  flex: none;
  padding: 0 0 2px;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  place-items: center;
}

.dialog-close:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.dialog-tip {
  margin: 18px 0;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  background: rgba(255, 254, 251, 0.7);
  border-left: 3px solid var(--gold);
  border-radius: 0 8px 8px 0;
}

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

.stroke-card {
  min-width: 0;
  padding: 8px;
  text-align: left;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 13px;
  cursor: zoom-in;
  transition: 150ms ease;
}

.stroke-card:hover {
  border-color: var(--accent);
  box-shadow: 0 10px 25px rgba(80, 56, 34, 0.1);
  transform: translateY(-2px);
}

.stroke-card img {
  display: block;
  width: 100%;
  aspect-ratio: 0.87;
  object-fit: contain;
  background: #ffffff;
  border-radius: 8px;
}

.stroke-card span {
  display: block;
  padding: 10px 3px 3px;
}

.stroke-card strong,
.stroke-card small {
  display: block;
}

.stroke-card strong {
  font-size: 12px;
}

.stroke-card small {
  margin-top: 4px;
  color: var(--muted);
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 15px;
  line-height: 1.6;
}

.image-dialog {
  width: min(900px, calc(100vw - 20px));
  max-height: calc(100vh - 20px);
  padding: 12px;
  background: #ffffff;
}

.image-dialog img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 44px);
  object-fit: contain;
}

.image-dialog-close {
  position: absolute;
  z-index: 2;
  top: 9px;
  right: 9px;
  background: rgba(255, 255, 255, 0.9);
}

[data-focus-unit] {
  cursor: zoom-in;
}

.focus-dialog {
  width: min(540px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  margin: auto;
  padding: 24px;
  color: var(--ink);
  text-align: center;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 30px 90px rgba(46, 34, 22, 0.3);
}

.focus-dialog::backdrop {
  background: rgba(35, 28, 21, 0.58);
  backdrop-filter: blur(4px);
}

.focus-kicker {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.focus-dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.focus-board {
  position: relative;
  width: min(430px, 78vw);
  aspect-ratio: 1;
  overflow: hidden;
  margin: 0 auto;
  background: #fff;
  border: 1px solid #8aa2be;
}

.focus-guides {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.focus-guides line {
  stroke: #8aa2be;
  stroke-width: 0.7;
  vector-effect: non-scaling-stroke;
}

.focus-guides .center-line {
  stroke-dasharray: 3 3;
  opacity: 0.72;
}

.focus-guides .descender-line {
  opacity: 0.7;
}

.focus-glyph {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  color: var(--ink);
  line-height: 1;
  white-space: nowrap;
  transform: translate(-50%, -50%);
}

.focus-board.subject-tibetan .focus-glyph,
.focus-board.subject-pinyin .focus-glyph {
  top: 58%;
}

.focus-caption {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.input-dialog {
  width: min(680px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  margin: auto;
  padding: 26px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 30px 90px rgba(46, 34, 22, 0.3);
}

.input-dialog::backdrop {
  background: rgba(35, 28, 21, 0.58);
  backdrop-filter: blur(4px);
}

.input-dialog h2 {
  margin: 5px 0 5px;
  font-family: "Songti SC", SimSun, serif;
  font-size: 26px;
}

.input-dialog-help {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 11px;
}

.input-dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.input-dialog textarea {
  min-height: 210px;
  margin-top: 13px;
  font-size: 31px;
}

.input-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.syllable-palette {
  display: grid;
  max-height: 250px;
  gap: 12px;
  overflow: auto;
  padding: 12px;
  background: #f4f8f6;
  border: 1px solid #d9e5e0;
  border-radius: 13px;
}

.syllable-group-title {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
}

.syllable-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.syllable-chip {
  min-width: 38px;
  height: 31px;
  padding: 3px 9px;
  color: var(--ink);
  font-family: "Pinyin Regular", "Times New Roman", serif;
  font-size: 15px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.syllable-chip:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.preview-area {
  min-width: 0;
  padding: 26px 34px 30px;
}

.preview-toolbar {
  display: flex;
  width: min(100%, 840px);
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin: 0 auto 18px;
}

.preview-toolbar h2 {
  font-size: 23px;
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.toolbar-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 17px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.toolbar-button--primary {
  min-width: 92px;
  color: #fff;
  background: #20252b;
  border-color: #20252b;
}

.toolbar-button:hover {
  border-color: var(--accent);
}

.save-icon {
  position: relative;
  width: 13px;
  height: 14px;
  border: 1.7px solid currentColor;
  border-top: 0;
}

.save-icon::before {
  position: absolute;
  top: -4px;
  left: 3px;
  width: 5px;
  height: 7px;
  border-right: 1.7px solid currentColor;
  border-bottom: 1.7px solid currentColor;
  content: "";
  transform: rotate(45deg);
}

.save-dialog {
  width: min(480px, calc(100vw - 24px));
  margin: auto;
  padding: 28px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 30px 90px rgba(46, 34, 22, 0.3);
}

.save-dialog::backdrop {
  background: rgba(35, 28, 21, 0.58);
  backdrop-filter: blur(4px);
}

.save-dialog h2 {
  margin: 5px 0 4px;
  font-family: "Songti SC", SimSun, serif;
  font-size: 26px;
}

.save-dialog > p:not(.kicker) {
  margin: 0 0 17px;
  color: var(--muted);
  font-size: 11px;
}

.save-dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

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

.save-format-grid button {
  min-height: 84px;
  padding: 14px;
  color: var(--ink);
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 13px;
  cursor: pointer;
}

.save-format-grid button:hover {
  border-color: var(--accent);
  box-shadow: 0 7px 18px rgba(90, 57, 35, 0.08);
}

.save-format-grid strong,
.save-format-grid small {
  display: block;
}

.save-format-grid small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 9px;
}

.export-toast {
  position: fixed;
  z-index: 100000;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 16px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.55;
  background: #20252b;
  border-radius: 12px;
  box-shadow: 0 14px 35px rgba(25, 30, 33, 0.26);
}

.export-toast.is-error {
  background: var(--accent-strong);
}

.export-toast.is-success {
  background: #267860;
}

.preview-status {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 11px;
  background: rgba(247, 243, 234, 0.62);
  border: 1px solid rgba(199, 186, 168, 0.9);
  border-radius: 999px;
}

.status-dot {
  width: 6px;
  height: 6px;
  background: #5e8b6b;
  border-radius: 50%;
}

.separator {
  color: #c2b6a5;
}

.preview-scroll {
  max-height: calc(100vh - 135px);
  overflow: auto;
  padding: 4px 8px 45px;
  scrollbar-color: #b9aa96 transparent;
  scrollbar-width: thin;
}

.pages {
  display: grid;
  justify-content: center;
  gap: 28px;
}

.sheet {
  --trace-color: #cf6f5a;
  --guide-color: #b7aa98;
  --row-height: 26mm;
  --glyph-size: 18.72mm;
  position: relative;
  width: 210mm;
  min-height: 297mm;
  padding: 14mm 16mm 12mm;
  color: #24201c;
  background:
    linear-gradient(rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.2)),
    var(--paper);
  box-shadow: var(--shadow);
  break-after: page;
  page-break-after: always;
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}

.sheet:last-child {
  break-after: auto;
  page-break-after: auto;
}

.sheet.subject-tibetan {
  background:
    radial-gradient(circle at 92% 8%, rgba(202, 76, 53, 0.045), transparent 18%),
    radial-gradient(circle at 8% 92%, rgba(49, 91, 168, 0.04), transparent 20%),
    var(--paper);
}

.sheet.subject-tibetan::before {
  position: absolute;
  inset: 5.5mm;
  border: 0.22mm solid rgba(149, 67, 48, 0.2);
  border-radius: 2mm;
  content: "";
  pointer-events: none;
}

.sheet.subject-tibetan::after {
  position: absolute;
  right: 16mm;
  bottom: 12mm;
  color: rgba(149, 67, 48, 0.2);
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 10pt;
  content: "༄༅། །";
  pointer-events: none;
}

.sheet-header {
  display: flex;
  min-height: 20mm;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10mm;
  padding-bottom: 4mm;
  border-bottom: 1px solid rgba(115, 100, 82, 0.22);
}

.sheet-title {
  display: flex;
  align-items: center;
  gap: 4mm;
}

.sheet-logo {
  display: block;
  width: 13mm;
  height: 13mm;
  flex: none;
  object-fit: contain;
}

.sheet-ornament {
  color: var(--accent);
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 20pt;
  line-height: 1;
}

.sheet-ornament:not(.is-tibetan) {
  min-width: 9mm;
  font-family: "Songti SC", SimSun, serif;
  font-size: 16pt;
  font-weight: 700;
  text-align: center;
}

.sheet-title h3 {
  margin: 0;
  font-family: "Songti SC", SimSun, serif;
  font-size: 20pt;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.02em;
}

.sheet-heading.is-tibetan {
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-weight: 400;
}

.sheet-title p {
  margin: 1.2mm 0 0;
  color: #8a7e70;
  line-height: 1.2;
}

.sheet-subtitle > span {
  display: block;
}

.sheet-subtitle [lang="bo"] {
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-size: 9.5pt;
  letter-spacing: 0;
}

.subtitle-cn {
  margin-top: 0.8mm;
  font-size: 7pt;
  letter-spacing: 0.08em;
}

.sheet-meta {
  display: flex;
  gap: 7mm;
  padding-top: 2mm;
  color: #675e54;
  font-size: 9pt;
  white-space: nowrap;
}

.meta-line {
  display: flex;
  min-width: 36mm;
  align-items: flex-end;
  gap: 1.5mm;
  padding-bottom: 1mm;
  border-bottom: 1px solid #9e9182;
}

.meta-line b {
  font-size: 11pt;
  font-weight: 700;
  line-height: 1;
}

.meta-label.is-tibetan {
  font-family: "Tibetan Uchen", "Microsoft Himalaya", serif;
  font-weight: 400;
}

.sheet-content {
  padding-top: 5mm;
}

.practice-row {
  position: relative;
  margin-bottom: var(--row-gap, 3mm);
}

.grid-row {
  display: grid;
  height: var(--row-height);
  grid-template-columns: repeat(var(--cells), minmax(0, 1fr));
  border-top: 1px solid var(--guide-medium);
  border-bottom: 1px solid var(--guide-medium);
}

.continuous-row {
  position: relative;
  height: var(--row-height);
  margin-bottom: 3mm;
  overflow: hidden;
}

.continuous-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.continuous-svg .continuous-guide {
  stroke: var(--guide-color);
  stroke-width: 0.9;
  vector-effect: non-scaling-stroke;
}

.continuous-svg .continuous-guide.main-guide {
  stroke-width: 1;
}

.continuous-svg .pinyin-inner-guide {
  stroke-dasharray: 3 3;
  opacity: 0.62;
}

.continuous-glyph {
  fill: #28231e;
  font-family: var(--practice-font, "Tibetan Uchen", "Microsoft Himalaya", serif);
  font-size: var(--row-glyph-size, var(--glyph-size));
  font-style: var(--practice-font-style, normal);
  font-weight: var(--practice-font-weight, 400);
  letter-spacing: 0;
}

.subject-pinyin .continuous-glyph {
  font-family: "Pinyin Step", "Times New Roman", Georgia, serif;
  font-weight: 400;
}

.continuous-glyph.trace {
  fill: var(--trace-color);
  opacity: 0.28;
}

.continuous-glyph.hidden {
  opacity: 0;
}

.pinyin-stroke-marker {
  fill: var(--trace-color);
  font-family: "Times New Roman", Georgia, serif;
  font-size: 6.5pt;
  letter-spacing: 0.04em;
  opacity: 0.72;
}

.subject-numbers .continuous-glyph {
  font-family: "Arial Rounded MT Bold", "Arial", sans-serif;
}

.sentence-row {
  isolation: isolate;
}

.sentence-role {
  position: absolute;
  z-index: 2;
  top: 0.8mm;
  right: 1.8mm;
  color: var(--trace-color);
  font-size: 6pt;
  font-weight: 800;
  letter-spacing: 0.08em;
  opacity: 0.58;
  pointer-events: none;
}

.sentence-blank .sentence-role {
  opacity: 0.36;
}

.stroke-study-block {
  margin-bottom: calc(var(--row-gap, 3mm) + 1mm);
  break-inside: avoid;
  page-break-inside: avoid;
}

.chinese-stroke-block {
  margin-bottom: calc(var(--row-gap, 3mm) + 1mm);
  break-inside: avoid;
  page-break-inside: avoid;
}

.tibetan-stroke-block {
  margin-bottom: calc(var(--row-gap, 3mm) + 1mm);
  break-inside: avoid;
  page-break-inside: avoid;
}

.tibetan-stroke-reference {
  display: block;
  width: 15mm;
  height: 15mm;
  margin: 0 0 1.5mm;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid var(--trace-soft);
  border-radius: 1.5mm;
}

.tibetan-stroke-reference img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.tibetan-stroke-block > .practice-row {
  margin-bottom: 0;
}

.hanzi-stroke-demo {
  display: flex;
  min-height: 12mm;
  align-items: center;
  gap: 4mm;
  padding: 1mm 3mm;
  background: var(--paper);
  border: 1px solid var(--guide-soft);
}

.hanzi-stroke-progress {
  display: flex;
  min-width: 0;
  max-width: calc(100% - 10mm);
  align-items: center;
  align-content: center;
  flex-wrap: wrap;
  gap: 0.8mm;
}

.hanzi-stroke-stage {
  display: block;
  width: 8mm;
  height: 8mm;
  flex: 0 0 8mm;
}

.hanzi-stage-path {
  stroke: none;
}

.hanzi-stage-path.is-previous {
  fill: #30343a;
}

.hanzi-stage-path.is-current {
  fill: var(--stroke-guide-color, #c94f3f);
}

.hanzi-stroke-fallback {
  color: var(--stroke-guide-color, #c94f3f);
  font-family: "KaiTi", "STKaiti", "Kaiti SC", serif;
  font-size: 11pt;
  font-weight: 700;
}

.hanzi-complete-glyph {
  margin-left: 1mm;
  color: var(--ink);
  font-family: "KaiTi", "STKaiti", "Kaiti SC", serif;
  font-size: 17pt;
  line-height: 1;
}

.hanzi-pinyin-strip {
  position: relative;
  display: grid;
  height: calc(var(--cell-size, 10mm) * 0.45);
  min-height: 7mm;
  grid-template-columns: repeat(var(--cells), minmax(0, 1fr));
  align-items: center;
  background: var(--paper);
  border: 1px solid var(--guide-soft);
  border-top: 0;
}

.hanzi-pinyin-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.hanzi-pinyin-lines line {
  stroke: var(--guide-medium);
  stroke-width: 0.8;
  vector-effect: non-scaling-stroke;
}

.hanzi-pinyin-lines line.is-dashed {
  stroke-dasharray: 3 3;
  opacity: 0.58;
}

.hanzi-pinyin-copy {
  position: relative;
  z-index: 1;
  overflow: hidden;
  padding: 0 0.5mm;
  color: #4c4c4c;
  font-family: "Times New Roman", Georgia, serif;
  font-size: calc(var(--cell-size, 10mm) * 0.3);
  line-height: 1;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hanzi-pinyin-copy.is-first {
  color: #1f1f1f;
  font-weight: 700;
}

.chinese-stroke-block > .practice-row {
  margin-bottom: 0;
}

.stroke-teaching-row {
  display: grid;
  min-height: 20mm;
  grid-template-columns: minmax(28mm, 0.9fr) minmax(0, 2.6fr);
  gap: 2.5mm;
  margin-bottom: 1.2mm;
}

.stroke-preview-card {
  display: grid;
  min-width: 0;
  grid-template-columns: 21mm minmax(0, 1fr);
  align-items: center;
  gap: 2mm;
  padding: 1.4mm 2mm;
  background: var(--trace-wash);
  border: 1px solid var(--trace-soft);
  border-radius: 2mm;
}

.stroke-preview-art {
  display: grid;
  min-width: 0;
  height: 17mm;
  place-items: center;
}

.stroke-preview-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.stroke-preview-meta {
  min-width: 0;
  color: var(--stroke-guide-color, #c94f3f);
  font-size: 7pt;
  font-weight: 800;
  line-height: 1.45;
  word-break: break-word;
}

.hanzi-stroke-letter,
.pinyin-stroke-letter {
  color: var(--stroke-guide-color, #c94f3f);
  font-family: "KaiTi", "STKaiti", "Kaiti SC", serif;
  font-size: 18mm;
  font-weight: 400;
  line-height: 1;
}

.pinyin-stroke-letter {
  font-family: "Times New Roman", Georgia, serif;
  font-weight: 700;
}

.stroke-steps {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  padding: 1.5mm 2mm;
  background: var(--guide-soft);
  border: 1px solid var(--guide-soft);
  border-radius: 2mm;
}

.stroke-steps-title {
  margin: 0 0 1.3mm;
  color: var(--muted);
  font-size: 6.5pt;
  font-weight: 700;
}

.stroke-step-list {
  display: flex;
  flex-wrap: wrap;
  gap: 1mm 1.6mm;
}

.stroke-step {
  display: inline-flex;
  min-height: 6.5mm;
  align-items: center;
  gap: 1mm;
  padding: 0.6mm 1.3mm 0.6mm 0.7mm;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--guide-soft);
  border-radius: 999px;
  white-space: nowrap;
}

.stroke-step b {
  display: grid;
  width: 4.6mm;
  height: 4.6mm;
  color: #fff;
  font-size: 6pt;
  line-height: 1;
  background: var(--stroke-guide-color, #c94f3f);
  border-radius: 50%;
  place-items: center;
}

.stroke-step strong {
  color: var(--stroke-guide-color, #c94f3f);
  font-family: "KaiTi", "STKaiti", "Kaiti SC", serif;
  font-size: 11pt;
  font-weight: 700;
  line-height: 1;
}

.stroke-step small,
.stroke-note-inline {
  color: var(--muted);
  font-size: 7pt;
  line-height: 1.35;
}

.stroke-study-block > .practice-row {
  margin-bottom: 0;
}

.grid-cell {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border-right: 1px solid var(--guide-medium);
}

.grid-cell:first-child {
  border-left: 1px solid var(--guide-medium);
}

.grid-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.grid-svg line {
  stroke: var(--guide-color);
  stroke-width: 0.8;
  vector-effect: non-scaling-stroke;
}

.grid-svg .main-guide {
  stroke-width: 1;
}

.grid-svg .secondary-guide {
  stroke-dasharray: 2 2;
  opacity: 0.62;
}

.grid-type-tian .grid-row,
.grid-type-mi .grid-row,
.grid-type-num-square .grid-row {
  border-color: var(--guide-color);
}

.grid-type-tian .grid-cell,
.grid-type-mi .grid-cell,
.grid-type-num-square .grid-cell {
  border-color: var(--guide-strong);
}

.grid-type-square .grid-row {
  border-color: var(--guide-color);
}

.grid-type-square .grid-cell {
  border-color: var(--guide-strong);
}

.grid-type-baseline .grid-row {
  border-top-color: transparent;
  border-bottom-color: transparent;
}

.grid-type-baseline .grid-cell {
  border-right-color: transparent;
}

.grid-type-baseline .grid-cell:first-child {
  border-left-color: transparent;
}

.grid-type-none .grid-row {
  border-color: transparent;
}

.grid-type-none .grid-cell,
.grid-type-none .grid-cell:first-child {
  border-color: transparent;
}

.cell-glyph {
  position: absolute;
  inset: 0;
  display: grid;
  color: #28231e;
  font-family: var(--practice-font, "Tibetan Uchen", "Microsoft Himalaya", serif);
  font-size: var(--row-glyph-size, var(--glyph-size));
  font-style: var(--practice-font-style, normal);
  font-weight: var(--practice-font-weight, 400);
  line-height: 1;
  transform: translateY(calc(-2.5% + var(--glyph-offset, 0%)));
  pointer-events: none;
  place-items: center;
  white-space: nowrap;
}

.cell-glyph.trace {
  color: var(--trace-color);
  opacity: 0.27;
}

.cell-glyph.hidden {
  visibility: hidden;
}

.number-half-glyph {
  right: 50%;
}

.stroke-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.stroke-svg path {
  fill: none;
  stroke: var(--trace-color);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.28;
  vector-effect: non-scaling-stroke;
}

.stroke-svg.solid path,
.stroke-svg.solid circle {
  opacity: 0.72;
}

.stroke-svg circle {
  fill: var(--trace-color);
  opacity: 0.45;
}

.sheet-footer {
  position: absolute;
  right: 16mm;
  bottom: 8mm;
  left: 16mm;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #a09587;
  font-size: 7pt;
  letter-spacing: 0.03em;
}

.page-number {
  font-variant-numeric: tabular-nums;
}

.empty-state {
  display: grid;
  min-height: 130mm;
  color: var(--muted);
  text-align: center;
  place-items: center;
}

.empty-state strong {
  display: block;
  margin-bottom: 7px;
  color: var(--ink);
  font-family: "Songti SC", SimSun, serif;
  font-size: 18pt;
}

.preview-footer {
  display: flex;
  width: min(100%, 840px);
  justify-content: space-between;
  gap: 20px;
  margin: 13px auto 0;
  color: var(--muted);
  font-size: 10px;
}

.preview-footer p {
  margin: 0;
}

@media (max-width: 980px) {
  body {
    overflow-x: hidden;
  }

  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    max-width: 100vw;
    overflow-x: hidden;
  }

  .controls {
    position: static;
    height: auto;
    width: 100%;
    max-width: 100vw;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .preview-area {
    padding: 22px 16px 30px;
  }

  .preview-scroll {
    max-height: none;
  }

  .pages {
    justify-content: start;
  }
}

@media (max-width: 620px) {
  .controls {
    overflow-x: hidden;
    padding: 22px 16px 28px;
  }

  .subject-tabs,
  .content-mode-switch,
  .two-column,
  .control-group,
  textarea,
  select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .two-column {
    grid-template-columns: 1fr;
  }

  .preview-toolbar,
  .preview-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .preview-actions {
    width: 100%;
    margin-left: 0;
  }

  .toolbar-button {
    flex: 1;
  }

  .preview-scroll {
    padding-bottom: 20px;
  }

  .letter-picker-grid {
    grid-template-columns: repeat(6, 1fr);
  }

  .stroke-dialog {
    width: calc(100vw - 16px);
    padding: 18px;
  }

  .stroke-gallery {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  html,
  body {
    width: 210mm;
    margin: 0;
    padding: 0;
    background: #ffffff;
  }

  .controls,
  .preview-toolbar,
  .preview-footer,
  .stroke-dialog,
  .image-dialog {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .preview-area {
    padding: 0;
  }

  .preview-scroll {
    max-height: none;
    overflow: visible;
    padding: 0;
  }

  .pages {
    display: block;
    padding: 0;
  }

  .sheet {
    margin: 0;
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
