:root {
  --paper: #f6f1e7;
  --paper-deep: #efe7d9;
  --card: #fffdf8;
  --ink: #252b26;
  --ink-soft: #4f574f;
  --muted: #8d887a;
  --line: rgba(94, 81, 57, 0.14);
  --accent: #9a5b35;
  --accent-soft: #c08a62;
  --danger: #a44736;
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; width: 100%; overflow-x: hidden; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 10%, rgba(193, 156, 105, 0.13), transparent 40%),
    var(--paper);
}
.login-card {
  width: 100%;
  max-width: 350px;
  padding: 30px 26px 24px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.86);
  box-shadow: 0 18px 50px rgba(74, 58, 34, 0.06);
}
.brand-mark {
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 37px;
  letter-spacing: 0.18em;
  text-align: center;
}
.login-sub {
  margin: 10px 0 28px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.login-card label, .editor-panel label, .editor-scroll label {
  display: block;
  margin-bottom: 15px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
}
.login-card input, .editor-scroll input, .editor-scroll textarea, .editor-scroll select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #fffdf8;
  color: var(--ink);
  font-size: 15px;
  outline: none;
}
.login-card input:focus, .editor-scroll input:focus, .editor-scroll textarea:focus, .editor-scroll select:focus {
  border-color: var(--accent-soft);
}
.login-note { margin: 18px 0 0; color: var(--muted); font-size: 10px; text-align: center; }
.form-error { margin: 0 0 12px; color: var(--danger); font-size: 12px; }

.primary-btn, .ghost-btn, .icon-btn, .text-btn, .mini-btn {
  border: 0;
  background: transparent;
}
.primary-btn {
  display: inline-block;
  padding: 11px 22px;
  border-radius: 2px;
  background: var(--ink);
  color: #fffaf0;
  font-size: 12px;
  letter-spacing: 0.08em;
}
.primary-btn:active { background: #3b443c; }
.primary-btn.small { padding: 8px 15px; font-size: 11px; }
.ghost-btn {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--ink-soft);
  font-size: 11px;
}
.ghost-btn:active { border-color: var(--accent-soft); color: var(--accent); }
.ghost-btn.small { padding: 6px 10px; font-size: 10px; }
.icon-btn {
  width: 34px;
  height: 34px;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}
.text-btn { padding: 2px; color: var(--accent); font-size: 11px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  width: 100%;
  height: 58px;
  display: flex;
  align-items: center;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 241, 231, 0.96);
}
.brand-btn {
  flex: none;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 21px;
  letter-spacing: 0.15em;
}
.main-nav { display: flex; margin-left: 42px; }
.main-nav button {
  margin-right: 26px;
  padding: 6px 0;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}
.main-nav button.is-active { border-bottom-color: var(--accent); color: var(--ink); }
.account-wrap { position: relative; margin-left: auto; }
.account-btn {
  padding: 7px 0;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
}
.account-btn .caret { margin-left: 5px; color: var(--muted); }
.account-menu {
  position: absolute;
  top: 34px;
  right: 0;
  z-index: 30;
  width: 150px;
  padding: 7px 0;
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: 0 14px 36px rgba(66, 51, 30, 0.12);
}
.account-menu button {
  display: block;
  width: 100%;
  padding: 9px 15px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
  text-align: left;
}
.account-menu button:hover { background: var(--paper); color: var(--accent); }

.main { width: 100%; max-width: 960px; margin: 0 auto; padding: 30px 20px 100px; overflow: hidden; }
.view { animation: fadeIn 220ms ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 24px; }
.section-kicker { margin: 0 0 5px; color: var(--muted); font-family: var(--mono); font-size: 8px; letter-spacing: 0.12em; }
h1 { margin: 0; font-family: var(--serif); font-size: 29px; font-weight: 400; letter-spacing: 0.04em; }
.head-actions { display: flex; align-items: center; }
.head-actions .ghost-btn { margin-right: 9px; }

