/* ===== 基础 ===== */
:root {
  --navy: #1f3a5f;
  --navy-2: #2c5282;
  --teal: #0e8a7d;
  --amber: #d97706;
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #1d2733;
  --ink-2: #556270;
  --line: #e2e8f0;
  --danger: #c0392b;
  --ok: #1e8e5a;
  --shadow: 0 2px 10px rgba(31, 58, 95, .08);
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--ink);
  overscroll-behavior: none;
}
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 860px; margin: 0 auto; }

/* ===== 顶栏 / 底栏 ===== */
#topbar {
  display: flex; align-items: center; gap: 8px;
  padding: env(safe-area-inset-top) 12px 0;
  height: calc(52px + env(safe-area-inset-top));
  background: var(--navy); color: #fff; flex: none;
}
#page-title { font-size: 17px; font-weight: 600; margin: 0; flex: 1;
  padding-top: env(safe-area-inset-top); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  border: none; background: rgba(255,255,255,.14); color: #fff;
  width: 36px; height: 36px; border-radius: 10px; font-size: 16px; cursor: pointer;
  margin-top: env(safe-area-inset-top);
}
#tabbar {
  display: flex; flex: none; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar a {
  flex: 1; text-align: center; text-decoration: none; color: var(--ink-2);
  font-size: 12px; padding: 7px 0 8px;
}
#tabbar a .tab-ico { display: block; font-size: 19px; line-height: 1.3; }
#tabbar a.active { color: var(--navy-2); font-weight: 600; }

#view { flex: 1; overflow: hidden; position: relative; display: flex; flex-direction: column; }
.scroll { overflow-y: auto; padding: 14px; flex: 1; -webkit-overflow-scrolling: touch; }

