:root {
  --bg: #f4f7fb;
  --card: #fff;
  --text: #172033;
  --muted: #687386;
  --line: #dfe5ee;
  --primary: #2457e6;
  --primary2: #163ca7;
  --good: #168a52;
  --warn: #b96f00;
  --bad: #be3434;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

button, input, select { font: inherit; }
.app { max-width: 1040px; margin: auto; padding: 18px; }
h1 { font-size: clamp(23px, 4vw, 35px); margin: 0 0 6px; }
.sub { color: var(--muted); font-size: 14px; line-height: 1.6; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.auth-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 14px 0;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.auth-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-photo { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.auth-actions { display: flex; gap: 8px; margin-left: auto; }
.auth-message { width: 100%; color: var(--bad); font-size: 14px; }

button, .btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  background: #e8edf6;
  color: var(--text);
  cursor: pointer;
}

button:disabled { cursor: not-allowed; opacity: .6; }
button.primary { background: var(--primary); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--primary2); }
button.good { background: #def5e8; color: #0d6a3d; }
button.warn { background: #fff0d2; color: #875000; }
button.bad { background: #fde3e3; color: #992828; }

select, input {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 9px 10px;
}

.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 14px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.stat b { display: block; font-size: 23px; margin-top: 5px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(31, 45, 80, .06);
}

.study-card { min-height: 430px; display: flex; flex-direction: column; justify-content: center; text-align: center; }
.badges { display: flex; gap: 8px; justify-content: center; margin-bottom: 15px; flex-wrap: wrap; }
.badge { font-size: 12px; background: #edf2ff; color: #284b9b; padding: 5px 9px; border-radius: 999px; }
.vocabulary-image-frame {
  width: min(100%, 280px);
  aspect-ratio: 1;
  margin: 0 auto 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #f7f9fc;
  opacity: 0;
  transform: translateY(5px);
  transition: opacity .18s ease, transform .18s ease;
}
.vocabulary-image-frame.is-loaded { opacity: 1; transform: translateY(0); }
.vocabulary-image-frame img { display: block; width: 100%; height: 100%; object-fit: cover; }
.study-card.has-vocabulary-image .word { font-size: clamp(42px, 8vw, 68px); margin-top: 6px; }
.word { font-size: clamp(48px, 10vw, 84px); font-weight: 760; letter-spacing: .03em; margin: 10px 0; }
.pinyin { font-size: 26px; color: #33415c; margin: 10px 0; }
.answerbox { margin: 14px auto 4px; max-width: 620px; width: 100%; background: #f7f9fc; border-radius: 14px; padding: 15px; }
.answerrow { display: grid; grid-template-columns: 90px 1fr; text-align: left; gap: 10px; padding: 7px 0; border-bottom: 1px solid #e8edf4; }
.answerrow:last-child { border-bottom: 0; }
.answerrow .k { color: var(--muted); }
.hidden { visibility: hidden; }
.is-hidden { display: none !important; }
.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.rating button { min-width: 120px; }
.rating small { display: block; font-size: 11px; opacity: .75; margin-top: 2px; }
.progress { height: 8px; background: #e7ebf2; border-radius: 99px; overflow: hidden; margin: 12px 0; }
.progress > div { height: 100%; background: var(--primary); width: 0; }
.tabs { display: flex; gap: 7px; margin: 18px 0 10px; flex-wrap: wrap; }
.tab.active { background: var(--primary); color: #fff; }
.panel { display: none; }
.panel.active { display: block; }
.settings-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 12px 0; }
.setting { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.sync-setting { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sync-setting .sub { margin-left: auto; }
label, .setting-label { font-size: 14px; color: var(--muted); display: block; margin-bottom: 7px; }
.import-label { display: inline-block; color: inherit; margin: 0; }
.list-info { margin-bottom: 8px; }
.table-scroll { overflow: auto; max-height: 650px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; white-space: nowrap; }
th { position: sticky; top: 0; background: #f7f9fc; }
.notice { border-left: 4px solid var(--primary); background: #eef3ff; padding: 12px 14px; border-radius: 8px; margin: 12px 0; color: #29426f; }
.error-notice { border-left-color: var(--bad); background: #fdeaea; color: #7d2424; }

@media (max-width: 560px) {
  .vocabulary-image-frame { width: min(100%, 220px); border-radius: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .vocabulary-image-frame { transition: none; transform: none; }
}
.admin-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 12px 0; }
.admin-form input, .admin-form select { width: 100%; }
.admin-form-actions { display: flex; align-items: end; gap: 8px; flex-wrap: wrap; }
.roster-list-header { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; }
.admin-table-scroll { max-height: 360px; margin-top: 8px; }
.inline-label { margin: 0; }
.teacher-summary { grid-template-columns: repeat(3, 1fr); margin: 14px 0; }
.teacher-table-scroll { max-height: 650px; }
.teacher-analytics { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.analytics-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.trend-chart { height: 220px; display: flex; align-items: end; gap: 4px; padding-top: 24px; overflow-x: auto; }
.trend-column { height: 100%; min-width: 26px; flex: 1; display: flex; flex-direction: column; justify-content: end; align-items: center; color: var(--muted); }
.trend-column > span { font-size: 11px; }
.trend-column small { font-size: 10px; margin-top: 4px; }
.trend-bar { width: 70%; max-width: 30px; background: var(--primary); border-radius: 5px 5px 0 0; }
.mistake-table-scroll { max-height: 240px; margin-top: 10px; }
.level-cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 12px 0; }
.level-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.level-card b { display: block; font-size: 19px; }
footer { color: var(--muted); font-size: 12px; margin: 24px 2px; line-height: 1.6; }

@media (max-width: 760px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .grid .stat:last-child { grid-column: 1 / -1; }
  .level-cards { grid-template-columns: 1fr 1fr; }
  .level-cards .level-card:last-child { grid-column: 1 / -1; }
  .settings-row { grid-template-columns: 1fr; }
  .admin-form { grid-template-columns: 1fr; }
  .teacher-summary { grid-template-columns: 1fr 1fr; }
  .teacher-analytics { grid-template-columns: 1fr; }
  .app { padding: 12px; }
  .card { padding: 16px; }
  .rating button { min-width: 46%; }
  .sync-setting .sub { width: 100%; margin-left: 0; }
  .auth-user { width: 100%; }
  .auth-actions { width: 100%; margin-left: 0; }
  .auth-actions button { flex: 1; }
}
