/* 行箸 Web · 水墨宣纸「研墨」风格 */

:root {
  --paper: #f6f1e3;
  --paper-deep: #ece5d1;
  --ink: #2a2a2a;
  --ink-secondary: #6e6a5e;
  --tone-mark: #8c8678;
  --rhyme: #b03a2e;
  --seal: #7a2e1b;
  --tone-level: #3e6b8a;
  --tone-level-bg: rgba(62, 107, 138, 0.10);
  --rhyme-bg: rgba(176, 58, 46, 0.10);
  --tone-unknown-bg: rgba(140, 134, 120, 0.10);
  --line: rgba(42, 42, 42, 0.12);
  --card: #fbf8ef;
  --card-hover: #fffdf6;
  --shadow-sm: 0 1px 2px rgba(42, 42, 42, 0.06), 0 2px 8px rgba(42, 42, 42, 0.05);
  --shadow-md: 0 6px 22px rgba(42, 42, 42, 0.10);
  --radius: 14px;
  --radius-sm: 10px;
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", Georgia, serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--serif);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 12% 18%, rgba(122, 46, 27, 0.035), transparent 42%),
    radial-gradient(circle at 88% 8%, rgba(62, 107, 138, 0.04), transparent 38%),
    radial-gradient(circle at 50% 120%, rgba(140, 134, 120, 0.05), transparent 55%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }

/* ── 顶部导航 ─────────────────────────────────────── */

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(246, 241, 227, 0.88);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-seal {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: var(--seal);
  color: var(--paper);
  border-radius: 8px;
  font-size: 20px;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(246, 241, 227, 0.25);
}

.brand-name { font-size: 22px; font-weight: 700; letter-spacing: 2px; }
.brand-sub { font-size: 13px; color: var(--ink-secondary); letter-spacing: 1px; }

.app-nav { display: flex; gap: 6px; }
.app-nav a {
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 15px;
  color: var(--ink-secondary);
  transition: background .18s, color .18s;
}
.app-nav a:hover { background: rgba(122, 46, 27, 0.07); color: var(--seal); }
.app-nav a.active { background: var(--seal); color: var(--paper); }

/* ── 主体 ─────────────────────────────────────────── */

.view {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}

.app-footer {
  border-top: 1px solid var(--line);
  padding: 18px 24px 28px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-secondary);
}
.app-footer a { color: var(--seal); text-decoration: underline; text-underline-offset: 3px; }

.offline-status {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink-secondary);
  background: var(--paper-deep);
}
.offline-status.ready { color: var(--seal); background: rgba(122, 46, 27, 0.10); }

/* ── 通用组件 ─────────────────────────────────────── */

.icon { display: block; flex: none; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px; height: 38px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-secondary);
  cursor: pointer;
  transition: background .18s, color .18s;
}
.icon-btn:hover { background: rgba(122, 46, 27, 0.08); color: var(--seal); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  font-family: var(--serif);
  font-size: 15px;
  color: var(--ink);
  cursor: pointer;
  transition: background .18s, color .18s, border-color .18s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--seal); color: var(--paper); }
