:root {
  color-scheme: light;
  --bg: #f7faf8;
  --surface: #ffffff;
  --surface-tint: #f3f8f4;
  --text: #24272b;
  --muted: #6c747b;
  --line: #dfe9e3;
  --green: #9acfa8;
  --green-deep: #3d8f65;
  --pink: #ee8ab7;
  --pink-soft: #fdebf3;
  --blue: #3477c8;
  --amber: #b46b09;
  --shadow: 0 18px 46px rgba(61, 103, 76, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100%;
  overflow-x: hidden;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% -8%, rgba(238, 138, 183, 0.22), transparent 28%),
    radial-gradient(circle at 95% 0%, rgba(154, 207, 168, 0.26), transparent 30%),
    linear-gradient(180deg, #fbfefd 0%, var(--bg) 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
textarea,
a {
  font: inherit;
}

.shell {
  width: min(100%, 760px);
  max-width: 100%;
  overflow-x: hidden;
  min-height: 100vh;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.94);
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 0 1px rgba(223, 233, 227, 0.65);
}

.brand-hero {
  position: relative;
  overflow: hidden;
  min-height: 236px;
  padding: 20px 18px 24px;
  background:
    linear-gradient(148deg, rgba(255, 255, 255, 0.96) 0%, rgba(255, 255, 255, 0.9) 46%, rgba(244, 250, 246, 0.9) 100%),
    url("/assets/handbook-cover.png") right -76px bottom -244px / 310px auto no-repeat;
  border-bottom: 1px solid rgba(223, 233, 227, 0.9);
}

.brand-hero::before,
.brand-hero::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.brand-hero::before {
  right: -80px;
  bottom: -130px;
  width: 260px;
  height: 260px;
  border: 44px solid rgba(154, 207, 168, 0.38);
  border-radius: 50%;
}

.brand-hero::after {
  right: 44px;
  top: 104px;
  width: 40px;
  height: 28px;
  background: var(--pink);
  border-radius: 28px 28px 28px 4px;
  transform: rotate(-28deg);
  opacity: 0.9;
}

.brand-topline {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand-logo {
  width: 150px;
  height: auto;
  display: block;
}

.hero-copy {
  position: relative;
  z-index: 1;
  margin-top: 34px;
  max-width: 470px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green-deep);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(30px, 8vw, 42px);
  line-height: 1.08;
  font-weight: 850;
}

h2 {
  margin-bottom: 4px;
  font-size: 21px;
}

h3 {
  margin-bottom: 6px;
  font-size: 16px;
}

.hero-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

.hero-marks {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.mark-line {
  display: block;
  width: 48px;
  height: 8px;
  border-radius: 999px;
}

.mark-line.pink {
  background: var(--pink);
}

.mark-line.green {
  background: var(--green);
}

.status-pill,
.badge {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}

.status-pill.ready {
  color: var(--green-deep);
  border-color: rgba(61, 143, 101, 0.24);
  background: rgba(154, 207, 168, 0.14);
}

.status-pill.warn {
  color: var(--amber);
  border-color: rgba(180, 107, 9, 0.28);
  background: rgba(180, 107, 9, 0.09);
}

.summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 14px 18px;
  padding: 14px;
  border: 1px solid rgba(223, 233, 227, 0.95);
  border-radius: 8px;
  background: linear-gradient(135deg, #ffffff 0%, var(--surface-tint) 100%);
}

.summary-copy {
  min-width: 0;
}

.label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.summary strong {
  display: inline-block;
  margin-right: 8px;
}

.summary-note {
  display: inline-block;
  color: var(--muted);
  font-size: 12px;
}

.download-link,
.primary-link {
  color: var(--green-deep);
  text-decoration: none;
  font-weight: 750;
}

.download-link {
  flex: 0 0 auto;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border-radius: 8px;
  background: rgba(238, 138, 183, 0.14);
  color: #b8467b;
  white-space: nowrap;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 18px 12px;
}

.tab {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.tab.active {
  border-color: rgba(154, 207, 168, 0.95);
  background: linear-gradient(135deg, rgba(154, 207, 168, 0.2), rgba(238, 138, 183, 0.1));
  color: var(--green-deep);
  font-weight: 800;
}

.panel {
  display: none;
  flex: 1;
  padding: 0 18px 18px;
}

.panel.active {
  display: block;
}

.reader-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.reader-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.98), rgba(243, 248, 244, 0.92)),
    linear-gradient(90deg, var(--pink) 0 36px, transparent 36px 46px, var(--green) 46px 82px, transparent 82px);
  background-size: auto, 100% 4px;
  background-position: 0 0, 0 100%;
  background-repeat: no-repeat;
}

.reader-source {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  word-break: break-word;
}

.badge {
  border-color: rgba(238, 138, 183, 0.34);
  background: var(--pink-soft);
  color: #b8467b;
}

