/* app.css — 版面、卡片、RWD。配色/字體變數見 tokens.css。 */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { -webkit-font-smoothing: antialiased; }
button { font-family: inherit; }
a { color: inherit; text-decoration: none; }
ul { margin: 0; padding-left: 1.1em; }

/* ---------- 全域動畫關鍵影格 ---------- */
@keyframes slide-down {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes flash-right {
  0%   { box-shadow: 0 0 0 0 rgba(159,230,160,.0); border-color: var(--border); }
  30%  { box-shadow: 0 0 0 6px rgba(159,230,160,.35); border-left-color: var(--success); }
  100% { box-shadow: 0 0 0 0 rgba(159,230,160,.0); border-left-color: var(--cyan); }
}
@keyframes flash-wrong {
  0%   { box-shadow: 0 0 0 0 rgba(255,107,107,.0); border-color: var(--border); }
  30%  { box-shadow: 0 0 0 6px rgba(255,107,107,.30); border-left-color: var(--danger); }
  100% { box-shadow: 0 0 0 0 rgba(255,107,107,.0); border-left-color: var(--cyan); }
}
@keyframes rank-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232,198,107,.0); }
  40%       { box-shadow: 0 0 0 18px rgba(232,198,107,.22); }
  70%       { box-shadow: 0 0 0 8px rgba(232,198,107,.10); }
}
@keyframes streak-pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); }
  70%  { transform: scale(.96); }
  100% { transform: scale(1); }
}

/* 數字/速度/% 等寬字，營造儀表板感（§3 質感規則） */
.study-counter, .term-en, .nav-en { font-family: var(--font-data); }

/* ---------- 殼 / 版面 ---------- */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.main { flex: 1; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: baseline; gap: 10px;
  padding: 16px 18px 8px;
}
.logo { font-family: var(--font-ui); font-weight: 600; letter-spacing: 2px; color: var(--cyan); }
.logo-sub { font-size: 13px; color: var(--text-muted); }

.view { padding: 12px 16px 96px; max-width: 720px; width: 100%; margin: 0 auto; }
.view > * { animation: slide-down .18s ease; }

/* ---------- 導覽（手機底部 / 桌面側欄） ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 48px; justify-content: center;
  color: var(--text-muted); border-radius: var(--radius-sm);
}
.nav-zh { font-size: 13px; }
.nav-en { font-size: 10px; letter-spacing: .5px; }
.nav-item.active { color: var(--cyan); position: relative; }
.nav-item.active .nav-en { color: var(--cyan); }
/* 底部 active 線指示器（手機） */
.nav-item.active::after {
  content: ''; position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%);
  width: 22px; height: 3px; border-radius: 99px; background: var(--cyan);
}
@media (min-width: 880px) {
  /* 桌面側欄改為左側豎線 */
  .nav-item.active::after {
    bottom: auto; top: 50%; transform: translateY(-50%);
    left: -12px; width: 3px; height: 22px;
  }
}

@media (min-width: 880px) {
  .app-shell { flex-direction: row; }
  .nav {
    position: sticky; top: 0; bottom: auto; height: 100vh; width: 168px;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    border-top: none; border-right: 1px solid var(--border); padding: 24px 12px;
  }
  .nav-item { flex: none; flex-direction: row; gap: 8px; justify-content: flex-start; padding: 0 12px; }
  .nav-zh { font-size: 15px; }
}

/* ---------- 通用卡片 / 狀態 ---------- */
.state-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 22px; text-align: center; margin-top: 24px;
}
.state-card h2 { margin: 0 0 8px; font-size: 20px; }
.state-card.success { border-color: #2f5a3a; }
.callsign {
  font-family: var(--font-data); color: var(--success);
  letter-spacing: 2px; font-size: 13px; margin-bottom: 10px;
}
.dim { color: var(--text-dim); margin: 0; line-height: 1.6; }

/* ---------- 學習流程 ---------- */
.study-progress {
  height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0;
}
.study-progress-fill {
  height: 100%; width: 0; background: var(--cyan);
  transition: width .4s cubic-bezier(.4,0,.2,1);
}
.study-counter { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--cyan); border-radius: var(--radius);
  padding: 20px 18px; line-height: 1.65;
}
.card[data-tier="scenario"] { border-left-color: var(--amber); }

.card-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.tier-badge {
  font-size: 12px; padding: 3px 9px; border-radius: 99px;
  background: var(--surface-3); color: var(--text-dim); border: 1px solid var(--border-soft);
}
.concept { font-size: 13px; color: var(--text-muted); }

.card-face .q { font-size: 18px; font-weight: 500; margin: 0 0 6px; }
.card-face .hint { font-size: 13px; color: var(--text-muted); margin: 4px 0 0; }
.card-face .setup {
  font-family: var(--font-data); font-size: 14px; color: var(--amber-soft);
  background: var(--surface-2); border-radius: var(--radius-sm);
  padding: 10px 12px; margin-bottom: 12px;
}

