:root {
  color-scheme: light;
  --ink: #2d332f;
  --ink-soft: #526057;
  --muted: #7b877f;
  --line: #dfe3dc;
  --line-soft: #ebece7;
  --canvas: #e9ede7;
  --paper: #fbfaf5;
  --panel: #f4f6f1;
  --accent: #4f715f;
  --accent-dark: #365543;
  --accent-soft: #e2ebe3;
  --user: #d8a8b2;
  --user-soft: #f7e9ec;
  --ai: #9eb7aa;
  --ai-soft: #e7efe9;
  --shadow: 0 14px 38px rgba(47, 58, 50, 0.08);
  --ui-font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --reading-font: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", serif;
  --reading-size: 19px;
  --chat-size: 14px;
  --compose-size: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--ui-font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 9px 13px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

button:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  cursor: default;
  opacity: 0.38;
}

.hidden {
  display: none !important;
}

.quiet {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink-soft);
}

.quiet:hover:not(:disabled) {
  border-color: #c7d2c9;
  background: white;
  color: var(--accent-dark);
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.7), transparent 32%),
    var(--canvas);
}

.panel {
  width: min(420px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  padding: 32px;
  border: 1px solid rgba(79, 113, 95, 0.15);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.panel h1 {
  margin: 0 0 24px;
  font-family: var(--reading-font);
  font-size: 27px;
  font-weight: 600;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus {
  border-color: #9caf9f;
  box-shadow: 0 0 0 3px rgba(79, 113, 95, 0.1);
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.error {
  color: #a84b4b;
}

.app {
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-columns: clamp(190px, 12vw, 238px) minmax(0, 1fr) clamp(300px, 18vw, 360px);
  overflow: hidden;
}

.library,
.discussion,
.toc {
  min-height: 0;
  overflow: auto;
  background: var(--panel);
}

.library {
  border-right: 1px solid var(--line);
}

.discussion {
  border-left: 1px solid var(--line);
}

.library header,
.discussion header,
.reader-head {
  border-bottom: 1px solid var(--line);
}

.library header {
  padding: 22px 18px 18px;
}

.library h1,
.discussion h2,
.reader-head h2 {
  margin: 0;
  color: var(--ink);
  font-weight: 600;
}

.library h1 {
  font-family: var(--reading-font);
  font-size: 24px;
}

.discussion h2,
.reader-head h2 {
  font-size: 16px;
}

#uploadForm {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.export-notes {
  width: 100%;
  margin-top: 8px;
  font-size: 13px;
}

#file {
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
}

#uploadStatus,
#chapterTitle,
.ai-status {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.book-list,
.toc {
  padding: 8px;
}

.book-list button,
.toc button {
  width: 100%;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-soft);
  text-align: left;
  line-height: 1.45;
}

.book-list button {
  margin-bottom: 3px;
  padding: 10px 11px;
  font-size: 13px;
}

.toc button {
  margin-bottom: 2px;
  padding: 8px 10px;
  font-size: 12px;
}

.book-list button:hover,
.toc button:hover {
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
}

.book-list button.active,
.toc button.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 600;
}

.reader {
  width: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.reader-head {
  min-height: 68px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: rgba(244, 246, 241, 0.94);
  backdrop-filter: blur(10px);
}

.book-meta {
  min-width: 0;
  flex: 1;
}

.reader-head h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.page-arrow {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  font-family: Georgia, serif;
  font-size: 24px;
  line-height: 1;
}

.reader-body {
  width: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: clamp(150px, 10vw, 190px) minmax(0, 1fr);
}

.toc {
  border-right: 1px solid var(--line);
}

.page-stage {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: minmax(0, 680px);
  justify-content: center;
  align-items: start;
  padding: 36px clamp(20px, 3vw, 48px) 80px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.5), transparent 36%),
    var(--canvas);
  scrollbar-color: #bcc7be transparent;
}

.content {
  width: 100%;
  max-width: 680px;
  min-width: 0;
  min-height: calc(100vh - 150px);
  padding: 58px clamp(38px, 5vw, 64px) 76px;
  border: 1px solid rgba(82, 96, 87, 0.12);
  border-radius: 6px;
  background: var(--paper);
  box-shadow: var(--shadow);
  color: #303630;
  font-family: var(--reading-font);
  font-size: var(--reading-size);
  font-weight: 400;
  line-height: 2.08;
  letter-spacing: 0.035em;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  text-align: justify;
  text-justify: inter-ideograph;
}

.reading-page {
  width: 100%;
  max-width: 680px;
  min-width: 0;
}

.bottom-page-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 26px 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.bottom-page-button {
  min-width: 92px;
  padding: 9px 14px;
  border-radius: 18px;
}

.content::selection,
.content *::selection {
  background: rgba(172, 194, 178, 0.55);
}

