/* === 先天六十四卦笔记本 v0.3 - 无衬线 + 淡底 === */
:root {
  --paper: #faf6ec;           /* 淡米色 */
  --paper-dark: #f0ebde;
  --paper-line: #d8cfb8;
  --ink: #2b2520;
  --ink-soft: #5a4e44;
  --gray: #999999;             /* 小象传灰色 */
  --caramel: #8b4513;
  --red: #c0392b;
  --blue: #2c6fa5;
  --gold: #b8860b;
  --word-bg: rgba(255, 220, 120, 0.22);
  --word-bg-hover: rgba(255, 220, 120, 0.36);
  --shadow: 0 2px 6px rgba(60, 40, 20, 0.08);
  --shadow-lg: 0 8px 32px rgba(60, 40, 20, 0.18);
  /* 统一无衬线字体栈 */
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Heiti SC", "Hiragino Sans GB", "Source Han Sans SC", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--paper);
  height: 100%; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button, input, textarea, select {
  font-family: var(--font-sans);
}

button { cursor: pointer; }

/* === 抽屉侧栏 === */
.scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 40;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
.scrim.show { opacity: 1; pointer-events: auto; }

.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: 280px; max-width: 80vw;
  background: var(--paper-dark);
  border-right: 1px solid var(--paper-line);
  display: flex; flex-direction: column;
  z-index: 50;
  transform: translateX(-100%);
  transition: transform 0.28s ease;
  box-shadow: var(--shadow-lg);
}
.sidebar.open { transform: translateX(0); }

.sidebar-header { padding: 18px 16px 8px; border-bottom: 1px solid var(--paper-line); }
.sidebar-header h1 {
  margin: 0; font-size: 17px; font-weight: 600;
  color: var(--caramel); letter-spacing: 2px;
  text-align: center;
}

.sidebar-search { padding: 10px 14px; border-bottom: 1px solid var(--paper-line); }
#gua-search {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  background: var(--paper);
  font-size: 13px; color: var(--ink);
  outline: none;
}
#gua-search:focus { border-color: var(--caramel); }

.gua-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.gua-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; cursor: pointer;
  border-bottom: 1px solid rgba(216, 207, 184, 0.5);
  transition: background 0.15s;
}
.gua-item:hover { background: rgba(139, 69, 19, 0.06); }
.gua-item.active {
  background: rgba(139, 69, 19, 0.12);
  border-left: 3px solid var(--caramel);
  padding-left: 13px;
}

.gua-item-num { font-size: 11px; color: var(--ink-soft); width: 22px; text-align: center; font-variant-numeric: tabular-nums; }
.gua-item-name { font-size: 17px; font-weight: 600; color: var(--ink); width: 26px; text-align: center; }
.gua-item-fullname { flex: 1; font-size: 12px; color: var(--ink-soft); }

/* === 主区 === */
.main { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* === 页眉 === */
.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  background: var(--paper-dark);
  border-bottom: 1px solid var(--paper-line);
  flex-shrink: 0;
}
.t-btn {
  background: transparent;
  border: 1px solid var(--paper-line);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px; color: var(--ink);
  transition: all 0.15s;
}
.t-btn:hover { background: var(--paper); border-color: var(--caramel); }
.t-btn:active { transform: scale(0.96); }

.current-title {
  flex: 1;
  font-size: 15px; font-weight: 600;
  color: var(--caramel);
  text-align: center; letter-spacing: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0 8px;
}

.color-group {
  display: flex; gap: 6px;
  padding: 0 4px 0 8px;
  border-left: 1px solid var(--paper-line);
  margin-left: 4px;
}
.color-dot {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--paper-line);
  transition: all 0.15s;
  padding: 0;
}
.color-dot.color-red { background: var(--red); }
.color-dot.color-blue { background: var(--blue); }
.color-dot.active {
  border-color: var(--ink);
  transform: scale(1.12);
  box-shadow: 0 0 0 2px var(--paper-dark);
}