.card-face.answer {
  margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--border);
  animation: slide-down .22s ease;
}
.card-face .a { font-size: 16px; margin: 0 0 10px; }
.card-face .explain { color: var(--text-dim); font-size: 15px; margin: 8px 0 0; }
.key-points { color: var(--text-dim); font-size: 15px; }
.key-points li { margin: 4px 0; }

/* physics 三件式 */
.physics { margin-top: 14px; border-top: 1px solid var(--border-soft); padding-top: 12px; }
.physics-row { display: flex; gap: 10px; margin-bottom: 8px; font-size: 14px; }
.physics-tag {
  flex: none; width: 36px; height: fit-content; text-align: center;
  font-size: 12px; padding: 2px 0; border-radius: var(--radius-sm);
  background: var(--surface-3); color: var(--cyan);
}
.physics-body { color: var(--text-dim); line-height: 1.6; }
.terms { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.term {
  display: inline-flex; gap: 6px; align-items: baseline;
  background: var(--surface-2); border: 1px solid var(--border-soft);
  border-radius: 99px; padding: 3px 10px; font-size: 12px;
}
.term-en { color: var(--cyan); }
.term-zh { color: var(--text-muted); }

/* ---------- 按鈕 ---------- */
.actions { display: flex; gap: 12px; margin-top: 20px; }
.btn {
  flex: 1; min-height: 48px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: 16px; cursor: pointer; transition: transform .06s ease, filter .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:hover { filter: brightness(1.12); }
.btn-primary { background: var(--amber); color: #1a1205; border-color: var(--amber); font-weight: 600; }
.btn-right { border-color: #2f5a3a; color: var(--success); }
.btn-wrong { border-color: #5a2a2e; color: var(--danger); }

.receipt {
  margin-top: 14px; font-family: var(--font-data); font-size: 13px;
  color: var(--success); line-height: 1.6;
}

/* ---------- 今日 Sortie ---------- */
.sortie-card {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--amber); border-radius: var(--radius);
  padding: 22px 20px; margin-top: 16px;
}
.sortie-kicker {
  font-family: var(--font-data); letter-spacing: 2px; font-size: 12px;
  color: var(--amber); text-transform: uppercase;
}
.streak-line {
  font-family: var(--font-data); font-size: 13px; color: var(--text-dim); margin: 6px 0 8px;
}
.current-module {
  font-size: 13px; color: var(--cyan); margin: 0 0 14px;
}
.sortie-card h2 { margin: 0 0 14px; font-size: 21px; }
.sortie-stats { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.chip {
  background: var(--surface-2); border: 1px solid var(--border-soft);
  border-radius: 99px; padding: 7px 14px; font-size: 14px; color: var(--text-dim);
}
.chip b { font-family: var(--font-data); color: var(--cyan); font-weight: 600; margin-right: 4px; }
.start-btn { display: block; text-align: center; line-height: 48px; flex: none; }

/* ---------- 紀錄簿 Logbook ---------- */
.tiles { display: flex; gap: 12px; margin-top: 16px; }
.tile {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 16px; text-align: center;
}
.tile-num { font-family: var(--font-data); font-size: 26px; color: var(--cyan); }
.tile-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.rank-card {
  display: flex; align-items: center; gap: 14px; margin-top: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--gold); border-radius: var(--radius); padding: 16px 18px;
}
.rank-stripes { font-family: var(--font-data); color: var(--gold); font-size: 18px; letter-spacing: 1px; }
.rank-zh { font-weight: 500; }
.rank-en { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.section-h { font-size: 15px; color: var(--text-dim); margin: 24px 0 10px; font-weight: 500; }
.mastery {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
}
.mastery.mastered { border-color: var(--gold); }
.mastery-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.mastery-name { font-size: 15px; }
.mastery-meta { font-family: var(--font-data); font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.mastery.mastered .mastery-meta { color: var(--gold); }
.mastery-bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.mastery-fill { height: 100%; background: var(--cyan); border-radius: 99px; transition: width .3s ease; }
.mastery.mastered .mastery-fill { background: var(--gold); }

/* ---------- Widget 互動圖 ---------- */
.widget-container {
  margin: 14px 0 10px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
}
.widget-wrap { line-height: 0; }
.widget-svg {
  width: 100%; height: auto; display: block;
  max-height: 320px; object-fit: contain;
}
.widget-caption {
  font-size: 12px; color: var(--text-muted);
  text-align: center; margin: 6px 8px 8px;
  font-style: italic; line-height: 1.4;
}
.widget-error {
  font-size: 13px; color: var(--text-muted);
  padding: 12px; text-align: center;
}

/* ---------- 授階階梯 Ranks ---------- */
.ranks-intro { margin-top: 16px; }
.ranks-intro .dim { margin-top: 6px; }
.ladder {
  margin-top: 16px; position: relative;
  display: flex; flex-direction: column; gap: 10px;
}
.ladder-step {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.ladder-step.locked { opacity: .5; }
.ladder-step.current { border-color: var(--gold); border-left: 4px solid var(--gold); background: var(--surface-2); }
.ladder-insignia { flex: none; width: 48px; display: flex; justify-content: center; }
.insignia-svg { display: block; }
.ladder-step.locked .insignia-svg { filter: grayscale(1); }
.ladder-body { flex: 1; min-width: 0; }
.ladder-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.ladder-zh { font-size: 17px; font-weight: 500; }
.ladder-en { font-size: 12px; color: var(--text-muted); font-family: var(--font-ui); }
.ladder-aircraft { font-size: 13px; color: var(--text-dim); margin-top: 3px; }
.ladder-status { font-family: var(--font-data); font-size: 12px; margin-top: 6px; color: var(--text-muted); }
.ladder-step.current .ladder-status { color: var(--gold); }
.ladder-step.unlocked:not(.current) .ladder-status { color: var(--success); }

/* 卡片答對/答錯閃光（JS 動態加 class） */
.card.graded-right { animation: flash-right .65s ease forwards; }
.card.graded-wrong  { animation: flash-wrong  .65s ease forwards; }

/* ---------- 首頁 Home ---------- */
.home-hero {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--cyan); border-radius: var(--radius);
  padding: 28px 22px; margin-top: 16px;
}
.home-title { font-size: 24px; margin: 6px 0 14px; font-weight: 700; }
.home-desc { color: var(--text-dim); line-height: 1.75; margin: 0 0 20px; font-size: 15px; }
.home-features { display: flex; flex-direction: column; gap: 8px; margin: 0 0 20px; }
.home-feat {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-2); border-radius: var(--radius-sm);
  padding: 10px 14px; border: 1px solid var(--border-soft);
}
.home-feat-icon { font-size: 18px; flex: none; }
.home-feat-label { font-weight: 600; font-size: 14px; min-width: 76px; }
.home-feat-desc { font-size: 13px; color: var(--text-dim); }
.home-meta { margin: 0 0 22px; }
.home-meta .dim { font-size: 13px; margin: 3px 0; }
.home-cta {
  display: block; text-align: center; line-height: 52px;
  font-size: 17px; border-radius: var(--radius); width: 100%;
}

/* ---------- MCQ 選擇題 ---------- */
.choices { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.choice-btn {
  width: 100%; text-align: left; padding: 14px 16px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; color: var(--text);
  display: flex; gap: 12px; align-items: flex-start;
  font-size: 15px; line-height: 1.55;
  transition: border-color .12s, background .12s;
  font-family: inherit;
}
.choice-btn:hover:not(:disabled) { border-color: var(--cyan); background: var(--surface-3); }
.choice-btn:disabled { cursor: default; }
.choice-label {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface-3); color: var(--cyan);
  font-family: var(--font-data); font-size: 13px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.choice-text { flex: 1; }
.choice-btn.choice-correct { border-color: var(--success); }
.choice-btn.choice-correct .choice-label { background: var(--success); color: #0a1f0d; }
.choice-btn.choice-selected-right { border-color: var(--success); background: rgba(159,230,160,.07); }
.choice-btn.choice-selected-right .choice-label { background: var(--success); color: #0a1f0d; }
.choice-btn.choice-selected-wrong { border-color: var(--danger); background: rgba(255,107,107,.07); }
.choice-btn.choice-selected-wrong .choice-label { background: var(--danger); color: #200a0a; }

/* ---------- 事實查核來源 ---------- */
.source-block {
  margin-top: 14px; padding: 12px 14px;
  background: var(--surface-2); border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
}
.source-label {
  font-size: 11px; color: var(--amber); font-family: var(--font-data);
  letter-spacing: 1px; text-transform: uppercase; margin-bottom: 5px;
}
.source-ref { font-size: 13px; color: var(--text-dim); margin-bottom: 3px; font-weight: 500; }
.source-note { font-size: 11px; color: var(--text-muted); line-height: 1.5; }

/* ---------- 解鎖慶祝徽章 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 10, 20, .72);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: fade-in .2s ease;
}
.celebrate {
  background: var(--surface); border: 1px solid var(--gold); border-radius: var(--radius);
  padding: 30px 26px; text-align: center; max-width: 340px; width: 100%;
  box-shadow: 0 0 0 1px rgba(232,198,107,.25), 0 24px 60px rgba(0,0,0,.5);
  animation: pop-in .28s cubic-bezier(.2,.9,.3,1.2), rank-pulse 1.8s ease .3s 2;
}
.celebrate-insignia { display: flex; justify-content: center; margin-bottom: 12px; }
.celebrate-insignia .insignia-svg { width: 96px; height: 84px; }
.celebrate h2 { margin: 6px 0 4px; font-size: 22px; }
.celebrate .btn { margin-top: 20px; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