.btn-primary:hover { background: #632414; }
.btn-soft { background: var(--paper-deep); color: var(--seal); }
.btn-soft:hover, .btn-soft.active { background: rgba(122, 46, 27, 0.16); }
.btn-outline { border-color: var(--seal); color: var(--seal); }
.btn-outline:hover { background: rgba(122, 46, 27, 0.08); }
.btn-ghost { color: var(--ink-secondary); border-color: var(--line); }
.btn-ghost:hover { background: rgba(42, 42, 42, 0.05); }
.btn-danger { background: var(--rhyme); color: #fff; }
.btn-danger:hover { background: #96301f; }
.btn-text { color: var(--ink-secondary); padding: 6px 8px; }
.btn-text:hover { color: var(--seal); }
.btn-block { width: 100%; }

/* 下拉菜单 */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  min-width: 210px;
  background: var(--card-hover);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 6px;
  display: none;
  z-index: 60;
}
.dropdown-menu.align-right { right: 0; }
.dropdown-menu.align-left { left: 0; }
.dropdown-menu.show { display: block; animation: pop .16s ease; }
.dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-family: var(--serif);
  font-size: 15px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.dropdown-item:hover { background: rgba(122, 46, 27, 0.08); }
.dropdown-item.selected { color: var(--seal); font-weight: 600; }
.dropdown-divider { height: 1px; margin: 6px 4px; background: var(--line); }

@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* 提示 */
#toast-root {
  position: fixed;
  right: 24px; bottom: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}
.toast {
  padding: 11px 18px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .22s, transform .22s;
  max-width: 340px;
}
.toast.show { opacity: 1; transform: none; }

/* 模态 */
.modal-overlay {
  position: fixed; inset: 0;
  z-index: 90;
  background: rgba(42, 42, 42, 0.32);
  display: grid; place-items: center;
  opacity: 0;
  transition: opacity .18s;
}
.modal-overlay.show { opacity: 1; }
.modal {
  width: min(420px, calc(100vw - 40px));
  background: var(--card-hover);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-md);
  transform: translateY(8px) scale(.98);
  transition: transform .18s;
}
.modal-overlay.show .modal { transform: none; }
.modal-title { margin: 0 0 10px; font-size: 20px; }
.modal-text { margin: 0 0 22px; color: var(--ink-secondary); line-height: 1.7; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* 加载 */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(122, 46, 27, 0.25);
  border-top-color: var(--seal);
  border-radius: 50%;
  display: inline-block;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hint-box {
  display: grid;
  place-items: center;
  min-height: 240px;
  color: var(--ink-secondary);
  text-align: center;
  padding: 40px 20px;
}
.hint-box p { margin: 0; font-size: 16px; }

.boot-screen {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
}
.boot-mark { font-size: 40px; font-weight: 700; letter-spacing: 8px; color: var(--seal); }
.boot-status { display: flex; align-items: center; gap: 10px; color: var(--ink-secondary); }
.boot-error { max-width: 560px; color: var(--rhyme); line-height: 1.9; white-space: pre-line; text-align: center; }

/* ── 书架 ─────────────────────────────────────────── */

.library-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.toolbar-count { color: var(--ink-secondary); font-size: 15px; }
.toolbar-actions { display: flex; gap: 10px; align-items: center; }

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

.poem-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 20px 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform .16s, box-shadow .16s, border-color .16s, background .16s;
}
.poem-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: rgba(176, 58, 46, 0.35);
  background: var(--card-hover);
}
.poem-card:focus-visible { outline: 2px solid var(--seal); outline-offset: 2px; }
.poem-card-main { flex: 1; min-width: 0; }
.poem-card-title { margin: 0 0 8px; font-size: 20px; font-weight: 600; line-height: 1.4; }
.poem-card-meta { margin: 0; font-size: 14px; color: var(--ink-secondary); }
.card-delete { opacity: 0; transition: opacity .16s; color: var(--ink-secondary); }
.poem-card:hover .card-delete, .poem-card:focus-within .card-delete { opacity: 1; }
.card-delete:hover { color: var(--rhyme); background: rgba(176, 58, 46, 0.10); }

