:root {
  --paper: #F5EFE6;
  --card: #FFFBF5;
  --ink: #2E2A26;
  --ink-2: #6B625A;
  --ink-3: #9C9289;
  --line: #E6DCCF;
  --accent: #3F6B66;      /* 安靜的深青綠：信任、不刺激 */
  --accent-soft: #DCE8E5;
  --warm: #D99A5B;
  --line-green: #06C755;
  --alert-bg: #FBEDE4;
  --alert-ink: #8A3F1E;
  --r: 18px;
  --serif: "Noto Serif TC", serif;
  --sans: "Noto Sans TC", -apple-system, "PingFang TC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }

.app {
  max-width: 460px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  position: relative;
}

.screen { display: none; flex-direction: column; min-height: calc(100dvh - 48px); animation: in .35s ease both; }
.screen.is-active { display: flex; }
@keyframes in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- 首頁 ---------- */
.home { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 24px 0; }
.bubble-art { position: relative; height: 112px; margin-bottom: 28px; }
.bubble-art .b {
  position: absolute; padding: 10px 16px; border-radius: 18px;
  font-size: 15px; background: var(--card); border: 1px solid var(--line);
}
.bubble-art .b1 { left: 0; top: 0; color: var(--ink-3); letter-spacing: 3px; border-bottom-left-radius: 6px; }
.bubble-art .b2 {
  right: 0; top: 52px; background: var(--accent); color: #fff; border-color: var(--accent);
  border-bottom-right-radius: 6px; animation: pop .6s .4s ease both;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.96); } to { opacity: 1; transform: none; } }

.title { font-family: var(--serif); font-weight: 700; font-size: 34px; line-height: 1.35; margin: 0 0 16px; letter-spacing: .5px; }
.lead { color: var(--ink-2); margin: 0 0 32px; }
.promise { list-style: none; padding: 0; margin: 20px 0 0; color: var(--ink-3); font-size: 14px; }
.promise li::before { content: "·"; margin-right: 8px; color: var(--accent); font-weight: 700; }

.fine { font-size: 12.5px; color: var(--ink-3); text-align: center; margin: 16px 0 0; }
.fine a { color: var(--ink-2); white-space: nowrap; }

/* ---------- 問題卡 ---------- */
.bar { display: flex; justify-content: space-between; align-items: center; height: 40px; margin-bottom: 20px; }
.back { background: none; border: 0; padding: 8px 0; color: var(--ink-2); font-size: 15px; }
.step { font-size: 13px; color: var(--ink-3); letter-spacing: 1px; }

.q { font-family: var(--serif); font-size: 26px; line-height: 1.45; margin: 0 0 8px; font-weight: 700; }
.q--sm { font-size: 22px; }
.hint { color: var(--ink-3); font-size: 14px; margin: 0 0 16px; }
.q + .chips { margin-top: 20px; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chips--stack { flex-direction: column; }
.chip {
  background: var(--card); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 12px 18px; text-align: left; font-size: 16px; transition: border-color .08s, background-color .08s;
}
.chips--stack .chip { padding: 15px 18px; }
.chip:hover { border-color: #CDBFAE; }
.chip.is-on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 500; }

.field {
  width: 100%; margin-top: 14px; padding: 14px 16px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--card); font: inherit; color: var(--ink);
}
.field:focus, .msg-text:focus { outline: none; border-color: var(--accent); }
.field--area { resize: vertical; min-height: 88px; }
.detail-label { display: block; margin-top: 24px; font-size: 15px; color: var(--ink-2); }
.detail-label + .field { margin-top: 8px; }
.opt { color: var(--ink-3); font-size: 13px; }

.foot { margin-top: auto; padding-top: 24px; }

/* ---------- 按鈕 ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; width: 100%;
  min-height: 54px; border-radius: 16px; border: 0; font-size: 17px; font-weight: 500;
  text-decoration: none; transition: transform .1s ease, opacity .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .35; cursor: default; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--line { background: var(--line-green); color: #fff; }
.btn--ghost { background: transparent; border: 1.5px solid var(--line); color: var(--ink); }
.link { background: none; border: 0; color: var(--ink-2); text-decoration: underline; text-underline-offset: 4px; font-size: 15px; padding: 12px; margin: 8px auto 0; display: block; }

/* ---------- 等待 ---------- */
.loading { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; text-align: center; }
.loading .btn { max-width: 280px; }
.loading-text { color: var(--ink-2); margin: 0; }
.dots { display: flex; gap: 8px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); opacity: .3; animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .25; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-4px); } }