.card-list { display: block; }
.card-item {
  position: relative;
  margin-bottom: 10px;
  padding: 17px 20px 15px;
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.68);
  cursor: pointer;
}
.card-item:hover { border-color: rgba(154, 91, 53, 0.35); background: var(--card); }
.card-item h3 { margin: 0 0 4px; overflow: hidden; color: var(--ink); font-family: var(--serif); font-size: 20px; font-weight: 400; text-overflow: ellipsis; white-space: nowrap; }
.card-item .card-meta { margin: 0 0 8px; color: var(--muted); font-size: 10px; letter-spacing: 0.04em; }
.card-item .card-preview { margin: 0; overflow: hidden; color: var(--ink-soft); font-family: var(--serif); font-size: 14px; line-height: 1.8; text-overflow: ellipsis; white-space: nowrap; }
.card-item h3, .card-item p { max-width: 100%; overflow-wrap: anywhere; }
.card-item .card-source { margin-top: 8px; color: var(--muted); font-size: 9px; }
.card-item .card-note-dot { position: absolute; top: 18px; right: 18px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent-soft); }
.empty-state { padding: 55px 12px; color: var(--muted); font-size: 13px; line-height: 1.8; text-align: center; }

.search-form { display: flex; margin-bottom: 7px; }
.search-form input {
  flex: 1;
  min-width: 0;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: 2px 0 0 2px;
  background: var(--card);
  font-size: 15px;
  outline: none;
}
.search-form input:focus { border-color: var(--accent-soft); }
.search-form .primary-btn { border-radius: 0 2px 2px 0; }
.search-hint { margin: 0 0 20px; color: var(--muted); font-size: 10px; }
.ai-fallback { padding: 22px 12px; border-top: 1px solid var(--line); text-align: center; }
.ai-fallback p { margin: 0 0 10px; color: var(--muted); font-size: 12px; }
.fine-print { color: var(--muted); font-size: 9px; line-height: 1.6; }
.ai-fallback .fine-print { margin-top: 9px; }

