/* 手機直向優先、字大、按鈕大 */
:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #1e3a8a;
  --primary-2: #2563eb;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --mid: #b45309;
  --mid-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --radius: 16px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Heiti TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 18px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary-2); text-decoration: none; }
h1 { font-size: 26px; margin: 0 0 4px; line-height: 1.3; }
h2 { font-size: 20px; margin: 0 0 10px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.center { text-align: center; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + var(--safe-t)) 16px 8px;
  background: rgba(245, 247, 251, .92);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--ink); font-size: 18px; }
.gear { font-size: 24px; padding: 6px 4px; }

main {
  max-width: 560px; margin: 0 auto;
  padding: 16px 16px calc(var(--tab-h) + var(--safe-b) + 28px);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: #fff; border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px; gap: 2px;
}
.tabbar a.on { color: var(--primary); font-weight: 700; }
.tab-icon { font-size: 24px; line-height: 1; }

.page-head { margin-bottom: 14px; }
.sub { margin: 0; color: var(--muted); font-size: 16px; }

/* 卡片 */
.cards { display: flex; flex-direction: column; gap: 12px; }
.card {
  display: block; background: var(--card); border-radius: var(--radius);
  padding: 16px; border: 1px solid var(--line); color: var(--ink);
  margin-bottom: 12px;
}
.cards .card { margin-bottom: 0; }
.card.warn { background: var(--mid-bg); border-color: #fcd34d; }
.card.warn p { margin: 6px 0; }
.warn.small { color: var(--mid); background: var(--mid-bg); padding: 10px 12px; border-radius: 12px; margin: 8px 0; }

/* 按鈕 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 52px; padding: 0 18px; border-radius: 14px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; font-size: 18px; font-weight: 600; cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .4; }
.btn.sm { min-height: 44px; padding: 0 14px; font-size: 16px; border-radius: 12px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.ghost { background: transparent; }
.btn.block { display: flex; width: 100%; margin-top: 10px; }
.btn.big { min-height: 60px; font-size: 20px; }
.btn.danger, .link.danger { color: var(--bad); }
.btn.play.slow { background: #eef2ff; }
.link { background: none; border: 0; color: var(--primary-2); font: inherit; font-size: 16px; padding: 10px 4px; cursor: pointer; }
.back { font-size: 18px; padding: 6px 0; display: inline-block; }
.play-row, .bubble-actions, .line-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-col { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }

/* 切換 */
.seg { display: flex; background: #e2e8f0; border-radius: 14px; padding: 4px; margin-bottom: 12px; }
.seg-btn {
  flex: 1; min-height: 48px; border: 0; background: transparent; border-radius: 11px;
  font: inherit; font-size: 17px; font-weight: 600; color: var(--muted);
}
.seg-btn.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; margin-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 42px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; font: inherit; font-size: 16px; color: var(--ink);
}
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 16px; margin-bottom: 12px; font-weight: 600;
}
.switch-row input { width: 26px; height: 26px; accent-color: var(--primary); }

