:root {
  color-scheme: light;
  --ink: #202428;
  --muted: #66727d;
  --line: #dce3e8;
  --paper: #f6f3ed;
  --panel: #fffdf9;
  --field: #ffffff;
  --accent: #2f6652;
  --accent-strong: #214d3e;
  --blue: #385f8d;
  --red: #9b4b46;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.reader-shell {
  width: min(940px, calc(100% - 24px));
  margin: 0 auto;
  padding: 18px 0 42px;
}

.reader-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

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

.kicker,
.muted-line {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.kicker {
  color: var(--accent);
  font-weight: 850;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 2.1rem;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.1rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid rgba(56, 95, 141, 0.24);
  border-radius: 999px;
  padding: 0 11px;
  background: rgba(56, 95, 141, 0.08);
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill[data-state="ok"] {
  border-color: rgba(47, 102, 82, 0.28);
  background: rgba(47, 102, 82, 0.1);
  color: var(--accent-strong);
}

.status-pill[data-state="error"] {
  border-color: rgba(155, 75, 70, 0.28);
  background: rgba(155, 75, 70, 0.1);
  color: var(--red);
}

.login-panel,
.reader-controls,
.passage-panel,
.discussion-panel {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.login-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 300px) auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
}

.reader-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) minmax(180px, 1fr) minmax(96px, 0.45fr) auto auto auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 800;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  color: var(--ink);
}

select,
input {
  min-height: 42px;
  padding: 0 10px;
}

textarea {
  resize: vertical;
  padding: 11px;
  line-height: 1.55;
}

.primary-action,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 13px;
  font-weight: 850;
  text-decoration: none;
  white-space: nowrap;
}

.small-action {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.84rem;
}

.primary-action {
  background: var(--accent);
  color: #fff;
}

.secondary-action {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.secondary-action:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.passage-panel,
.discussion-panel {
  padding: 16px;
}

.passage-head,
.discussion-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.paragraph-card {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.paragraph-original {
  margin: 0 0 8px;
  font-size: 1rem;
  line-height: 1.72;
}

.discussion-panel {
  display: grid;
  gap: 12px;
}

.discussion-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}

.discussion-message {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fff;
  line-height: 1.65;
  white-space: pre-wrap;
  height: auto;
}

.discussion-message p {
  margin: 0;
}

.discussion-message p + p {
  margin-top: 8px;
}

.discussion-message.assistant {
  background: #f7faf8;
  border-color: rgba(47, 102, 82, 0.18);
}

.discussion-message.memory {
  background: #fffaf2;
  border-color: rgba(143, 101, 44, 0.24);
}

.discussion-role {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 850;
}

.prompt-preview {
  overflow: auto;
  max-height: 360px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #f8fafb;
  white-space: pre-wrap;
}

.ai-answer {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  background: #f8fafb;
  line-height: 1.72;
  white-space: pre-wrap;
}

@media (max-width: 720px) {
  .reader-header,
  .passage-head,
  .discussion-head {
    display: grid;
  }

  .login-panel,
  .reader-controls {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 1.8rem;
  }
}
