: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;
}
.mission {
  display: block;
  width: 100%;
  margin: 0;
  padding: 11px 16px;
  background: var(--accent);
  color: #fffdf8;
  text-align: center;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  line-height: 1.4;
}
.mission:hover { background: #6e3610; }
.mission-title, .mission-sub { display: block; }
.mission-sub {
  margin-top: 2px;
  font-weight: 500;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}
body:has(> .mission) {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
body:has(> .mission) .shell {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  width: 100%;
  max-width: none;
  margin: 0;
}
body:has(> .mission) .main {
  height: auto;
  flex: 1;
}
.shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 240px;
  height: 100vh;
  max-width: none;
  margin: 0;
}
.rail {
  background: var(--rail);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
}
.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;
}
.ad-slot {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: #fff8ee;
}
.ad-kicker {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  color: var(--muted);
}
.ad-slot a {
  display: grid;
  gap: 4px;
  color: var(--ink);
  text-decoration: none;
}
.ad-slot strong { color: var(--accent); font-size: 1rem; }
.ad-slot span { font-size: 0.82rem; line-height: 1.45; }
.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); }
.orig-list button {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--accent);
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
}
.orig-list button:hover { border-color: var(--accent); }
.rail-foot {
  margin-top: 8px;
  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;
}
.talk-roll { margin-top: 4px; }
.talk-label { color: var(--muted); font-size: 0.85rem; text-align: center; }
.talk-window { height: 132px; overflow: hidden; }
.talk-track { display: grid; gap: 8px; }
.talk-track.rolling { animation: talkUp linear infinite; }
.talk-line {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.82rem;
  line-height: 1.4;
}
.talk-line strong { color: var(--accent); }
@keyframes talkUp {
  from { transform: translateY(0); }
  to { transform: translateY(-50%); }
}
.talk-roll:hover .talk-track { animation-play-state: paused; }
.comment-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  display: grid;
  gap: 8px;
}
.comment-card h2 { margin: 0; font-size: 1rem; }
.comment-card input, .comment-card textarea { width: 100%; font-size: 16px; }
.comment-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.comment-list li {
  border-top: 1px dashed var(--line);
  padding-top: 8px;
  font-size: 0.88rem;
  line-height: 1.45;
}
.comment-list strong { color: var(--accent); }
.comment-list button.ghost { margin-top: 6px; padding: 4px 10px; font-size: 0.82rem; }
.board-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}
.board-page header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.board-page h1 { margin: 0; font-size: 1.4rem; }
.board-back { color: var(--accent); }
.board-note { color: var(--muted, #6d6256); }
.bio { display: grid; gap: 12px; }
.bio p { margin: 0; line-height: 1.75; }
.board-form, .board-list {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-top: 16px;
}
.board-form { display: grid; gap: 8px; }
.board-form[hidden] { display: none; }
.board-form input, .board-form textarea, .board-form select { width: 100%; font-size: 16px; }
.board-status { min-height: 1.2em; color: var(--accent); }
.main {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  background: transparent;
}
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.lib-switch { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--muted); font-size: 0.85rem; }
.lib-switch select { font: inherit; font-size: 16px; padding: 4px 8px; }
.lib-note { flex: 0 1 auto; min-height: 0; max-height: 9.5rem; overflow-y: auto; background: #fffdf8; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 0.9rem; line-height: 1.55; }
.lib-note[hidden] { display: none; }
.lib-note p { margin: 0 0 8px; }
.lib-note ul { margin: 0; padding-left: 1.2em; }
.lib-note a { color: var(--accent); }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.notice-wrap { position: relative; }
.notice-btn { position: relative; }
.notice-dot { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: #9a3412; }
.notice-panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: min(320px, calc(100vw - 32px)); background: #fffdf8; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; box-shadow: 0 8px 24px rgba(43, 36, 28, 0.12); }
.notice-panel[hidden] { display: none; }
.notice-head { font-weight: 700; margin-bottom: 8px; }
.notice-item { border-top: 1px solid var(--line); padding-top: 8px; }
.notice-item strong { display: block; }
.notice-item p { margin: 4px 0 8px; color: var(--muted); font-size: 0.88rem; line-height: 1.45; }
.notice-bar { display: flex; gap: 8px; align-items: center; background: #fff7ed; border: 1px solid #e7d3b0; border-radius: 12px; padding: 8px 10px; }
.notice-bar[hidden] { display: none; }
.notice-bar p { margin: 0; flex: 1; font-size: 0.9rem; line-height: 1.4; }
.auth-who { font-weight: 700; color: var(--accent); white-space: nowrap; }
#authDialog { max-width: 420px; width: calc(100vw - 32px); }
#authDialog input, #authDialog select { width: 100%; font-size: 16px; }
#authDialog fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.checks label { display: flex; gap: 6px; align-items: center; font-size: 0.9rem; }
.checks input { width: auto; }
.dev-mask {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(43, 36, 28, 0.45);
  padding: 16px;
}
.dev-mask[hidden] { display: none; }
.dev-pop {
  width: min(360px, calc(100vw - 32px));
  background: #fff;
  border-radius: 14px;
  padding: 14px;
}
.dev-pop img { width: 100%; height: auto; display: block; }
.dev-pop strong { font-size: 1.1rem; letter-spacing: 0.04em; }
.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;
}
.avatar.scene {
  width: 112px;
  height: 74px;
  border-radius: 12px;
  object-position: center;
}
.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 .avatar.scene {
  width: 40px;
  height: 40px;
  border-radius: 10px;
}
.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; }
.top, .warn, .notice-bar, .examples, .composer { flex-shrink: 0; }
.warn {
  background: var(--warn);
  border: 1px solid #f0df9c;
  color: #5c4810;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
}
.chat {
  flex: 1 1 auto;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.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;
}
.rate-row { display: flex; gap: 8px; }
.rate {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.85rem;
}
.rate[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.fix-box { display: grid; gap: 6px; }
.fix-box[hidden] { display: none; }
.fix-box textarea { width: 100%; font-size: 16px; }
.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);
  max-height: calc(100vh - 32px);
  overflow: auto;
}
.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) {
  body:has(> .mission) {
    display: block;
    height: auto;
    overflow: visible;
  }
  .shell {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
    max-width: none;
  }
  .main {
    order: 1;
    height: auto;
    max-height: none;
    overflow: visible;
    min-height: 0;
    padding: 10px 10px calc(8px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  .rail { max-height: none; overflow: visible; }
  .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; }
}