/* === 双页 === */
.spread {
  flex: 1; display: flex; overflow: hidden;
  background: var(--paper);
  background-image:
    linear-gradient(to right, rgba(139, 69, 19, 0.04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(139, 69, 19, 0.03) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* 左页：可滚动 */
.page-left {
  flex: 1;
  padding: 22px 28px 32px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  user-select: text;
  border-right: 1px solid var(--paper-line);
}

/* 右页：不滚动，超出渐变透明 */
.page-right {
  width: 380px;
  padding: 22px 22px 24px;
  display: flex; flex-direction: column; gap: 16px;
  overflow: hidden;
  background: linear-gradient(to left, rgba(240, 235, 222, 0.5), transparent 30%);
  -webkit-mask-image: linear-gradient(to bottom, black 75%, transparent 100%);
  mask-image: linear-gradient(to bottom, black 75%, transparent 100%);
}

.page-header {
  display: flex; justify-content: space-between; align-items: baseline;
  border-bottom: 1px solid var(--red);
  padding-bottom: 6px;
  margin-bottom: 14px;
}
.kicker { font-size: 11px; color: var(--ink-soft); letter-spacing: 1.5px; }
.save-status { font-size: 11px; color: var(--ink-soft); font-style: italic; }

/* === 卦名条 === */
.gua-title-bar { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.gua-badge {
  width: 56px; height: 56px;
  background: var(--red); color: #fff;
  font-size: 28px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; box-shadow: var(--shadow);
  flex-shrink: 0;
}
.gua-titles { flex: 1; }
.gua-titles h2 {
  margin: 0 0 2px;
  font-size: 24px; font-weight: 600;
  color: var(--ink); letter-spacing: 2px;
}
.pinyin { font-size: 12px; color: var(--ink-soft); font-style: italic; }
.gua-symbol { font-size: 40px; color: var(--caramel); line-height: 1; }

/* === 段落 === */
.gua-section { margin-bottom: 16px; }
.sec-label {
  font-size: 12px; color: var(--red);
  letter-spacing: 2px; margin-bottom: 6px;
  font-weight: 600;
  border-left: 3px solid var(--red);
  padding-left: 8px;
}
.sec-text {
  font-size: 15px; line-height: 1.85;
  color: var(--ink); text-indent: 2em;
  user-select: text; -webkit-user-select: text;
}
.sec-text.primary {
  font-size: 17px; font-weight: 500;
  background: rgba(255,255,255,0.4);
  padding: 8px 12px; border-radius: 4px;
}

/* === 词注解标记 === */
.word-mark {
  background: var(--word-bg);
  border-radius: 3px;
  padding: 0 2px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px dashed rgba(180, 130, 0, 0.4);
}
.word-mark:hover { background: var(--word-bg-hover); }
.word-mark.has-note { border-bottom: 1px solid rgba(180, 130, 0, 0.7); }

.word-notes { margin: 4px 0 8px 0; padding-left: 2em; }
.word-note-item {
  display: inline-flex; align-items: flex-start;
  gap: 6px;
  background: rgba(255, 220, 120, 0.10);
  padding: 4px 10px;
  border-radius: 4px;
  margin: 3px 4px 3px 0;
  font-size: 12px; line-height: 1.5;
  color: var(--ink-soft);
  border-left: 2px solid rgba(255, 180, 0, 0.5);
  cursor: pointer;
  max-width: 100%;
}
.word-note-item .wni-quote { color: var(--gold); font-weight: 600; flex-shrink: 0; }
.word-note-item .wni-text {
  flex: 1;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  -webkit-mask-image: linear-gradient(to right, black 70%, transparent 100%);
  mask-image: linear-gradient(to right, black 70%, transparent 100%);
}
.word-note-item.expanded .wni-text {
  display: block;
  -webkit-line-clamp: unset;
  -webkit-mask-image: none;
  mask-image: none;
}

.para-notes { margin-top: 6px; }
.para-note-brief {
  display: block;
  padding: 8px 12px;
  margin: 4px 0;
  background: rgba(255,255,255,0.4);
  border-left: 3px solid var(--paper-line);
  border-radius: 0 4px 4px 0;
  font-size: 13px; line-height: 1.7;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.para-note-brief.color-red { border-left-color: var(--red); }
.para-note-brief.color-blue { border-left-color: var(--blue); }
.para-note-brief:hover { background: rgba(255,255,255,0.65); }
.para-note-brief .pnb-text {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  -webkit-mask-image: linear-gradient(to right, black 60%, transparent 100%);
  mask-image: linear-gradient(to right, black 60%, transparent 100%);
}
.para-note-brief .pnb-meta {
  font-size: 10px; color: var(--ink-soft);
  margin-top: 4px; letter-spacing: 1px;
}

/* === 六爻 === */
.lines-list { margin-top: 8px; }
.line-item {
  display: flex; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--paper-line);
  align-items: flex-start;
}
.line-item:last-child { border-bottom: none; }
.line-tag {
  display: flex; flex-direction: column; align-items: center;
  min-width: 52px; padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255,255,255,0.4);
  flex-shrink: 0;
}
.line-yao {
  width: 32px; height: 14px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 4px;
}
.line-yao svg { width: 100%; height: 100%; }
.line-name {
  font-size: 12px; font-weight: 600;
  color: var(--ink); letter-spacing: 1px;
}
.line-body { flex: 1; }
.line-text {
  font-size: 14px; line-height: 1.7;
  color: var(--ink); user-select: text;
}
.line-text.selectable { cursor: text; }
.line-xiang {
  /* 小象传：灰色斜体 */
  font-size: 12px; color: var(--gray);
  line-height: 1.6; margin-top: 4px;
  font-style: italic;
  user-select: text;
}
.line-xiang.selectable { cursor: text; }

/* === 右页：上下卦 + 自定义含义 === */
.borders-block { display: flex; flex-direction: column; gap: 10px; flex-shrink: 0; }

.border-card {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.45);
  border: 1px solid var(--paper-line);
  border-radius: 8px;
}
.border-symbol { font-size: 24px; color: var(--caramel); line-height: 1; padding-top: 2px; flex-shrink: 0; }
.border-meta { flex: 1; min-width: 0; }
.border-name { font-size: 16px; font-weight: 600; color: var(--ink); line-height: 1.2; }
.border-nature { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }
.border-meaning {
  width: 100%;
  min-height: 36px;
  margin-top: 6px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: rgba(255,255,255,0.5);
  font-family: var(--font-sans);
  font-size: 12px; line-height: 1.5;
  color: var(--ink);
  resize: none;
  outline: none;
  user-select: text; -webkit-user-select: text;
  display: block;
  /* 隐藏滚动条 */
  overflow: hidden;
}
.border-meaning::placeholder { color: #c2bba8; font-style: italic; }
.border-meaning:focus { border-color: var(--caramel); background: rgba(255,255,255,0.8); overflow: auto; }

/* === 右页：卦总结 === */
.summary-block { flex-shrink: 0; }
.summary-title {
  font-size: 13px; font-weight: 600;
  color: var(--red);
  letter-spacing: 2px;
  border-left: 3px solid var(--red);
  padding-left: 8px;
  margin-bottom: 8px;
}
.summary-input {
  width: 100%;
  min-height: 100px;
  padding: 10px 12px;
  border: 1px solid var(--paper-line);
  border-radius: 6px;
  background: rgba(255,255,255,0.45);
  font-family: var(--font-sans);
  font-size: 14px; line-height: 1.7;
  color: var(--ink);
  resize: none; outline: none;
  user-select: text; -webkit-user-select: text;
}
.summary-input:focus { border-color: var(--caramel); background: rgba(255,255,255,0.7); }

/* === 右页：段注释完整版堆叠 === */
.para-detail-block { flex-shrink: 0; }
.para-detail-title {
  font-size: 13px; font-weight: 600;
  color: var(--red);
  letter-spacing: 2px;
  border-left: 3px solid var(--red);
  padding-left: 8px;
  margin-bottom: 8px;
}
.para-detail-empty {
  font-size: 12px; color: var(--ink-soft);
  text-align: center; padding: 24px 12px;
  background: rgba(255,255,255,0.3);
  border-radius: 6px;
  font-style: italic;
}
.para-detail-list { display: flex; flex-direction: column; gap: 10px; }
.para-detail-item {
  position: relative;
  padding: 10px 28px 10px 12px;
  border-radius: 6px;
  background: rgba(255,255,255,0.55);
  border-left: 4px solid var(--paper-line);
  font-size: 13px; line-height: 1.7;
  color: var(--ink);
  user-select: text;
}
.para-detail-item.color-red { border-left-color: var(--red); }
.para-detail-item.color-blue { border-left-color: var(--blue); }
.para-detail-item .pdi-quote {
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--paper-line);
  font-weight: 600;
  letter-spacing: 1px;
}
.para-detail-item .pdi-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  user-select: text; -webkit-user-select: text;
}
.para-detail-item .pdi-close {
  position: absolute;
  top: 6px; right: 8px;
  background: transparent;
  border: none;
  font-size: 16px;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
}
.para-detail-item .pdi-close:hover { color: var(--red); }

/* === 弹层 === */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--paper);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-small { max-width: 480px; }
.modal-search { max-width: 520px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--paper-line);
}
.modal-header h2 { margin: 0; font-size: 17px; color: var(--caramel); letter-spacing: 2px; }
.close-btn {
  background: transparent; border: none;
  font-size: 26px; line-height: 1;
  color: var(--ink-soft); cursor: pointer;
  padding: 0 8px;
}
.close-btn:hover { color: var(--red); }

