:root {
  --line: #06c755;
  --line-dark: #05a947;
  --ink: #20312a;
  --muted: #6f8179;
  --paper: #f5f0e6;
  --chat: #9fbed1;
  --white: #fff;
  --shadow: 0 22px 70px rgba(22, 58, 43, .18);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans TC", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,.85) 0 8%, transparent 9%),
    linear-gradient(135deg, #d9f3df, #f8edcc 55%, #d7edf1);
  display: grid;
  place-items: center;
  padding: 24px;
}

button { font: inherit; }
.app-shell {
  width: min(1180px, 100%);
  height: min(820px, calc(100vh - 48px));
  min-height: 620px;
  display: grid;
  grid-template-columns: 350px 1fr;
  overflow: hidden;
  background: var(--white);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 30px;
  box-shadow: var(--shadow);
}

.profile-panel {
  position: relative;
  padding: 28px 30px 22px;
  overflow-y: auto;
  background:
    linear-gradient(rgba(255,255,255,.82), rgba(255,255,255,.94)),
    repeating-linear-gradient(45deg, #f3ead7 0 10px, #f8f2e6 10px 20px);
  border-right: 1px solid #dce5df;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 900; letter-spacing: .08em; }
.brand-dot { width: 17px; height: 17px; border-radius: 50% 50% 50% 5px; background: var(--line); transform: rotate(-18deg); }
.portrait-wrap { width: 190px; height: 190px; margin: 28px auto 18px; position: relative; }
.portrait { width: 100%; height: 100%; object-fit: cover; border-radius: 40% 40% 46% 46%; border: 7px solid white; box-shadow: 0 14px 32px rgba(37,86,62,.18); }
.online-dot { position: absolute; right: 9px; bottom: 18px; width: 27px; height: 27px; border: 5px solid white; border-radius: 50%; background: var(--line); }
.eyebrow { margin: 0; color: var(--line-dark); text-align: center; font-size: 13px; font-weight: 800; letter-spacing: .13em; }
h1 { margin: 5px 0 8px; text-align: center; font-size: 30px; }
h1 small { font-size: 14px; color: var(--muted); font-weight: 500; }
.bio { margin: 0 auto 23px; max-width: 280px; color: #5d6d66; font-size: 14px; line-height: 1.8; text-align: center; }
.topic-list { display: grid; gap: 8px; }
.topic {
  display: grid;
  grid-template-columns: 40px 1fr;
  grid-template-rows: 23px 20px;
  gap: 0 8px;
  width: 100%;
  padding: 11px 13px;
  border: 0;
  border-radius: 15px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: .2s ease;
}
.topic:hover { background: #edf8f0; transform: translateX(3px); }
.topic.active { color: #fff; background: var(--line); box-shadow: 0 8px 18px rgba(6,199,85,.24); }
.topic > span { grid-row: 1 / 3; display: grid; place-items: center; font-size: 23px; background: rgba(255,255,255,.7); border-radius: 12px; }
.topic b { font-size: 15px; }
.topic small { opacity: .72; }
.source-note { margin: 20px 0 0; color: #94a099; text-align: center; font-size: 11px; }

.chat-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 76px 34px minmax(0, 1fr) auto;
  overflow: hidden;
  background: var(--chat);
  position: relative;
}
.chat-panel::before { content: ""; position: absolute; inset: 110px 0 90px; opacity: .11; pointer-events: none; background-image: radial-gradient(circle, #27495c 1px, transparent 1.5px); background-size: 28px 28px; }
.chat-header { z-index: 2; display: flex; align-items: center; gap: 12px; padding: 12px 22px; background: rgba(255,255,255,.96); border-bottom: 1px solid #d9e0dc; }
.header-avatar { width: 50px; height: 50px; border-radius: 18px; object-fit: cover; }
.chat-header strong { display: block; font-size: 17px; }
.chat-header div > span { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.chat-header i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.header-actions { margin-left: auto; display: flex; gap: 22px; color: #5a6c64; font-size: 23px; }
.mobile-profile { display: none; border: 0; background: none; font-size: 22px; }
.date-chip { z-index: 1; place-self: center; align-self: end; padding: 4px 12px; border-radius: 20px; background: rgba(45,72,87,.35); color: white; font-size: 11px; }
.messages {
  z-index: 1;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 26px 28px;
  scroll-behavior: smooth;
}
.message { display: flex; gap: 9px; align-items: flex-end; margin: 12px 0; animation: pop .28s ease both; }
.message.me { justify-content: flex-end; }
.avatar { width: 38px; height: 38px; object-fit: cover; border-radius: 14px; box-shadow: 0 3px 8px rgba(35,68,84,.18); }
.bubble { position: relative; max-width: min(590px, 78%); padding: 11px 14px; border-radius: 17px; background: white; box-shadow: 0 3px 9px rgba(35,68,84,.12); line-height: 1.75; white-space: pre-wrap; font-size: 15px; }
.message.bot .bubble { border-bottom-left-radius: 4px; }
.message.me .bubble { background: #b7ef84; border-bottom-right-radius: 4px; }
.asset-link { display: block; margin-top: 8px; color: #087f3c; font-weight: 700; word-break: break-all; }
.time { color: rgba(34,56,67,.64); font-size: 10px; white-space: nowrap; }
.typing .bubble { display: flex; gap: 5px; padding: 15px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: #9aa8a1; animation: blink 1s infinite alternate; }
.typing i:nth-child(2) { animation-delay: .2s; }.typing i:nth-child(3) { animation-delay: .4s; }
.quiz-options { display: grid; gap: 8px; margin-top: 11px; }
.quiz-option { border: 1px solid #d4ded8; border-radius: 12px; background: #fff; padding: 9px 11px; text-align: left; cursor: pointer; }
.quiz-option:hover { border-color: var(--line); background: #f0fff5; }
.quiz-option.correct { color: #057d36; border-color: var(--line); background: #e7faee; font-weight: 700; }
.quiz-option.wrong { color: #b83b3b; border-color: #ee8686; background: #fff1f1; }
.quiz-option:disabled { cursor: default; }
.name-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 12px; white-space: normal; }
.name-form label { grid-column: 1 / -1; color: #4d6257; font-size: 12px; font-weight: 700; }
.name-form input { min-width: 0; border: 1px solid #bed0c5; border-radius: 10px; padding: 10px 11px; font: inherit; color: var(--ink); background: #fff; }
.name-form input:focus { outline: 3px solid rgba(6,199,85,.2); border-color: var(--line); }
.name-form button { border: 0; border-radius: 10px; padding: 9px 13px; color: #fff; background: var(--line-dark); font-weight: 800; cursor: pointer; }
.name-form :disabled { opacity: .58; cursor: default; }
.friendship-certificate { width: min(430px, 100%); margin-top: 13px; padding: 22px 18px 17px; color: #473821; text-align: center; white-space: normal; background: #fffaf0; border: 5px double #b68a40; box-shadow: inset 0 0 0 1px #e5c98e; }
.friendship-certificate::before { content: "詩友情長"; display: block; margin-bottom: 4px; color: #a34937; font-size: 11px; font-weight: 800; letter-spacing: .35em; }
.friendship-certificate h3 { margin: 0; color: #733428; font-family: "Noto Serif TC", serif; font-size: 22px; letter-spacing: .12em; }
.friendship-certificate strong { display: inline-block; margin: 12px 0 7px; padding: 0 22px 3px; color: #193f34; border-bottom: 1px solid #b68a40; font-family: "Noto Serif TC", serif; font-size: 26px; }
.friendship-certificate p { margin: 5px auto 14px; max-width: 350px; font-size: 13px; line-height: 1.8; }
.friendship-certificate footer { color: #766245; font-size: 11px; }

.composer {
  z-index: 2;
  min-width: 0;
  padding: 10px 16px 15px;
  background: rgba(255,255,255,.97);
  border-top: 1px solid #dce2df;
  box-shadow: 0 -5px 18px rgba(47, 81, 97, .08);
}
.variant-row {
  min-width: 0;
  min-height: 30px;
  display: flex;
  gap: 7px;
  margin-bottom: 7px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
.variant { border: 1px solid #cddbd3; border-radius: 20px; background: #fff; padding: 5px 12px; color: #53675d; font-size: 12px; cursor: pointer; white-space: nowrap; }
.variant.active { color: #fff; border-color: var(--line); background: var(--line); }
.input-row { display: flex; align-items: center; gap: 9px; }
.plus { width: 36px; height: 36px; border: 0; border-radius: 50%; background: #eef2ef; color: #718078; font-size: 24px; }
.fake-input { flex: 1; padding: 10px 14px; border-radius: 18px; color: #9aa69f; background: #f2f4f3; font-size: 13px; }
.send { border: 0; border-radius: 18px; padding: 9px 16px; color: #fff; background: var(--line); font-weight: 800; cursor: pointer; }
.send:disabled { opacity: .4; cursor: default; }
.drawer-backdrop { display: none; }

@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes blink { from { opacity: .25; transform: translateY(1px); } to { opacity: 1; transform: translateY(-2px); } }

@media (max-width: 760px) {
  body { padding: 0; }
  .app-shell { height: 100vh; min-height: 0; border-radius: 0; grid-template-columns: 1fr; }
  .profile-panel { position: fixed; z-index: 10; inset: 0 auto 0 0; width: min(340px, 88vw); transform: translateX(-105%); transition: transform .25s ease; box-shadow: 20px 0 45px rgba(24,55,42,.25); }
  .profile-panel.open { transform: translateX(0); }
  .drawer-backdrop { position: fixed; z-index: 9; inset: 0; background: rgba(15,35,27,.42); }
  .drawer-backdrop.open { display: block; }
  .mobile-profile { display: block; }
  .chat-panel { height: 100vh; grid-template-rows: 70px 30px minmax(0, 1fr) auto; }
  .messages { padding: 12px 14px 22px; }
  .bubble { max-width: 82%; font-size: 14px; }
  .header-actions { display: none; }
  .fake-input { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
