:root {
  --bg: #fef6e4;
  --card: #ffffff;
  --primary: #ff8c42;
  --primary-dark: #e8731f;
  --green: #3ecf8e;
  --green-dark: #2bb673;
  --blue: #4aa3ff;
  --red: #ff6b6b;
  --gold: #ffc93c;
  --text: #3a3550;
  --muted: #8a86a0;
  --radius: 22px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; border: none; }
input, select { font-family: inherit; }

/* ---------- 登入 (KUROMI) ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(160deg, #ffd9ec 0%, #d3bfff 55%, #b388ff 100%);
  padding: 20px;
}
.login-box {
  background: #fff;
  border-radius: 28px;
  padding: 40px 28px 34px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(90, 60, 160, 0.25);
  text-align: center;
  border: 3px solid #2b2b2b;
}
.login-logo {
  width: 110px; height: 110px;
  margin: 0 auto 8px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 6px 0 #ff5fa2;
}
.login-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.login-title {
  font-size: 30px; margin: 16px 0 2px;
  color: #2b2b2b; font-weight: 800; letter-spacing: 1px;
}
.login-title .pink { color: #ff5fa2; }
.login-sub { color: #9b6bff; margin: 0 0 24px; font-size: 15px; font-weight: 600; }
.login-form { text-align: left; }
.login-form label {
  display: block; font-size: 14px; margin: 14px 0 6px;
  color: #2b2b2b; font-weight: 700;
}
.login-form input,
.login-form select {
  width: 100%;
  padding: 14px 16px;
  border: 2.5px solid #e6d9ff;
  border-radius: 14px;
  font-size: 17px;
  outline: none;
  background: #fbf7ff;
  box-sizing: border-box;
}
.login-form input:focus,
.login-form select:focus { border-color: #ff5fa2; background: #fff; }
.login-form .btn {
  margin-top: 24px;
  background: #2b2b2b;
  color: #fff;
  border-radius: 16px;
  font-size: 18px;
  padding: 16px;
  box-shadow: 0 6px 0 #ff5fa2;
}
.login-form .btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #ff5fa2;
}
.login-error {
  background: #ffe3ee; color: #d63384; padding: 10px 14px;
  border-radius: 12px; margin-top: 14px; font-size: 14px;
}
.login-remember {
  display: flex; align-items: center; gap: 8px;
  margin-top: 14px; font-size: 14px; color: #2b2b2b; font-weight: 600; cursor: pointer;
}
.login-form input[type="checkbox"] {
  width: auto; padding: 0; border: none; background: none; margin: 0;
}

/* ---------- 頂欄 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #fff;
  border-bottom: 2px solid #f0e9d8;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.user-emoji { font-size: 32px; }
.user-name { font-size: 18px; font-weight: 700; }
.topbar-stats { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.stat-badge {
  background: #f6f1e4; padding: 5px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  background: #f6f1e4; width: 40px; height: 40px; border-radius: 12px;
  font-size: 20px; display: flex; align-items: center; justify-content: center;
  text-decoration: none;
}

/* ---------- 學習區 ---------- */
.learn-main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 40px;
}
.progress-wrap { margin-bottom: 14px; }
.progress-text { font-size: 14px; color: var(--muted); margin-bottom: 6px; text-align: center; }
.progress-bar { height: 12px; background: #eee4cf; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, #3ecf8e, #ffc93c); width: 0; border-radius: 999px; transition: width .3s; }

.word-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.06);
  min-height: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.word-badge {
  align-self: flex-start;
  background: #e8f4ff; color: #2a7de0;
  font-size: 12px; font-weight: 700; padding: 4px 12px; border-radius: 999px;
}
.word-en {
  font-size: 46px; font-weight: 800; color: var(--text);
  background: none; padding: 8px 16px; border-radius: 16px;
  margin-top: 6px; line-height: 1.2; word-break: break-word;
  transition: background .15s;
}
.word-en:active { background: #fff1e0; }
.word-ipa { color: var(--muted); font-size: 16px; margin-top: 4px; }
.word-zh {
  font-size: 30px; font-weight: 700; color: var(--primary-dark);
  background: none; padding: 8px 16px; border-radius: 16px;
  margin-top: 6px;
}
.word-zh:active { background: #fff1e0; }
.word-pos { color: var(--muted); font-size: 14px; margin-top: 4px; }
.word-examples {
  width: 100%;
  margin-top: 20px;
  display: flex; flex-direction: column; gap: 10px;
}
.example {
  background: #faf7ee;
  border-radius: 14px;
  padding: 12px 14px;
  text-align: left;
}
.example-en { font-size: 16px; }
.example-zh { font-size: 14px; color: var(--muted); margin-top: 4px; }

.actions {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.actions .btn { padding: 16px 8px; font-size: 15px; line-height: 1.25; }

.btn-again { background: #ffe3e3; color: #c0392b; border-radius: var(--radius); }
.btn-known { background: var(--green); color: #fff; border-radius: var(--radius); }
.btn-easy { background: var(--gold); color: #7a5a00; border-radius: var(--radius); }

.empty-state { text-align: center; padding: 50px 20px; }
.empty-emoji { font-size: 80px; }
.empty-state h2 { font-size: 26px; margin: 12px 0 4px; }
.empty-state p { color: var(--muted); margin: 0 0 20px; }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border-radius: 16px;
  padding: 14px 22px;
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
  text-align: center;
  transition: transform .05s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); }
.btn-ghost { background: #f1ece0; color: var(--text); }
.btn-block { width: 100%; }

/* ---------- 彈窗 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-box {
  background: #fff; border-radius: 24px; padding: 26px 22px;
  width: 100%; max-width: 420px; max-height: 90vh; overflow: auto;
}
.modal-box h2 { margin: 0 0 16px; font-size: 22px; }
.modal-box label { display: block; font-size: 14px; color: var(--muted); margin: 14px 0 6px; }
.modal-box input, .modal-box select {
  width: 100%; padding: 13px 14px; border: 2px solid #eee;
  border-radius: 13px; font-size: 16px; outline: none; background: #fff;
}
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }
.reward-box { text-align: center; }
.reward-emoji { font-size: 72px; }
#reward-title { margin: 8px 0 6px; }
#reward-msg { color: var(--muted); margin: 0 0 20px; }

/* ---------- 單詞本 ---------- */
.vocab-box { max-width: 520px; }
.vocab-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.vocab-head h2 { margin: 0; font-size: 22px; }
.vocab-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.vocab-tab {
  flex: 1; padding: 10px 6px; border-radius: 14px;
  background: #f1ece0; color: var(--text); font-weight: 700; font-size: 14px;
  text-align: center;
}
.vocab-count {
  display: inline-block; margin-left: 4px; padding: 1px 7px;
  background: rgba(0,0,0,0.12); border-radius: 999px; font-size: 12px;
}
.vocab-tab.active[data-cat="again"] { background: #ff6b6b; color: #fff; }
.vocab-tab.active[data-cat="known"] { background: #ffb83c; color: #6b4a00; }
.vocab-tab.active[data-cat="easy"]  { background: #3ecf8e; color: #fff; }
.vocab-list { display: flex; flex-direction: column; gap: 10px; }
.vocab-empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 15px; }
.vocab-item {
  border: 2px solid #f0e9d8; border-radius: 16px; padding: 12px 14px; background: #fff;
}
.vocab-item.vocab-again { border-left: 6px solid #ff6b6b; }
.vocab-item.vocab-known { border-left: 6px solid #ffb83c; }
.vocab-item.vocab-easy  { border-left: 6px solid #3ecf8e; }
.vocab-row { display: flex; align-items: center; gap: 10px; }
.vocab-word {
  font-size: 20px; font-weight: 800; color: var(--text);
  background: none; padding: 4px 2px; border-bottom: 2px dashed #d9cff2; text-align: left;
}
.vocab-zh { background: none; color: var(--muted); font-size: 16px; padding: 4px 2px; }
.vocab-exs { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.vocab-ex { display: flex; align-items: flex-start; gap: 6px; }
.vocab-speaker {
  background: #f4eefc; color: #7a5fd0; border-radius: 8px;
  width: 30px; height: 30px; font-size: 15px; flex: 0 0 30px;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.vocab-ex-text { font-size: 14px; line-height: 22px; color: #555; }
.vocab-ex-text b { color: var(--text); }

/* ---------- 管理員 ---------- */
.admin-body { background: #f4f1ea; }
.admin-main { max-width: 900px; margin: 0 auto; padding: 18px; }
.panel {
  background: #fff; border-radius: 18px; padding: 20px;
  margin-bottom: 18px; box-shadow: 0 6px 20px rgba(0,0,0,0.04);
}
.panel h2 { margin: 0 0 14px; font-size: 19px; }
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin-bottom: 14px;
}
.form-grid input, .form-grid select {
  padding: 12px 13px; border: 2px solid #eee; border-radius: 12px; font-size: 15px; outline: none;
}
.msg { margin-top: 12px; font-size: 14px; }
.msg.ok { color: #1f9d5c; }
.msg.err { color: #c0392b; }

.user-list { display: flex; flex-direction: column; gap: 10px; }
.user-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #faf8f1; border-radius: 14px; padding: 12px 14px;
}
.user-row .u-emoji { font-size: 30px; }
.user-row .u-main { min-width: 120px; }
.user-row .u-name { font-weight: 700; font-size: 16px; }
.user-row .u-sub { font-size: 12px; color: var(--muted); }
.user-row .u-stat { font-size: 13px; color: var(--muted); white-space: nowrap; }
.user-row .u-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.user-row .u-actions select {
  padding: 7px 8px; border: 2px solid #eee; border-radius: 10px; font-size: 13px;
}
.mini-btn {
  background: #fff; border: 2px solid #eee; border-radius: 10px;
  padding: 7px 11px; font-size: 13px; font-weight: 600; color: var(--text);
}
.mini-btn.danger { color: #c0392b; border-color: #ffd6d6; }
.mini-btn.off { opacity: .45; }

/* ---------- 等級徽章 ---------- */
.lv-badge {
  background: linear-gradient(135deg, #ff8c42, #ff5fa2);
  color: #fff; font-size: 12px; font-weight: 800;
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}

/* ---------- 單詞本熟練度 ---------- */
.vocab-trophy { font-size: 18px; flex: 0 0 auto; }
.vocab-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.vocab-ipa { font-size: 14px; color: #7a5fd0; font-weight: 600; white-space: nowrap; }
.mastery-bar {
  flex: 1; height: 8px; background: #eee4cf; border-radius: 999px; overflow: hidden;
}
.mastery-fill {
  height: 100%; background: linear-gradient(90deg, #ffb83c, #3ecf8e);
  border-radius: 999px; transition: width .3s;
}
.mastery-score { font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap; }

/* ---------- 統計 ---------- */
.stats-box { max-width: 520px; }
.stats-level { margin-bottom: 14px; }
.stats-level-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.stats-lv { font-size: 20px; font-weight: 800; color: var(--primary-dark); }
.stats-exp { font-size: 13px; color: var(--muted); }
.stats-expbar { height: 10px; background: #eee4cf; border-radius: 999px; overflow: hidden; }
.stats-exp-fill { height: 100%; background: linear-gradient(90deg, #ff8c42, #ffc93c); border-radius: 999px; transition: width .3s; }
.stats-cards { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.stat-card { background: #faf7ee; border-radius: 14px; padding: 12px 8px; text-align: center; }
.stat-num { font-size: 24px; font-weight: 800; color: var(--text); }
.stat-lab { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stats-sub { font-size: 15px; margin: 0 0 10px; color: var(--text); }
.stats-chart {
  display: flex; align-items: flex-end; gap: 6px;
  background: #faf7ee; border-radius: 14px; padding: 12px 10px; margin-bottom: 16px;
}
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.chart-val { font-size: 12px; font-weight: 700; color: var(--text); height: 16px; }
.chart-bars { display: flex; align-items: flex-end; gap: 2px; height: 110px; width: 100%; justify-content: center; }
.chart-bar { width: 14px; border-radius: 4px 4px 0 0; transition: height .3s; }
.chart-new { background: #3ecf8e; }
.chart-rev { background: #ffc93c; }
.chart-lab { font-size: 11px; color: var(--muted); }
.stats-dist { display: flex; flex-direction: column; gap: 8px; }
.dist-row {
  display: flex; align-items: center; justify-content: space-between;
  background: #faf7ee; border-radius: 12px; padding: 10px 14px;
}
.dist-row.dist-again { border-left: 5px solid #ff6b6b; }
.dist-row.dist-known { border-left: 5px solid #ffb83c; }
.dist-row.dist-easy { border-left: 5px solid #3ecf8e; }
.dist-row.dist-mastered { border-left: 5px solid #ff5fa2; }
.dist-lab { font-size: 15px; font-weight: 600; }
.dist-num { font-size: 18px; font-weight: 800; color: var(--text); }

/* ---------- 考試 ---------- */
.exam-box { max-width: 480px; }
.exam-desc { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.exam-mode-btn {
  width: 100%; background: #faf7ee; border: 2px solid #f0e9d8;
  border-radius: 16px; padding: 18px 14px; margin-bottom: 10px;
  font-size: 18px; font-weight: 800; color: var(--text); text-align: left;
}
.exam-mode-btn span { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-top: 4px; }
.exam-mode-btn:active { background: #fff1e0; }
.exam-progress { font-size: 14px; color: var(--muted); margin-bottom: 14px; text-align: center; }
.exam-question { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 16px; }
.exam-speak-btn {
  background: #e8f4ff; color: #2a7de0; font-size: 20px; font-weight: 700;
  padding: 16px 24px; border-radius: 16px;
}
.exam-choices { display: flex; flex-direction: column; gap: 10px; }
.exam-choice {
  background: #faf7ee; border: 2px solid #f0e9d8; border-radius: 14px;
  padding: 14px 16px; font-size: 16px; font-weight: 600; color: var(--text); text-align: left;
}
.exam-choice:active { background: #fff1e0; }
.exam-choice.chosen-correct { background: #d9f7e6; border-color: #3ecf8e; }
.exam-choice.chosen-wrong { background: #ffe3e3; border-color: #ff6b6b; }
.exam-spell-zh { font-size: 26px; font-weight: 800; color: var(--text); }
.exam-spell-hint { font-size: 14px; color: var(--muted); }
.exam-input-wrap { display: flex; gap: 8px; width: 100%; }
.exam-input {
  flex: 1; padding: 14px 16px; border: 2px solid #eee; border-radius: 14px;
  font-size: 18px; outline: none;
}
.exam-input:focus { border-color: #ff5fa2; }
.exam-input-btn { padding: 0 20px; border-radius: 14px; }
.exam-feedback {
  margin-top: 14px; padding: 12px 14px; border-radius: 12px; font-size: 15px; font-weight: 600;
}
.exam-feedback.correct { background: #d9f7e6; color: #1f9d5c; }
.exam-feedback.wrong { background: #ffe3e3; color: #c0392b; }
#btn-exam-next { margin-top: 14px; }
#btn-exam-again { margin-bottom: 8px; }
.exam-result-emoji { font-size: 64px; text-align: center; }
#exam-done h3 { text-align: center; margin: 8px 0 6px; }
#exam-result-msg { text-align: center; color: var(--muted); margin: 0 0 18px; }

/* ---------- 家長中心 ---------- */
.parent-body { background: #f4f1ea; }
.parent-main { max-width: 760px; margin: 0 auto; padding: 18px; }
.children-tabs { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.child-tab {
  padding: 12px 18px; border-radius: 14px; background: #fff;
  border: 2px solid #eee; font-size: 16px; font-weight: 700; color: var(--text);
}
.child-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.child-empty {
  background: #fff; border-radius: 18px; padding: 40px 20px; text-align: center; color: var(--muted);
}

/* ---------- 綁定（管理員） ---------- */
.bind-grid { grid-template-columns: 1fr 1fr auto; align-items: center; }
.bind-select { padding: 12px 13px; border: 2px solid #eee; border-radius: 12px; font-size: 15px; outline: none; }
.bind-list { display: flex; flex-direction: column; gap: 8px; }
.bind-row {
  display: flex; align-items: center; justify-content: space-between;
  background: #faf8f1; border-radius: 12px; padding: 10px 14px; font-size: 15px; font-weight: 600;
}

/* ---------- 佈置作業（家長） ---------- */
.assign-form { display: flex; flex-direction: column; gap: 12px; }
.assign-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.assign-row label { font-size: 14px; color: var(--muted); min-width: 90px; }
.assign-row input, .assign-row select {
  padding: 11px 12px; border: 2px solid #eee; border-radius: 12px; font-size: 15px; outline: none;
}
.assign-row input[type="number"] { width: 80px; }
.assign-list { display: flex; flex-direction: column; gap: 8px; }
.assign-item {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #faf8f1; border-radius: 12px; padding: 11px 14px;
}
.assign-item.done { opacity: .55; }
.assign-label { font-weight: 700; font-size: 15px; }
.assign-status { font-size: 13px; font-weight: 700; white-space: nowrap; }
.assign-item.done .assign-status { color: #1f9d5c; }
.assign-time { margin-left: auto; font-size: 12px; color: var(--muted); }

/* ---------- 作業（小朋友） ---------- */
.icon-btn { position: relative; }
.hw-badge {
  position: absolute; top: -5px; right: -5px;
  background: var(--red); color: #fff; font-size: 11px; font-weight: 800;
  min-width: 18px; height: 18px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.hw-box { max-width: 480px; }
.hw-list { display: flex; flex-direction: column; gap: 10px; }
.hw-empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 15px; }
.hw-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #faf7ee; border: 2px solid #f0e9d8; border-radius: 14px; padding: 14px 16px;
}
.hw-label { font-size: 16px; font-weight: 700; }
.hw-go { padding: 10px 18px; font-size: 15px; }