:root {
  --paper: #f5f0e5;
  --paper-deep: #efe8d9;
  --card: #fffdf8;
  --ink: #2e332d;
  --muted: #7c8177;
  --sage: #7d9983;
  --sage-deep: #5c7863;
  --sage-soft: #e9efe6;
  --line: #e5ddce;
  --line-strong: #d4c9b7;
  --warn: #9a623f;
  --error: #9d5a4a;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(70, 63, 45, 0.07);
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
  background:
    radial-gradient(1100px 560px at 8% -12%, #fbf7ee 0%, rgba(251, 247, 238, 0) 60%),
    radial-gradient(900px 520px at 108% 0%, #eef2e9 0%, rgba(238, 242, 233, 0) 55%),
    var(--paper);
}

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.35;
  margin: 0;
}

p {
  margin: 0;
}

a {
  color: var(--sage-deep);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button, input, textarea {
  font-family: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.warn-text {
  color: var(--warn);
  font-weight: 600;
}

.page {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px 18px calc(28px + env(safe-area-inset-bottom));
}

.site-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--sage-soft);
  color: var(--sage-deep);
  font-family: var(--serif);
  font-size: 22px;
  border: 1px solid #dbe4d8;
}

.brand h1 {
  font-size: 22px;
  letter-spacing: 0.04em;
}

.tagline {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.free-badge, .ai-badge {
  flex: none;
  display: inline-block;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--sage-deep);
  background: var(--sage-soft);
  border: 1px solid #dbe4d8;
  white-space: nowrap;
}

.free-badge {
  margin-top: 4px;
}

.hero {
  margin: 0 2px 22px;
}

.hero-title {
  font-size: 23px;
  letter-spacing: 0.03em;
  color: #343a32;
}

.hero-subtitle {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.8;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.panel-head h2 {
  font-size: 18px;
  letter-spacing: 0.03em;
}

.quiet-note {
  color: var(--muted);
  font-size: 12px;
}

#diaryInput {
  width: 100%;
  min-height: 196px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffefb;
  padding: 15px 16px;
  font-size: 16px;
  line-height: 1.85;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

#diaryInput::placeholder {
  color: #a6aa9f;
}

#diaryInput:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(125, 153, 131, 0.16);
}

.compose-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.compose-meta .is-over {
  color: var(--error);
  font-weight: 600;
}

.save-option {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  user-select: none;
}

.save-option input {
  width: 16px;
  height: 16px;
  accent-color: var(--sage-deep);
}

.examples {
  margin-top: 18px;
}

.examples-title {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 9px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  text-align: left;
  border: 1px solid #dce5d9;
  background: var(--sage-soft);
  color: #40503f;
  border-radius: 999px;
  padding: 9px 13px;
  font-size: 12.5px;
  line-height: 1.5;
  min-height: 44px;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.chip:hover {
  background: #dfe9dc;
  border-color: #cbd9c7;
}

.compose-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn {
  min-height: 44px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 14.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 0.16s ease, border-color 0.16s ease, opacity 0.16s ease;
}

.btn-primary {
  background: var(--sage-deep);
  color: #fff;
  flex: 1;
}

.btn-primary:hover {
  background: #4f6b57;
}

.btn-primary:disabled {
  opacity: 0.62;
  cursor: wait;
}

.btn-ghost {
  border-color: var(--line-strong);
  color: var(--ink);
}

.btn-ghost:hover {
  background: #f6f2e9;
}

.btn-small {
  min-height: 44px;
  padding: 0 13px;
  font-size: 12.5px;
  border: 1px solid var(--line);
  background: #fffefb;
  color: var(--ink);
}

.btn-small:hover {
  background: #f7f3ea;
}

.result-panel {
  min-height: 430px;
  display: flex;
  flex-direction: column;
}

.result-status {
  color: var(--sage-deep);
  font-size: 12px;
  margin-bottom: 10px;
}

.result-status.is-error {
  color: var(--error);
}

.empty-state {
  flex: 1;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px 12px;
}

.empty-mark {
  font-size: 34px;
  color: var(--sage);
  line-height: 1;
  margin-bottom: 8px;
}

.empty-state > p:first-of-type {
  font-family: var(--serif);
  font-size: 16px;
}

.result-body {
  flex: 1;
}

.result-body.streaming {
  position: relative;
}

.raw-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.95;
  font-size: 15px;
}

.diary-section {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffefa;
  padding: 15px 16px 14px;
  margin-bottom: 12px;
}

.diary-section:last-child {
  margin-bottom: 0;
}

.diary-section h3 {
  font-size: 15.5px;
  color: var(--sage-deep);
  letter-spacing: 0.1em;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.diary-section h3::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sage);
  flex: none;
}

.diary-section p {
  line-height: 1.95;
  font-size: 14.8px;
  white-space: pre-wrap;
  word-break: break-word;
}

.crisis-card {
  border: 1px solid #e6c9bb;
  background: #fbf1ea;
  border-radius: 14px;
  padding: 18px;
  line-height: 1.95;
  color: #6d4636;
  white-space: pre-wrap;
}

.crisis-title {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #7d4d3a;
}

.crisis-card p {
  margin: 0;
  white-space: pre-wrap;
}

.error-card {
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  padding: 18px;
  color: var(--error);
  background: #fdf8f4;
}

.error-card .btn {
  margin-top: 12px;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 14px;
}

.history {
  margin-top: 26px;
}

.history-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.history-head h2 {
  font-size: 17px;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.history-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
}

.history-date {
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.03em;
}

