:root {
  --bg: #ffffff;
  --ink: #16181d;
  --muted: #5f6670;
  --line: #e6e8ec;
  --soft: #f5f6f8;
  --accent: #c8102e;
  --accent-soft: #fdecee;
  --blue: #1f4fbf;
  --blue-soft: #eaf0fd;
  --gold: #f2b705;
  --warn: #fff6db;
  --warn-line: #f0d27a;
  --ok: #1e7b4f;
  --ok-soft: #e7f5ee;
  --nav-h: 64px;
  color-scheme: light;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 17px/1.45 var(--font);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1 { font-size: 24px; margin: 6px 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 26px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.blurb { color: var(--muted); margin: 4px 0 12px; font-size: 15px; }
main { max-width: 640px; margin: 0 auto; padding: 0 16px; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(1.4) blur(8px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; flex: 1; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: inset 0 0 0 4px var(--accent), inset 0 0 0 7px var(--gold); }
.net { font-size: 13px; font-weight: 600; color: #7a5b00; background: var(--warn); border: 1px solid var(--warn-line); padding: 2px 8px; border-radius: 99px; }
.iconbtn { width: 44px; height: 44px; border: 0; background: transparent; border-radius: 12px; display: grid; place-items: center; color: var(--ink); }
.iconbtn:active { background: var(--soft); }
.ico { display: inline-grid; place-items: center; }
.ico svg { width: 22px; height: 22px; }

/* search and chips */
.searchwrap { position: sticky; top: 65px; z-index: 4; background: var(--bg); padding: 12px 0 8px; }
input, textarea {
  font: inherit; color: var(--ink); width: 100%; padding: 12px 14px; border: 1.5px solid var(--line);
  border-radius: 14px; background: #fff; outline: none;
}
input:focus, textarea:focus { border-color: var(--ink); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  flex: none; border: 1.5px solid var(--line); background: #fff; color: var(--ink); border-radius: 99px;
  padding: 8px 14px; font: 600 15px/1.2 var(--font); white-space: nowrap;
}
.chip[aria-selected="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

/* phrase cards */
.list { display: grid; gap: 10px; }
.card {
  border: 1.5px solid var(--line); border-radius: 16px; padding: 12px 12px 12px 16px; background: #fff;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: start; cursor: pointer;
}
.card:active { background: var(--soft); }
.card .en { font-weight: 700; font-size: 17px; }
.card .vi { font-size: 22px; line-height: 1.3; color: #9d0c24; grid-column: 1; }
.card .say { color: var(--muted); font-size: 15px; font-style: italic; grid-column: 1; }
.card .acts { grid-row: 1 / span 3; grid-column: 2; display: flex; flex-direction: column; gap: 4px; }
.card .star[aria-pressed="true"] { color: var(--gold); }
.card .star[aria-pressed="true"] svg { fill: var(--gold); }
.empty { color: var(--muted); padding: 20px 4px; text-align: center; }

/* buttons */
.btn {
  font: 700 17px/1 var(--font); border: 0; border-radius: 14px; padding: 15px 18px; background: var(--ink); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
}
.btn:active { opacity: .85; }
.btn.big { padding: 18px; font-size: 19px; }
.btn.ghost { background: #fff; color: var(--ink); border: 1.5px solid var(--line); }
.btn.small { width: auto; padding: 10px 14px; font-size: 15px; }
.linkbtn { border: 0; background: none; color: #fff; font: 600 16px var(--font); padding: 12px; text-decoration: underline; }
.pill { border: 1.5px solid var(--line); background: #fff; border-radius: 99px; padding: 8px 14px; font: 600 15px var(--font); color: var(--ink); }
.twobtn { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.bigbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 112px;
  border: 0; border-radius: 18px; background: var(--blue); color: #fff; font: 700 18px/1.2 var(--font); text-align: center; padding: 14px;
  cursor: pointer;
}
.bigbtn small { font-weight: 500; font-size: 13px; opacity: .9; }
.bigbtn .ico svg { width: 34px; height: 34px; }
.bigbtn.alt { background: var(--blue-soft); color: var(--blue); }
.bigbtn.red { background: var(--accent); }
.bigbtn:active { transform: scale(.98); }

/* places */
.place .vi { white-space: pre-line; font-size: 18px; }
.addplace { margin-top: 14px; border: 1.5px dashed var(--line); border-radius: 16px; padding: 12px 14px; }
.addplace summary { font-weight: 700; cursor: pointer; }
.addplace label { display: grid; gap: 6px; margin: 12px 0; font-size: 15px; color: var(--muted); }
.em { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.em a { font-weight: 700; color: var(--accent); text-decoration: none; font-size: 18px; white-space: nowrap; }

/* photo results */
.thumb { display: block; width: 100%; max-height: 260px; object-fit: cover; border-radius: 14px; margin: 0 0 10px; }
.thumb.small { width: auto; max-width: 160px; max-height: 160px; }
.result { border: 1.5px solid var(--line); border-radius: 18px; padding: 14px; margin-top: 8px; }
.result h2 { margin: 0 0 4px; font-size: 21px; }
.result .sum { margin: 0 0 10px; }
.warn { background: var(--warn); border: 1px solid var(--warn-line); border-radius: 12px; padding: 10px 12px; margin: 8px 0; font-size: 15px; }
.warn ul { margin: 0; padding-left: 18px; }
.good { background: var(--ok-soft); color: var(--ok); border-radius: 12px; padding: 10px 12px; margin: 8px 0; font-weight: 600; font-size: 15px; }
.bad { background: var(--accent-soft); color: #8c0b20; border-radius: 12px; padding: 10px 12px; margin: 8px 0; font-size: 15px; }
.bad .btn { margin-top: 8px; background: var(--accent); }
.line { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.line:first-of-type { border-top: 0; }
.line .en { font-weight: 700; }
.line .vi { color: var(--muted); font-size: 15px; }
.line .note { font-size: 14px; color: var(--muted); font-style: italic; grid-column: 1; }
.line .price { text-align: right; grid-row: 1 / span 3; grid-column: 2; }
.line .aud { font-weight: 800; font-size: 18px; }
.line .vnd { color: var(--muted); font-size: 13px; }
.totalrow { display: flex; justify-content: space-between; font-weight: 800; font-size: 18px; border-top: 2px solid var(--ink); padding-top: 10px; margin-top: 6px; }
.via { font-size: 12px; color: var(--muted); margin-top: 10px; }
.loading { display: flex; align-items: center; gap: 12px; padding: 16px; border-radius: 16px; background: var(--soft); margin-top: 8px; }
.spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--ink); animation: spin 0.9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.histitem { display: flex; gap: 10px; align-items: center; border: 1.5px solid var(--line); border-radius: 14px; padding: 8px; cursor: pointer; }
.histitem img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; flex: none; }
.histitem .t { font-weight: 700; }
.histitem .d { color: var(--muted); font-size: 13px; }

/* talk */
.typebox { display: grid; gap: 8px; margin: 6px 0 12px; }
.dirrow { display: flex; }
.note { background: var(--warn); border: 1px solid var(--warn-line); border-radius: 12px; padding: 10px 12px; font-size: 15px; }
.bubble { border-radius: 18px; padding: 14px; border: 1.5px solid var(--line); }
.bubble.mine { background: var(--blue-soft); border-color: #cfdcf7; }
.bubble.theirs { background: var(--accent-soft); border-color: #f6c9d0; }
.bubble .orig { font-size: 15px; color: var(--muted); }
.bubble .big { font-size: 24px; line-height: 1.3; font-weight: 600; margin: 4px 0; }
.bubble .say { color: var(--muted); font-style: italic; font-size: 15px; }
.bubble .back { font-size: 14px; color: var(--muted); margin-top: 4px; }
.bubble .row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.bubble.err { background: var(--soft); }

/* money */
.conv { border: 1.5px solid var(--line); border-radius: 18px; padding: 14px; margin-top: 10px; }
.conv label { font-weight: 700; color: var(--muted); font-size: 15px; }
#amtIn { font-size: 32px; font-weight: 700; padding: 10px 12px; margin: 6px 0; }
.eq { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 10px; }
#amtOut { font-size: 34px; font-weight: 800; }
.tipcard { background: var(--soft); border-radius: 16px; padding: 12px 14px; margin-top: 12px; font-size: 15px; }
.tipcard p { margin: 6px 0; }
.numgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.num { border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 12px; cursor: pointer; }
.num b { display: block; font-size: 18px; }
.num span { color: #9d0c24; font-size: 17px; }

/* bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(5, 1fr);
  background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  height: var(--nav-h); border: 0; background: none; color: var(--muted); font: 600 12px/1.1 var(--font);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.tabs button[aria-current="page"] { color: var(--accent); }
.tabs .ico svg { width: 24px; height: 24px; }

/* viewer */
.viewer { position: fixed; inset: 0; z-index: 20; background: #fff; display: flex; flex-direction: column; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); }
.vtop { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.vlabel { color: var(--muted); font-weight: 600; font-size: 15px; }
.vbox { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.vvi { font-weight: 700; line-height: 1.22; text-align: center; white-space: pre-line; overflow-wrap: anywhere; color: var(--ink); }
.vfoot { display: grid; gap: 8px; }
.ven { font-size: 18px; font-weight: 600; text-align: center; }
.vsay { font-size: 16px; color: var(--muted); font-style: italic; text-align: center; }

/* listening */
.listen { position: fixed; inset: 0; z-index: 25; background: rgba(16,18,24,.94); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px; text-align: center; }
.listen .btn { background: #fff; color: var(--ink); max-width: 320px; }
.pulse { width: 110px; height: 110px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; animation: pulse 1.4s ease-in-out infinite; }
.pulse svg { width: 48px; height: 48px; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(200,16,46,.6); } 50% { box-shadow: 0 0 0 26px rgba(200,16,46,0); } }
.lstitle { font-size: 22px; font-weight: 700; margin: 12px 0 0; }
.lstext { font-size: 20px; min-height: 2.6em; max-width: 520px; }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(16,18,24,.45); display: flex; align-items: flex-end; }
.sheetin { background: #fff; width: 100%; max-height: 88vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 12px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheetin p { font-size: 15px; }
.row { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; margin: 10px 0 14px; }
.row input { width: 22px; height: 22px; flex: none; margin-top: 1px; }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom)); z-index: 40; background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 14px; font-size: 15px; text-align: center; }

/* ---------- live talk ---------- */
body.live-on { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 170px); }
.livehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-top: 6px; }
.livehead h1 { margin-bottom: 0; }
.toggles { margin: 8px 0 4px; }
.chip.tg { font-size: 13px; padding: 7px 11px; color: var(--muted); }
.chip.tg[aria-pressed="true"] { background: var(--ok-soft); border-color: #b7dfc9; color: var(--ok); }
.chip.tg[aria-pressed="true"]::before { content: "\2713  "; }
.convo { display: grid; gap: 10px; margin-top: 10px; }
.intro { background: var(--soft); border-radius: 18px; padding: 14px; font-size: 15px; }
.intro p { margin: 4px 0 8px; }
.introvi { font-size: 21px; line-height: 1.3; color: #9d0c24; font-weight: 600; margin: 4px 0 10px; }
.intro .row { display: flex; gap: 8px; flex-wrap: wrap; }
.bub { border-radius: 20px; padding: 12px 14px; max-width: 92%; border: 1.5px solid var(--line); }
.bub.me { justify-self: end; background: var(--blue-soft); border-color: #cfdcf7; border-bottom-right-radius: 6px; }
.bub.them { justify-self: start; background: var(--accent-soft); border-color: #f6c9d0; border-bottom-left-radius: 6px; }
.bub .said { font-size: 14px; color: var(--muted); }
.bub .out { font-size: 21px; line-height: 1.3; font-weight: 600; margin-top: 4px; }
.bub.latest .out { font-size: 30px; line-height: 1.25; }
.bub .out.pending { display: flex; align-items: center; gap: 10px; font-size: 16px; color: var(--muted); font-weight: 500; }
.bub .err { color: #8c0b20; font-size: 15px; margin-top: 4px; }
.bub.hearing { border-style: dashed; }
.bub.hearing .out { font-size: 22px; color: var(--muted); min-height: 1.3em; }
.minirow { display: flex; gap: 4px; margin-top: 6px; justify-content: flex-end; }
.mini { width: 40px; height: 40px; border-radius: 12px; border: 0; background: rgba(255,255,255,.7); display: grid; place-items: center; color: var(--ink); }
.mini svg { width: 20px; height: 20px; }
.talkbar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 6;
  background: rgba(255,255,255,.97); border-top: 1px solid var(--line); padding: 6px 16px 10px;
}
.livehint { margin: 0 0 6px; min-height: 20px; text-align: center; font-size: 14px; font-weight: 600; color: var(--muted); }
.talkrow { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: 1fr 64px 1fr; gap: 8px; align-items: stretch; }
.talkbtn {
  border: 0; border-radius: 20px; min-height: 96px; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font: 700 19px/1.15 var(--font); padding: 8px; position: relative;
}
.talkbtn small { font: 500 13px/1.2 var(--font); opacity: .92; }
.talkbtn .ico svg { width: 30px; height: 30px; }
.talkbtn.me { background: var(--blue); }
.talkbtn.them { background: var(--accent); }
.talkbtn.on { box-shadow: 0 0 0 4px #fff, 0 0 0 7px currentColor; }
.talkbtn.me.on { color: #fff; box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--blue); }
.talkbtn.them.on { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--accent); }
.talkbtn[data-phase="listening"] { animation: listenpulse 1.2s ease-in-out infinite; }
.talkbtn[data-phase="listening"] small::after { content: " \00b7  listening"; }
.talkbtn[data-phase="working"] { opacity: .8; }
@keyframes listenpulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.035); } }
.typebtn { border: 1.5px solid var(--line); background: #fff; border-radius: 16px; font: 700 14px var(--font); color: var(--ink); }