/* ===== 通用组件 ===== */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.muted { color: var(--ink-2); font-size: 13px; }
.tag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #e8f0fa; color: var(--navy-2); margin-right: 6px; }
.tag.teal { background: #e0f2ef; color: var(--teal); }
.tag.amber { background: #fdf0dd; color: var(--amber); }
.btn {
  display: inline-block; border: none; border-radius: 10px; cursor: pointer;
  padding: 10px 16px; font-size: 14px; font-weight: 600;
  background: var(--navy-2); color: #fff;
}
.btn:active { transform: scale(.97); }
.btn.teal { background: var(--teal); }
.btn.amber { background: var(--amber); }
.btn.ghost { background: #fff; color: var(--navy-2); border: 1px solid var(--navy-2); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.row { display: flex; align-items: center; gap: 10px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--ink);
}
textarea { resize: none; }
label.fld { display: block; margin-bottom: 12px; font-size: 13px; color: var(--ink-2); }
label.fld input, label.fld select, label.fld textarea { margin-top: 5px; }

/* ===== 首页周格 ===== */
.week-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.week-cell {
  background: #fff; border-radius: 12px; box-shadow: var(--shadow);
  padding: 10px 4px; text-align: center; text-decoration: none; color: var(--ink);
  position: relative; font-size: 12px;
}
.week-cell .wn { font-size: 17px; font-weight: 700; color: var(--navy-2); display: block; }
.week-cell .wt { display: block; margin-top: 2px; font-size: 11px; color: var(--ink-2);
  max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.dots { margin-top: 5px; font-size: 9px; letter-spacing: 1px; }
.dots .d { color: #cdd6e2; }
.dots .d.on { color: var(--teal); }

.module-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.module-tile {
  border-radius: var(--radius); padding: 16px; color: #fff; text-decoration: none;
  min-height: 92px; display: flex; flex-direction: column; justify-content: space-between;
  box-shadow: var(--shadow);
}
.module-tile .mt-title { font-size: 16px; font-weight: 700; }
.module-tile .mt-sub { font-size: 12px; opacity: .88; }
.mt-reading { background: linear-gradient(135deg, #2c5282, #3b6ea5); }
.mt-listening { background: linear-gradient(135deg, #0e8a7d, #14a899); }
.mt-writing { background: linear-gradient(135deg, #b45309, #d97706); }
.mt-speaking { background: linear-gradient(135deg, #8a4a8e, #a85fb0); }

/* ===== 翻页（阅读） ===== */
.page-wrap { flex: 1; display: flex; flex-direction: column; padding: 0 14px; min-height: 0; }
.page-stage {
  flex: 1; min-height: 0; position: relative; overflow: hidden;
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  margin: 12px 0; display: flex;
}
.page {
  position: absolute; inset: 0; padding: 22px 22px 16px;
  display: none; flex-direction: column; animation: fade .22s ease;
}
.page.active { display: flex; }
@keyframes fade { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }
.page-body { flex: 1; min-height: 0; overflow: hidden; }
.passage-title { font-size: 17px; font-weight: 700; color: var(--navy); margin: 0 0 12px; }
.passage-p { font-size: 15px; line-height: 1.85; margin: 0 0 11px; text-align: justify; }
.pager { display: flex; align-items: center; gap: 10px; padding: 0 0 12px; flex: none; }
.pager button { flex: none; }
.pager .indicator { flex: 1; text-align: center; font-size: 13px; color: var(--ink-2); }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip { background: #e8f0fa; color: var(--navy-2); border-radius: 999px; padding: 6px 13px; font-size: 14px; }

/* ===== 听力 ===== */
.q-block { margin-bottom: 14px; line-height: 1.7; font-size: 14.5px; }
.q-block .q-stem { font-weight: 600; margin-bottom: 6px; }
.opt { display: block; padding: 5px 0; }
.script-line { display: block; padding: 7px 10px; border-radius: 8px; font-size: 14px; line-height: 1.75; }
.script-line:active { background: #eaf3ff; }
.audio-bar {
  position: sticky; top: 0; z-index: 2; background: var(--teal); color: #fff;
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.audio-bar .btn { background: rgba(255,255,255,.2); }
.audio-bar select, .audio-bar input[type=range] { accent-color: #fff; }
.audio-bar label { color: rgba(255,255,255,.92); font-size: 12px; }
.pulse { animation: pulse 1.1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* ===== 专项听写 / 逐句听写 ===== */
.drill-intro ul { margin: 8px 0 0; padding-left: 18px; }
.drill-intro li { font-size: 13.5px; line-height: 1.85; }
.drill-tile .mt-title { font-size: 15px; }
.dt-noun { background: linear-gradient(135deg, #0e8a7d, #14a899); }
.dt-liaison { background: linear-gradient(135deg, #2c5282, #3b6ea5); }
.dt-number { background: linear-gradient(135deg, #b45309, #d97706); }
.dict-row { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 9px; flex-wrap: wrap; }
.dict-row .num { flex: none; width: 20px; font-size: 13px; color: var(--ink-2); padding-top: 10px; text-align: right; }
.dict-row input { flex: 1; min-width: 180px; }
.dict-row .rp {
  flex: none; border: none; background: #e8f0fa; color: var(--navy-2);
  border-radius: 9px; width: 38px; height: 38px; cursor: pointer; font-size: 14px;
}
.dict-row .rp:active { background: #dbe7f5; }
.dict-diff { width: 100%; font-size: 13px; line-height: 1.65; margin: -2px 0 2px 28px; }
.dict-diff .miss { color: var(--danger); font-weight: 600; }
.dict-diff .ok { color: var(--ok); font-weight: 600; }
input.d-bad { border-color: var(--danger) !important; background: #fdf3f2; }
input.d-good { border-color: var(--ok) !important; background: #f2faf5; }
.drill-verdict {
  border-radius: 10px; padding: 10px 12px; font-size: 14px; line-height: 1.8;
}
.drill-verdict.pass { background: #eaf7f0; border: 1px solid #bfe6d0; }
.drill-verdict.fail { background: #fdf0ee; border: 1px solid #f3cdc7; }
.drill-verdict .muted { display: block; }
.ww-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 14px;
}
.ww-item:last-child { border-bottom: none; }
.ww-item .ww-w { font-weight: 600; color: var(--navy-2); cursor: pointer; }
.skills-card summary {
  cursor: pointer; font-weight: 600; font-size: 15px; list-style: none;
  display: flex; align-items: center; gap: 6px; user-select: none;
}
.skills-card summary::-webkit-details-marker { display: none; }
.skills-card summary::after { content: '▸'; margin-left: auto; color: var(--ink-2); transition: transform .15s; }
.skills-card[open] summary::after { transform: rotate(90deg); }
.skill-sec h4 { margin: 12px 0 5px; font-size: 14px; color: var(--navy-2); }
.skill-sec ul { margin: 0; padding-left: 18px; }
.skill-sec li { font-size: 13.5px; line-height: 1.75; margin-bottom: 3px; }
.chip.speak { cursor: pointer; background: #eef4fb; border: 1px solid var(--line); }
.chip.speak:active { background: #dfeaf6; }

/* ===== 写作 ===== */
.write-page { display: none; flex-direction: column; flex: 1; min-height: 0; }
.write-page.active { display: flex; }
.guide-item { border-left: 3px solid var(--navy-2); padding: 4px 0 4px 12px; margin: 10px 0; font-size: 14px; line-height: 1.75; }
.guide-item b { color: var(--navy-2); }
.example-body { font-size: 14.5px; line-height: 1.9; background: #fbf7ee; border-radius: 10px; padding: 14px; }
.seg { display: flex; gap: 8px; margin-bottom: 10px; }
.seg .btn { flex: 1; }

/* ===== 口语 ===== */
.chat { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 84%; padding: 10px 13px; border-radius: 14px; font-size: 14.5px; line-height: 1.7; white-space: pre-wrap; }
.bubble.ai { background: #fff; box-shadow: var(--shadow); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.me { background: var(--navy-2); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.sys { background: #fff4e0; color: #92590c; align-self: center; font-size: 12.5px; text-align: center; }
.chat-bar { flex: none; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fff; display: flex; gap: 8px; }
.mic {
  flex: none; width: 48px; height: 48px; border-radius: 50%; border: none; font-size: 21px;
  background: #e8f0fa; cursor: pointer;
}
.mic.rec { background: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
.question-item { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; font-size: 14px; line-height: 1.7; }
.question-item .qi-role { font-size: 11px; font-weight: 700; color: var(--navy-2); }

/* ===== 单词卡 ===== */
.study-stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; min-height: 0; }
.flashcard {
  width: 100%; max-width: 460px; min-height: 300px; perspective: 1200px; cursor: pointer;
}
.flash-inner {
  position: relative; width: 100%; min-height: 300px; transition: transform .5s;
  transform-style: preserve-3d;
}
.flashcard.flipped .flash-inner { transform: rotateY(180deg); }
.flash-face {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: 18px;
  background: #fff; box-shadow: var(--shadow); padding: 22px; display: flex; flex-direction: column;
  overflow-y: auto;
}
.flash-back { transform: rotateY(180deg); background: #f7faff; }
.flash-term { font-size: 25px; font-weight: 700; color: var(--navy); }
.flash-context { font-size: 13.5px; color: var(--ink-2); font-style: italic; margin-top: 8px; line-height: 1.7; }
.flash-hint { margin-top: auto; text-align: center; color: #9aa7b5; font-size: 12.5px; padding-top: 14px; }
.rate-row { display: flex; gap: 8px; margin-top: 16px; width: 100%; max-width: 460px; }
.rate-row .btn { flex: 1; }
.rate-bad { background: var(--danger); }
.rate-meh { background: var(--amber); }
.rate-good { background: var(--ok); }
.big-stat { font-size: 30px; font-weight: 700; color: var(--navy-2); }

.empty { text-align: center; color: var(--ink-2); padding: 50px 20px; font-size: 14px; line-height: 1.9; }
.spinner { display: inline-block; width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: rgba(29,39,51,.92); color: #fff; padding: 9px 16px; border-radius: 999px;
  font-size: 13px; z-index: 99; max-width: 86%;
}
