:root {
  --bg: #faf6f0;
  --outside: #f3ede4;
  --card: #fff;
  --ink: #2e2a26;
  --muted: #8a7f73;
  --green: #4f7a63;
  --green-dark: #3e5f4e;
  --green-soft: #e4efe8;
  --peach: #e9a87c;
  --peach-soft: #fbefe4;
  --line: #efe7dc;
  --danger: #c0564a;
  --shadow: 0 18px 45px rgba(74, 61, 47, 0.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--outside);
  color: var(--ink);
  font-family: "Sukhumvit Set", "Noto Sans Thai", Tahoma, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.48; }
a { color: var(--green-dark); }

#app { min-height: 100%; height: 100%; }
.shell {
  width: min(100%, 520px);
  height: 100dvh;
  min-height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.screen { min-height: 100dvh; width: min(100%, 520px); margin: 0 auto; background: var(--bg); padding: max(30px, env(safe-area-inset-top)) 24px 30px; }
.screen.center { display: flex; flex-direction: column; justify-content: center; }
.topbar { display: flex; align-items: center; gap: 12px; padding: max(12px, env(safe-area-inset-top)) 18px 12px; background: rgba(250,246,240,.94); border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); }
.topbar h1 { font-size: 18px; margin: 0; }
.topbar .sub { color: var(--muted); font-size: 12px; }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(145deg, var(--green-dark), #75a58b); color: #fff; box-shadow: 0 5px 15px rgba(79,122,99,.25); }
.brand-avatar { width: 76px; height: 76px; font-size: 34px; margin: 0 auto 16px; }
.brand { text-align: center; }
.brand h1 { font-size: 34px; margin: 0; }
.brand p { color: var(--muted); max-width: 340px; margin: 8px auto 28px; }
.content { min-height: 0; overflow-y: auto; padding: 18px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.content.with-composer { padding-bottom: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px; margin-bottom: 14px; }
.card.soft { background: var(--green-soft); border-color: transparent; }
.card.peach { background: var(--peach-soft); border-color: transparent; }
.card.alert { border-color: #edc3bc; background: #fff8f6; }
.card h2, .card h3, .card h4, .section-title { margin: 0 0 8px; }
.muted, .hint { color: var(--muted); font-size: 13px; }
.eyebrow { color: var(--green); font-weight: 750; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
.btn { width: 100%; border: 0; border-radius: 14px; padding: 13px 16px; background: var(--green); color: #fff; font-weight: 750; margin-top: 10px; }
.btn:hover { background: var(--green-dark); }
.btn.secondary { background: var(--green-soft); color: var(--green-dark); }
.btn.ghost { background: transparent; color: var(--green-dark); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 12px; background: var(--green-soft); color: var(--green-dark); }
.provider { display: flex; align-items: center; justify-content: center; gap: 10px; background: #fff; color: var(--ink); border: 1px solid var(--line); }
.google-button { min-height: 44px; display: grid; place-items: center; margin-top: 10px; overflow: hidden; }
.auth-divider { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 16px 0 6px; }
.auth-divider::before, .auth-divider::after { content: ""; height: 1px; background: var(--line); }
.email-panel { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.otp-input { text-align: center; letter-spacing: 8px; font-size: 24px; font-weight: 800; }
.field { margin: 14px 0; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; }
.input, textarea, select { width: 100%; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 13px; padding: 12px 14px; outline: none; }
.input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(79,122,99,.12); }
textarea { min-height: 96px; resize: vertical; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row > .grow { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 999px; padding: 8px 13px; }
.chip.on, .chip:hover { border-color: var(--green); background: var(--green-soft); color: var(--green-dark); }
.progress { display: flex; gap: 6px; justify-content: center; margin-bottom: 28px; }
.progress span { width: 36px; height: 4px; border-radius: 9px; background: var(--line); }
.progress span.on { background: var(--green); }
.consent { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; margin: 14px 0; }
.consent input { margin-top: 5px; width: 18px; height: 18px; accent-color: var(--green); }

.messages { display: flex; flex-direction: column; gap: 10px; }
.message { display: flex; gap: 8px; align-items: flex-end; }
.message.user { justify-content: flex-end; }
.message .mini { width: 28px; height: 28px; font-size: 14px; flex: none; }
.bubble { max-width: 82%; white-space: pre-wrap; background: #fff; border: 1px solid var(--line); border-radius: 18px 18px 18px 6px; padding: 11px 14px; }
.message.user .bubble { background: var(--green); color: #fff; border-color: var(--green); border-radius: 18px 18px 6px 18px; }
.quick-replies { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; align-self: center; width: min(100%,460px); margin: 4px auto 8px; }
.quick-reply { flex: 0 1 auto; max-width: 100%; min-width: 0; border: 1px solid var(--green); background: var(--green-soft); color: var(--green-dark); border-radius: 999px; padding: 9px 16px; text-align: center; font: inherit; line-height: 1.35; overflow-wrap: anywhere; }
.quick-reply:hover, .quick-reply:focus-visible { background: var(--green); color: #fff; outline: none; }
.quick-reply:disabled { opacity: .55; cursor: wait; }
.quick-hint { flex-basis: 100%; color: var(--muted); font-size: 11px; text-align: center; margin-top: 2px; }
/* Fresh-news attribution/media card (chat_rules_improve5 §G4) — a LINE-style link preview under อิง's bubble. */
.fresh-card { display: flex; align-items: stretch; gap: 0; max-width: min(82%, 320px); align-self: flex-start; margin: 2px 0 8px 36px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; text-decoration: none; color: var(--ink); box-shadow: 0 2px 8px rgba(74, 61, 47, 0.06); }
.fresh-card:active { opacity: .85; }
.fresh-card-thumb { position: relative; flex: 0 0 92px; width: 92px; min-height: 68px; background: var(--outside); display: flex; align-items: center; justify-content: center; }
.fresh-card-thumb.is-hidden { display: none; }
.fresh-card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fresh-card-play { position: absolute; z-index: 1; color: #fff; font-size: 14px; background: rgba(0, 0, 0, .5); width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; padding-left: 2px; }
.fresh-card-body { display: flex; flex-direction: column; justify-content: center; gap: 4px; padding: 10px 12px; min-width: 0; }
.fresh-card-title { font-size: 13px; line-height: 1.35; color: var(--ink); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.fresh-card-source { font-size: 11px; color: var(--muted); }
.typing { display: inline-flex; gap: 4px; }
.typing i { display: block; width: 7px; height: 7px; border-radius: 50%; background: #3489db; animation: typing-colors 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: -.8s; }.typing i:nth-child(3) { animation-delay: -.4s; }
@keyframes typing-colors {
  0%,100% { background: #3489db; transform: translateY(0); }
  33% { background: #8b5bd6; transform: translateY(-2px); }
  66% { background: #35ad68; transform: translateY(0); }
}
.bottom-dock { position: relative; z-index: 4; min-height: 0; background: #fff; }
.composer-wrap { border-top: 1px solid var(--line); padding: 8px 12px 6px; background: rgba(250,246,240,.98); }
.composer { display: grid; grid-template-columns: 1fr 46px; gap: 8px; }
.composer textarea { height: 50px; min-height: 50px; max-height: 96px; resize: none; padding-top: 12px; padding-bottom: 8px; }
.send { border: 0; border-radius: 14px; background: var(--green); color: #fff; font-weight: 800; }
.quota-top { flex: none; padding: 5px 9px; border-radius: 999px; background: var(--green-soft); color: var(--green-dark); font-size: 11px; font-weight: 750; white-space: nowrap; }
.disclaimer { font-size: 10.5px; color: var(--muted); text-align: center; margin-top: 5px; }
.safety-card { margin-left: 36px; padding: 12px; border: 1px solid #edc3bc; border-radius: 14px; background: #fff8f6; font-size: 13px; }
.card.wall { background: var(--green-soft); border-color: transparent; text-align: center; }
.card.wall a { color: var(--green-dark); font-weight: 700; }
.wall-offer { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.wall-offer .muted { display: block; font-size: 12.5px; margin-bottom: 10px; }
.wall-actions { display: flex; gap: 8px; justify-content: center; }
.wall-actions .btn { flex: 1; }
.wall-cheat { display: flex; align-items: center; gap: 6px; justify-content: center; margin-top: 8px; opacity: .8; }
.wall-cheat .btn { padding: 4px 10px; font-size: 12px; }
.wall-safety { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); text-align: center; font-size: 12px; }
.wall-safety a { color: var(--green-dark); font-weight: 700; }
/* Inline value-moment offer — a distinct card in the message stream, deliberately NOT styled like a .bubble. */
.inline-offer { margin: 14px 8px 6px; padding: 14px 16px; background: #fbf8f3; border: 1px dashed var(--peach); border-left: 4px solid var(--peach); border-radius: 14px; }
.inline-offer b { color: var(--ink); }
.inline-offer p { color: var(--muted); font-size: 12.5px; margin: 4px 0 10px; }
.inline-offer .wall-actions { display: flex; gap: 8px; }
.inline-offer .wall-actions .btn { flex: 1; }

.tabs { display: grid; grid-template-columns: repeat(5,1fr); border-top: 1px solid var(--line); background: #fff; padding: 7px 4px max(7px, env(safe-area-inset-bottom)); }
.tab { border: 0; background: transparent; color: var(--muted); font-size: 10px; padding: 5px 2px; text-decoration: none; text-align: center; }
.tab b { display: block; font-size: 19px; font-weight: 400; }
.tab.on { color: var(--green-dark); font-weight: 750; }
.moods { display: grid; grid-template-columns: repeat(5,1fr); gap: 7px; }
.mood { border: 1px solid var(--line); border-radius: 14px; background: #fff; font-size: 23px; padding: 10px 0; }
.mood.on { background: var(--green-soft); border-color: var(--green); }
.streak { font-size: 26px; font-weight: 800; color: var(--green-dark); }
.memory { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: start; }
.memory .memory-icon { font-size: 23px; }
.locked { background: repeating-linear-gradient(-45deg,#f4eee6,#f4eee6 8px,#faf6f0 8px,#faf6f0 16px); color: var(--muted); }
.menu-row { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.menu-row:last-child { border-bottom: 0; }
.menu-row .chev { color: var(--muted); }
.badge { display: inline-block; padding: 3px 8px; border-radius: 999px; background: var(--green-soft); color: var(--green-dark); font-size: 11px; font-weight: 750; }
.know-card { display: flex; align-items: center; gap: 14px; color: var(--ink); text-decoration: none; background: linear-gradient(135deg,#e4efe8,#fbefe4); border-radius: 18px; padding: 16px; margin-bottom: 14px; }
.know-card small { display: block; color: var(--muted); margin-top: 3px; }
.know-ring { --know: 0deg; width: 66px; height: 66px; flex: none; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--green) var(--know),#dce5df 0); position: relative; }
.know-ring::before { content: ""; position: absolute; inset: 7px; border-radius: inherit; background: var(--card); }
.know-ring span { position: relative; font-weight: 850; color: var(--green-dark); font-size: 14px; }
.know-ring.large { width: 92px; height: 92px; }
.know-ring.large span { font-size: 19px; }
.rel-card { display: flex; align-items: center; gap: 14px; background: linear-gradient(135deg,#e4efe8,#eef4ea); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-bottom: 14px; }
.rel-card .grow { min-width: 0; }
.rel-card b { color: var(--green-dark); }
.rel-card small { display: block; color: var(--muted); margin: 3px 0 8px; }
.rel-bar { height: 8px; border-radius: 999px; background: #dce5df; overflow: hidden; }
.rel-fill { height: 100%; border-radius: 999px; background: var(--green); transition: width .5s ease; }
.rel-gift { text-align: center; background: linear-gradient(135deg,#fbefe4,#e4efe8); border: 1px solid #ecd9c4; border-radius: 18px; padding: 20px 16px; margin-bottom: 14px; }
.rel-gift h3 { font-size: 19px; color: var(--green-dark); margin-top: 4px; }
.rel-gift p { color: var(--ink); margin: 6px 0 10px; }
.rel-gift-perk { display: inline-block; background: var(--green-soft); color: var(--green-dark); border-radius: 999px; padding: 6px 14px; font-weight: 750; margin-bottom: 6px; }
/* Recommendation card — deliberately NOT a chat bubble and NOT อิง's green voice: neutral surface with a
   dashed accent border + a labeled pill, so it always reads as a marked recommendation, never as อิง. */
.rec-card { background: #fbf8f3; border: 1px dashed var(--peach); border-left: 4px solid var(--peach); border-radius: 14px; padding: 14px 16px; margin-bottom: 14px; }
.rec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.rec-badge { display: inline-block; background: var(--peach-soft); color: #9a5a2a; border-radius: 999px; padding: 3px 12px; font-size: 11px; font-weight: 800; letter-spacing: .03em; }
.rec-dismiss { border: 0; background: none; color: var(--muted); font-size: 20px; line-height: 1; padding: 0 4px; }
.rec-card b { color: var(--ink); }
.rec-card p { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.rec-card .btn.secondary { margin-top: 4px; }
.quiz-hero { display: flex; align-items: center; gap: 18px; padding: 18px 6px 24px; }
.quiz-hero h2, .quiz-hero p { margin: 3px 0; }
.quiz-hero p { color: var(--muted); font-size: 13px; }
.quiz-sets { display: grid; gap: 11px; }
.quiz-set-card { display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 12px; padding: 16px; border: 1px solid var(--line); background: #fff; border-radius: 18px; color: var(--ink); text-decoration: none; }
.quiz-set-card.complete { border-color: #b8d1c1; background: #f8fcf9; }
.quiz-set-card small { display: block; color: var(--muted); margin-top: 3px; }
.quiz-set-emoji { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 15px; background: var(--peach-soft); font-size: 25px; }
.quiz-dots { display: flex; justify-content: center; gap: 8px; margin: 4px 0 24px; }
.quiz-dot { width: 10px; height: 10px; border-radius: 50%; background: #e5ded4; transition: .2s; }
.quiz-dot.done { background: #9fc2ab; }
.quiz-dot.current { width: 24px; border-radius: 10px; background: var(--green); }
.quiz-close { flex: none; font-size: 22px; line-height: 1; }
.quiz-question { animation: quiz-in .2s ease-out; }
.quiz-question h2 { font-size: clamp(25px,7vw,32px); line-height: 1.25; margin: 7px 0 20px; }
@keyframes quiz-in { from { opacity: .2; transform: translateX(10px); } }
.quiz-options { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.quiz-option { min-height: 72px; border: 1px solid var(--line); border-radius: 16px; background: #fff; color: var(--ink); padding: 13px 12px; text-align: left; font-weight: 700; transition: transform .15s,border-color .15s,background .15s; }
.quiz-option:hover { border-color: #9fc2ab; transform: translateY(-1px); }
.quiz-option.on { border-color: var(--green); background: var(--green-soft); color: var(--green-dark); box-shadow: inset 0 0 0 1px var(--green); }
.quiz-options.compact .quiz-option { min-height: 58px; }
.quiz-skip { display: block; margin: 19px auto 0; border: 0; background: transparent; color: var(--muted); text-decoration: underline; padding: 8px; }
.quiz-ack { min-height: 0; margin-top: 12px; padding: 0; border-radius: 14px; color: var(--green-dark); background: var(--green-soft); text-align: center; opacity: 0; transform: translateY(5px); transition: .2s; }
.quiz-ack.show { min-height: 48px; padding: 12px; opacity: 1; transform: none; }
.quiz-finish { text-align: center; padding: 22px 0 12px; }
.quiz-finish h2 { font-size: 28px; line-height: 1.3; }
.quiz-finish p { color: var(--muted); }
.finish-confetti { font-size: 58px; }
.quiz-review { margin-top: 20px; }
.quiz-review summary { cursor: pointer; color: var(--green-dark); font-weight: 750; padding: 12px 0; }
.quiz-answer-row { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; border: 0; border-top: 1px solid var(--line); background: transparent; text-align: left; padding: 13px 2px; color: var(--ink); }
.quiz-answer-row small { grid-column: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quiz-answer-row b { grid-column: 2; grid-row: 1 / span 2; align-self: center; color: var(--green); }
.sections { display: grid; gap: 12px; }
.section-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 16px; white-space: pre-wrap; }
.section-card h4 { color: var(--green-dark); margin: 0 0 7px; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.skeleton { height: 92px; border-radius: 16px; margin-bottom: 12px; background: linear-gradient(90deg,#f0e9df 25%,#faf6f0 50%,#f0e9df 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.toast { position: fixed; z-index: 99; left: 50%; bottom: 90px; transform: translate(-50%,20px); background: var(--ink); color: #fff; border-radius: 12px; padding: 10px 14px; opacity: 0; pointer-events: none; transition: .2s; max-width: min(90vw,420px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(46,42,38,.42); display: grid; align-items: end; }
.sheet { width: min(100%,520px); max-height: 88dvh; overflow: auto; margin: 0 auto; border-radius: 24px 24px 0 0; background: var(--bg); padding: 20px 18px max(24px,env(safe-area-inset-bottom)); }
.plan-card { border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-top: 12px; background: #fff; }
.plan-card.featured { border-color: var(--green); box-shadow: 0 8px 25px rgba(79,122,99,.14); }
.price { font-size: 25px; font-weight: 850; color: var(--green-dark); }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.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; }

@media (min-width: 700px) {
  body { padding: 20px 0; }
  .shell { height: calc(100dvh - 40px); min-height: calc(100dvh - 40px); max-height: calc(100dvh - 40px); }
  .shell, .screen { border-radius: 24px; overflow: hidden; }
  .screen { min-height: calc(100dvh - 40px); }
}

@media (max-width: 420px) {
  .topbar.has-action .badge { display: none; }
  .topbar.has-action h1 { font-size: 16px; }
}
