:root {
  --bg1: #fff5ec; --bg2: #ffe9f0; --bg3: #eaf3ff;
  --ink: #3b2f2f; --muted: #9a8b86;
  --coco: #ff8a5c; --coco-d: #f96f3d;
  --ai: #ffffff; --user: #ffd9a8;
  --shadow: 0 10px 30px rgba(255,138,92,.18);
  --r: 22px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Noto Sans SC", "Baloo 2", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2) 45%, var(--bg3));
  background-attachment: fixed;
}
#app { max-width: 560px; margin: 0 auto; height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* ---------- Picker ---------- */
.hero { text-align: center; padding: 32px 20px 12px; }
.hero-emoji { font-size: 64px; filter: drop-shadow(0 6px 10px rgba(0,0,0,.12)); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px); } }
.hero h1 { font-family: "Baloo 2", sans-serif; font-size: 34px; margin: 8px 0 2px; }
.hero h1 span { color: var(--coco-d); }
.hero p { color: var(--muted); margin: 4px 0 0; font-size: 14px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 16px; overflow-y: auto; }
.card {
  background: rgba(255,255,255,.82); border-radius: var(--r); padding: 18px 16px;
  box-shadow: var(--shadow); text-align: left; transition: transform .12s ease, box-shadow .12s ease;
  border: 2px solid transparent; display: flex; flex-direction: column; gap: 6px; min-height: 116px;
}
.card:active { transform: scale(.97); }
.card .c-emoji { font-size: 32px; }
.card .c-zh { font-weight: 700; font-size: 17px; }
.card .c-en { color: var(--muted); font-size: 12px; font-family: "Baloo 2", sans-serif; }
.card.emotional { background: linear-gradient(150deg, #fff, #ffeef4); border-color: #ffd4e3; }
.tag { align-self: flex-start; font-size: 10px; padding: 2px 8px; border-radius: 999px; background: #ffe1cf; color: var(--coco-d); margin-top: auto; }
.card.emotional .tag { background: #ffd9e6; color: #d6437f; }
.tiny { text-align: center; color: var(--muted); font-size: 11px; padding: 10px 0 16px; }

/* ---------- Chat ---------- */
.bar { display: flex; align-items: center; gap: 10px; padding: 14px 16px; }
.bar-title { font-weight: 700; font-size: 18px; flex: 1; }
.ghost { width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.7); font-size: 18px; box-shadow: var(--shadow); color: var(--ink); }
.pill { font-size: 12px; padding: 6px 12px; border-radius: 999px; background: #fff; box-shadow: var(--shadow); white-space: nowrap; }
.pill.idle { color: var(--muted); }
.pill.listening { color: #fff; background: #ff5d6c; }
.pill.thinking { color: #fff; background: #ffac42; }
.pill.speaking { color: #fff; background: #38c172; }
.pill.error { color: #fff; background: #e3526a; }

.thread { flex: 1; overflow-y: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 86%; padding: 12px 15px; border-radius: 20px; box-shadow: var(--shadow); line-height: 1.4; animation: pop .18s ease; }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }
.msg.ai { align-self: flex-start; background: var(--ai); border-bottom-left-radius: 6px; }
.msg.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 6px; }
.msg .en { font-family: "Baloo 2", sans-serif; font-size: 17px; }
.msg .zh { color: var(--muted); font-size: 13px; margin-top: 3px; }
.msg .meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.badge { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: #fff0e6; color: var(--coco-d); }
.replay { font-size: 14px; background: #fff0e6; width: 28px; height: 28px; border-radius: 50%; }
.typing span { display: inline-block; width: 7px; height: 7px; margin: 0 2px; border-radius: 50%; background: var(--coco); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

.composer { display: flex; align-items: center; gap: 10px; padding: 10px 16px; }
#text-input { flex: 1; border: none; outline: none; padding: 13px 18px; border-radius: 999px; background: rgba(255,255,255,.85); box-shadow: var(--shadow); font-size: 15px; }
.send { font-size: 16px; }
.mic { position: relative; width: 64px; height: 64px; border-radius: 50%; background: linear-gradient(160deg, var(--coco), var(--coco-d)); box-shadow: 0 10px 24px rgba(249,111,61,.45); display: grid; place-items: center; flex: none; }
.mic .mic-icon { font-size: 26px; }
.mic.rec { background: linear-gradient(160deg, #ff6b6b, #e3526a); }
.mic .mic-ring { position: absolute; inset: 0; border-radius: 50%; border: 3px solid rgba(255,107,107,.6); opacity: 0; }
.mic.rec .mic-ring { animation: ring 1.1s ease-out infinite; }
@keyframes ring { from { opacity: .7; transform: scale(1); } to { opacity: 0; transform: scale(1.5); } }
.mic:disabled { filter: grayscale(.5) brightness(.95); box-shadow: none; }
.hint { text-align: center; color: var(--muted); font-size: 12px; padding: 0 16px 16px; }

/* ---------- Voice + speed bar (picker) ---------- */
.voicebar {
  display: flex; align-items: center; gap: 10px; width: calc(100% - 32px);
  margin: 4px 16px 0; padding: 13px 16px; border-radius: 18px; text-align: left;
  background: rgba(255,255,255,.7); box-shadow: var(--shadow); color: var(--ink);
}
.voicebar:active { transform: scale(.99); }
.vb-label { font-weight: 700; font-size: 13px; white-space: nowrap; }
.vb-summary { font-size: 13px; color: var(--coco-d); font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vb-go { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* ---------- Voice chip (chat bar) ---------- */
.voice-chip { font-size: 12px; padding: 6px 11px; border-radius: 999px; background: #fff; box-shadow: var(--shadow); color: var(--coco-d); white-space: nowrap; max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.voice-chip.clone { color: #fff; background: linear-gradient(160deg, var(--coco), var(--coco-d)); }

/* ---------- Settings sheet (voice + speed) ---------- */
.sheet { position: fixed; inset: 0; z-index: 45; display: flex; align-items: flex-end; justify-content: center; background: rgba(59,47,47,.42); backdrop-filter: blur(3px); animation: fade .15s ease; }
.sheet-card { width: 100%; max-width: 560px; background: linear-gradient(160deg, #fff, #fff6ef); border-radius: 26px 26px 0 0; padding: 18px 20px calc(20px + env(safe-area-inset-bottom)); box-shadow: 0 -16px 50px rgba(249,111,61,.25); animation: rise .22s ease; }
@keyframes rise { from { transform: translateY(40px); opacity: .4; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h3 { font-family: "Baloo 2", sans-serif; margin: 0; font-size: 19px; }
.field { margin-bottom: 18px; }
.field-label { display: block; font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 9px; }
.field-label b { float: right; font-weight: 600; color: var(--coco-d); }
.select { width: 100%; font-family: inherit; font-size: 15px; padding: 12px 14px; border-radius: 14px; border: none; background: #fff; box-shadow: var(--shadow); color: var(--ink); -webkit-appearance: none; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23f96f3d' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 16px center; }
.field-actions { display: flex; gap: 8px; margin-top: 10px; }
.chip-btn { font-size: 13px; font-weight: 600; padding: 9px 14px; border-radius: 999px; color: var(--coco-d); background: #fff0e6; box-shadow: var(--shadow); }
.chip-btn:active { transform: scale(.96); }
.chip-btn:disabled { filter: grayscale(.4) opacity(.7); }
.slider { width: 100%; height: 30px; -webkit-appearance: none; appearance: none; background: transparent; }
.slider::-webkit-slider-runnable-track { height: 8px; border-radius: 999px; background: linear-gradient(90deg, #ffd9a8, var(--coco)); }
.slider::-moz-range-track { height: 8px; border-radius: 999px; background: linear-gradient(90deg, #ffd9a8, var(--coco)); }
.slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 26px; height: 26px; margin-top: -9px; border-radius: 50%; background: #fff; border: 3px solid var(--coco-d); box-shadow: 0 4px 10px rgba(249,111,61,.4); cursor: pointer; }
.slider::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 3px solid var(--coco-d); box-shadow: 0 4px 10px rgba(249,111,61,.4); cursor: pointer; }
.slider-ticks { display: flex; justify-content: space-between; margin-top: 4px; font-size: 10px; color: var(--muted); }
.m-primary.full { width: 100%; padding: 14px; margin-top: 4px; }

/* ---------- Clone modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 18px; background: rgba(59,47,47,.42); backdrop-filter: blur(3px); animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.modal-card { position: relative; width: 100%; max-width: 440px; background: linear-gradient(160deg, #fff, #fff6ef); border-radius: var(--r); padding: 24px 22px 20px; box-shadow: 0 24px 60px rgba(249,111,61,.3); max-height: 92dvh; overflow-y: auto; animation: pop .2s ease; }
.modal-card h2 { font-family: "Baloo 2", sans-serif; margin: 0 0 8px; font-size: 22px; }
.modal-sub { color: var(--muted); font-size: 13px; line-height: 1.55; margin: 0 0 14px; }
.modal-sub span { font-size: 12px; }
.modal-close { position: absolute; top: 12px; right: 14px; width: 32px; height: 32px; border-radius: 50%; font-size: 22px; color: var(--muted); background: rgba(0,0,0,.04); }
.read-prompt { background: #fff0e6; border-radius: 14px; padding: 14px 16px; font-family: "Baloo 2", sans-serif; font-size: 16px; line-height: 1.5; color: var(--ink); margin-bottom: 16px; }
.rec-row { display: flex; align-items: center; gap: 14px; }
.rec-btn { font-size: 15px; font-weight: 600; padding: 12px 20px; border-radius: 999px; color: #fff; background: linear-gradient(160deg, var(--coco), var(--coco-d)); box-shadow: 0 8px 20px rgba(249,111,61,.4); }
.rec-btn.rec { background: linear-gradient(160deg, #ff6b6b, #e3526a); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.04); } }
.rec-timer { font-variant-numeric: tabular-nums; font-size: 15px; color: var(--muted); }
.clone-playback { width: 100%; margin-top: 14px; height: 38px; }
.consent { display: flex; align-items: flex-start; gap: 9px; margin: 16px 0 6px; font-size: 13px; line-height: 1.5; color: var(--ink); cursor: pointer; }
.consent input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--coco-d); flex: none; }
.consent small { color: var(--muted); font-size: 11px; }
.clone-status { min-height: 18px; font-size: 13px; color: var(--coco-d); margin: 6px 0 2px; }
.clone-status.err { color: #e3526a; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }
.m-ghost { font-size: 14px; padding: 11px 18px; border-radius: 999px; color: var(--muted); background: rgba(0,0,0,.05); }
.m-primary { font-size: 14px; font-weight: 600; padding: 11px 20px; border-radius: 999px; color: #fff; background: linear-gradient(160deg, var(--coco), var(--coco-d)); box-shadow: var(--shadow); }
.m-primary:disabled { filter: grayscale(.6) opacity(.6); box-shadow: none; cursor: default; }
