/* ===== 設計基礎：夜空 × 月光 ===== */
:root {
  --bg: #f4f3ee;
  --bg-2: #ebeaf3;
  --card: #ffffff;
  --text: #16213a;
  --muted: #6b7280;
  --line: #e3e4ea;
  --navy: #16213a;
  --navy-2: #253764;
  --primary: #3b4cc0;
  --primary-2: #2f3da0;
  --amber: #f5b73b;
  --amber-2: #d99a1a;
  --amber-soft: #fff4d6;
  --green: #1f9d6b;
  --danger: #d6453d;
  --danger-soft: #fdecec;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 6px 20px rgba(22, 33, 58, .08), 0 1px 2px rgba(22, 33, 58, .06);
  --shadow-lg: 0 14px 40px rgba(22, 33, 58, .16);
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 18px; line-height: 1.5;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 320px);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ===== 標題列 ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top));
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 100%);
  color: #fff;
  box-shadow: 0 2px 12px rgba(22, 33, 58, .25);
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 600; letter-spacing: .5px; }
.topbar-spacer { width: 76px; }
.icon-btn {
  background: rgba(255,255,255,.1); border: none; color: #fff;
  font-size: 17px; padding: 8px 12px; min-width: 76px; border-radius: 999px;
}
.icon-btn:active { background: rgba(255,255,255,.22); }

main { padding: 18px 16px; padding-bottom: 130px; max-width: 640px; margin: 0 auto; }

/* ===== 通用元件 ===== */
.card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  margin-bottom: 16px; box-shadow: var(--shadow);
}
.card-title { margin: 0 0 14px; font-size: 19px; font-weight: 600; display: flex; gap: 4px; }
.muted { color: var(--muted); font-size: 15px; margin: 6px 0; }
.error { color: var(--danger); font-size: 15px; min-height: 1.4em; margin: 6px 0 4px; }

.btn {
  min-height: 50px; font-size: 18px; font-weight: 500;
  border-radius: var(--radius-sm); border: 1.5px solid var(--line);
  background: #fff; color: var(--text);
  padding: 10px 18px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); box-shadow: 0 6px 16px rgba(59, 76, 192, .3); }
.btn.primary:active { background: var(--primary-2); }
.btn.danger { color: var(--danger); border-color: #f3c4c1; background: var(--danger-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.block { width: 100%; }
.btn.small { min-height: 42px; font-size: 16px; padding: 6px 14px; border-radius: 10px; }
.btn.previewing { background: var(--amber-soft); border-color: var(--amber); color: #7a5300; }

.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; min-width: 0; }
.row .btn.small { flex: 0 0 auto; }
.stack > * + * { margin-top: 10px; }

input[type=text], input[type=number], select {
  width: 100%; min-height: 50px; font-size: 19px; padding: 8px 14px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: #fafafa; color: var(--text); transition: border-color .15s, background .15s;
  -webkit-appearance: none; appearance: none;
}
input:focus, select:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(59, 76, 192, .15); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 5px; letter-spacing: .3px; }
.unit { flex: 0 0 auto; color: var(--muted); }
.custom-pause { margin-top: 10px; }
.custom-pause input { max-width: 140px; }