.calendar-panel { margin-bottom: 18px; padding: 12px 16px 11px; border: 1px solid var(--line); background: rgba(255, 253, 248, 0.55); }
.calendar-head { display: flex; align-items: center; justify-content: space-between; }
.calendar-title-wrap { display: flex; align-items: center; }
.calendar-title { border: 0; background: transparent; color: var(--ink-soft); font-family: var(--serif); font-size: 16px; }
.calendar-view { margin-left: 7px; padding: 2px 5px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 9px; }
.calendar-grid.is-year { grid-template-columns: repeat(4, 1fr); grid-row-gap: 6px; }
.calendar-month { height: 42px; border: 0; background: transparent; color: var(--ink-soft); font-size: 12px; }
.calendar-month .dot { display: inline-block; width: 4px; height: 4px; margin-left: 4px; border-radius: 50%; background: var(--accent-soft); }
.calendar-week { display: grid; grid-template-columns: repeat(7, 1fr); margin: 10px 0 4px; color: var(--muted); font-size: 9px; text-align: center; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.calendar-cell { position: relative; height: 34px; border: 0; background: transparent; color: var(--ink-soft); font-size: 11px; }
.calendar-cell.is-muted { color: #c2baaa; }
.calendar-cell.is-selected { background: var(--paper-deep); color: var(--accent); }
.calendar-cell .dot { position: absolute; left: 50%; bottom: 4px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--accent-soft); }
.calendar-foot { display: flex; align-items: center; justify-content: space-between; min-height: 20px; margin-top: 7px; border-top: 1px solid var(--line); padding-top: 8px; }
.calendar-foot span { color: var(--muted); font-size: 9px; }

.friend-list { display: grid; grid-template-columns: repeat(2, 1fr); grid-column-gap: 10px; grid-row-gap: 10px; }
.friend-item { padding: 17px 18px; border: 1px solid var(--line); background: rgba(255, 253, 248, 0.65); }
.friend-item h3 { margin: 0 0 4px; font-family: var(--serif); font-size: 19px; font-weight: 400; }
.friend-item p { margin: 0 0 13px; color: var(--muted); font-size: 10px; }
.friend-item .ghost-btn { font-size: 10px; }

.floating-new {
  position: fixed;
  right: 22px;
  bottom: 24px;
  z-index: 15;
  width: 47px;
  height: 47px;
  border: 1px solid rgba(154, 91, 53, 0.3);
  border-radius: 50%;
  background: var(--ink);
  color: #fffaf0;
  font-size: 23px;
  line-height: 1;
  box-shadow: 0 8px 22px rgba(50, 40, 25, 0.18);
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 80;
  max-width: 80%;
  padding: 10px 18px;
  border-radius: 2px;
  background: rgba(37, 43, 38, 0.94);
  color: #fffaf0;
  font-size: 12px;
  transform: translateX(-50%);
}

.overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(39, 37, 31, 0.38);
}
.detail-panel, .editor-panel {
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(94, 81, 57, 0.2);
  background: var(--card);
  box-shadow: 0 25px 70px rgba(40, 31, 20, 0.2);
}
.editor-panel { max-width: 620px; }
.detail-top { display: flex; align-items: center; justify-content: space-between; min-height: 48px; padding: 8px 15px 6px 22px; border-bottom: 1px solid var(--line); }
.detail-kicker { color: var(--muted); font-family: var(--mono); font-size: 8px; letter-spacing: 0.12em; }
.detail-top-actions { display: flex; align-items: center; }
.note-toggle {
  margin-right: 6px;
  padding: 5px 8px;
  border: 1px solid rgba(154, 91, 53, 0.28);
  border-radius: 2px;
  background: transparent;
  color: var(--accent);
  font-family: var(--serif);
  font-size: 12px;
}
.note-toggle.is-on { background: var(--paper-deep); }
.detail-scroll, .editor-scroll { overflow-y: auto; padding: 28px 30px 24px; -webkit-overflow-scrolling: touch; }
.poem-title { margin: 0; font-family: var(--serif); font-size: 28px; font-weight: 400; line-height: 1.4; text-align: center; }
.poem-author { margin: 6px 0 25px; color: var(--muted); font-family: var(--serif); font-size: 12px; text-align: center; }
.poem-body { color: var(--ink); font-family: var(--serif); font-size: 19px; line-height: 2.1; text-align: center; word-wrap: break-word; overflow-wrap: anywhere; }
.poem-body sup {
  position: relative;
  top: -0.45em;
  margin-left: 1px;
  color: var(--accent);
  font-family: var(--sans);
  font-size: 9px;
  cursor: pointer;
  touch-action: manipulation;
}
.poem-body sup::before {
  content: '';
  position: absolute;
  top: -10px;
  right: -8px;
  bottom: -10px;
  left: -8px;
}
.poem-notes { margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--line); }
.notes-label { margin: 0 0 7px; color: var(--muted); font-size: 9px; letter-spacing: 0.1em; }
#detailNotesBody { color: var(--ink-soft); font-size: 14px; line-height: 1.8; white-space: pre-wrap; }
.detail-footer { margin-top: 27px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 9px; }
.detail-actions { display: flex; flex-wrap: wrap; margin-top: 12px; }
.detail-actions button { margin: 0 8px 7px 0; }
.ann-popover {
  position: fixed;
  z-index: 90;
  width: 250px;
  max-width: calc(100vw - 30px);
  padding: 13px 15px;
  border: 1px solid rgba(94, 81, 57, 0.18);
  background: #fffdf8;
  box-shadow: 0 15px 45px rgba(40, 31, 20, 0.18);
  font-size: 12px;
  line-height: 1.7;
}
.ann-popover .ann-term { margin-bottom: 5px; color: var(--accent); font-family: var(--serif); font-size: 17px; }
.ann-popover .ann-pinyin { margin-left: 7px; color: var(--muted); font-family: var(--serif); font-size: 11px; }
.ann-popover .ann-note { color: var(--ink-soft); }
.ann-popover .ann-source { margin-top: 7px; color: var(--muted); font-size: 8px; }

