:root {
  --bg: #f4efe6;
  --panel: #fffdf8;
  --ink: #2b241c;
  --muted: #6d6256;
  --accent: #8b4513;
  --line: #e6dccb;
  --user: #efe6d6;
  --bot: #ffffff;
  --warn: #fff3cd;
  --danger: #b00020;
  --rail: #faf6ef;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  background: radial-gradient(circle at top, #fff8ee, var(--bg));
  color: var(--ink);
  min-height: 100vh;
}
.shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 240px;
  min-height: 100vh;
  max-width: 1280px;
  margin: 0 auto;
}
.rail {
  background: var(--rail);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.rail.right { border-right: none; border-left: 1px solid var(--line); }
.rail-brand {
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.18em;
  font-size: 0.95rem;
}
.rail h2 { margin: 8px 0 0; font-size: 1rem; }
.rail-note { margin: 0; color: var(--muted); font-size: 0.85rem; line-height: 1.5; }
.orig-list { display: grid; gap: 8px; margin-top: 8px; }
.orig-list a {
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}
.orig-list a:hover { border-color: var(--accent); }
.rail-foot {
  margin-top: auto;
  color: var(--danger);
  font-size: 0.78rem;
  line-height: 1.45;
  border-top: 1px dashed #e2b4b4;
  padding-top: 12px;
}
.flowers { text-align: center; font-size: 1.6rem; line-height: 1.6; }
.bouquet.soft { opacity: 0.85; filter: saturate(1.1); }
.support-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  text-align: center;
}
.support-label { color: var(--muted); font-size: 0.85rem; }
.support-num {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  margin: 6px 0 12px;
}
.support-btn {
  width: 100%;
  background: linear-gradient(135deg, #c48a4a, #8b4513);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
}
.main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  min-height: 100vh;
  background: transparent;
}
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.brand { display: flex; gap: 12px; align-items: center; }
.avatar {
  width: 48px; height: 48px; border-radius: 50%;
  object-fit: cover;
  object-position: 50% 12%;
  background: #efe6d6;
  border: 1px solid var(--line);
  display: block;
}
.bot-row {
  align-self: flex-start;
  max-width: 92%;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.bot-row .avatar {
  width: 40px; height: 40px; flex-shrink: 0; margin-top: 2px;
}
.bot-row .msg-wrap { max-width: 100%; flex: 1; min-width: 0; }
.msg.thinking {
  color: var(--muted);
  font-weight: 600;
}
.msg.bot { white-space: normal; }
.reason {
  margin: 0 0 10px;
  background: #faf6ef;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}
.reason summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 700;
}
.reason-body, .answer { white-space: pre-wrap; }
.reason-body {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}
h1 { font-size: 1.15rem; margin: 0; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }
.warn {
  background: var(--warn);
  border: 1px solid #f0df9c;
  color: #5c4810;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
}
.chat {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 420px;
}
.msg {
  max-width: 92%;
  padding: 12px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  line-height: 1.55;
  border: 1px solid var(--line);
}
.msg.user { align-self: flex-end; background: var(--user); }
.msg.bot { align-self: flex-start; background: var(--bot); }
.msg.sys { align-self: center; background: transparent; border: none; color: var(--muted); font-size: 0.9rem; }
.msg-wrap { align-self: flex-start; max-width: 92%; display: grid; gap: 4px; }
.dose-risk {
  color: var(--danger);
  font-size: 0.75rem;
  line-height: 1.4;
  font-weight: 600;
}
.examples { display: flex; flex-wrap: wrap; gap: 8px; }
.example {
  background: #fff;
  color: var(--accent);
  border: 1px dashed var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  cursor: pointer;
}
.example:hover { border-color: var(--accent); background: #fff8f0; }
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  resize: vertical;
  background: #fff;
}
.row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
}
button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
}
dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  max-width: 520px;
  width: calc(100% - 24px);
}
.settings-form { padding: 20px; display: grid; gap: 12px; }
.settings-form h2 { margin: 0; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0; }
.sponsor {
  margin: 0;
  padding: 10px 12px;
  background: #fff8ee;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.88rem;
  line-height: 1.55;
}
.sponsor a { color: var(--accent); word-break: break-all; }
label { display: grid; gap: 6px; font-size: 0.92rem; }
input, select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font: inherit;
  background: #fff;
}
.wan-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(43, 36, 28, 0.42);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.wan-overlay[hidden] { display: none; }
.wan-card {
  position: relative;
  z-index: 2;
  width: min(360px, calc(100vw - 32px));
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px 22px 22px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(80, 50, 20, 0.28);
  animation: wanPop 0.55s cubic-bezier(0.2, 1.2, 0.3, 1);
}
.wan-avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 12%;
  border: 3px solid #f3e2c4;
  display: block;
  margin: 0 auto 12px;
}
.wan-title {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.12em;
}
.wan-sub { margin: 8px 0 18px; color: var(--muted); }
.wan-card button {
  background: linear-gradient(135deg, #c48a4a, #8b4513);
  border-radius: 999px;
  padding: 10px 22px;
}
.wan-petals { position: absolute; inset: 0; pointer-events: none; }
.wan-petal {
  position: absolute;
  top: -12%;
  font-size: 22px;
  animation: wanFall linear forwards;
}
@keyframes wanPop {
  from { transform: scale(0.72) translateY(18px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}
@keyframes wanFall {
  0% { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 0; }
  12% { opacity: 1; }
  100% { transform: translate3d(var(--dx, 40px), 118vh, 0) rotate(360deg); opacity: 0.15; }
}

@media (max-width: 800px), (max-height: 540px) {
  .shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    max-width: none;
  }
  .main {
    order: 1;
    min-height: 0;
    padding: 10px 10px calc(8px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  .rail.right { order: 2; }
  .rail.left { order: 3; }
  .rail.left, .rail.right {
    border: none;
    border-top: 1px solid var(--line);
    padding: 12px;
  }
  .rail-foot { margin-top: 8px; }
  .top { align-items: flex-start; }
  h1 { font-size: 1rem; }
  .sub { font-size: 0.78rem; }
  .warn { font-size: 0.8rem; }
  .chat {
    min-height: 28dvh;
    max-height: 46dvh;
    padding: 12px;
    border-radius: 12px;
  }
  .composer {
    position: sticky;
    bottom: 0;
    z-index: 4;
    background: #f4efe6;
    padding-bottom: env(safe-area-inset-bottom);
  }
  dialog {
    max-height: calc(100dvh - 16px);
    overflow: auto;
  }
  .bot-row, .msg { max-width: 100%; }
  .examples {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .example { flex: 0 0 auto; }
  .composer textarea { font-size: 16px; }
  button, .support-btn { min-height: 44px; }
}
