:root {
  --bg: #fff8eb;
  --card: #ffffff;
  --ink: #2b2d42;
  --muted: #6c757d;
  --primary: #f59f00;
  --primary-dark: #e67700;
  --accent: #339af0;
  --success: #2b8a3e;
  --danger: #e03131;
  --border: #ffe8cc;
  --radius: 20px;
  --shadow: 0 8px 24px rgba(245, 159, 0, 0.12);
}

html[data-font-size="sm"] { font-size: 14px; }
html[data-font-size="md"] { font-size: 16px; }
html[data-font-size="lg"] { font-size: 18px; }
html[data-font-size="xl"] { font-size: 20px; }

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Noto Sans TC', 'Fredoka', system-ui, sans-serif;
  background: linear-gradient(180deg, #fff4d9 0%, #fffaf0 40%, #f1f8ff 100%);
  color: var(--ink);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* Banners */
.pwa-banner, .update-banner, .inapp-banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 18px; font-size: 0.92rem; font-weight: 700;
}
.pwa-banner { background: #fff3bf; border-bottom: 2px solid #ffd43b; }
.pwa-banner-actions { display: flex; gap: 8px; }
.update-banner { background: #2b8a3e; color: #fff; justify-content: center; cursor: pointer; }
.inapp-banner { background: #e7f5ff; color: #1864ab; border-bottom: 2px solid #a5d8ff; }
.btn-mini-close { background: #1971c2; color: #fff; border: 0; border-radius: 999px; padding: 4px 12px; cursor: pointer; font-weight: 700; }

.streak-banner {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 90; background: linear-gradient(90deg, #ff6b6b, #f59f00); color: #fff;
  padding: 8px 20px; border-radius: 999px; font-weight: 900; box-shadow: 0 8px 20px rgba(255,107,107,0.35);
}

/* Header */
.top-header {
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 3px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.header-inner {
  max-width: 1180px; margin: 0 auto; padding: 10px 16px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.brand-badge {
  width: 46px; height: 46px; border-radius: 14px;
  background: linear-gradient(135deg, #ffa94d, #ff6b6b);
  display: grid; place-items: center; font-size: 1.6rem; box-shadow: 0 4px 10px rgba(255,107,107,0.3);
}
.brand-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.brand h1 { margin: 0; font-size: 1.3rem; font-weight: 900; }
.badge-pill {
  background: #fff3bf; color: #d9480f; border: 1.5px solid #ffd43b;
  padding: 2px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 800;
}
.subtitle { margin: 2px 0 0; font-size: 0.8rem; color: var(--muted); }

.header-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.font-size-control {
  display: flex; align-items: center; gap: 3px; background: #fff9db;
  padding: 3px 6px; border-radius: 999px; border: 1.5px solid #ffe066;
}
.ctrl-label { font-size: 0.75rem; font-weight: 800; padding: 0 4px; color: #e67700; }
.fs-btn {
  border: 0; background: transparent; padding: 3px 7px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 700; cursor: pointer; color: var(--ink);
}
.fs-btn.active { background: var(--primary); color: #fff; }
.pill-btn, .stat-pill {
  border: 1.5px solid #ffe8cc; background: #fff; border-radius: 999px;
  padding: 6px 12px; font-weight: 700; font-size: 0.85rem; cursor: pointer;
}
.stat-pill { cursor: default; background: #fff9db; }
.offline-pill { background: #e7f5ff; border-color: #74c0fc; color: #1864ab; }

/* Curriculum bar */
.curriculum-bar {
  max-width: 1180px; margin: 0 auto; padding: 8px 16px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  border-top: 1px dashed #ffe8cc;
}
.subject-switch, .grade-switch { display: flex; flex-wrap: wrap; gap: 4px; }
.subj-btn, .grade-btn {
  border: 2px solid #ffe8cc; background: #fff; border-radius: 12px;
  padding: 5px 11px; font-weight: 800; font-size: 0.85rem; cursor: pointer; transition: 0.15s;
}
.subj-btn.active { background: #339af0; color: #fff; border-color: #1c7ed6; }
.grade-btn.active { background: #f59f00; color: #fff; border-color: #e67700; }
.unit-picker-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 1; min-width: 240px; }
.unit-select {
  flex: 1; min-width: 190px; padding: 7px 10px; border-radius: 12px;
  border: 2px solid #ffd8a8; font-weight: 700; font-family: inherit; background: #fff;
}

/* Main Nav */
.main-nav {
  max-width: 1180px; margin: 0 auto; padding: 6px 16px 10px;
  display: flex; gap: 6px; overflow-x: auto;
}
.nav-tab {
  white-space: nowrap; border: 2px solid transparent; background: #fff4e6;
  color: #d9480f; border-radius: 14px; padding: 8px 14px; font-weight: 800;
  font-size: 0.9rem; cursor: pointer; transition: 0.15s;
}
.nav-tab.active { background: #ff922b; color: #fff; box-shadow: 0 4px 12px rgba(255,146,43,0.3); }

/* Layout & Cards */
.container { max-width: 1180px; margin: 16px auto 40px; padding: 0 16px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.card {
  background: var(--card); border-radius: var(--radius); border: 2px solid var(--border);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px;
}
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.muted { color: var(--muted); font-size: 0.9rem; margin: 4px 0 0; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 16px; }

/* Buttons & Inputs */
.btn {
  border: 0; border-radius: 14px; padding: 9px 16px; font-weight: 800;
  font-family: inherit; cursor: pointer; transition: transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-primary { background: linear-gradient(135deg, #ffa94d, #f59f00); color: #fff; box-shadow: 0 4px 0 #d97706; }
.btn-accent { background: linear-gradient(135deg, #4dabf7, #228be6); color: #fff; box-shadow: 0 4px 0 #1971c2; }
.btn-ghost { background: #f8f9fa; color: var(--ink); border: 2px solid #dee2e6; }
.input, .textarea {
  width: 100%; padding: 9px 12px; border-radius: 12px; border: 2px solid #dee2e6;
  font-family: inherit; font-size: 0.95rem;
}
.form-stack { display: flex; flex-direction: column; gap: 10px; }
.form-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* Race 3D & Question */
.race-top-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.race-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.adaptive-badge { background: #e6fcf5; color: #0ca678; border: 1.5px solid #63e6be; padding: 4px 10px; border-radius: 999px; font-weight: 800; font-size: 0.82rem; }
.racetrack-wrap { position: relative; border-radius: 18px; overflow: hidden; border: 3px solid #ffd8a8; background: #9be2ff; margin-bottom: 14px; }
.race-3d-canvas { width: 100%; height: 300px; display: block; }
.drag-hint-pill {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(255, 253, 245, 0.92); border: 2px solid #5c4033;
  color: #5c4033; padding: 4px 14px; border-radius: 999px;
  font-size: 0.82rem; font-weight: 800; white-space: nowrap; pointer-events: none;
}
.race-2d-fallback { padding: 20px; background: #e7f5ff; }
.lane { margin-bottom: 10px; font-weight: 800; }
.lane-bar { background: #fff; border-radius: 999px; height: 28px; overflow: hidden; border: 2px solid #adb5bd; }
.lane-fill { height: 100%; display: flex; align-items: center; justify-content: flex-end; padding-right: 8px; transition: width 0.3s; }
.lane-fill.player { background: #ffa94d; }
.lane-fill.rival { background: #748ffc; }
.hud-overlay {
  position: absolute; top: 10px; left: 10px; display: flex; gap: 8px;
  background: rgba(255,255,255,0.88); padding: 5px 12px; border-radius: 999px; font-weight: 800; font-size: 0.85rem;
}

.question-panel { background: #fff9db; border: 2px solid #ffe066; border-radius: 16px; padding: 16px; }
.q-prompt-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.q-prompt { font-size: 1.25rem; font-weight: 900; margin: 0; }
.math-svg { max-width: 210px; max-height: 120px; display: block; margin: 6px auto 10px; background: #fff; border-radius: 12px; padding: 4px; border: 1.5px solid #ffe8cc; }
.choices-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-top: 10px; }
.choice-btn {
  background: #fff; border: 2.5px solid #ffd8a8; border-radius: 14px; padding: 12px;
  font-size: 1.05rem; font-weight: 800; font-family: inherit; cursor: pointer; text-align: center; transition: 0.12s;
}
.choice-btn:hover { border-color: #f59f00; background: #fff4e6; }
.choice-btn.correct { background: #d3f9d8; border-color: #2b8a3e; color: #2b8a3e; }
.choice-btn.wrong { background: #ffe3e3; border-color: #e03131; color: #c92a2a; }
.explain-box { margin-top: 12px; background: #fff; border-left: 5px solid #339af0; padding: 10px 14px; border-radius: 10px; font-weight: 700; }

/* Shop */
.shop-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.pill-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.shop-pill {
  border: 2px solid #ffe8cc; background: #fff; border-radius: 12px; padding: 7px 11px;
  font-weight: 800; font-size: 0.85rem; cursor: pointer;
}
.shop-pill.active { background: #f59f00; color: #fff; border-color: #d97706; }

/* Cards */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.study-card {
  background: #fff9db; border: 2px solid #ffe066; border-radius: 16px; padding: 14px;
  text-align: center; cursor: pointer; transition: transform 0.15s;
}
.study-card:hover { transform: translateY(-3px); }
.study-emoji { font-size: 2.2rem; }
.study-en { font-size: 1.2rem; font-weight: 900; margin: 4px 0; }
.study-zh { font-weight: 700; color: #d9480f; }
.study-ex { font-size: 0.82rem; color: var(--muted); margin-top: 6px; }
.tips-box { margin-top: 14px; display: grid; gap: 8px; }
.tip-item { background: #e7f5ff; border-radius: 12px; padding: 10px 14px; font-weight: 700; }

/* Split-screen PK */
.pk-arena { border: 3px solid #ffd8a8; border-radius: 20px; overflow: hidden; background: #fff; }
.pk-half { padding: 14px; transition: transform 0.25s; }
.pk-p2 { background: #edf2ff; }
.pk-p2.flipped { transform: rotate(180deg); }
.pk-p1 { background: #fff4e6; }
.pk-divider { background: #2b2d42; color: #ffd43b; text-align: center; padding: 6px; font-weight: 900; }
.pk-player-head { display: flex; align-items: center; gap: 10px; font-weight: 900; margin-bottom: 8px; }
.pk-track { flex: 1; background: #fff; border-radius: 999px; height: 22px; overflow: hidden; border: 2px solid #adb5bd; }
.pk-car-fill { height: 100%; color: #fff; font-size: 0.78rem; display: flex; align-items: center; justify-content: center; transition: width 0.25s; }
.pk-car-fill.p1 { background: #f76707; }
.pk-car-fill.p2 { background: #3b5bdb; }
.pk-prompt { font-size: 1.1rem; font-weight: 900; margin-bottom: 8px; text-align: center; }
.pk-choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.pk-choice-btn { padding: 10px; border-radius: 12px; border: 2px solid #adb5bd; background: #fff; font-weight: 800; cursor: pointer; }

/* Exam, Mistakes, Cert, AI, Board */
.exam-btn-group { display: flex; flex-wrap: wrap; gap: 8px; }
.mistake-list, .custom-packs-list { display: grid; gap: 8px; max-height: 360px; overflow-y: auto; }
.mistake-item, .pack-item {
  background: #fff4e6; border: 1.5px solid #ffd8a8; border-radius: 12px; padding: 10px 12px;
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px;
}
.cert-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.cert-canvas { width: 100%; border-radius: 12px; border: 2px solid #ffd43b; background: #fffdf5; }
.ai-status { padding: 10px; border-radius: 10px; background: #e7f5ff; font-weight: 700; white-space: pre-wrap; font-size: 0.88rem; }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi-card { background: #fff9db; border: 2px solid #ffe066; border-radius: 14px; padding: 12px; text-align: center; }
.kpi-card strong { display: block; font-size: 1.4rem; color: #d9480f; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { border-bottom: 1px solid #ffe8cc; padding: 8px; text-align: left; }
.data-table th { background: #fff4e6; }

/* Modal & Toast & Footer */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal-card { background: #fff; border-radius: 20px; padding: 22px; max-width: 420px; text-align: center; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #2b2d42; color: #fff; padding: 10px 20px; border-radius: 999px;
  font-weight: 800; z-index: 120; box-shadow: 0 8px 20px rgba(0,0,0,0.25);
}
.site-footer {
  text-align: center; padding: 16px; color: var(--muted); font-size: 0.85rem;
  border-top: 2px solid var(--border); background: #fff;
}
