:root {
  --ink: #1a1a1a;
  --muted: #666;
  --line: #e5e5e5;
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --accent: #8b4513;
  --accent-soft: #f0e6d8;
  --radius: 12px;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 24px 20px;
  overflow-y: auto;
}

.panel h1 {
  margin: 0 0 6px;
  font-size: 1.35rem;
  color: var(--accent);
}

.hint {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

.license-box {
  margin: 0 0 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.license-status {
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--ink);
}

.license-status.ok {
  color: #2f6b3a;
}

.license-status.warn {
  color: #8a5a00;
}

.license-status.err {
  color: #9b2c2c;
}

.license-form {
  margin-top: 10px;
}

.license-form label {
  margin-top: 0;
}

.license-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.license-row input {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.04em;
}

.license-row button {
  flex-shrink: 0;
  white-space: nowrap;
}

.license-tip {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

label {
  display: block;
  margin: 12px 0 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="text"],
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
}

input:focus,
textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

textarea { resize: vertical; line-height: 1.5; }

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin: 14px 0 4px;
}

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--ink);
  font-size: 0.92rem;
  cursor: pointer;
}

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

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.95rem;
  cursor: pointer;
  font-family: inherit;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.ghost { background: transparent; }
button:hover { filter: brightness(0.97); }

.suggest-wrap {
  position: relative;
  margin-bottom: 4px;
}

.suggest-box {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 40;
  max-height: 260px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  padding: 4px;
}

.suggest-box[hidden] {
  display: none !important;
}

.suggest-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
}

.suggest-item:hover,
.suggest-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.suggest-item .sg-title {
  font-weight: 600;
  line-height: 1.3;
}

.suggest-item .sg-meta {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 400;
}

.suggest-item.active .sg-meta {
  color: var(--accent);
}

.suggest-empty {
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.library { margin-top: 28px; }
.library h2 {
  font-size: 0.95rem;
  margin: 0 0 10px;
  color: var(--muted);
  font-weight: 600;
}

.match-picker {
  margin-bottom: 18px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--accent);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.match-picker-title {
  margin: 0 0 4px;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.match-picker button {
  text-align: left;
  padding: 8px 12px;
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
  font-size: 0.9rem;
}

.match-picker button:hover {
  background: var(--accent);
  color: #fff;
}

.quick-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-list button {
  padding: 6px 10px;
  font-size: 0.85rem;
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

.preview-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 28px 20px 48px;
  overflow: auto;
}

.sheet {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
  padding: 18mm 16mm 16mm;
  color: #111;
}

.sheet.empty {
  display: flex;
  align-items: center;
  justify-content: center;
}

.placeholder {
  color: #999;
  font-size: 1.05rem;
}

.poem-header {
  text-align: center;
  margin-bottom: 22px;
  border-bottom: 1px solid #ddd;
  padding-bottom: 14px;
}

.poem-title {
  font-size: 2rem;
  font-weight: 700;
  margin: 0 0 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 4px;
}

.poem-title .title-han {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "华文楷体", serif;
}

.poem-meta {
  margin: 0;
  color: #444;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 4px;
}

.poem-meta .meta-han {
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "华文楷体", serif;
  color: #444;
}

.poem-meta .meta-sep {
  min-width: 0.9em;
  margin: 0 2px;
}

.poem-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  margin-top: 28px;
}

.line {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 4px;
}

.char-cell {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 1.6em;
}

.pinyin {
  font-size: 0.72rem;
  color: #555;
  line-height: 1.2;
  font-family: "Segoe UI", "Arial", sans-serif;
  white-space: nowrap;
  min-height: 1.1em;
}

.han {
  font-size: 1.7rem;
  line-height: 1.35;
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "华文楷体", serif;
}

.sheet.large .han { font-size: 2.2rem; }
.sheet.large .pinyin { font-size: 0.85rem; }
.sheet.large .poem-title .title-han { font-size: 2.4rem; }
.sheet.large .poem-meta .meta-han { font-size: 1.25rem; }
.sheet.large .line { gap: 4px 8px; }
.sheet.large .poem-body { gap: 26px; }

.sheet.hide-pinyin .pinyin { display: none; }

.poem-notes {
  margin-top: 32px;
  padding-top: 18px;
  border-top: 1px dashed #ccc;
  max-width: 36em;
  margin-left: auto;
  margin-right: auto;
  text-align: left;
}

.notes-heading {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.12em;
}

.notes-heading + .notes-heading,
.gloss-list + .notes-heading {
  margin-top: 16px;
}

.gloss-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.gloss-list li {
  font-size: 0.95rem;
  line-height: 1.55;
  color: #333;
}

.gloss-word {
  font-weight: 700;
  color: var(--ink);
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "华文楷体", serif;
}

.gloss-mean {
  color: #444;
}

.notes-explain {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.75;
  color: #333;
  text-align: justify;
}

.sheet.hide-notes .poem-notes {
  display: none;
}

.sheet.large .notes-heading { font-size: 1.1rem; }
.sheet.large .gloss-list li,
.sheet.large .notes-explain { font-size: 1.05rem; }

.footer-note {
  margin-top: 36px;
  text-align: center;
  color: #999;
  font-size: 0.8rem;
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .panel { border-right: none; border-bottom: 1px solid var(--line); }
  .sheet {
    width: 100%;
    min-height: auto;
    padding: 28px 18px;
  }
}

@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .app { display: block; }
  .preview-wrap { padding: 0; }
  .sheet {
    width: 100%;
    min-height: auto;
    box-shadow: none;
    padding: 12mm 14mm;
  }
  @page {
    size: A4;
    margin: 10mm;
  }
}
