:root {
  --primary: #2563eb;
  --primary-button: #2b67ee;
  --navy: #1b2f78;
  --canvas: #f5f7fb;
  --chip: #e4edff;
  --text: #10224f;
  --body: #26345e;
  --secondary: #5b6785;
  --hint: #7a859f;
  --line: #e3e9fb;
  --border: #d5ddf5;
  --shadow: 0 8px 24px rgba(8, 20, 84, 0.08);
  --error: #c62828;
  --ok: #1f9d63;
  font-family: "Khmer Sangam MN", "Noto Sans Khmer", "Segoe UI", Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 50% -10%, #e4edff, transparent 60%),
    var(--canvas);
  color: var(--text);
}

button, textarea { font: inherit; }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.phone {
  position: relative;
  width: min(440px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  background: #fff;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 8px 16px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.mark {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--chip);
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.12);
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.2px;
  color: var(--primary);
}

.brand p { margin: 1px 0 0; font-size: 12px; color: var(--hint); font-weight: 500; }

.top-actions { display: flex; gap: 4px; align-items: center; }

.nav-link { font-size: 13px; text-decoration: none; padding: 6px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--body);
  cursor: pointer;
  font-size: 18px;
}

.icon-btn:hover { background: var(--canvas); }

.banner {
  margin: 0 16px 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: #eaf3ff;
  color: #1f3f9e;
  font-size: 12px;
  line-height: 1.4;
}

.banner.live {
  background: #e3f6ec;
  color: var(--ok);
}

.stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px 16px 20px;
}

.hero { text-align: center; padding: 12px 8px 4px; }

.hero-mark {
  width: 84px;
  height: 84px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(37, 99, 235, 0.16), rgba(27, 47, 120, 0.08));
  color: var(--navy);
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.1);
}

.hero h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.4px;
}

.hero p {
  margin: 10px 12px 0;
  color: var(--secondary);
  font-size: 14px;
  line-height: 1.45;
}

.actions { display: grid; gap: 12px; margin-top: 24px; }