.cover-preview {
  display: grid;
  grid-template-columns: minmax(116px, 148px) 1fr;
  gap: 16px;
  padding: 16px;
  background:
    radial-gradient(circle at 4% 100%, rgba(154, 207, 168, 0.24), transparent 36%),
    linear-gradient(135deg, #ffffff 0%, #fbf7fa 100%);
  border-bottom: 1px solid var(--line);
}

.cover-preview img {
  display: block;
  width: 100%;
  aspect-ratio: 0.707;
  object-fit: cover;
  object-position: top center;
  border: 1px solid rgba(223, 233, 227, 0.92);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(61, 103, 76, 0.12);
}

.cover-copy {
  align-self: center;
  min-width: 0;
}

.cover-copy span {
  display: block;
  margin-bottom: 8px;
  color: var(--green-deep);
  font-size: 12px;
  font-weight: 800;
}

.cover-copy strong {
  display: block;
  margin-bottom: 8px;
  font-size: 24px;
  line-height: 1.16;
}

.cover-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.pdf-preview {
  height: min(58vh, 520px);
  background: var(--surface-tint);
  border-top: 1px solid rgba(223, 233, 227, 0.85);
}

.pdf-preview iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.hidden {
  display: none;
}

.doc-fallback {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 16px 20px;
}

.doc-fallback p {
  margin-bottom: 10px;
  color: var(--muted);
  word-break: break-word;
}

.doc-icon {
  display: grid;
  place-items: center;
  flex: 0 0 58px;
  width: 58px;
  height: 72px;
  border: 1px solid rgba(61, 143, 101, 0.24);
  border-radius: 8px;
  background: rgba(154, 207, 168, 0.12);
  color: var(--green-deep);
  font-size: 13px;
  font-weight: 800;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.topic-grid button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(61, 103, 76, 0.06);
}

.topic-grid button:nth-child(2n) {
  background: #fff7fb;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(243, 248, 244, 0.88));
}

.context-copy {
  min-width: 0;
}

.context-state {
  display: block;
  color: var(--green-deep);
  font-size: 13px;
  font-weight: 800;
}

.context-note {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.context-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.context-button {
  min-height: 34px;
  border: 1px solid rgba(61, 143, 101, 0.24);
  border-radius: 8px;
  padding: 0 10px;
  background: rgba(154, 207, 168, 0.12);
  color: var(--green-deep);
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
  white-space: nowrap;
}

.context-button.danger {
  border-color: rgba(238, 138, 183, 0.34);
  background: rgba(238, 138, 183, 0.12);
  color: #b8467b;
}

.context-button:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.chat-panel-collapsed .chat-window {
  min-height: 132px;
  height: 132px;
}

.chat-panel-collapsed .message.history-message {
  display: none;
}

.chat-window {
  height: calc(100vh - 398px);
  min-height: 350px;
  overflow-y: auto;
  padding: 4px 0 14px;
}

.message {
  display: flex;
  gap: 10px;
  margin: 12px 0;
}

.message.user {
  flex-direction: row-reverse;
}

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface-tint);
  color: var(--green-deep);
  font-size: 12px;
  font-weight: 800;
}

.brand-avatar {
  background: linear-gradient(135deg, var(--green), var(--pink));
  color: #ffffff;
}

.message.user .avatar {
  background: rgba(238, 138, 183, 0.14);
  color: #b8467b;
}

.bubble {
  max-width: min(82%, 560px);
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  line-height: 1.58;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.assistant .bubble {
  background: linear-gradient(135deg, #ffffff, #f7fbf8);
}

.bubble.streaming::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1.1em;
  margin-left: 3px;
  border-radius: 999px;
  background: var(--green-deep);
  vertical-align: -0.18em;
  animation: cursor-blink 1s steps(2, start) infinite;
}

.message.user .bubble {
  border-color: rgba(238, 138, 183, 0.26);
  background: rgba(238, 138, 183, 0.1);
}

.bubble p {
  margin-bottom: 0;
}

.markdown-body {
  white-space: normal;
}

.markdown-body h3,
.markdown-body h4 {
  margin: 14px 0 8px;
  color: #111827;
  font-size: 15px;
  line-height: 1.45;
}

.markdown-body h3:first-child,
.markdown-body h4:first-child {
  margin-top: 0;
}

.markdown-body p {
  margin: 0 0 10px;
}

.markdown-body p:last-child {
  margin-bottom: 0;
}

.markdown-body ol,
.markdown-body ul {
  margin: 8px 0 12px;
  padding-left: 22px;
}

.markdown-body li {
  margin: 5px 0;
  padding-left: 2px;
}

.markdown-body strong {
  font-weight: 800;
}

.markdown-body code {
  display: inline-block;
  max-width: 100%;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(61, 143, 101, 0.1);
  color: var(--green-deep);
  font-size: 0.92em;
  vertical-align: baseline;
}

.markdown-body a {
  color: var(--green-deep);
  font-weight: 750;
  overflow-wrap: anywhere;
}

.meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

@keyframes cursor-blink {
  50% {
    opacity: 0;
  }
}

.suggestions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 10px;
}

.suggestions button {
  flex: 0 0 auto;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.composer {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

textarea {
  width: 100%;
  max-height: 120px;
  min-height: 44px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  outline: none;
}

textarea:focus {
  border-color: rgba(61, 143, 101, 0.62);
  box-shadow: 0 0 0 3px rgba(154, 207, 168, 0.18);
}

.composer button {
  flex: 0 0 72px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--green-deep);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.composer button:disabled {
  background: #a7b5ad;
  cursor: wait;
}

@media (max-width: 520px) {
  .shell {
    width: 100%;
  }

  .brand-hero {
    min-height: 228px;
    background-size: 280px auto;
    background-position: right -92px bottom -238px;
  }

  .brand-logo {
    width: 138px;
  }

  .summary {
    align-items: flex-start;
    flex-direction: column;
    flex-wrap: wrap;
    gap: 10px;
  }

  .download-link {
    width: 100%;
    min-width: 0;
  }

  .reader-head {
    flex-wrap: wrap;
  }

  .cover-preview {
    grid-template-columns: 108px 1fr;
    gap: 12px;
    padding: 14px;
  }

  .cover-copy strong {
    font-size: 20px;
  }

  .cover-copy p {
    font-size: 12px;
  }

  .topic-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .chat-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .context-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .context-button {
    min-width: 0;
  }

  .chat-window {
    height: calc(100vh - 390px);
  }
}
