/* 英文練習 — 精簡蘋果風格；手機單欄、iPad 雙欄 */
:root {
  color-scheme: light;
  --bg: #F5F5F7;
  --card: #FFFFFF;
  --ink: #1D1D1F;
  --muted: #6E6E73;
  --faint: #86868B;
  --sep: #D2D2D7;
  --fill: #E8E8ED;
  --blue: #0071E3;
  --blue-h: #0077ED;
  --blue-l: #E8F1FC;
  --green: #1E8E3E;
  --green-l: #E9F6EC;
  --orange: #B25E00;
  --orange-l: #FFF4E5;
  --red: #D70015;
  --red-l: #FDECEE;
  --r: 14px;
  --r-lg: 20px;
  --w: 720px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro TC", "PingFang TC", "Helvetica Neue", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 17px; line-height: 1.47; -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; text-align: inherit; }
button:disabled { cursor: default; opacity: .4; }
h1, h2, h3, p { margin: 0; }

/* 頂欄 */
.top { position: sticky; top: 0; z-index: 10; background: rgba(245, 245, 247, .82); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-bottom: .5px solid var(--sep); padding-top: env(safe-area-inset-top); }
.top-in { max-width: var(--w); margin: 0 auto; height: 48px; display: flex; align-items: center; justify-content: space-between; padding: 0 max(16px, env(safe-area-inset-left)); }
.brand { font-weight: 600; font-size: 17px; letter-spacing: -.2px; }
body[data-view="home"] .brand { visibility: hidden; }
.hud { display: flex; align-items: center; gap: 14px; }
.pill { font-size: 14px; font-weight: 600; color: var(--blue); background: var(--blue-l); border-radius: 999px; padding: 4px 12px; }
.link { color: var(--blue); font-size: 17px; }
.link.strong { font-weight: 600; text-align: left; }

main { max-width: var(--w); margin: 0 auto; padding: 8px max(16px, env(safe-area-inset-left)) 48px; }
.foot { text-align: center; color: var(--faint); font-size: 12px; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }

/* 首頁 */
.hero { padding: 20px 4px 4px; }
.eyebrow { color: var(--muted); font-size: 15px; }
.hero h1 { font-size: 34px; font-weight: 700; letter-spacing: -.5px; line-height: 1.15; }
.ghead { font-size: 13px; font-weight: 400; color: var(--muted); letter-spacing: .3px; margin: 26px 16px 7px; }
.group { background: var(--card); border-radius: var(--r); overflow: hidden; }
.row { width: 100%; display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 11px 16px; text-align: left; position: relative; background: var(--card); }
.group > .row:not(:first-child)::before, .group > div:not(:first-child) > .row:first-child::before, .group > div > .row + .row::before,
.form .frow + .frow::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: .5px; background: var(--sep); }
.row:active:not(:disabled):not(.static) { background: #F2F2F7; }
.row .rt { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.row .rt b { font-weight: 400; font-size: 17px; }
.row .rt small { color: var(--muted); font-size: 14px; line-height: 1.35; margin-top: 1px; }
.row .rd { color: var(--muted); font-size: 16px; }
.row .chev { color: #C7C7CC; font-size: 22px; line-height: 1; margin-left: 2px; }
.row .check { color: var(--blue); font-weight: 600; }
.row.danger .rt b { color: var(--red); }
.row .dot { width: 9px; height: 9px; border-radius: 50%; }
.dot.ok { background: var(--green); } .dot.no { background: var(--red); }
.foot-note { color: var(--faint); font-size: 13px; margin: 14px 16px 0; }
.lead { color: var(--muted); margin: 6px 4px 0; font-size: 15px; }
.note { color: var(--faint); font-size: 13px; margin: 6px 4px 0; text-align: center; }

/* 導覽列 */
.navbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; height: 44px; margin: 0 -4px; }
.navbar h2 { font-size: 17px; font-weight: 600; text-align: center; white-space: nowrap; }
.back { color: var(--blue); font-size: 17px; justify-self: start; padding: 6px 4px; }
.navr { justify-self: end; color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; padding-right: 4px; }
.pbar { height: 3px; background: var(--fill); border-radius: 2px; overflow: hidden; margin: 2px 0 14px; }
.pbar i { display: block; height: 100%; background: var(--blue); transition: width .3s ease; }

/* 練習卡 */
.card { background: var(--card); border-radius: var(--r-lg); padding: 28px 20px; }
.card.word, .card.sent { text-align: center; }
.card .emoji { font-size: 56px; line-height: 1.1; margin-bottom: 6px; }
.card .en { font-size: 40px; font-weight: 700; letter-spacing: -.5px; line-height: 1.15; word-break: break-word; }
.card.sent .en { font-size: 28px; font-weight: 600; letter-spacing: -.3px; line-height: 1.3; }
.card .zh { font-size: 19px; color: var(--muted); margin-top: 8px; }
.pos { font-size: 14px; color: var(--faint); margin-right: 8px; font-style: italic; }
.card .focus { margin-top: 16px; font-size: 15px; color: var(--muted); background: var(--bg); border-radius: 12px; padding: 10px 14px; text-align: left; }
.ex { width: 100%; margin-top: 20px; padding: 12px 14px; border-radius: 12px; background: var(--bg); display: flex; flex-direction: column; text-align: left; }
.ex span { font-size: 17px; font-weight: 500; }
.ex span::before { content: "▶︎ "; color: var(--blue); font-size: 13px; }
.ex small { color: var(--muted); font-size: 14px; }
.side { display: flex; flex-direction: column; }

/* 按鈕 */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 50px; padding: 0 20px; border-radius: 12px; background: var(--fill); color: var(--blue); font-size: 17px; font-weight: 500; transition: transform .08s; }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:active:not(:disabled) { background: var(--blue-h); }
.btn.plain { background: transparent; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 15px; border-radius: 10px; }
.btn.rec { background: var(--red) !important; color: #fff !important; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(215, 0, 21, .35); } 50% { box-shadow: 0 0 0 8px rgba(215, 0, 21, 0); } }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.controls .btn.primary { grid-column: 1 / -1; }
.nav { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.nav.single { grid-template-columns: 1fr; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 22px; }
.actions.left { justify-content: flex-start; margin-left: 4px; }
.actions .btn { min-width: 132px; }

/* 發音結果 */
.res { background: var(--card); border-radius: var(--r-lg); padding: 18px 20px; }
.res-top { display: flex; align-items: center; gap: 16px; }
.score { font-size: 48px; font-weight: 700; letter-spacing: -1px; line-height: 1; font-variant-numeric: tabular-nums; min-width: 72px; }
.score.good { color: var(--green); } .score.mid { color: var(--orange); } .score.low { color: var(--red); }
.res-msg { font-size: 19px; font-weight: 600; }
.res-src { font-size: 13px; color: var(--faint); }
.ws { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.w { display: inline-flex; flex-direction: column; align-items: center; padding: 6px 12px; border-radius: 10px; background: var(--bg); }
.w span { font-size: 19px; font-weight: 600; }
.w i { font-style: normal; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.w.g span { color: var(--green); } .w.m span { color: var(--orange); } .w.b span { color: var(--red); }
.w.b { background: var(--red-l); } .w.m { background: var(--orange-l); }
.w.om span { color: var(--faint); text-decoration: line-through; }
.tip { margin-top: 14px; font-size: 15px; color: var(--ink); background: var(--bg); border-radius: 12px; padding: 10px 14px; }
.heard { margin-top: 8px; font-size: 13px; color: var(--faint); }
.res .link { margin-top: 10px; font-size: 15px; }
.err { color: var(--red); font-size: 15px; }

/* 測驗 */
.card.q { padding: 24px 18px; }
.qprompt { font-size: 21px; font-weight: 600; text-align: center; margin-bottom: 16px; }
.qprompt.en { font-size: 24px; }
.btn.listen { width: 100%; margin-bottom: 16px; background: var(--blue-l); }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt { min-height: 60px; padding: 10px 12px; border-radius: 12px; background: var(--bg); font-size: 19px; font-weight: 500; text-align: center; border: 1.5px solid transparent; transition: background .15s; }
.opt.en { font-size: 20px; }
.opt:active:not(:disabled) { background: var(--fill); }
.opt.right { background: var(--green-l); border-color: var(--green); color: var(--green); opacity: 1; }
.opt.wrong { background: var(--red-l); border-color: var(--red); color: var(--red); opacity: 1; }
.opt.dim { opacity: .45; }
.fb { margin-top: 16px; border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; font-size: 15px; }
.fb b { font-size: 17px; font-weight: 600; }
.fb.ok { background: var(--green-l); } .fb.ok b { color: var(--green); }
.fb.no { background: var(--red-l); } .fb.no b { color: var(--red); }

/* 完成頁 */
.card.done { text-align: center; padding: 32px 20px; }
.done h2 { font-size: 28px; font-weight: 700; letter-spacing: -.4px; margin-bottom: 8px; }
.done .group { text-align: left; background: var(--bg); }
.done .group .row { background: var(--bg); }
.done .ghead { text-align: left; margin-left: 4px; }
.bignum { font-size: 56px; font-weight: 700; letter-spacing: -1px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.bignum span { font-size: 24px; color: var(--faint); font-weight: 500; }
.sum { color: var(--muted); font-size: 17px; margin: 6px 0; }
.adv { margin-top: 22px; padding: 16px; border-radius: 14px; background: var(--blue-l); }
.adv .actions { margin-top: 12px; }
.adv .actions .btn { min-width: 96px; }

/* chips / sheet */
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.chips.left { justify-content: flex-start; margin-top: 0; }
.chip { display: inline-flex; align-items: baseline; gap: 6px; background: var(--card); border: .5px solid var(--sep); border-radius: 999px; padding: 6px 14px; font-size: 15px; font-weight: 500; }
.done .chip { background: var(--bg); border-color: transparent; }
.chip small { color: var(--muted); font-weight: 400; font-size: 13px; }
.modal { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .28); display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.sheet { width: 100%; max-width: 560px; max-height: 86vh; overflow: auto; background: var(--bg); border-radius: 14px 14px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .22s ease; }
@keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; height: 48px; margin-bottom: 8px; }
.sheet-head h3 { font-size: 17px; font-weight: 600; grid-column: 2; }
.sheet-head .link { grid-column: 3; justify-self: end; font-weight: 600; }
.pick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.pickbtn { background: var(--card); border-radius: 12px; min-height: 52px; padding: 8px 12px; font-size: 17px; text-align: center; }
.pickbtn:active { background: var(--fill); }
.pinin { width: 100%; font-size: 24px; text-align: center; padding: 12px; margin-top: 14px; border-radius: 12px; border: 0; background: var(--card); letter-spacing: 8px; }

/* 聊天 */
.chat { display: flex; flex-direction: column; gap: 8px; padding: 8px 0 96px; }
.msg { max-width: 82%; padding: 9px 14px; border-radius: 19px; font-size: 17px; }
.msg.me { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 6px; }
.msg.coco { align-self: flex-start; background: var(--card); border-bottom-left-radius: 6px; }
.msg .en { font-size: 18px; line-height: 1.4; }
.msg .tools { display: flex; gap: 16px; margin-top: 4px; }
.msg .tools .link { font-size: 14px; }
.zhline { color: var(--muted); font-size: 15px; margin-top: 4px; }
.fix { margin-top: 8px; padding: 8px 12px; border-radius: 12px; background: var(--bg); display: flex; flex-direction: column; font-size: 14px; color: var(--muted); }
.fix .link { font-size: 17px; margin-top: 2px; }
.fix small { color: var(--faint); font-size: 13px; }
.sugg { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.sugg .chip { background: var(--bg); border: 0; color: var(--blue); }
.typing { display: flex; gap: 4px; padding: 6px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; background: rgba(245, 245, 247, .86); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-top: .5px solid var(--sep); padding: 8px max(16px, env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom)); }
.composer-in { max-width: var(--w); margin: 0 auto; display: flex; gap: 8px; align-items: center; }
.composer input { flex: 1; min-width: 0; height: 40px; border-radius: 20px; border: .5px solid var(--sep); background: var(--card); padding: 0 16px; font-size: 17px; outline: none; }
.composer input:focus { border-color: var(--blue); }
.btn.round { width: 40px; min-height: 40px; height: 40px; padding: 0; border-radius: 50%; font-size: 18px; }
body[data-view="chat"] .foot { display: none; }

/* 紀錄 / 設定 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.stat { background: var(--card); border-radius: var(--r); padding: 14px 8px; text-align: center; display: flex; flex-direction: column; }
.stat b { font-size: 26px; font-weight: 700; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th, .tbl td { padding: 10px 16px; text-align: left; white-space: nowrap; }
.tbl th { font-size: 13px; font-weight: 400; color: var(--muted); }
.tbl tr + tr td, .tbl tbody tr:first-child td { border-top: .5px solid var(--sep); }
.form .frow { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 50px; padding: 6px 16px; width: 100%; }
.form input:not([type=checkbox]), .form select { border: 0; background: transparent; text-align: right; color: var(--muted); font-size: 17px; min-width: 0; flex: 1; outline: none; }
.form select { flex: 0 1 auto; -webkit-appearance: none; appearance: none; }
.fval { color: var(--muted); }
.switch { -webkit-appearance: none; appearance: none; width: 51px; height: 31px; border-radius: 16px; background: var(--fill); position: relative; transition: background .2s; flex: 0 0 auto; cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .2); transition: transform .2s; }
.switch:checked { background: #34C759; }
.switch:checked::after { transform: translateX(20px); }

/* 載入、提示 */
.loading { text-align: center; padding: 80px 10px; color: var(--muted); font-size: 15px; }
.loading.sm { padding: 6px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.spinner { width: 28px; height: 28px; margin: 0 auto 12px; border: 3px solid var(--fill); border-top-color: var(--faint); border-radius: 50%; animation: spin .8s linear infinite; }
.loading.sm .spinner { width: 20px; height: 20px; margin: 0; border-width: 2.5px; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(29, 29, 31, .92); color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 15px; z-index: 40; max-width: calc(100% - 32px); text-align: center; }
.toast[hidden] { display: none; }

/* ---------- 小手機 ---------- */
@media (max-width: 360px) {
  .opts { grid-template-columns: 1fr; }
  .card .en { font-size: 34px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- iPad 直向（768+）：首頁與紀錄雙欄、字更大 ---------- */
@media (min-width: 768px) {
  :root { --w: 980px; }
  html, body { font-size: 18px; }
  main { padding-top: 16px; }
  .hero { padding: 28px 4px 4px; }
  .hero h1 { font-size: 40px; }
  .home-grid, .rec-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; align-items: start; }
  .topic-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; align-items: start; }
  .row { min-height: 56px; }
  .card { padding: 36px 32px; }
  .card .emoji { font-size: 72px; }
  .card .en { font-size: 52px; }
  .card.sent .en { font-size: 34px; }
  .card .zh { font-size: 22px; }
  .opts { gap: 14px; }
  .opt { min-height: 76px; font-size: 22px; }
  .card.q, .nav.single, .card.done { max-width: 720px; margin-left: auto; margin-right: auto; }
  .stats { grid-template-columns: repeat(6, 1fr); }
  .chat, .composer-in { max-width: 760px; margin-left: auto; margin-right: auto; }
  .msg { max-width: 70%; font-size: 18px; }
  .msg .en { font-size: 20px; }
  .sheet { border-radius: 14px; margin-bottom: auto; margin-top: auto; }
  .modal { align-items: center; }
  .pick { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- iPad 橫向 / 電腦（1024+）：練習頁左卡右操作 ---------- */
@media (min-width: 1024px) {
  .practice { display: grid; grid-template-columns: 1.15fr 1fr; gap: 24px; align-items: start; }
  .practice .card { min-height: 420px; display: flex; flex-direction: column; justify-content: center; }
  .practice .controls { margin-top: 0; }
  .practice .nav { margin-top: auto; padding-top: 16px; }
  .practice .side { min-height: 420px; }
}

/* ---------- 手機橫向：卡片縮小，避免要捲動 ---------- */
@media (max-height: 500px) and (orientation: landscape) {
  .card { padding: 16px; }
  .card .emoji { font-size: 40px; }
  .card .en { font-size: 32px; }
  .practice { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
}