.editor-scroll { padding: 22px 26px 24px; }
.editor-scroll h2 { margin: 0 0 20px; font-family: var(--serif); font-size: 22px; font-weight: 400; }
.editor-scroll textarea { resize: vertical; line-height: 1.7; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; grid-column-gap: 12px; }
.editor-section-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; color: var(--muted); font-size: 11px; }
.annotation-row { display: grid; grid-template-columns: 1fr 1fr; grid-column-gap: 7px; margin-bottom: 7px; padding: 8px; border: 1px solid var(--line); }
.annotation-row input, .annotation-row textarea { margin: 0; background: transparent; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 4px 2px; font-size: 12px; }
.annotation-row textarea { grid-column: 1 / 3; min-height: 36px; }
.annotation-row .remove-ann { justify-self: end; color: var(--muted); font-size: 10px; }
.check-line { display: flex !important; align-items: center; color: var(--ink-soft) !important; font-size: 11px !important; }
.check-line input { display: inline-block !important; width: 15px !important; height: 15px; margin: 0 7px 0 0 !important; }
.editor-ai-line { display: flex; align-items: center; margin: 2px 0 15px; }
.editor-ai-line .fine-print { margin-left: 9px; }
.editor-actions { display: flex; justify-content: flex-end; margin-top: 18px; }
.editor-actions .ghost-btn { margin-right: 9px; }
.panel-title { margin: 0 0 20px; font-family: var(--serif); font-size: 22px; font-weight: 400; }
.admin-subtitle { margin: 22px 0 12px; padding-top: 16px; border-top: 1px solid var(--line); font-family: var(--serif); font-size: 17px; font-weight: 400; }
.privacy-users { max-height: 220px; margin: 10px 0 20px; overflow-y: auto; border-top: 1px solid var(--line); }
.privacy-user { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); }
.privacy-user span { color: var(--ink-soft); font-size: 12px; }
.privacy-user label { display: inline-flex !important; align-items: center; margin: 0 0 0 10px !important; color: var(--muted) !important; font-size: 10px !important; }
.privacy-user input { display: inline-block !important; width: 14px !important; margin: 0 4px 0 0 !important; }
#friendCards .card-item { cursor: pointer; }
#friendCards .friend-card-copy { margin-top: 8px; }
@media (max-width: 620px) {
  .topbar { height: 54px; padding: 0 14px; }
  .brand-btn { font-size: 19px; }
  .main-nav { margin-left: 20px; }
  .main-nav button { margin-right: 17px; font-size: 11px; }
  .account-btn { font-size: 11px; }
  .main { padding: 24px 13px 90px; overflow: hidden; }
  .main-nav { overflow: hidden; min-width: 0; }
  .account-btn { max-width: 82px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .poem-body sup::before { top: -14px; right: -11px; bottom: -14px; left: -11px; }
  h1 { font-size: 26px; }
  .friend-list { grid-template-columns: 1fr; }
  .overlay { align-items: flex-end; padding: 0; }
  .detail-panel, .editor-panel { max-width: none; max-height: 92vh; border-left: 0; border-right: 0; border-bottom: 0; }
  .detail-scroll, .editor-scroll { padding: 23px 18px 25px; }
  .poem-title { font-size: 25px; }
  .poem-body { font-size: 18px; line-height: 2; }
  .ann-popover { left: 15px !important; right: 15px; bottom: 15px; top: auto !important; width: auto; max-width: none; }
  .floating-new { right: 17px; bottom: 18px; }
}

@media (max-width: 380px) {
  .topbar { padding: 0 10px; }
  .brand-btn { font-size: 17px; letter-spacing: 0.09em; }
  .main-nav { margin-left: 10px; }
  .main-nav button { margin-right: 11px; font-size: 10px; }
  .account-btn { max-width: 54px; font-size: 10px; }
  .main { padding-left: 10px; padding-right: 10px; }
  .head-actions .ghost-btn { padding: 7px 9px; }
}
