@font-face {
  font-family: "ErjianziFont";
  src: url("erjianzi.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

:root {
  --bg-page: #f8f7f4;
  --bg-card: #ffffff;
  --border-color: #e2dfd7;
  --border-focus: #8c8577;
  --text-main: #1d1c1a;
  --text-muted: #6e6a63;
  --font-serif: "ErjianziFont", "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", serif;
  --font-sans: "ErjianziFont", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.page-wrap {
  max-width: 960px;
  margin: 2.5rem auto 4rem;
  padding: 0 1.5rem;
}

/* Top Controls Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.toggle-group {
  display: inline-flex;
  background: #ebe8e1;
  padding: 3px;
  border-radius: 8px;
}

.toggle-btn {
  border: none;
  background: transparent;
  padding: 0.42rem 0.9rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.toggle-btn.active {
  background: var(--bg-card);
  color: var(--text-main);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* Three Rows Stack */
.rows-stack {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.tier-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.row-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding-left: 0.15rem;
}

.row-box {
  width: 100%;
  min-height: 120px;
  padding: 1rem 1.15rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  font-size: 2.1rem;
  line-height: 1.7;
  letter-spacing: 0.02em;
  color: var(--text-main);
  word-break: break-word;
  white-space: pre-wrap;
}

body.font-serif .row-box,
body.font-serif .cjk-cell {
  font-family: var(--font-serif);
}

body.font-sans .row-box,
body.font-sans .cjk-cell {
  font-family: var(--font-sans);
}

.input-box {
  resize: vertical;
  outline: none;
  transition: border-color 0.15s ease;
}

.input-box:focus {
  border-color: var(--border-focus);
}

/* Character List Section Below */
.list-section {
  margin-top: 2.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
}

.list-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.list-search {
  flex: 1;
  min-width: 220px;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-card);
  font-size: 0.9rem;
  color: var(--text-main);
  outline: none;
}

.list-search:focus,
.list-select:focus {
  border-color: var(--border-focus);
}

.list-select {
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-card);
  font-size: 0.9rem;
  color: var(--text-main);
  outline: none;
  cursor: pointer;
}

.list-count {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.list-table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
}

.char-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.char-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  background: #f2efe9;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
}

.char-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid #efece6;
  vertical-align: middle;
}

.char-table tbody tr:last-child td {
  border-bottom: none;
}

.char-table tbody tr:hover {
  background: #fbfaf7;
  cursor: pointer;
}

.ref-cell {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.cjk-cell {
  font-size: 1.75rem;
  line-height: 1.25;
}

.pron-cell {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.details-cell {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.derived-pairs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
}

.derived-pair {
  display: inline-flex;
  align-items: baseline;
  gap: 0.2rem;
  color: var(--text-main);
}

.derived-pair .arrow {
  font-size: 0.75rem;
  color: var(--text-muted);
}