/* 今天 */
.stats { display: flex; gap: 10px; margin-bottom: 14px; }
.stat { flex: 1; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 8px; text-align: center; }
.stat b { display: block; font-size: 28px; color: var(--primary); line-height: 1.2; }
.stat span { font-size: 14px; color: var(--muted); }
.steps { display: flex; flex-direction: column; gap: 10px; }
.step { display: flex; align-items: center; gap: 14px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; color: var(--ink); }
.step-n { flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 20px; }
.step-body { flex: 1; }
.step-title { font-weight: 700; font-size: 20px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.mins { font-size: 14px; color: var(--muted); font-weight: 500; }
.step-desc { color: var(--muted); font-size: 15px; }
.chev { color: var(--muted); font-size: 28px; }
.tip { background: #eef2ff; border-radius: 14px; padding: 12px 14px; margin: 16px 0 0; font-size: 16px; }

/* 情境列表 */
.scenario { display: flex; gap: 14px; align-items: flex-start; }
.scenario-icon { font-size: 34px; line-height: 1.2; }
.scenario-title { font-weight: 700; font-size: 20px; }
.en-sub { font-weight: 500; font-size: 14px; color: var(--muted); margin-left: 8px; }
.scenario-goal { color: #334155; font-size: 16px; margin-top: 2px; }
.level { color: var(--primary-2); font-size: 14px; margin-top: 4px; letter-spacing: 2px; }

/* 對話 */
.session-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.session-title { font-weight: 700; font-size: 20px; }
.persona { font-size: 15px; color: var(--muted); }
.session-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.turn-status { color: var(--muted); font-size: 15px; }
.chat { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.bubble { border-radius: 18px; padding: 12px 14px; max-width: 92%; }
.bubble .who { font-size: 13px; color: var(--muted); margin-bottom: 2px; }
.bubble .en { font-size: 20px; line-height: 1.45; }
.bubble.customer { background: #fff; border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble.customer.repeat { background: #f8fafc; }
.bubble.me { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 6px; }
.bubble.me .who { color: #c7d2fe; }
.chat.listen-only .bubble.customer .en:not(.peek) { filter: blur(7px); user-select: none; }
.zh { color: #334155; font-size: 17px; margin-top: 8px; }
.zh.big { font-size: 20px; font-weight: 600; color: var(--ink); margin-top: 0; }
.note { font-size: 15px; color: var(--mid); background: var(--mid-bg); border-radius: 10px; padding: 6px 10px; margin-top: 8px; }
.task { border-left: 5px solid var(--primary-2); }
.task-head { display: flex; justify-content: space-between; align-items: center; }
.task-text { font-size: 18px; margin-top: 4px; }
.hint { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.hint .en { font-size: 19px; font-weight: 600; }

/* 對話中：按住說話固定在底部分頁列上方，對話變長也不用捲動找按鈕 */
.talk-wrap {
  position: sticky; bottom: calc(var(--tab-h) + var(--safe-b)); z-index: 5;
  margin: 0 -16px; padding: 6px 16px 8px;
  background: linear-gradient(to bottom, rgba(245, 247, 251, 0), var(--bg) 18px);
}
.talk-wrap .hold { min-height: 72px; }

/* 按住說話 */
.talk { display: flex; flex-direction: column; align-items: stretch; gap: 8px; margin: 8px 0; }
.live { min-height: 28px; text-align: center; color: var(--primary-2); font-size: 18px; font-style: italic; }
.hold {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 84px; border-radius: 22px; border: 0;
  background: var(--primary); color: #fff; font: inherit; font-size: 22px; font-weight: 700;
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  box-shadow: 0 6px 16px rgba(30, 58, 138, .25);
}
.hold .mic { font-size: 30px; }
.hold[data-state="listening"] { background: #dc2626; animation: pulse 1.2s infinite; }
.hold[data-state="working"] { background: #64748b; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .5); } 50% { box-shadow: 0 0 0 14px rgba(220, 38, 38, 0); } }
.type-box { display: flex; gap: 8px; }
.type-input {
  flex: 1; min-height: 52px; border-radius: 14px; border: 1px solid #cbd5e1;
  padding: 0 14px; font: inherit; font-size: 18px; background: #fff;
}

/* 聽力 */
.line { position: relative; }
.line-n { position: absolute; right: 14px; top: 12px; color: var(--muted); font-size: 13px; }
.line .play-row { margin-top: 0; }
.line .en { font-size: 20px; margin-top: 12px; line-height: 1.45; }
.en.masked { color: transparent; background: repeating-linear-gradient(90deg, #e2e8f0 0 70%, transparent 70% 100%); background-size: 26px 100%; border-radius: 8px; user-select: none; }

/* 跟讀 */
.target .meta { font-size: 14px; color: var(--muted); display: flex; justify-content: space-between; }
.best { color: var(--ok); font-weight: 600; }
.target-en { font-size: 24px; font-weight: 700; line-height: 1.4; margin-top: 6px; }
.result { margin: 10px 0; }
.score-row { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.score { font-size: 44px; font-weight: 800; line-height: 1; white-space: nowrap; flex: none; }
.score small { font-size: 18px; margin-left: 2px; }
.score.high { color: var(--ok); } .score.mid { color: var(--mid); } .score.low { color: var(--bad); }
.score-msg { font-size: 17px; }
.words { display: flex; flex-wrap: wrap; gap: 8px; }
.word {
  display: inline-flex; flex-direction: column; align-items: center;
  border: 0; border-radius: 12px; padding: 8px 12px; font: inherit; font-size: 20px; font-weight: 600;
  min-height: 48px; justify-content: center;
}
.word small { font-size: 12px; font-weight: 500; }
.word.ok { background: var(--ok-bg); color: var(--ok); }
.word.unclear { background: var(--mid-bg); color: var(--mid); outline: 2px solid #f59e0b; }
.word.missing { background: var(--bad-bg); color: var(--bad); outline: 2px solid #ef4444; text-decoration: underline wavy; }
.heard { margin-top: 12px; font-size: 16px; color: #334155; }
.tag { display: inline-block; font-size: 13px; font-weight: 700; background: #e2e8f0; color: #334155; border-radius: 8px; padding: 1px 8px; margin-right: 8px; vertical-align: 2px; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.nav-row { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }

/* 句型 */
.phrase-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.lv { font-size: 13px; color: var(--primary-2); font-weight: 700; }
.star { border: 0; background: none; font-size: 26px; color: #f59e0b; min-width: 44px; min-height: 44px; }
.phrase .en { font-size: 18px; color: #334155; margin-top: 4px; }

/* 回饋 */
.card.good { border-left: 5px solid var(--ok); }
.card.good ul { margin: 0; padding-left: 22px; }
.card.improve { border-left: 5px solid var(--mid); }
.fb-item { border-top: 1px solid var(--line); padding: 12px 0; }
.fb-item:first-of-type { border-top: 0; padding-top: 0; }
.fb-ctx { font-size: 14px; color: var(--muted); }
.fb-you { margin-top: 4px; color: #475569; }
.fb-better { margin-top: 6px; font-weight: 700; font-size: 19px; }
.fb-zh { color: #334155; font-size: 16px; }
.fb-tip { margin-top: 6px; background: #fffbeb; border-radius: 10px; padding: 8px 10px; font-size: 16px; }
.transcript summary { font-weight: 700; cursor: pointer; min-height: 32px; }
.tr { border-top: 1px solid var(--line); padding: 8px 0; font-size: 16px; }
.tr-c { color: #334155; }
.tr-u { color: var(--primary); }

/* 設定 */
.field { margin-bottom: 16px; }
.field-label { font-weight: 700; margin-bottom: 8px; }
.select { width: 100%; min-height: 50px; font: inherit; font-size: 17px; border-radius: 12px; border: 1px solid #cbd5e1; padding: 0 10px; background: #fff; margin-bottom: 6px; }
.radio { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.radio input { width: 24px; height: 24px; accent-color: var(--primary); }
.radio.disabled { color: var(--muted); }
.checks { list-style: none; padding: 0; margin: 0 0 8px; }
.checks li { padding: 4px 0; }

#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tab-h) + var(--safe-b) + 14px); z-index: 20;
  background: #0f172a; color: #fff; border-radius: 14px; padding: 12px 16px; font-size: 16px;
  opacity: 0; transform: translateY(10px); transition: all .2s; pointer-events: none;
}
#toast.show { opacity: 1; transform: none; }