.search-input {
  margin: 14px 20px 8px;
  padding: 10px 14px;
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  background: var(--paper);
  font-size: 15px; font-family: var(--font-sans);
  outline: none; color: var(--ink);
}
.search-input:focus { border-color: var(--caramel); }
.search-result { flex: 1; overflow-y: auto; padding: 6px 12px 14px; }
.search-hint {
  font-size: 11px; color: var(--ink-soft);
  padding: 10px 20px 14px;
  border-top: 1px solid var(--paper-line);
  line-height: 1.6;
}

.search-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--paper-line);
  cursor: pointer;
  transition: background 0.15s;
  border-radius: 6px;
}
.search-item:hover { background: rgba(139, 69, 19, 0.08); }
.search-item-num { color: var(--ink-soft); width: 22px; text-align: center; font-size: 11px; }
.search-item-name { font-size: 16px; font-weight: 600; color: var(--ink); width: 24px; text-align: center; }
.search-item-fullname { flex: 1; font-size: 13px; color: var(--ink-soft); }

.bagua-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  padding: 16px; overflow-y: auto;
}
.bagua-card {
  background: rgba(255,255,255,0.5);
  border: 1px solid var(--paper-line);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}
.bagua-card:hover { background: rgba(255,255,255,0.8); border-color: var(--caramel); }
.bagua-card .bagua-symbol { font-size: 32px; color: var(--caramel); margin-bottom: 4px; }
.bagua-card .bagua-name { font-size: 18px; font-weight: 600; color: var(--ink); }
.bagua-card .bagua-pinyin { font-size: 11px; color: var(--ink-soft); font-style: italic; }
.bagua-card .bagua-nature { font-size: 12px; color: var(--red); margin-top: 4px; }
.bagua-card .bagua-attrs { font-size: 10px; color: var(--blue); margin-top: 6px; line-height: 1.4; }

