/* ============ AI 英語口說老師 — 樣式 ============ */
:root {
  --bg: #0f1226;
  --bg-soft: #171a35;
  --card: #1d2142;
  --card-2: #252a52;
  --line: #323765;
  --text: #eef0ff;
  --muted: #9aa0d0;
  --brand: #6366f1;
  --brand-2: #8b5cf6;
  --ok: #22c55e;
  --ok-soft: rgba(34,197,94,.16);
  --bad: #f43f5e;
  --bad-soft: rgba(244,63,94,.16);
  --warn: #f59e0b;
  --miss: #f59e0b;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Noto Sans TC", -apple-system, "Segoe UI", Roboto, "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: radial-gradient(1200px 600px at 20% -10%, #25275a 0%, transparent 60%),
              radial-gradient(900px 500px at 100% 0%, #3a1f5e 0%, transparent 55%),
              var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 720px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }

/* ---- 頂部列 ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; backdrop-filter: blur(14px);
  background: linear-gradient(180deg, rgba(15,18,38,.92), rgba(15,18,38,.55));
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.brand-logo { font-size: 26px; }
.brand-text { font-weight: 800; font-size: 18px; letter-spacing: .3px;
  background: linear-gradient(90deg, #c7d2fe, #f0abfc); -webkit-background-clip: text; background-clip: text; color: transparent; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.icon-btn { background: var(--card); border: 1px solid var(--line); color: var(--text);
  width: 38px; height: 38px; border-radius: 12px; font-size: 16px; cursor: pointer; transition: .15s; }
.icon-btn:active { transform: scale(.94); }

.badge { font-size: 12px; padding: 5px 10px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: #86efac; border: 1px solid rgba(34,197,94,.4); }
.badge-warn { background: rgba(245,158,11,.16); color: #fcd34d; border: 1px solid rgba(245,158,11,.4); }
.badge-bad { background: var(--bad-soft); color: #fda4af; border: 1px solid rgba(244,63,94,.4); }

/* ---- 主內容 ---- */
.view { flex: 1; padding: 18px 16px 30px; }

/* ---- 底部導覽 ---- */
.tabbar {
  position: sticky; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px;
  padding: 8px 8px calc(8px + var(--safe-b));
  background: linear-gradient(0deg, rgba(15,18,38,.96), rgba(15,18,38,.7));
  border-top: 1px solid var(--line); backdrop-filter: blur(14px);
}
.tab { background: none; border: 0; color: var(--muted); display: flex; flex-direction: column;
  align-items: center; gap: 2px; padding: 6px 2px; border-radius: 12px; cursor: pointer; transition: .15s; }
.tab span { font-size: 20px; line-height: 1; }
.tab i { font-style: normal; font-size: 11px; font-weight: 700; }
.tab.active { color: var(--text); background: var(--card); }
.tab:active { transform: scale(.93); }

/* ---- 卡片與通用元件 ---- */
.card { background: linear-gradient(180deg, var(--card), var(--bg-soft));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.section-title { font-size: 15px; font-weight: 800; margin: 22px 4px 12px; color: var(--muted); letter-spacing: .5px; }

.btn { border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 800; font-size: 15px;
  cursor: pointer; transition: .15s; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
  box-shadow: 0 8px 22px rgba(99,102,241,.45); }
.btn-ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.btn-ok { background: linear-gradient(135deg, #16a34a, #22c55e); color: #fff; }
.btn-mic { background: linear-gradient(135deg, #e11d48, #f43f5e); color: #fff; box-shadow: 0 8px 22px rgba(244,63,94,.45); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; min-width: 120px; }

.pill { display: inline-block; padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--card-2); border: 1px solid var(--line); color: var(--muted); }
.pill-lv { background: rgba(139,92,246,.18); color: #d8b4fe; border-color: rgba(139,92,246,.4); }

/* ---- 首頁 ---- */
.hero { text-align: center; padding: 8px 6px 4px; }
.hero h1 { font-size: 24px; margin: 6px 0 6px; }
.hero p { color: var(--muted); margin: 0 0 4px; font-size: 14px; line-height: 1.6; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 6px; }
.mode-card { text-align: left; cursor: pointer; padding: 16px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--card), var(--bg-soft)); border: 1px solid var(--line); transition: .18s; }
.mode-card:hover { border-color: var(--brand); transform: translateY(-2px); }
.mode-card:active { transform: scale(.98); }
.mode-card .mc-ico { font-size: 30px; }
.mode-card h3 { margin: 8px 0 4px; font-size: 17px; }
.mode-card p { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.5; }

.stat-row { display: flex; gap: 10px; margin-top: 14px; }
.stat { flex: 1; text-align: center; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 6px; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 11px; color: var(--muted); }

/* ---- 練習通用 ---- */
.lesson-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.lesson-head .ttl { font-size: 18px; font-weight: 800; }
.progress { height: 8px; background: var(--card-2); border-radius: 999px; overflow: hidden; margin: 4px 0 16px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .3s; }

.target-sentence { font-size: 26px; line-height: 1.5; font-weight: 700; margin: 8px 0; letter-spacing: .2px; word-spacing: 2px; }
.target-sentence .w { padding: 1px 2px; border-radius: 6px; transition: .2s; }
.w-ok { color: #86efac; background: var(--ok-soft); }
.w-bad { color: #fda4af; background: var(--bad-soft); text-decoration: underline wavy var(--bad); text-underline-offset: 4px; }
.w-miss { color: #fcd34d; background: rgba(245,158,11,.16); text-decoration: underline dotted var(--miss); text-underline-offset: 4px; }
.translation { color: var(--muted); font-size: 15px; margin: 2px 0 6px; }
.phonetic { color: #c4b5fd; font-size: 14px; font-family: "Times New Roman", serif; }

.heard { background: var(--bg-soft); border: 1px dashed var(--line); border-radius: 12px;
  padding: 10px 12px; color: var(--text); font-size: 15px; min-height: 20px; }
.heard .muted { color: var(--muted); }

.score-ring { display: flex; align-items: center; gap: 16px; }
.ring { --p: 0; width: 84px; height: 84px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--ringc, var(--ok)) calc(var(--p) * 1%), var(--card-2) 0);
  display: grid; place-items: center; position: relative; }
.ring::before { content: ""; position: absolute; inset: 8px; border-radius: 50%; background: var(--card); }
.ring b { position: relative; font-size: 22px; }
.score-meta { flex: 1; }
.score-meta .lvl { font-size: 18px; font-weight: 800; }
.score-meta .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

.feedback { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.fb-item { display: flex; gap: 9px; align-items: flex-start; font-size: 14px; line-height: 1.5;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.fb-item .ico { flex: none; }
.fb-good { border-color: rgba(34,197,94,.35); }
.fb-warn { border-color: rgba(245,158,11,.35); }

.listening { display: inline-flex; align-items: center; gap: 8px; }
.dot-pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.6); opacity: .4; } }

.input-line { width: 100%; background: var(--bg-soft); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 13px 14px; font-size: 16px; outline: none; }
.input-line:focus { border-color: var(--brand); }

/* ---- 單字卡 ---- */
.flash-wrap { perspective: 1200px; }
.flash { position: relative; height: 300px; cursor: pointer; transform-style: preserve-3d; transition: transform .5s; }
.flash.flipped { transform: rotateY(180deg); }
.flash-face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 22px;
  background: linear-gradient(180deg, var(--card), var(--bg-soft)); border: 1px solid var(--line); box-shadow: var(--shadow); text-align: center; }
.flash-front .word { font-size: 40px; font-weight: 800; }
.flash-back { transform: rotateY(180deg); }
.flash-back .mean { font-size: 26px; font-weight: 800; }
.flash-back .ex { color: var(--muted); font-size: 15px; line-height: 1.6; }

/* ---- 對話 ---- */
.chat { display: flex; flex-direction: column; gap: 12px; }
.bubble { max-width: 86%; padding: 12px 14px; border-radius: 16px; font-size: 15px; line-height: 1.55; }
.bubble small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.b-ai { align-self: flex-start; background: var(--card-2); border-top-left-radius: 4px; }
.b-me { align-self: flex-end; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-top-right-radius: 4px; }
.b-me small { color: rgba(255,255,255,.8); }
.suggest-line { color: var(--muted); font-size: 13px; margin: 6px 2px; }

/* ---- 文法填空 ---- */
.gap-sentence { font-size: 20px; line-height: 1.7; margin: 8px 0 16px; }
.gap-blank { display: inline-block; min-width: 70px; border-bottom: 2px solid var(--brand); text-align: center; font-weight: 800; color: #c7d2fe; }
.opt-grid { display: grid; gap: 10px; }
.opt { text-align: left; background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 13px 15px; font-size: 16px; cursor: pointer; transition: .15s; }
.opt:hover { border-color: var(--brand); }
.opt.correct { background: var(--ok-soft); border-color: var(--ok); color: #bbf7d0; }
.opt.wrong { background: var(--bad-soft); border-color: var(--bad); color: #fecaca; }
.explain { margin-top: 12px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 14px; line-height: 1.6; color: var(--text); }

/* ---- 設定面板 ---- */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0,0,0,.5); backdrop-filter: blur(2px); }
.sheet.hidden { display: none; }
.sheet-card { width: 100%; max-width: 720px; background: var(--bg-soft); border-top-left-radius: 22px;
  border-top-right-radius: 22px; border: 1px solid var(--line); padding: 20px 18px calc(24px + var(--safe-b)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h3 { margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; font-size: 14px; color: var(--muted); }
.field select, .field input[type=range] { width: 100%; }
.field select { background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 10px; font-size: 15px; }
.hint { font-size: 13px; color: var(--muted); line-height: 1.6; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; }

/* ---- 雜項 ---- */
.hidden { display: none !important; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.tip-banner { background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.35); color: #fcd34d;
  border-radius: 12px; padding: 11px 13px; font-size: 13px; line-height: 1.5; margin-bottom: 14px; }
@media (min-width: 640px) { .tab i { font-size: 12px; } .target-sentence { font-size: 30px; } }