/* ---------- 結果 ---------- */
.tabs { display: flex; gap: 6px; background: #EBE2D6; padding: 4px; border-radius: 14px; margin: 8px 0 14px; }
.tab { flex: 1; background: none; border: 0; padding: 10px 0; border-radius: 11px; font-size: 15px; color: var(--ink-2); }
.tab[hidden] { display: none; }
.tab.is-on { background: var(--card); color: var(--ink); font-weight: 500; box-shadow: 0 1px 3px rgba(46,42,38,.08); }

/* 仿 LINE 聊天室：一眼就認得「這是要傳出去的樣子」 */
.chat { border-radius: var(--r); overflow: hidden; box-shadow: 0 1px 0 var(--line), 0 8px 24px -12px rgba(46,42,38,.25); }
.chat-head {
  display: flex; align-items: center; gap: 10px; height: 46px; padding: 0 14px;
  background: #F7F8FA; color: #1E2329; font-weight: 700; font-size: 16px; border-bottom: 1px solid #E3E6EA;
}
.chat-chev { font-size: 22px; font-weight: 400; color: #6B7480; line-height: 1; margin-top: -2px; }
.chat-body { background: var(--line-bg, #A9BEDB); padding: 16px 12px 18px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: flex-end; gap: 6px; }
.row[hidden] { display: none; }
.row--me { justify-content: flex-end; }
.row--them { justify-content: flex-start; }
.row-meta { font-size: 10.5px; color: rgba(30,35,41,.6); line-height: 1.3; text-align: right; flex: none; padding-bottom: 2px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none; align-self: flex-start;
  background: #EAD9C6; color: #7A5A3C; display: grid; place-items: center; font-size: 14px; font-weight: 700;
}
.bubble {
  position: relative; max-width: 78%; padding: 9px 13px; border-radius: 18px;
  font-size: 16px; line-height: 1.65; color: #1E2329; word-break: break-word;
}
.bubble--me { background: #8DE07B; border-top-right-radius: 4px; }
.bubble--them { background: #fff; border-top-left-radius: 4px; }
.msg-text {
  font: inherit; font-size: 16px; line-height: 1.65; width: 78%; max-width: 78%;
  border: 2px solid transparent; resize: none; display: block; outline: none; overflow: hidden;
}
.msg-text:hover { border-color: rgba(30,35,41,.12); }
.msg-text:focus { border-color: #3D8B2F; }
.typing .bubble { padding: 12px 16px; }
.dots--sm i { width: 7px; height: 7px; background: #8A929C; }

.edit-hint { font-size: 12.5px; color: var(--ink-3); margin: 8px 2px 0; }
.edit-hint::before { content: "✎ "; }
.msg-why { margin: 10px 0 0; font-size: 14px; color: var(--ink-2); }
.msg-why::before { content: "什麼時候用："; color: var(--warm); font-weight: 500; }

.btn--rehearse { margin-top: 18px; }
.btn--rehearse::before { content: "▶"; font-size: 11px; margin-right: 8px; opacity: .8; }

/* ---------- 預演 ---------- */
.rehearse { margin-top: 26px; }
.rehearse-title { font-family: var(--serif); font-size: 19px; margin: 0 0 12px; }
.cards {
  display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory;
  margin: 0 -20px; padding: 2px 20px 6px; scrollbar-width: none; overscroll-behavior-x: contain;
}
.cards::-webkit-scrollbar { display: none; }
.card {
  flex: 0 0 calc(100% - 28px); scroll-snap-align: center; border-radius: var(--r); overflow: hidden;
  background: var(--card); border: 1px solid var(--line);
}
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-size: 13px; color: var(--ink-2); }
.card-kind { font-weight: 700; color: var(--ink); }
.card-kind small { font-weight: 400; color: var(--ink-3); margin-left: 6px; }
.card-n { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.card .chat-body { gap: 10px; padding: 14px 12px; }
.card .row--me .bubble { max-width: 80%; }
.suggest-label { font-size: 10.5px; color: rgba(30,35,41,.65); text-align: right; margin: 2px 4px -6px 0; }
.card-tip { padding: 12px 14px 14px; font-size: 14px; color: var(--ink-2); line-height: 1.6; }
.card-tip::before { content: "💡 "; }
.card[data-kind="hard"] .card-kind { color: var(--alert-ink); }
.card[data-kind="best"] .card-kind { color: var(--accent); }

.cards-dots { display: flex; justify-content: center; gap: 8px; margin-top: 12px; }
.cards-dots button { width: 8px; height: 8px; border-radius: 50%; border: 0; padding: 0; background: #D5C9BA; transition: width .2s, background .2s; }
.cards-dots button.is-on { width: 22px; border-radius: 4px; background: var(--accent); }
.rehearse-err { text-align: center; color: var(--alert-ink); font-size: 14px; margin: 12px 0 0; }

.actions { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; margin-top: 16px; }
.after { text-align: center; color: var(--ink-2); font-size: 14px; margin: 20px 0 0; }

/* ---------- 安全網 ---------- */
.crisis { background: var(--alert-bg); color: var(--alert-ink); border-radius: 14px; padding: 14px 16px; margin: 16px 0 4px; font-size: 14.5px; line-height: 1.7; }
.crisis strong { display: block; margin-bottom: 4px; }
.crisis a { color: var(--alert-ink); font-weight: 700; white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px;
  transition: all .25s ease; pointer-events: none;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 600px) {
  .app { padding-top: 48px; }
  .title { font-size: 38px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