.annotation-mark {
  border-radius: 2px;
  padding: 1px 0;
  color: inherit;
}

.annotation-mark.user {
  background: linear-gradient(transparent 58%, rgba(216, 168, 178, 0.55) 58%);
}

.annotation-mark.ai {
  background: linear-gradient(transparent 58%, rgba(158, 183, 170, 0.62) 58%);
}

.margin-notes {
  position: absolute;
  top: 48px;
  right: clamp(10px, 2vw, 28px);
  width: 128px;
  display: grid;
  align-content: start;
  gap: 10px;
  padding-top: 12px;
}

.empty-notes {
  margin: 4px 0;
  color: #9ba69e;
  font-size: 11px;
  letter-spacing: 0.04em;
}

.note-bubble {
  width: 30px;
  min-height: 30px;
  display: flex;
  align-items: flex-start;
  padding: 6px;
  overflow: hidden;
  border: 0;
  border-radius: 15px;
  text-align: left;
  box-shadow: 0 3px 10px rgba(47, 58, 50, 0.05);
  transition: width 0.18s ease, border-radius 0.18s ease;
}

.note-bubble.user {
  background: var(--user-soft);
  color: #754956;
}

.note-bubble.ai {
  background: var(--ai-soft);
  color: #466354;
}

.note-bubble.expanded {
  width: 100%;
  padding: 10px 11px;
  border-radius: 10px;
}

.note-dot {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border-radius: 50%;
}

.user .note-dot {
  background: var(--user);
}

.ai .note-dot {
  background: var(--ai);
}

.note-body {
  display: none;
  margin-left: 7px;
  font-size: 12px;
  line-height: 1.6;
}

.note-bubble.expanded .note-body {
  display: block;
}

.discussion {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  padding-bottom: 0;
}

.discussion header {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

.discussion header button {
  display: none;
}

.selected-quote {
  margin: 12px 16px 0;
  padding: 10px 11px;
  border-left: 3px solid var(--user);
  border-radius: 0 8px 8px 0;
  background: var(--user-soft);
  color: #75505a;
  font-family: var(--reading-font);
  font-size: 13px;
  line-height: 1.65;
}

.chat-history {
  align-content: start;
  display: grid;
  gap: 14px;
  overflow: auto;
  margin: 0;
  padding: 18px 16px 24px;
  scrollbar-color: #c7d0c9 transparent;
}

.chat-message {
  max-width: 92%;
  padding: 11px 13px;
  border-radius: 14px;
  font-size: var(--chat-size);
  line-height: 1.7;
}

.chat-message.user {
  justify-self: end;
  border-bottom-right-radius: 4px;
  background: var(--user-soft);
  color: #68434d;
}

.chat-message.ai {
  justify-self: start;
  border: 1px solid rgba(79, 113, 95, 0.1);
  border-bottom-left-radius: 4px;
  background: rgba(255, 255, 255, 0.62);
  color: #35483d;
}

.chat-message p {
  margin: 0 0 0.75em;
}

.chat-message p:last-child,
.chat-message ul:last-child,
.chat-message ol:last-child {
  margin-bottom: 0;
}

.chat-message ul,
.chat-message ol {
  margin: 0.35em 0 0.85em;
  padding-left: 1.5em;
}

.chat-message li {
  margin: 0.28em 0;
}

.chat-message strong {
  color: #263c2f;
  font-weight: 650;
}

.chat-compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
  background: rgba(244, 246, 241, 0.94);
}

.chat-compose textarea {
  min-height: 72px;
  max-height: 180px;
  background: rgba(255, 255, 255, 0.72);
  font-size: var(--compose-size);
  line-height: 1.55;
}

.chat-compose button {
  align-self: end;
}

.selection-menu {
  position: fixed;
  z-index: 30;
  display: flex;
  gap: 3px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: #34453a;
  box-shadow: 0 8px 22px rgba(31, 43, 35, 0.22);
}

.selection-menu button {
  border: 0;
  padding: 7px 9px;
  background: transparent;
  font-size: 12px;
}

.selection-menu button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.chat-toggle {
  display: none;
  position: fixed;
  right: 16px;
  bottom: 18px;
  z-index: 10;
  border-radius: 18px;
  box-shadow: 0 7px 20px rgba(47, 58, 50, 0.18);
}

.font-controls {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px;
  border: 1px solid rgba(79, 113, 95, 0.14);
  border-radius: 22px;
  background: rgba(251, 250, 245, 0.92);
  box-shadow: 0 7px 20px rgba(47, 58, 50, 0.13);
  backdrop-filter: blur(10px);
}

.font-controls button {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  font-weight: 650;
}

