:root,
body[data-theme="paper"] {
  --bg: #efe7d6;
  --bg-deep: #e4d8c0;
  --paper: #faf6ec;
  --ink: #2a241c;
  --muted: #6d6458;
  --line: #d8ccb4;
  --seal: #b5442f;
  --seal-soft: #f3d2c8;
  --ok: #2f6b4f;
  --ok-soft: #d9ebe1;
  --warn: #9a3b2f;
  --shadow: 0 18px 40px rgba(70, 48, 24, 0.12);
  --zone-1: #c45c26;
  --zone-2: #2f6b8a;
  --zone-3: #7a4ea3;
  --zone-4: #2f7a4a;
  --zone-5: #a63d5c;
  --sans: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  --serif: "STSong", "SimSun", "Noto Serif SC", serif;
  --mono: "Cascadia Mono", "Consolas", "Courier New", monospace;
}

body[data-theme="ink"] {
  --bg: #14110e;
  --bg-deep: #1c1814;
  --paper: #221d18;
  --ink: #f3eadb;
  --muted: #b3a793;
  --line: #3a3229;
  --seal: #e07a5f;
  --seal-soft: #3b241d;
  --ok: #7dcea0;
  --ok-soft: #24352c;
  --warn: #f0a090;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
}

#app {
  width: min(1280px, calc(100% - 24px));
  height: 100vh;
  margin: 0 auto;
  padding: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  background: transparent;
}

#app[hidden],
.page-view[hidden] {
  display: none;
}

.topbar,
.board,
.dock {
  background: var(--paper);
  border: 1px solid var(--line);
}

.dialog-card {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  border-radius: 14px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 148px;
}

.brand strong {
  display: block;
  font-size: 16px;
}

.brand small {
  color: var(--muted);
}

.seal {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--seal);
  color: #fff8ee;
  font-family: var(--serif);
  font-size: 20px;
}

.mode-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
}

.nav-btn,
.icon-btn,
.chip,
.primary-btn,
.ghost-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.nav-btn.is-active,
.chip.is-active,
.primary-btn {
  background: var(--seal);
  border-color: var(--seal);
  color: #fff8ee;
}

.icon-btn:hover,
.chip:hover,
.nav-btn:hover,
.ghost-btn:hover {
  border-color: var(--seal);
}

.top-actions {
  display: flex;
  gap: 8px;
}

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: transparent;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  padding: 0;
  border: none;
  box-shadow: none;
  background: transparent;
  overflow-x: auto;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.tool-split {
  width: 1px;
  height: 22px;
  background: var(--line);
  flex-shrink: 0;
}

.tool-label {
  color: var(--muted);
  font-size: 13px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.article-select {
  min-width: 180px;
  max-width: 260px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}

.article-select-category {
  min-width: 118px;
  max-width: 150px;
}

.article-select:disabled {
  opacity: 0.7;
  cursor: default;
}

.board {
  flex: 1;
  min-height: 0;
  padding: 10px 12px;
  border-radius: 16px;
  text-align: left;
  display: flex;
  flex-direction: column;
}

.prompt {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.article-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 6px;
  flex-shrink: 0;
}

.article-head h2 {
  margin: 0;
  font-size: 16px;
}

.article-head p {
  margin: 4px 0 0;
}

.legend {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.legend .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.legend .dot.match { background: var(--ok); }
.legend .dot.differ { background: var(--warn); }
.legend .dot.current { background: var(--seal); }

.compare-board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 4px;
  overflow: auto;
  padding: 6px 2px;
  border-top: 1px dashed var(--line);
}

.compare-break {
  flex-basis: 100%;
  height: 10px;
}

.compare-cell {
  width: 42px;
  min-height: 68px;
  padding: 4px 2px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  border: 1px solid transparent;
}

.cell-source {
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.1;
}

.cell-code {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--ink);
  max-width: 100%;
  text-align: center;
  line-height: 1.2;
  word-break: break-word;
}

body[data-practice="pinyin"] .compare-cell {
  width: 58px;
}

body[data-practice="pinyin"] .cell-code,
body[data-practice="pinyin"] .hint-code {
  text-transform: none;
  letter-spacing: 0;
}

.cell-code.is-fade {
  color: #b7ad9c;
}

.cell-code.is-empty {
  min-height: 14px;
}

.cell-typed {
  min-height: 22px;
  font-size: 18px;
  line-height: 1.1;
}

.compare-cell.is-match {
  background: var(--ok-soft);
}

.compare-cell.is-match .cell-typed {
  color: var(--ok);
}

.compare-cell.is-differ {
  background: color-mix(in srgb, var(--warn) 12%, var(--paper));
}

.compare-cell.is-differ .cell-typed {
  color: var(--warn);
}

.compare-cell.is-current {
  background: var(--seal-soft);
  border-color: var(--seal);
}

.compare-cell.is-extra {
  border-color: var(--warn);
}

.dock {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  border-radius: 14px;
  flex-shrink: 0;
}

.current-hint {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 180px;
}

.hint-char {
  font-family: var(--serif);
  font-size: 24px;
  line-height: 1;
}

.hint-code {
  font-family: var(--mono);
  font-size: 18px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--seal);
}

.hint-code.is-fade,
.hint-roots.is-fade {
  opacity: 0.45;
}

.hint-roots {
  display: inline-flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px;
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1;
}