.author-groups { display: flex; flex-direction: column; gap: 8px; }
.author-header {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 6px;
  border: none;
  background: transparent;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  color: var(--seal);
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.author-header:hover { color: var(--rhyme); }
.author-chevron { display: inline-flex; transition: transform .18s; transform: rotate(-90deg); }
.author-chevron.open { transform: rotate(0); }
.author-count { margin-left: auto; font-size: 13px; font-weight: 400; color: var(--ink-secondary); }
.author-group { margin-bottom: 14px; }
.author-group .library-grid { margin-top: 14px; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 52vh;
  gap: 8px;
  text-align: center;
}
.empty-mark {
  width: 78px; height: 78px;
  display: grid; place-items: center;
  border: 1.5px solid var(--seal);
  border-radius: 14px;
  color: var(--seal);
  font-size: 40px;
  margin-bottom: 12px;
}
.empty-title { margin: 0; font-size: 22px; }
.empty-sub { margin: 0 0 20px; color: var(--ink-secondary); }

/* ── 添加诗词 ─────────────────────────────────────── */

.add-head { margin-bottom: 18px; }
.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: var(--card-hover);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  transition: border-color .18s, box-shadow .18s;
}
.search-box:focus-within {
  border-color: var(--seal);
  box-shadow: 0 0 0 4px rgba(122, 46, 27, 0.08);
}
.search-box .icon { color: var(--ink-secondary); }
.search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink);
}
.corpus-status {
  margin: 12px 4px 0;
  font-size: 13px;
  color: var(--ink-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-error { color: var(--rhyme); }

.results-meta {
  margin: 10px 4px 0;
  font-size: 13px;
  color: var(--ink-secondary);
}
.load-more { display: flex; justify-content: center; padding: 16px 0 6px; }
.load-more .btn { min-width: 200px; }
.load-more-sentinel { height: 1px; }

.result-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.result-card {
  padding: 18px 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.result-title { margin: 0 0 6px; font-size: 19px; font-weight: 600; }
.result-meta { margin: 0 0 10px; font-size: 14px; color: var(--ink-secondary); }
.result-content {
  margin: 0;
  font-size: 15px;
  line-height: 1.9;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-all;
}
.result-content.is-snippet { color: var(--ink-secondary); }
.result-content mark {
  background: rgba(176, 58, 46, 0.16);
  color: var(--rhyme);
  font-weight: 700;
  border-radius: 3px;
  padding: 0 1px;
}
.result-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}
.tag-in-library { color: var(--rhyme); font-size: 14px; font-weight: 600; }

/* ── 阅读页 ───────────────────────────────────────── */

.reader-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.reader-topbar-right { display: flex; gap: 6px; }

.reader-article {
  max-width: 880px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 40px clamp(20px, 5vw, 60px) 48px;
}
.reader-header {
  text-align: center;
  padding-bottom: 26px;
  margin-bottom: 26px;
  border-bottom: 1px solid var(--line);
}
.reader-title { margin: 0 0 10px; font-size: clamp(26px, 4vw, 34px); font-weight: 700; letter-spacing: 2px; }
.reader-meta { margin: 0; color: var(--ink-secondary); font-size: 15px; letter-spacing: 1px; }

/* 平仄 / 韵脚 */
.poem-body { display: flex; flex-direction: column; gap: 22px; }
.poem-line { display: flex; flex-wrap: wrap; align-items: flex-start; row-gap: 4px; }
.poem-char { display: inline-flex; flex-direction: column; align-items: center; }

.tone-badge {
  width: var(--badge-size, 18px);
  height: var(--badge-size, 18px);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tone-level { background: var(--tone-level-bg); }
.tone-oblique { background: var(--rhyme-bg); }
.tone-unknown { background: var(--tone-unknown-bg); }
.tone-spacer { background: transparent; }
.tone-dot { display: block; border-radius: 50%; }
.tone-dot.is-level {
  width: 58%; height: 58%;
  border: 2px solid var(--tone-level);
  box-sizing: border-box;
}
.tone-dot.is-oblique { width: 52%; height: 52%; background: var(--rhyme); }
.tone-glyph { line-height: 1; font-weight: 700; }
.tone-level .tone-glyph { color: var(--tone-level); }
.tone-oblique .tone-glyph { color: var(--rhyme); }
.tone-unknown .tone-glyph { color: var(--ink-secondary); }

.char {
  font-family: var(--serif);
  color: var(--ink);
  font-weight: 500;
  line-height: 1.35;
  padding: 0 1px;
}
.char.rhymed {
  border: 1.5px solid var(--rhyme);
  border-radius: 50%;
  padding: 1px 6px;
}
.rhyme-label {
  color: var(--rhyme);
  margin-left: 10px;
  white-space: nowrap;
  align-self: flex-start;
  font-weight: 600;
}

.poem-line-issue {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--rhyme-bg);
  border-radius: 10px;
  padding: 8px 12px;
  flex-wrap: wrap;
}
.issue-warn { color: var(--rhyme); font-weight: 700; }

.reader-notes {
  margin-top: 34px;
  padding-top: 22px;
  border-top: 1px dashed var(--line);
  color: var(--ink-secondary);
  font-size: 14px;
}
.notes-title { margin: 16px 0 8px; font-size: 15px; color: var(--rhyme); }
.note { margin: 4px 0; line-height: 1.7; }

.plain-poem { display: flex; flex-direction: column; gap: 12px; }
.plain-line { margin: 0; font-weight: 500; }

/* 平仄图例 */
.tone-legend { display: flex; flex-direction: column; gap: 8px; }
.legend-title { font-size: 13px; color: var(--ink-secondary); }
.legend-row { display: flex; flex-wrap: wrap; gap: 16px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-label { font-size: 13px; color: var(--ink-secondary); }
.legend-note { font-size: 13px; line-height: 1.7; }

/* 设置抽屉 */
.settings-scrim {
  position: fixed; inset: 0;
  background: rgba(42, 42, 42, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s;
  z-index: 70;
}
.settings-scrim.show { opacity: 1; pointer-events: auto; }
.settings-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(360px, 90vw);
  background: var(--card-hover);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 30px rgba(42, 42, 42, 0.12);
  transform: translateX(102%);
  transition: transform .26s cubic-bezier(.2, .8, .2, 1);
  z-index: 80;
  overflow-y: auto;
}
.settings-drawer.open { transform: none; }
.settings-panel { padding: 22px 24px 40px; display: flex; flex-direction: column; gap: 6px; }
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.settings-head h3 { margin: 0; font-size: 20px; color: var(--seal); }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  font-size: 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.setting-label { margin-top: 16px; font-size: 15px; }
.setting-value { font-size: 13px; color: var(--ink-secondary); }

.switch {
  appearance: none;
  width: 46px; height: 26px;
  border-radius: 999px;
  background: rgba(140, 134, 120, 0.35);
  position: relative;
  cursor: pointer;
  transition: background .2s;
  flex: none;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .2s;
}
.switch:checked { background: var(--seal); }
.switch:checked::after { transform: translateX(20px); }

.chip-row { display: flex; gap: 10px; margin-top: 10px; }
.chip {
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-family: var(--serif);
  font-size: 15px;
  color: var(--ink);
  cursor: pointer;
  transition: all .18s;
}
.chip.selected { background: var(--seal); color: var(--paper); border-color: var(--seal); }

.slider {
  width: 100%;
  margin: 10px 0 4px;
  accent-color: var(--seal);
}
.settings-legend {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px dashed var(--line);
}

/* ── 习作检测 ─────────────────────────────────────── */

.check-card {
  max-width: 820px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 28px clamp(20px, 4vw, 36px);
}
.check-heading { margin: 0 0 8px; font-size: 24px; color: var(--seal); }
.check-hint { margin: 0 0 18px; font-size: 14px; color: var(--ink-secondary); line-height: 1.8; }
.check-input {
  width: 100%;
  resize: vertical;
  min-height: 150px;
  padding: 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.9;
  color: var(--ink);
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
.check-input:focus { border-color: var(--seal); box-shadow: 0 0 0 4px rgba(122, 46, 27, 0.08); }
.check-card .btn-block { margin-top: 16px; }

.check-result { max-width: 820px; margin: 20px auto 0; }
.check-output {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 28px clamp(20px, 4vw, 36px);
}
.check-form { margin: 0 0 22px; color: var(--ink-secondary); font-size: 15px; }

.issue-list { margin-top: 26px; padding-top: 20px; border-top: 1px dashed var(--line); }
.issue-title { margin: 0 0 10px; font-size: 17px; color: var(--rhyme); }
.issue-none { margin: 0; font-size: 17px; color: var(--tone-level); font-weight: 600; }
.issue-item { margin: 7px 0; line-height: 1.8; }
.issue-unknown { margin-top: 14px; font-size: 13px; color: var(--ink-secondary); }

/* ── 响应式 ───────────────────────────────────────── */

@media (max-width: 760px) {
  .header-inner { padding: 10px 16px; gap: 12px; }
  .brand-sub { display: none; }
  .brand-name { font-size: 19px; }
  .app-nav a { padding: 7px 12px; font-size: 14px; }
  .view { padding: 18px 16px 48px; }
  .library-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .poem-card { padding: 16px 14px; }
  .poem-card-title { font-size: 18px; }
  .reader-article { padding: 26px 18px 32px; }
  .card-delete { opacity: .55; }
  #toast-root { left: 16px; right: 16px; bottom: 16px; align-items: stretch; }
  .toast { max-width: none; }
}