.word-quote {
  margin: 14px 20px 8px;
  padding: 10px 12px;
  background: rgba(255, 220, 120, 0.18);
  border-left: 3px solid var(--gold);
  border-radius: 0 4px 4px 0;
  font-size: 13px;
  color: var(--ink); font-weight: 500;
  user-select: text;
}
.word-note-input {
  flex: 1;
  margin: 8px 20px;
  padding: 10px 12px;
  border: 1px solid var(--paper-line);
  border-radius: 6px;
  background: var(--paper);
  font-family: var(--font-sans);
  font-size: 14px; line-height: 1.7;
  color: var(--ink);
  resize: none; outline: none;
  min-height: 140px;
  user-select: text; -webkit-user-select: text;
}
.word-note-input:focus { border-color: var(--caramel); }
.modal-actions {
  display: flex; gap: 8px;
  padding: 0 20px 16px;
  justify-content: flex-end;
}
.btn-primary, .btn-secondary {
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 14px;
  border: 1px solid var(--paper-line);
}
.btn-primary { background: var(--caramel); color: #fff; border-color: var(--caramel); }
.btn-primary:hover { background: #6d3410; }
.btn-secondary { background: transparent; color: var(--ink-soft); border-color: var(--paper-line); }
.btn-secondary:hover { background: var(--paper); }

/* === 设置弹层 === */
.settings-body { padding: 16px 20px 20px; }
.settings-section { margin-bottom: 18px; }
.settings-section:last-child { margin-bottom: 0; }
.settings-section-title {
  font-size: 13px; font-weight: 600;
  color: var(--red);
  letter-spacing: 1px;
  border-left: 3px solid var(--red);
  padding-left: 8px;
  margin-bottom: 10px;
}
.settings-hint {
  font-size: 12px; color: var(--ink-soft);
  line-height: 1.6;
  margin: 0 0 12px;
}
.settings-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.settings-status {
  margin-top: 10px;
  font-size: 12px;
  color: var(--ink-soft);
  min-height: 18px;
}
.settings-status.success { color: var(--blue); }
.settings-status.error { color: var(--red); }

/* === 移动端 === */
@media (max-width: 900px) {
  .spread { flex-direction: column; }
  .page-left {
    border-right: none;
    border-bottom: 1px solid var(--paper-line);
    padding: 18px 18px 24px;
  }
  .page-right {
    width: 100%;
    height: 320px;
    border-top: 1px solid var(--paper-line);
    padding: 16px 18px;
    -webkit-mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
  }
  .gua-title-bar { gap: 10px; }
  .gua-badge { width: 48px; height: 48px; font-size: 24px; }
  .gua-titles h2 { font-size: 20px; }
  .gua-symbol { font-size: 32px; }
  .topbar { padding: 6px 8px; gap: 4px; }
  .t-btn { padding: 5px 8px; font-size: 13px; }
  .current-title { font-size: 13px; }
  .color-dot { width: 22px; height: 22px; }
}