.hint-plus {
  color: var(--muted);
  font-size: 14px;
}

.hint-root {
  min-width: 1em;
}

.hint-id {
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}

.input-park {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.compare-cell .cell-typed {
  width: 100%;
  display: flex;
  justify-content: center;
}

.follow-caret {
  display: block;
  width: 100%;
  min-width: 28px;
  height: 22px;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: 18px/1.1 var(--serif);
  text-align: center;
  caret-color: var(--seal);
  outline: none;
}

.compare-cell.is-current .follow-caret {
  box-shadow: 0 2px 0 var(--seal);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(70px, 1fr));
  flex: 1;
  border: none;
  box-shadow: none;
  background: transparent;
}

.metric {
  padding: 4px 8px;
  text-align: center;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: none;
}

.metric b {
  display: block;
  font-size: 18px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.keyboard-body {
  padding-top: 4px;
}

.dialog-wide {
  width: min(980px, 100%);
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}

.kb-row.row-1 {
  padding-left: 22px;
}

.kb-row.row-2 {
  padding-left: 56px;
}

.kb-key {
  width: 86px;
  min-height: 72px;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 88%, white);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.kb-letter {
  font-family: var(--mono);
  font-size: 16px;
}

.kb-name {
  font-family: var(--serif);
  font-size: 18px;
}

.kb-roots {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 1px;
}

.kb-key.zone-1 { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--zone-1) 45%, transparent); }
.kb-key.zone-2 { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--zone-2) 45%, transparent); }
.kb-key.zone-3 { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--zone-3) 45%, transparent); }
.kb-key.zone-4 { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--zone-4) 45%, transparent); }
.kb-key.zone-5 { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--zone-5) 45%, transparent); }

.kb-key.is-next {
  transform: translateY(-3px);
  background: var(--seal-soft);
  border-color: var(--seal);
}

.kb-key.is-typed {
  background: var(--ok-soft);
}

.dialog {
  position: fixed;
  inset: 0;
  background: rgba(28, 22, 16, 0.35);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}

.dialog[hidden] {
  display: none;
}

.dialog-card {
  width: min(680px, 100%);
  max-height: 84vh;
  overflow: auto;
  border-radius: 18px;
}

.dialog-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px 0;
}

.dialog-body {
  padding: 8px 20px 20px;
  line-height: 1.7;
}

.dialog-body table {
  width: 100%;
  border-collapse: collapse;
}

.dialog-body th,
.dialog-body td {
  border-bottom: 1px solid var(--line);
  padding: 6px 4px;
  text-align: left;
}

.settings-body {
  display: grid;
  gap: 12px;
}

.settings-about {
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.settings-about-version,
.settings-about-notes {
  margin: 0;
  color: var(--muted);
}

.settings-about-notes {
  margin-top: 6px;
  padding-left: 1.2em;
}

.settings-about-notes li + li {
  margin-top: 2px;
}

.check-line {
  display: flex;
  gap: 8px;
  align-items: center;
}

.page-view {
  width: min(1400px, calc(100% - 24px));
  height: 100vh;
  margin: 0 auto;
  padding: 10px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  background: transparent;
}

.page-view .topbar {
  justify-content: space-between;
}

.articles-stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(240px, 300px) 1fr;
  gap: 12px;
}

.article-side,
.article-form {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 16px;
}

.article-editor-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

.article-library {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.article-lib {
  list-style: none;
  padding: 6px;
  margin: 0;
  display: grid;
  gap: 4px;
}

.article-lib-item {
  width: 100%;
  display: grid;
  gap: 2px;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.article-lib-item:hover,
.article-lib-item.is-active {
  background: var(--bg);
  border-color: var(--line);
}

.article-lib-title {
  display: grid;
  gap: 2px;
}

.article-lib-title small {
  color: var(--muted);
  font-size: 12px;
}

.article-lib-meta {
  color: var(--muted);
  font-size: 12px;
}

.article-form-head {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  flex-shrink: 0;
}

.article-lib-empty {
  margin: 0;
  padding: 16px 12px;
}

.field-line {
  display: grid;
  gap: 6px;
}

.field-line input,
.field-line select,
.field-line textarea {
  width: 100%;
  min-width: 0;
  max-width: none;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}

.field-caption {
  display: block;
  line-height: 1.4;
}

.field-text {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-text textarea {
  flex: 1;
  min-height: 0;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  resize: none;
  line-height: 1.7;
}

.article-form-foot {
  display: grid;
  gap: 6px;
  flex-shrink: 0;
}

.article-form-actions {
  display: flex;
  gap: 8px;
}

@media (max-width: 860px) {
  .articles-stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(180px, 28vh) 1fr;
  }

  .article-form-head {
    grid-template-columns: 1fr;
  }
}

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

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.weak-list {
  list-style: none;
  padding: 0;
  display: grid;
  gap: 6px;
}

.weak-list li {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 4px;
}

.muted {
  color: var(--muted);
}

.done-card,
.empty-card {
  padding: 24px 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--paper);
  padding: 8px 14px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
}

.toast.is-on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
  }

  .metrics {
    grid-template-columns: repeat(3, 1fr);
  }

  .kb-key {
    width: 58px;
    min-height: 58px;
  }

  .kb-roots {
    display: none;
  }

  .passage-card {
    font-size: 22px;
  }
}