.action {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 18px;
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.action:hover { border-color: #c5d4fb; }

.action-icon {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--chip);
  display: grid;
  place-items: center;
  color: var(--primary);
  flex: none;
  font-size: 18px;
}

.action strong { display: block; font-size: 15px; }
.action span { display: block; margin-top: 2px; color: var(--secondary); font-size: 13px; }

.recent { margin-top: 28px; }
.recent h3 { margin: 0 0 10px; font-size: 13px; color: var(--hint); font-weight: 600; }

.recent button, .history-item {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  text-align: left;
  padding: 12px 14px;
  margin-bottom: 8px;
  border-radius: 14px;
  cursor: pointer;
  color: var(--text);
}

.recent button small, .history-item small {
  display: block;
  margin-top: 2px;
  color: var(--hint);
  font-size: 12px;
}

.thread { display: flex; flex-direction: column; gap: 12px; }

.bubble {
  max-width: 86%;
  padding: 12px 14px;
  border-radius: 18px;
  line-height: 1.45;
  font-size: 14.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.user {
  margin-left: auto;
  background: var(--primary-button);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.bubble.assistant {
  background: var(--canvas);
  color: var(--text);
  border-bottom-left-radius: 6px;
}

.bubble-tools {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.bubble-tools button {
  border: 0;
  background: transparent;
  color: var(--hint);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}

.bubble-tools button.on { color: var(--primary); }

.thinking {
  margin: 0 16px 6px;
  color: var(--hint);
  font-size: 13px;
}

.speak-status {
  margin: 0;
  padding: 8px 16px 0;
  color: var(--secondary);
  font-size: 13px;
}

.speak-status.error { color: var(--error); }

.bubble.speech.pass { box-shadow: inset 3px 0 0 var(--ok); }

.bubble.speech.fail { box-shadow: inset 3px 0 0 var(--error); }

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex: none;
  padding: 12px 12px 18px;
  border-top: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 -10px 24px rgba(16, 34, 79, 0.05);
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 13px 16px;
  min-height: 48px;
  max-height: 140px;
  outline: none;
  color: var(--text);
  line-height: 1.4;
  background: var(--canvas);
}

.composer textarea:focus { border-color: var(--primary); background: #fff; }

.composer #send,
.composer .mic {
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 50%;
  padding: 0;
  display: grid;
  place-items: center;
}

.composer #send {
  border: 0;
  background: var(--primary-button);
  color: #fff;
  font-size: 0;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M3.4 20.6 21 12 3.4 3.4l2.1 7.2L16 12l-10.5 1.4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 22px;
}

.composer #send:disabled {
  background-color: #c5cedd;
  cursor: default;
}

.composer .mic {
  border: 0;
  background: var(--chip);
  color: var(--primary);
  cursor: pointer;
}

.composer .mic svg { width: 22px; height: 22px; display: block; }

.composer .mic[aria-pressed="true"] {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}

.composer .mic:disabled {
  color: #b0b8c9;
  cursor: default;
}

.voice-mode {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 12px 18px 28px;
  background:
    radial-gradient(420px 280px at 50% 78%, #e7efff, transparent 70%),
    #f7f9ff;
  text-align: center;
}

.voice-bar {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  flex: none;
}

.voice-mode[hidden] { display: none !important; }

.voice-close {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
  padding: 4px 0;
}

.voice-orb {
  width: 148px;
  height: 148px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  background: radial-gradient(circle at 38% 32%, #c5d8ff, #4d82f5 46%, #1d4ed8 78%);
  box-shadow: 0 0 0 18px rgba(43, 103, 238, 0.12);
}

.voice-mode.listening .voice-orb,
.voice-mode.speaking .voice-orb {
  animation: voice-pulse 1.5s ease-in-out infinite;
}

.voice-mode.speaking .voice-orb {
  animation-duration: 0.85s;
  box-shadow: 0 0 0 18px rgba(31, 157, 99, 0.16);
}

.voice-mode.working .voice-orb { cursor: default; opacity: 0.85; }

.voice-mode.error .voice-orb {
  background: radial-gradient(circle at 38% 32%, #ffd5d5, #e25b5b 70%);
}

.voice-talk {
  flex: 1;
  width: 100%;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.voice-turn {
  margin: 0;
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
}

.voice-turn span {
  display: block;
}

.voice-turn span:first-child {
  margin-bottom: 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--hint);
}

.voice-turn span:last-child {
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.voice-turn.user {
  align-self: flex-end;
  background: var(--chip);
  border-color: transparent;
}

.voice-turn.assistant { align-self: flex-start; }

.voice-read {
  margin-top: 8px;
  border: 0;
  border-radius: 999px;
  padding: 4px 12px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.voice-read:disabled {
  opacity: 0.6;
  cursor: default;
}

.voice-state {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
}

.voice-hint {
  margin: -8px 0 0;
  max-width: 32ch;
  color: var(--secondary);
  font-size: 13px;
  line-height: 1.4;
}

@keyframes voice-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.sheet {
  width: min(440px, calc(100% - 24px));
  border: 0;
  border-radius: 20px;
  padding: 8px 16px 18px;
  box-shadow: var(--shadow);
}

.sheet::backdrop { background: rgba(16, 34, 79, 0.35); }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0;
}

.sheet-head h2 { font-size: 16px; }

.text-btn {
  border: 0;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-weight: 600;
}

.empty-note { color: var(--secondary); font-size: 14px; }

.error {
  color: var(--error);
  background: #fdecea;
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 13px;
}

/* Review additions */
.bubble.error {
  background: #fdecec;
  color: var(--error);
  border: 1px solid #f6c9c9;
}
.bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(37, 99, 235, 0.08);
  padding: 0 4px;
  border-radius: 4px;
}
.bubble-tools button.retry {
  color: var(--primary);
  font-weight: 600;
}
.bubble-tools button.retry:disabled { opacity: 0.5; }

/* ---- UI pass: icons, tools, thinking dots, 2x2 actions ---- */
.icon-btn { display: grid; place-items: center; color: var(--secondary); }
.icon-btn svg { width: 20px; height: 20px; }

.mark,
.hero-mark {
  background: linear-gradient(145deg, #3b82f6, #1d4ed8);
  color: #fff;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.28);
}
.hero-mark { width: 64px; height: 64px; font-size: 28px; margin-bottom: 12px; border-radius: 20px; }
.hero { padding-top: 8px; }
.hero h2 { font-size: 22px; }

.actions { grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.action {
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 14px;
  border-radius: 16px;
  min-height: 118px;
  transition: border-color 0.15s, transform 0.15s;
}
.action:hover { transform: translateY(-1px); }
.action:active { transform: scale(0.98); }
.action-icon { width: 40px; height: 40px; border-radius: 12px; font-size: 17px; }
.action strong { font-size: 14px; }
.action span { font-size: 12.5px; line-height: 1.35; }

.bubble-tools { gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.bubble-tools button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--secondary);
  font-size: 12.5px;
  font-weight: 600;
}
.bubble-tools button svg { width: 16px; height: 16px; flex: none; }
.bubble-tools button:hover { background: var(--canvas); color: var(--primary); }
.bubble-tools button.on { color: var(--primary); background: var(--chip); }
.bubble-tools button.retry { border: 1px solid var(--primary); }

.thinking {
  align-self: flex-start;
  margin: 0 16px 8px;
  padding: 12px 16px;
  width: fit-content;
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  background: var(--canvas);
}
.thinking[hidden] { display: none; }
.dots { display: inline-flex; gap: 5px; align-items: center; height: 10px; }
.dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hint);
  animation: dot 1.1s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.composer textarea { padding: 13px 16px; font-size: 15px; }

.voice-bar { justify-content: space-between; align-items: center; }
.voice-title { font-weight: 700; color: var(--text); }
.voice-close {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow);
}
.voice-close svg { width: 16px; height: 16px; }

@media (prefers-reduced-motion: reduce) {
  .dots i, .action { animation: none; transition: none; }
}

/* Tap a Chinese word to hear it */
.zh-word {
  display: inline;
  padding: 0 1px;
  margin: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: inherit;
  color: inherit;
  cursor: pointer;
  border-bottom: 1.5px dotted rgba(37, 99, 235, 0.55);
  border-radius: 3px;
}
.zh-word:hover { background: rgba(37, 99, 235, 0.08); color: var(--primary); }
.zh-word.playing { background: var(--chip); color: var(--primary); border-bottom-style: solid; }
.zh-word.loading { opacity: 0.6; }
.bubble.user .zh-word { border-bottom-color: rgba(255, 255, 255, 0.6); }

.hero p.hero-tip { margin-top: 6px; font-size: 12.5px; color: var(--hint); }
.hero-tip .zh-word { cursor: default; }

/* ---- Loading states ---- */
@keyframes spin { to { transform: rotate(360deg); } }
.spin-path { transform-origin: 12px 12px; animation: spin 0.8s linear infinite; }
.bubble-tools button.busy { color: var(--primary); background: var(--chip); }

.composer #send.busy {
  background-image: none;
  background-color: var(--primary-button);
  position: relative;
}
.composer #send.busy::after {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

.zh-word.loading {
  opacity: 1;
  animation: word-wait 0.9s ease-in-out infinite;
}
@keyframes word-wait {
  0%, 100% { background: rgba(37, 99, 235, 0.06); }
  50% { background: rgba(37, 99, 235, 0.22); }
}
.zh-word.playing:not(.loading)::after {
  content: " 🔊";
  font-size: 0.8em;
}

.voice-orb { position: relative; }
.voice-mode.working .voice-orb::after {
  content: "";
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 3px solid rgba(37, 99, 235, 0.15);
  border-top-color: var(--primary);
  animation: spin 1s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .spin-path, .composer #send.busy::after, .voice-mode.working .voice-orb::after { animation-duration: 2.4s; }
  .zh-word.loading { animation: none; background: rgba(37, 99, 235, 0.15); }
}

/* ---- Language switch ---- */
.lang-select {
  height: 32px;
  padding: 0 26px 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%235b6785' stroke-width='2' d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center / 12px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  appearance: none;
  cursor: pointer;
}

/* ---- Follow-up chips ---- */
.follow-ups { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.follow-ups button {
  border: 1px solid #c9d7fb;
  background: #fff;
  color: var(--primary);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.follow-ups button:hover { background: var(--chip); }

/* ---- My words on home ---- */
.word-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.word-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 64px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.word-chip span { font-size: 18px; font-weight: 700; color: var(--text); }
.word-chip small { font-size: 11.5px; color: var(--secondary); }
.recent.my-words .word-chip { width: auto; margin: 0; }

/* ---- Word sheet ---- */
.word-sheet { width: min(420px, calc(100% - 24px)); }
.word-sheet[open] { animation: sheet-in 0.18s ease-out; }
@keyframes sheet-in { from { transform: translateY(12px); opacity: 0; } }
.ws-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.ws-word { font-size: 40px; font-weight: 800; line-height: 1.15; color: var(--text); }
.ws-pinyin { margin-top: 4px; font-size: 18px; color: var(--primary); font-weight: 600; min-height: 22px; }
.ws-meaning { margin: 12px 0 16px; font-size: 16px; color: var(--body); line-height: 1.45; }
.ws-meaning.muted { color: var(--hint); }
.ws-actions { display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 8px; }
.ws-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 46px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.ws-btn svg { width: 18px; height: 18px; flex: none; }
.ws-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws-btn.primary { background: var(--primary-button); border-color: var(--primary-button); color: #fff; }
.ws-btn.primary.recording { background: var(--error); border-color: var(--error); animation: rec 1.2s ease-in-out infinite; }
@keyframes rec { 50% { box-shadow: 0 0 0 6px rgba(198, 40, 40, 0.18); } }
.ws-btn.on { color: #b7791f; border-color: #f2d48f; background: #fff8e6; }
.ws-btn.busy { opacity: 0.85; }
.ws-result {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
}
.ws-result.good { background: #e3f6ec; color: #17734a; }
.ws-result.bad { background: #fdecec; color: var(--error); }

/* ==== Word sheet v2: bottom sheet on phones, card on wide screens ==== */
.word-sheet {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0 auto;
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow: auto;
  border: 0;
  border-radius: 24px 24px 0 0;
  padding: 8px 20px calc(22px + env(safe-area-inset-bottom));
  background: #fff;
  color: var(--text);
  box-shadow: 0 -12px 40px rgba(16, 34, 79, 0.18);
}
.word-sheet::backdrop { background: rgba(16, 34, 79, 0.4); }
.word-sheet[open] { animation: sheet-up 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes sheet-up { from { transform: translateY(100%); } }
@media (min-width: 700px) {
  .word-sheet { inset: 0; margin: auto; height: fit-content; border-radius: 24px; padding-bottom: 22px; }
  .word-sheet[open] { animation: sheet-in 0.18s ease-out; }
  .ws-handle { display: none; }
}

.ws-handle { width: 40px; height: 5px; margin: 0 auto 6px; border-radius: 3px; background: #d5ddf0; }
.ws-top { display: flex; justify-content: space-between; align-items: center; }
.ws-icon {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--canvas);
  color: var(--secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.ws-icon svg { width: 20px; height: 20px; }
.ws-icon span, .ws-play span {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}
.ws-icon:hover { color: var(--primary); }
.ws-icon.on { color: #d4a017; background: #fff6dc; }

.ws-hero { text-align: center; margin-top: -10px; }
.ws-word {
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Noto Sans SC",
    "Microsoft YaHei", sans-serif;
  font-size: 56px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: 2px;
  color: var(--text);
}
.ws-sound { display: inline-flex; align-items: center; gap: 10px; margin-top: 6px; }
.ws-pinyin { font-size: 21px; font-weight: 600; color: var(--primary); min-height: 0; margin: 0; }
.ws-play {
  position: relative;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--primary-button);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.3);
}
.ws-play svg { width: 20px; height: 20px; }
.ws-play.busy { background: var(--chip); color: var(--primary); box-shadow: none; }

.ws-card { margin-top: 16px; padding: 14px 16px; border-radius: 16px; background: var(--canvas); }
.ws-card h3 {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--hint);
}
.ws-meaning { margin: 0; font-size: 17px; line-height: 1.45; color: var(--text); }
.ws-meaning.muted { color: var(--hint); font-size: 15px; }
.ws-hint { margin: 0 0 12px; font-size: 13px; line-height: 1.4; color: var(--secondary); }

.ws-say {
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 14px;
  background: var(--primary-button);
  color: #fff;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.25);
}
.ws-say svg { width: 20px; height: 20px; }
.ws-say.recording { background: var(--error); box-shadow: none; animation: rec 1.2s ease-in-out infinite; }
.ws-say.busy { background: #8fabef; box-shadow: none; }

.ws-practice .ws-result { margin: 12px 0 0; border-radius: 14px; font-size: 14px; }
.ws-result.score {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
}
.ws-ring {
  --p: 0;
  --c: #1f9d63;
  flex: none;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), #e6ebf5 0);
}
.ws-result.bad .ws-ring { --c: #e5484d; }
.ws-ring span {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 800;
  color: var(--c);
}
.ws-verdict strong { display: block; font-size: 15px; line-height: 1.35; }
.ws-result.good .ws-verdict strong { color: #17734a; }
.ws-result.bad .ws-verdict strong { color: #c62828; }
.ws-verdict small { display: block; margin-top: 3px; font-size: 13px; color: var(--secondary); }

.quiz-mine {
  margin-top: 10px;
  width: 100%;
  height: 44px;
  border: 1px dashed #b9cbf6;
  border-radius: 14px;
  background: #f6f9ff;
  color: var(--primary);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.bubble.note { background: #fff8e6; color: #7a5a12; border: 1px solid #f2d48f; font-weight: 600; }

/* ==== Quiz (v2): full screen on phones, card on wide screens ==== */
.quiz-sheet {
  display: none;
  height: 100dvh;
  max-height: 100dvh;
  border-radius: 0;
  padding: 0;
  overflow: hidden;
}
.quiz-sheet[open] { display: flex; flex-direction: column; }
@media (min-width: 700px) {
  .quiz-sheet { height: min(720px, 92vh); border-radius: 24px; }
}
.qz-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px 10px;
  flex: none;
}
.qz-close {
  width: 38px; height: 38px; border: 0; border-radius: 50%;
  background: transparent; color: var(--secondary);
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.qz-close:hover { background: var(--canvas); }
.qz-close svg { width: 22px; height: 22px; }
.qz-progress { flex: 1; height: 12px; border-radius: 6px; background: #e8edf7; overflow: hidden; }
.qz-progress span {
  display: block; height: 100%; width: 0; border-radius: 6px;
  background: linear-gradient(90deg, #3b82f6, #2563eb);
  transition: width 0.35s ease;
}
.qz-count { min-width: 30px; text-align: right; font-size: 14px; font-weight: 800; color: var(--secondary); }

.qz-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.qz-main { flex: 1; min-height: 0; overflow: auto; padding: 8px 20px 16px; display: flex; flex-direction: column; gap: 14px; }
.qz-ask { margin: 4px 0 0; font-size: 20px; font-weight: 800; color: var(--text); line-height: 1.35; }

.qz-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 150px; padding: 18px;
  border-radius: 20px;
  background: linear-gradient(160deg, #f3f7ff, #e9f0ff);
  border: 1px solid #dce6fb;
}
.qz-card-word {
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 60px; font-weight: 600; line-height: 1.1; color: var(--text); letter-spacing: 2px;
}
.qz-card-pinyin { font-size: 20px; font-weight: 600; color: var(--primary); }
.qz-card-meaning { font-size: 26px; font-weight: 800; color: var(--text); text-align: center; line-height: 1.35; }
.qz-card-listen {
  margin-top: 6px; display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border: 0; border-radius: 999px;
  background: #fff; color: var(--primary); font: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
}
.qz-card-listen svg { width: 18px; height: 18px; }
.qz-card.listen { min-height: 190px; }
.qz-play {
  width: 104px; height: 104px; border: 0; border-radius: 50%;
  background: var(--primary-button); color: #fff;
  display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 0 0 10px rgba(37, 99, 235, 0.12), 0 12px 24px rgba(37, 99, 235, 0.3);
}
.qz-play svg { width: 44px; height: 44px; }
.qz-play span, .qz-review-play span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.qz-play:active { transform: scale(0.96); }
.qz-card-hint { margin-top: 8px; font-size: 13px; color: var(--secondary); font-weight: 600; }

.qz-options { display: grid; gap: 10px; }
.qz-option {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px; padding: 10px 14px;
  border: 2px solid #e2e8f3; border-bottom-width: 4px; border-radius: 16px;
  background: #fff; color: var(--text);
  font: inherit; font-size: 17px; font-weight: 700; text-align: left;
  cursor: pointer; transition: transform 0.08s, border-color 0.15s, background 0.15s;
}
.qz-option:hover:not(:disabled) { border-color: #a9c1f7; background: #f7faff; }
.qz-option:active:not(:disabled) { transform: translateY(2px); border-bottom-width: 2px; }
.qz-letter {
  flex: none; width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  border: 2px solid #e2e8f3; color: var(--secondary); font-size: 13px; font-weight: 800;
}
.qz-option-text { flex: 1; }
.qz-option.zh .qz-option-text {
  font-family: "PingFang SC", "Noto Sans CJK SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 26px; font-weight: 600; text-align: center; margin-right: 42px;
}
.qz-option:disabled { cursor: default; opacity: 0.55; }
.qz-option.right { opacity: 1; border-color: #22a06b; background: #e5f7ee; color: #146c46; animation: pop 0.25s; }
.qz-option.right .qz-letter { border-color: #22a06b; background: #22a06b; color: #fff; }
.qz-option.wrong { opacity: 1; border-color: #e5484d; background: #fdeeee; color: #b42318; animation: shake 0.3s; }
.qz-option.wrong .qz-letter { border-color: #e5484d; background: #e5484d; color: #fff; }
@keyframes pop { 50% { transform: scale(1.02); } }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.qz-mic {
  align-self: center; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; height: 60px; border: 0; border-radius: 18px;
  background: var(--primary-button); color: #fff;
  font: inherit; font-size: 17px; font-weight: 800; cursor: pointer;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.28);
}
.qz-mic svg { width: 24px; height: 24px; }
.qz-mic.recording { background: var(--error); box-shadow: none; animation: rec 1.2s ease-in-out infinite; }
.qz-mic.busy { background: #8fabef; box-shadow: none; }
.qz-main .ws-result { margin: 0; }

.qz-foot { flex: none; padding: 12px 20px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 6px; }
.qz-foot:empty { padding: 0; }
.qz-feedback {
  margin: -12px -20px calc(-16px - env(safe-area-inset-bottom));
  padding: 16px 20px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 6px;
  animation: slide-up 0.22s ease-out;
}
@keyframes slide-up { from { transform: translateY(100%); } }
.qz-feedback.good { background: #d9f5e6; }
.qz-feedback.bad { background: #fde3e3; }
.qz-feedback-head { display: flex; align-items: center; gap: 10px; font-size: 19px; }
.qz-feedback.good .qz-feedback-head { color: #146c46; }
.qz-feedback.bad .qz-feedback-head { color: #b42318; }
.qz-feedback-icon {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-size: 16px; font-weight: 900;
}
.qz-feedback.good .qz-feedback-icon { background: #22a06b; }
.qz-feedback.bad .qz-feedback-icon { background: #e5484d; }
.qz-explain { margin: 0 0 6px; font-size: 15.5px; color: var(--body); line-height: 1.45; }
.qz-primary {
  height: 54px; border: 0; border-radius: 16px;
  background: var(--primary-button); color: #fff;
  font: inherit; font-size: 17px; font-weight: 800; cursor: pointer;
  box-shadow: 0 4px 0 #1d4ed8;
}
.qz-primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #1d4ed8; }
.qz-feedback.good .qz-primary { background: #22a06b; box-shadow: 0 4px 0 #17734a; }
.qz-feedback.bad .qz-primary { background: #e5484d; box-shadow: 0 4px 0 #b42318; }
.qz-link { height: 44px; border: 0; background: none; color: var(--secondary); font: inherit; font-weight: 700; cursor: pointer; }

.qz-loading { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; color: var(--secondary); text-align: center; }
.qz-loading p { margin: 0; font-size: 15px; }
.qz-error { color: var(--error); }
.qz-loading .qz-primary { width: min(260px, 100%); }
.qz-spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--chip); border-top-color: var(--primary); animation: spin 0.8s linear infinite; }

.qz-done { align-items: center; text-align: center; padding-top: 18px; }
.qz-ring {
  --p: 0; --c: #22a06b;
  width: 150px; height: 150px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), #e8edf7 0);
  animation: pop 0.4s;
}
.qz-ring.ok { --c: #f59e0b; }
.qz-ring.low { --c: #e5484d; }
.qz-ring-inner { width: 122px; height: 122px; border-radius: 50%; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.qz-ring-emoji { font-size: 34px; line-height: 1; }
.qz-ring-inner strong { margin-top: 4px; font-size: 26px; font-weight: 900; color: var(--text); }
.qz-done-title { margin: 4px 0 0; font-size: 22px; font-weight: 800; }
.qz-stats { display: flex; gap: 8px; justify-content: center; }
.qz-stat { padding: 6px 12px; border-radius: 999px; font-size: 14px; font-weight: 700; }
.qz-stat.good { background: #e5f7ee; color: #146c46; }
.qz-stat.bad { background: #fdeeee; color: #b42318; }
.qz-review { width: 100%; text-align: left; padding: 12px 14px; border-radius: 18px; background: var(--canvas); }
.qz-review h3 { margin: 0 0 6px; font-size: 13px; font-weight: 800; color: var(--secondary); }
.qz-review-row {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 10px 4px; border: 0; border-bottom: 1px solid var(--line);
  background: none; font: inherit; text-align: left; cursor: pointer;
}
.qz-review-row:last-of-type { border-bottom: 0; }
.qz-review-word { font-family: "PingFang SC", "Noto Sans CJK SC", "Noto Sans SC", sans-serif; font-size: 24px; font-weight: 600; color: var(--text); flex: none; }
.qz-review-text { flex: 1; display: flex; flex-direction: column; }
.qz-review-py { color: var(--primary); font-weight: 700; font-size: 14px; }
.qz-review-meaning { color: var(--secondary); font-size: 14px; }
.qz-review-play { color: var(--primary); display: grid; place-items: center; }
.qz-review-play svg { width: 20px; height: 20px; }
.qz-saved { margin: 8px 0 0; font-size: 13px; color: #b7791f; font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .qz-option.right, .qz-option.wrong, .qz-feedback, .qz-ring { animation: none; }
}


/* ==== Voice message (record → text → send) ==== */
.rec-bar {
  flex: 1;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px 0 6px;
  border-radius: 24px;
  background: #fff1f1;
  border: 1px solid #f6c9c9;
}
.rec-bar[hidden] { display: none; }
.composer.recording textarea,
.composer.transcribing textarea,
.composer.recording #send,
.composer.transcribing #send { display: none; }
.rec-cancel {
  width: 36px; height: 36px; flex: none;
  border: 0; border-radius: 50%;
  background: #fff; color: var(--secondary);
  display: grid; place-items: center; cursor: pointer;
}
.rec-cancel svg { width: 18px; height: 18px; }
.rec-dot { width: 10px; height: 10px; flex: none; border-radius: 50%; background: var(--error); animation: rec-blink 1s ease-in-out infinite; }
@keyframes rec-blink { 50% { opacity: 0.25; } }
.rec-time { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--error); flex: none; }
.rec-label { font-size: 13px; color: var(--secondary); line-height: 1.3; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.composer.recording .mic { background: var(--error); color: #fff; animation: rec 1.2s ease-in-out infinite; }
.composer.transcribing .rec-bar { background: var(--chip); border-color: #c9d7fb; }
.composer.transcribing .rec-dot { background: none; border: 2.5px solid #b9cbf6; border-top-color: var(--primary); width: 16px; height: 16px; animation: spin 0.8s linear infinite; }
.composer.transcribing .rec-time, .composer.transcribing .rec-cancel { display: none; }
.composer.transcribing .mic { opacity: 0.5; }
.bubble.user.voice::before {
  content: "🎤 ";
  font-size: 0.9em;
}
@media (prefers-reduced-motion: reduce) {
  .rec-dot, .composer.recording .mic { animation: none; }
}

/* Mascot on the first screen (falls back to the 學 tile when the image is missing) */
.hero-mark.mascot {
  width: 120px;
  height: 120px;
  margin-bottom: 8px;
  background: none;
  box-shadow: none;
  border-radius: 0;
}
.hero-mark.mascot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 14px rgba(27, 47, 120, 0.18));
  animation: mascot-in 0.45s ease-out both;
}
@keyframes mascot-in {
  from { opacity: 0; transform: translateY(8px) scale(0.94); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .hero-mark.mascot img { animation: none; }
}
@media (max-height: 640px) {
  .hero-mark.mascot { width: 88px; height: 88px; }
}

/* Quiz result: the panda above the score ring */
.qz-mascot {
  width: 132px;
  height: 132px;
  object-fit: contain;
  margin-bottom: -6px;
  filter: drop-shadow(0 8px 14px rgba(27, 47, 120, 0.18));
  animation: mascot-pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes mascot-pop {
  from { opacity: 0; transform: translateY(14px) scale(0.8); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .qz-mascot { animation: none; }
}
@media (max-height: 640px) {
  .qz-mascot { width: 96px; height: 96px; }
}

/* Panda icon in the header (falls back to the "AI" badge) */
.mark.has-icon { background: none; box-shadow: 0 6px 14px rgba(37, 99, 235, 0.22); border-radius: 12px; overflow: hidden; }
.mark.has-icon img { width: 100%; height: 100%; display: block; }

/* Shortcut pictures: one colour each, so the four are easy to tell apart */
.action-icon svg { width: 24px; height: 24px; display: block; }
.action-icon.tint-blue { background: #e3ecff; color: #2563eb; }
.action-icon.tint-green { background: #dcf5e7; color: #15935a; }
.action-icon.tint-amber { background: #ffedd2; color: #c96a06; }
.action-icon.tint-violet { background: #ece5ff; color: #6d3fe0; }

/* A drawn picture instead of the line icon: no tile behind it, a little bigger */
.action-icon.pic { width: 56px; height: 56px; background: none; border-radius: 0; }
.action-icon.pic img { width: 100%; height: 100%; object-fit: contain; display: block; }