/* 分段切換 */
.tabs {
  display: flex; background: rgba(22, 33, 58, .08); border-radius: 999px; padding: 4px; margin-bottom: 16px;
}
.tabs button {
  flex: 1; min-height: 46px; border: none; background: transparent; border-radius: 999px;
  font-size: 18px; color: var(--muted); font-weight: 500; transition: all .2s ease;
}
.tabs button.active { background: #fff; color: var(--navy); font-weight: 600; box-shadow: 0 2px 8px rgba(22, 33, 58, .15); }

/* 提示橫幅 */
.banner {
  background: var(--amber-soft); color: #7a5300; border-left: 4px solid var(--amber);
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 16px; font-size: 16px;
}
.banner-title { font-weight: 600; }
.banner details { margin-top: 6px; }
.banner summary { cursor: pointer; font-weight: 500; }
.banner ol { margin: 8px 0 0; padding-left: 22px; font-size: 15px; }
.tip {
  display: flex; align-items: flex-start; gap: 10px; background: #fff; border: 1.5px dashed #c7cbe6;
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 16px; font-size: 15px; color: var(--muted);
}
.tip b { color: var(--text); }
.tip > div { flex: 1; }
.tip-close { background: none; border: none; color: var(--muted); font-size: 18px; padding: 0 4px; }

/* 列表 */
ul.list { list-style: none; margin: 0 0 8px; padding: 0; }
ul.list li {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
  box-shadow: var(--shadow); position: relative; transition: box-shadow .15s;
}
ul.list li.editing { box-shadow: var(--shadow-lg); border: 1.5px solid var(--primary); }
.item-en { font-size: 22px; font-weight: 600; word-break: break-word; line-height: 1.3; }
.item-syl { font-size: 15px; color: var(--primary); letter-spacing: 1px; margin-top: 2px; font-weight: 500; }
.item-syl em { font-style: normal; font-size: 12px; color: var(--muted); background: #eef0f6; padding: 1px 6px; border-radius: 6px; letter-spacing: 0; }
.item-zh { font-size: 18px; color: #3b4356; margin-top: 2px; }
.item-actions { display: flex; gap: 8px; margin-top: 12px; justify-content: flex-end; }
.empty { text-align: center; color: var(--muted); padding: 34px 10px !important; box-shadow: none !important; background: transparent !important; }

.section-title { font-size: 18px; font-weight: 600; margin: 6px 4px 10px; display: flex; justify-content: space-between; align-items: baseline; color: var(--navy); }
.section-title span { font-size: 14px; color: var(--muted); font-weight: normal; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 10px; }
.pager span { font-size: 16px; color: var(--muted); white-space: nowrap; }

/* 學習頁 */
.batch { margin-bottom: 14px; }
.learn-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px !important; }
.learn-row.is-selected { background: linear-gradient(90deg, var(--amber-soft) 0%, #fff 55%); border-left: 4px solid var(--amber); }
.learn-row .texts { flex: 1; min-width: 0; }
.learn-row .item-en { font-size: 20px; }
.learn-row .item-zh { font-size: 17px; }
.chip { flex: 0 0 auto; position: relative; }
.chip input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; left: 0; top: 0; cursor: pointer; }
.chip span {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 58px; height: 58px; border-radius: 14px; font-size: 14px; font-weight: 600; line-height: 1.1;
  border: 2px solid var(--line); color: var(--muted); background: #fafafa; transition: all .15s ease;
}
.chip span::before { content: "○"; font-size: 20px; margin-bottom: 1px; }
.chip input:checked + span::before { content: "✓"; }
.chip-play input:checked + span { background: var(--amber); border-color: var(--amber); color: #3a2a00; }
.chip-learned input:checked + span { background: var(--green); border-color: var(--green); color: #fff; }

details.section { margin: 8px 0 14px; }
details.section > summary {
  list-style: none; cursor: pointer; font-size: 18px; font-weight: 600; color: var(--navy);
  padding: 12px 14px; display: flex; justify-content: space-between; align-items: center;
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary span { font-size: 14px; color: var(--muted); font-weight: normal; flex: 1; text-align: right; margin-right: 10px; }
details.section > summary::after { content: "▾"; color: var(--muted); transition: transform .2s; }
details.section[open] > summary::after { transform: rotate(180deg); }
details.section[open] > summary { border-radius: var(--radius) var(--radius) 0 0; }
details.section > ul.list, details.section > .card { margin-top: 10px; }
details.section > .card { border-radius: var(--radius); }
details.sub summary { cursor: pointer; color: var(--primary); font-size: 16px; padding: 6px 0; }
details.sub[open] summary { margin-bottom: 8px; }

.setting { margin-bottom: 16px; }
.setting > .label { font-size: 14px; color: var(--muted); margin-bottom: 7px; letter-spacing: .3px; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pills label { flex: 1 1 0; min-width: 62px; position: relative; }
.pills input { position: absolute; opacity: 0; width: 0; height: 0; }
.pills span {
  display: block; text-align: center; min-height: 46px; line-height: 46px; padding: 0 8px; white-space: nowrap; border-radius: 999px;
  border: 1.5px solid var(--line); background: #fafafa; font-weight: 500; transition: all .15s ease;
}
.pills input:checked + span { background: var(--navy); color: #fff; border-color: var(--navy); box-shadow: 0 4px 10px rgba(22, 33, 58, .25); }

.sticky-bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  padding: 10px 16px; padding-bottom: calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 78%, rgba(244, 243, 238, 0));
}
.sticky-bottom .inner { max-width: 640px; margin: 0 auto; }
.sticky-bottom .hint { text-align: center; font-size: 14px; color: var(--muted); margin: 0 0 6px; }
.play-btn {
  width: 100%; min-height: 64px; font-size: 23px; font-weight: 600; border-radius: 999px;
  background: linear-gradient(135deg, var(--primary) 0%, #5566d6 100%);
}
.play-btn:not(:disabled) { box-shadow: 0 10px 28px rgba(59, 76, 192, .4); }

/* ===== 首頁 ===== */
.hero {
  position: relative; overflow: hidden; text-align: center; color: #fff;
  background: radial-gradient(120% 120% at 80% -10%, #3a4f8f 0%, var(--navy-2) 40%, var(--navy) 100%);
  border-radius: 24px; padding: 30px 20px 26px; margin-bottom: 18px; box-shadow: var(--shadow-lg);
}
.hero::before, .hero::after {
  content: ""; position: absolute; border-radius: 50%; background: #fff; opacity: .5;
  width: 3px; height: 3px; box-shadow: 40px 30px 0 0 #fff, 120px 10px 0 0 #fff, 220px 50px 0 0 #fff, 300px 20px 0 0 #fff, 70px 90px 0 0 #fff, 260px 110px 0 0 #fff, 180px 130px 0 0 #fff;
  left: 10px; top: 10px;
}
.hero::after { left: 30px; top: 60px; opacity: .25; transform: scale(.7); }
.hero-icon { width: 76px; height: 76px; margin: 0 auto 10px; color: var(--amber); filter: drop-shadow(0 0 18px rgba(245, 183, 59, .55)); position: relative; }
.hero-icon svg { width: 100%; height: 100%; }
.hero h2 { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: 1px; position: relative; }
.hero-stats { margin: 10px 0 0; font-size: 15px; color: rgba(255,255,255,.75); display: flex; justify-content: center; align-items: center; gap: 14px; position: relative; }
.hero-stats b { color: #fff; font-size: 20px; font-weight: 600; margin-right: 2px; }
.hero-stats i { width: 1px; height: 16px; background: rgba(255,255,255,.3); }

.tiles { display: flex; flex-direction: column; gap: 12px; }
.tile {
  display: flex; align-items: center; gap: 16px; width: 100%; text-align: left;
  background: #fff; border: none; border-radius: 20px; padding: 20px 18px;
  box-shadow: var(--shadow); transition: transform .1s ease, box-shadow .15s ease;
}
.tile:active { transform: scale(.985); box-shadow: var(--shadow-lg); }
.tile-icon { width: 60px; height: 60px; border-radius: 16px; display: grid; place-items: center; flex: 0 0 auto; }
.tile-icon svg { width: 34px; height: 34px; }
.tile-learn .tile-icon { background: linear-gradient(135deg, #3b4cc0, #6a7be0); color: #fff; }
.tile-input .tile-icon { background: linear-gradient(135deg, var(--amber), #ffd37a); color: #4a3300; }
.tile-sub .tile-icon { background: #eef0f6; color: var(--navy-2); width: 48px; height: 48px; border-radius: 12px; }
.tile-sub .tile-icon svg { width: 26px; height: 26px; }
.tile-text { flex: 1; display: flex; flex-direction: column; }
.tile-text b { font-size: 24px; font-weight: 600; letter-spacing: 1px; }
.tile-sub .tile-text b { font-size: 18px; }
.tile-text small { font-size: 14px; color: var(--muted); margin-top: 2px; }
.tile-arrow { font-size: 28px; color: #c3c6d4; }

/* ===== 備份頁 ===== */
.import-result { margin-top: 14px; }
.summary { background: #f7f7fb; border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 12px; font-size: 16px; }
.summary-line { padding: 3px 0; }
.summary-line b { font-size: 20px; margin-right: 4px; }
.summary-line .ok { color: var(--green); }
.summary-line .warn { color: var(--amber-2); }
.dupes { margin-top: 6px; }
.dupes summary { cursor: pointer; color: var(--primary); font-size: 15px; }
.dupes ul { margin: 6px 0 0; padding-left: 20px; font-size: 15px; max-height: 200px; overflow: auto; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%) translateY(10px);
  background: var(--navy); color: #fff; padding: 12px 22px; border-radius: 999px;
  font-size: 16px; z-index: 50; max-width: 90vw; text-align: center; box-shadow: var(--shadow-lg);
  opacity: 0; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 播放頁（純黑夜間模式）===== */
body.play-mode { background: #000; color: #c7c7c7; }
body.play-mode .topbar { background: #000; color: #777; box-shadow: none; }
body.play-mode .icon-btn { color: #999; background: #151515; }
body.play-mode main { padding-bottom: 40px; }
.play-hint { text-align: center; font-size: 13px; color: #555; margin: 0 0 24px; }
.play-main { text-align: center; padding: 30px 0 20px; min-height: 260px; display: flex; flex-direction: column; justify-content: center; }
.play-en { font-size: 42px; font-weight: 600; color: #d8d8d8; word-break: break-word; line-height: 1.25; transition: color .2s; }
.play-syl { font-size: 24px; color: #666; margin-top: 12px; min-height: 1.6em; letter-spacing: 1px; }
.play-syl .dot { margin: 0 8px; color: #444; }
.play-syl .on { color: var(--amber); text-shadow: 0 0 14px rgba(245, 183, 59, .5); }
.play-syl .auto { font-size: 12px; color: #444; margin-left: 10px; vertical-align: middle; border: 1px solid #333; padding: 1px 6px; border-radius: 6px; letter-spacing: 0; }
.play-zh { font-size: 28px; color: #9a9a9a; margin-top: 16px; transition: color .2s; }
.play-zh.on, .play-en.on { color: var(--amber); text-shadow: 0 0 18px rgba(245, 183, 59, .45); }
.play-meta { display: flex; justify-content: space-around; margin: 24px 0 18px; font-size: 13px; color: #666; letter-spacing: 1px; }
.play-meta b { display: block; font-size: 26px; color: #cfcfcf; font-weight: 500; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.play-bar { height: 4px; background: #1a1a1a; border-radius: 2px; overflow: hidden; margin: 0 0 30px; }
.play-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--amber-2), var(--amber)); transition: width .5s linear; }
.play-stop {
  width: 100%; min-height: 78px; font-size: 26px; font-weight: 500;
  background: #161616; color: #e5e5e5; border: 1px solid #2a2a2a; border-radius: 999px;
}
.play-stop:active { background: #222; }
.play-stop:disabled { opacity: .4; }
.play-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.94);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  z-index: 40; color: #ddd; font-size: 22px; text-align: center; padding: 24px;
}
.play-overlay .btn { background: var(--primary); color: #fff; border-color: var(--primary); min-height: 64px; font-size: 22px; padding: 0 34px; border-radius: 999px; }
.play-overlay .btn.ghost { background: transparent; border-color: #333; color: #888; }