.font-controls span {
  min-width: 32px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.mobile-only {
  display: none;
}

@media (max-width: 1380px) {
  .app {
    grid-template-columns: 190px minmax(0, 1fr) 300px;
  }

  .reader-body {
    grid-template-columns: 150px minmax(0, 1fr);
  }

  .page-stage {
    grid-template-columns: minmax(0, 640px);
    padding-inline: 20px;
  }

  .content {
    max-width: 640px;
    padding-inline: clamp(34px, 4vw, 52px);
  }

  .reading-page {
    max-width: 640px;
  }

  .margin-notes {
    width: 34px;
  }

  .note-bubble.expanded {
    width: 176px;
  }
}

@media (max-width: 900px) {
  html,
  body {
    height: auto;
  }

  .app {
    width: 100%;
    max-width: 100vw;
    min-height: 100vh;
    height: auto;
    display: block;
    overflow: visible;
    overflow-x: hidden;
  }

  .library {
    width: 100%;
    max-width: 100vw;
    display: none;
    max-height: 54vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .library.open {
    display: block;
  }

  .library header {
    padding: 16px;
  }

  .reader {
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    min-height: 100vh;
  }

  .reader-head {
    width: 100%;
    max-width: 100vw;
    position: sticky;
    top: 0;
    z-index: 8;
    min-height: 62px;
    padding: 9px 12px;
  }

  .book-meta {
    order: 2;
    min-width: 0;
    overflow: hidden;
  }

  .mobile-actions {
    order: 1;
    display: flex;
    gap: 6px;
  }

  .page-nav {
    order: 3;
  }

  .reader-body {
    width: 100%;
    max-width: 100vw;
    display: block;
    overflow-x: hidden;
  }

  .toc {
    width: 100%;
    max-width: 100vw;
    display: none;
    max-height: 46vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .toc.open {
    display: block;
  }

  .page-stage {
    display: block;
    width: 100%;
    max-width: 100vw;
    min-height: calc(100vh - 62px);
    padding: 18px 16px 82px;
    overflow-x: hidden;
  }

  .content {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: calc(100vh - 100px);
    padding: 36px 34px 54px;
    line-height: 2;
    letter-spacing: 0.025em;
    box-shadow: 0 8px 24px rgba(47, 58, 50, 0.07);
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .reading-page {
    width: 100%;
    max-width: 100%;
  }

  .margin-notes {
    position: static;
    width: 100%;
    margin-top: 12px;
    padding: 0;
  }

  .note-bubble.expanded {
    width: min(100%, 380px);
  }

  .discussion {
    width: 100vw;
    max-width: 100vw;
    position: fixed;
    inset: 0;
    z-index: 20;
    transform: translateX(100%);
    transition: transform 0.2s ease;
  }

  .discussion.open {
    transform: translateX(0);
  }

  .discussion header button {
    display: inline-block;
  }

  .chat-toggle {
    display: block;
    right: 16px;
    bottom: 72px;
  }

  .font-controls {
    right: 14px;
    bottom: 16px;
  }

  .mobile-only {
    display: flex;
  }
}

@media (max-width: 560px) {
  .reader-head {
    align-items: center;
    flex-wrap: wrap;
  }

  .book-meta {
    width: 100%;
    flex: 1 1 100%;
  }

  .reader-head h2 {
    font-size: 14px;
  }

  #chapterTitle {
    font-size: 11px;
  }

  .page-nav {
    width: 100%;
    justify-content: center;
    padding-top: 2px;
  }

  .page-arrow {
    width: 30px;
    height: 30px;
  }

  .page-stage {
    padding: 10px 8px 78px;
  }

  .content {
    box-sizing: border-box;
    width: auto;
    max-width: none;
    margin: 0;
    min-height: calc(100vh - 130px);
    padding: 28px 22px 46px;
    border-radius: 4px;
    line-height: 1.95;
    letter-spacing: 0.02em;
    text-align: left;
  }

  .bottom-page-nav {
    gap: 12px;
    padding-top: 20px;
  }

  .bottom-page-button {
    min-width: 86px;
  }

  .chat-message {
    max-width: 94%;
  }

  .selection-menu {
    max-width: calc(100vw - 24px);
  }
}

/* co-reading-layout-fix-20260605-clean */
.library,.discussion,.toc{min-width:0}
.book-list button,.toc button,.chat-message{overflow-wrap:anywhere;word-break:break-word}
#chapterTitle{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
@media (max-width:1500px){
  .app{grid-template-columns:190px minmax(0,1fr)}
  .discussion{width:min(380px,100vw);max-width:100vw;position:fixed;top:0;right:0;bottom:0;z-index:20;transform:translateX(100%);transition:transform .2s ease;box-shadow:-12px 0 28px rgba(47,58,50,.12)}
  .discussion.open{transform:translateX(0)}
  .discussion header button,.chat-toggle{display:inline-block}
  .chat-toggle{right:16px;bottom:72px}
}