.history-excerpt {
  margin: 5px 0 10px;
  font-size: 13.5px;
  line-height: 1.7;
  color: #4c5148;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-actions {
  display: flex;
  gap: 8px;
}

.history-actions .btn {
  min-height: 40px;
  padding: 0 12px;
  font-size: 12px;
  border: 1px solid var(--line);
  background: #fffefb;
  border-radius: 999px;
}

.site-footer {
  margin-top: 30px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
}

.footer-links {
  margin-top: 6px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.footer-links a {
  color: var(--sage-deep);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(42, 40, 31, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: auto;
  background: var(--card);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 24px 70px rgba(30, 28, 20, 0.24);
}

.modal-card h2 {
  font-size: 17px;
  margin-bottom: 4px;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

.modal-close:hover {
  color: var(--ink);
}

#shareImage {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  margin: 12px 0;
  background: var(--paper);
}

#downloadImage {
  width: 100%;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  max-width: calc(100vw - 36px);
  background: rgba(46, 51, 45, 0.94);
  color: #fff;
  font-size: 13px;
  line-height: 1.6;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(30, 28, 20, 0.2);
}

/* 后台登录 */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
}

.login-card h1 {
  font-size: 20px;
  margin-bottom: 6px;
}

.login-form {
  display: grid;
  gap: 9px;
  margin-top: 20px;
}

.login-form label {
  font-size: 13px;
  color: #565b52;
}

.login-form input {
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 13px;
  font-size: 16px;
  background: #fffefb;
  outline: none;
}

.login-form input:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(125, 153, 131, 0.16);
}

.login-form .btn {
  margin-top: 6px;
}

.login-back {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
}

.form-error {
  margin-top: 12px;
  color: var(--error);
  background: #fbf1ec;
  border: 1px solid #eccfc5;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
}

/* 后台 */
.admin-wrap {
  max-width: 1040px;
}

.admin-header .tagline {
  margin-top: 2px;
}

.admin-nav {
  display: flex;
  gap: 14px;
  font-size: 13px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.notice {
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 18px;
  font-size: 13px;
  line-height: 1.75;
}

.notice-warn {
  background: #fbf3e9;
  border: 1px solid #ecd8bf;
  color: #7c5334;
}

.notice ul {
  margin: 6px 0 0;
  padding-left: 20px;
}

.admin-panel {
  margin-bottom: 18px;
}

.admin-panel .panel-head {
  margin-bottom: 16px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat {
  background: #fbf8f0;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  color: var(--muted);
  font-size: 11.5px;
}

.stat-value {
  font-family: var(--serif);
  font-size: 21px;
  color: var(--sage-deep);
}

.cap-usage {
  margin-top: 16px;
}

.cap-usage-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.cap-track {
  height: 8px;
  border-radius: 999px;
  background: #eee8db;
  overflow: hidden;
}

.cap-bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--sage);
  transition: width 0.3s ease;
}

.table-wrap {
  overflow-x: auto;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  min-width: 620px;
}

.stats-table th, .stats-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.stats-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 11.5px;
}

.stats-table tr:last-child td {
  border-bottom: 0;
}

.settings-form fieldset {
  border: 0;
  padding: 0;
  margin: 0 0 22px;
}

.settings-form legend {
  font-family: var(--serif);
  font-size: 16px;
  margin-bottom: 10px;
  color: var(--sage-deep);
}

.settings-form label {
  display: block;
  font-size: 12.5px;
  color: #565b52;
  margin-bottom: 12px;
}

.settings-form input[type="text"],
.settings-form input[type="number"],
.settings-form textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffefb;
  padding: 10px 12px;
  font-size: 15px;
  line-height: 1.7;
  outline: none;
}

.settings-form textarea {
  resize: vertical;
}

.settings-form input:focus,
.settings-form textarea:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(125, 153, 131, 0.14);
}

.prompt-area {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px !important;
  line-height: 1.65 !important;
}

.number-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.settings-actions .btn-primary {
  flex: none;
}

.form-message {
  font-size: 13px;
}

.form-message.is-ok {
  color: var(--sage-deep);
}

.form-message.is-error {
  color: var(--error);
}

/* 隐私与说明 */
.prose-page {
  max-width: 860px;
}

.back-link {
  font-size: 13px;
  margin-top: 8px;
}

.prose {
  padding: 26px 22px;
}

.prose h2 {
  font-size: 17px;
  color: var(--sage-deep);
  margin: 24px 0 8px;
}

.prose h2:first-of-type {
  margin-top: 18px;
}

.prose p, .prose li {
  line-height: 1.95;
  font-size: 14px;
  color: #454a41;
}

.prose p + p {
  margin-top: 10px;
}

.prose ul {
  margin: 8px 0;
  padding-left: 20px;
}

.prose li + li {
  margin-top: 6px;
}

.prose strong {
  color: var(--ink);
}

@media (min-width: 900px) {
  .page {
    padding: 38px 32px 36px;
  }

  .site-header {
    margin-bottom: 30px;
  }

  .brand h1 {
    font-size: 26px;
  }

  .brand-mark {
    width: 52px;
    height: 52px;
    font-size: 25px;
  }

  .hero-title {
    font-size: 30px;
  }

  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 22px;
  }

  .panel {
    padding: 24px;
  }

  #diaryInput {
    min-height: 248px;
  }

  .result-panel {
    min-height: 520px;
    position: sticky;
    top: 24px;
  }

  .history-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .admin-wrap {
    padding-top: 30px;
  }

  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .number-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .prose {
    padding: 32px 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

:focus-visible {
  outline: 2px solid var(--sage);
  outline-offset: 2px;
}
