:root {
  --bg: #F5F4FB;
  --bg-2: #F7F5FF;
  --card: #FFFFFF;
  --ink: #1F2937;
  --muted: #6B7280;
  --line: #EDEDF3;
  --accent: #8B5CF6;
  --accent-2: #A78BFA;
  --accent-soft: #F4EFFF;
  --ok: #22C55E;
  --ok-bg: #F0FDF4;
  --bad: #F43F5E;
  --bad-bg: #FDF2F8;
  --shadow: 0 8px 24px rgba(60, 50, 120, 0.06);
  --radius: 20px;
  --max: 960px;
}

/* 本地字体：Nunito 仅含拉丁字符（约 38KB），中文交给系统字体，避免依赖 Google Fonts */
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 200 1000;
  font-display: swap;
  src: url("fonts/nunito-latin-var.woff2") format("woff2");
}

@font-face {
  font-family: "Nunito";
  font-style: italic;
  font-weight: 200 1000;
  font-display: swap;
  src: url("fonts/nunito-latin-var-italic.woff2") format("woff2");
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Nunito", -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  color: var(--ink);
  /* 参考仪表盘的平铺浅灰紫底，不用光斑；卡片靠白底与阴影分层 */
  background: var(--bg);
  overflow-x: hidden;
}

.bg-blob {
  display: none;
}

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px;
  padding-top: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  position: relative;
  /* 三列按 1fr:2fr:1fr 分配：两侧永远等宽（tabs 始终居中），中列最多占一半宽度，
     空间不足时各列按比例收缩，物理上不会互相压盖 */
  display: grid;
  grid-template-columns: 1fr minmax(auto, 2fr) 1fr;
  align-items: center;
  gap: 16px;
  margin: 0 -24px 22px;
  padding: 16px 24px;
}

.brand {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand h1 {
  white-space: nowrap;
}

.brand-logo {
  height: 48px;
  width: auto;
  display: block;
}

.logo {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.25);
}

.logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  width: 100%;
  justify-self: center;
}

.tab,
.ghost-btn,
.primary-btn,
.chip,
.option,
.select-trigger {
  font: inherit;
  cursor: pointer;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 700;
  white-space: nowrap;
}

.tab.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.toolbar,
.review-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px auto;
  width: 100%;
  max-width: 1280px;
}

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* 自定义题库下拉：原生 select 的弹出列表各系统渲染不一（直角+蓝色高亮），改为统一风格组件 */
.select {
  position: relative;
  min-width: 150px;
}

/* 大类选择（小学/初中/高中/拓展文字短，用更窄宽度） */
.select-sm {
  min-width: 96px;
}

.select-trigger {
  width: 100%;
  display: block;
  text-align: left;
  border: 1px solid var(--line);
  /* 自定义箭头：距右边框 12px，与左侧文字内边距对称 */
  background: #fff url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--ink);
  border-radius: 12px;
  padding: 8px 34px 8px 12px;
}

.select.is-open .select-trigger {
  border-color: #C4B5FD;
}

.select-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  z-index: 30;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 264px;
  overflow-y: auto;
}

.select.is-open .select-menu {
  display: block;
}

.select-menu li {
  padding: 8px 12px;
  border-radius: 9px;
  color: var(--ink);
  white-space: nowrap;
  cursor: pointer;
}

.select-menu li:hover {
  color: var(--accent);
}

.select-menu li.is-selected {
  color: var(--accent);
  font-weight: 700;
}

/* "即将上线"题库：不可选，灰显 */
.select-menu li.is-disabled {
  color: #b3b3b3;
  cursor: not-allowed;
  font-style: italic;
}

.select-menu li.is-disabled:hover {
  color: #b3b3b3;
}

/* 错题复习：今日待复习入口（沿用 primary-btn 配色，去掉工具栏内多余上边距） */
.due-btn {
  margin-top: 0;
  padding: 7px 16px;
}

/* 错题卡片上的复习状态行 */
.due-line {
  margin: 8px 0 0;
}

.due-line.is-due {
  color: var(--accent);
  font-weight: 700;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ghost-btn,
.primary-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 16px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  padding: 8px 16px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.ghost-btn:hover,
.tab:hover,
.chip:hover {
  border-color: #C4B5FD;
  color: var(--accent);
}

/* 重置进度：柔和警示风 */
.reset-btn {
  justify-self: end;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #FDF2F8;
  border-color: #FBCFE8;
  color: #E11D48;
}

.reset-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.reset-btn:hover {
  border-color: #F9A8D4;
  color: #BE123C;
  background: #FCE7F3;
}

.primary-btn {
  margin-top: 16px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.stage {
  flex: 1;
  min-height: 380px;
  background: var(--card);
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 48px 32px 36px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
}

.hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.prompt {
  margin: 12px 0 0;
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 800;
  line-height: 1.35;
}

.phonetic {
  margin: 10px 0 0;
  color: var(--accent-2);
  letter-spacing: 0.04em;
  font-size: 1.2rem;
}

.letters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 40px;
  min-height: 64px;
}

.letter {
  min-width: 36px;
  height: 54px;
  padding: 0 6px;
  border-bottom: 3px solid #D6D6E0;
  color: #A8A8B8;
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 50px;
  transition: color 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}

.letter.space {
  min-width: 24px;
  border-bottom-color: transparent;
}

.letter.ok {
  color: var(--ok);
  border-bottom-color: var(--ok);
}

.letter.bad {
  color: var(--bad);
  border-bottom-color: var(--bad);
  transform: translateY(-2px);
}

.letter.current {
  border-bottom-color: var(--accent);
  color: var(--accent);
}

.feedback {
  min-height: 24px;
  margin: 18px 0 0;
  color: var(--bad);
  font-weight: 700;
}

/* 语法讲解卡：按单元展示句型 / 例句 / 易错点，可点标题栏收起 */
.lesson {
  margin: 0 0 20px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--accent-soft);
  text-align: left;
}

.lesson-bar {
  cursor: pointer;
  list-style: none;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent);
}

.lesson-bar::-webkit-details-marker {
  display: none;
}

.lesson-bar::after {
  content: " 收起";
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--muted);
}

.lesson:not([open]) .lesson-bar::after {
  content: " 展开";
}

.lesson-body {
  margin-top: 10px;
}

.lesson-summary {
  margin: 0 0 12px;
  color: var(--ink);
  line-height: 1.7;
}

.lesson-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.lesson-list {
  display: grid;
  gap: 6px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

.lesson-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
}

.lesson-tag {
  flex: none;
  padding: 1px 8px;
  border: 1px solid var(--accent-2);
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  font-size: 0.75rem;
}

.lesson-en {
  font-weight: 700;
}

.lesson-zh {
  color: var(--muted);
  font-size: 0.92rem;
}

.lesson-mistake {
  margin: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--bad-bg);
  color: var(--ink);
  line-height: 1.7;
}

.lesson-mistake .lesson-label {
  display: inline;
  margin-right: 6px;
  color: var(--bad);
}

.grammar-meta {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.grammar-q {
  margin: 0 0 18px;
  font-size: 1.25rem;
  font-weight: 700;
  text-align: left;
}

.grammar-q-zh {
  margin: -8px 0 18px;
  color: var(--muted);
  font-size: 1.02rem;
  text-align: left;
}

.options {
  display: grid;
  gap: 10px;
}

.option {
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--ink);
}

.option:hover {
  border-color: var(--accent-2);
}

.option.correct {
  background: var(--ok-bg);
  border-color: var(--ok);
}

.option.wrong {
  background: var(--bad-bg);
  border-color: var(--bad);
}

.explain {
  margin-top: 16px;
  text-align: left;
  background: var(--accent-soft);
  border-radius: 14px;
  padding: 14px 16px;
  line-height: 1.65;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
}

.chip.is-active {
  background: var(--accent-soft);
  border-color: #C4B5FD;
  color: var(--accent);
  font-weight: 700;
}

.review-list {
  display: grid;
  gap: 12px;
  text-align: left;
}

.review-card {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 16px;
  padding: 14px 16px;
}

.review-card .kind {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 8px;
  margin-bottom: 8px;
}

.review-card p {
  margin: 4px 0;
}

.review-card .muted {
  color: var(--muted);
  font-size: 0.92rem;
}

.practice-btn {
  margin-top: 10px;
  border: 0;
  background: var(--accent-soft);
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  border-radius: 10px;
  padding: 7px 12px;
  cursor: pointer;
}

.empty {
  color: var(--muted);
  margin: 48px 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 18px auto;
  width: 100%;
  max-width: 1280px;
}

.stat {
  background: var(--card);
  border: 0;
  border-radius: 18px;
  padding: 14px 16px;
  text-align: left;
  box-shadow: var(--shadow);
}

/* 参考仪表盘：一卡一色的浅底 tint */
.stat--violet { background: #F4EFFF; }
.stat--green  { background: #F0FDF4; }
.stat--pink   { background: #FDF2F8; }
.stat--orange { background: #FFF7ED; }

.stat--violet strong { color: #7C3AED; }
.stat--green  strong { color: #16A34A; }
.stat--pink   strong { color: #E11D48; }
.stat--orange strong { color: #EA580C; }

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.stat strong {
  font-size: 1.4rem;
  font-weight: 800;
}

.shortcuts {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  margin: 18px 8px 32px;
}

.hidden {
  display: none !important;
}

.hidden-input {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 24px));
  height: 44px;
  border: 1px dashed #C4B5FD;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  padding: 0 12px;
  font: inherit;
  z-index: 5;
}

body:not(.is-typing) .hidden-input {
  display: none;
}

body.is-desktop .hidden-input {
  position: fixed;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
  top: 0;
  left: 0;
}

/* 中等宽度：收紧 tabs 内边距与字号，避免 tab 文字换行挤压 header */
@media (max-width: 1080px) {
  .header {
    gap: 10px;
  }

  .tab {
    padding: 8px 10px;
    font-size: 0.92rem;
  }

  .tagline {
    display: none;
  }
}

@media (max-width: 720px) {
  /* 移动端恢复流式换行：logo+重置一行，tabs 独占一行 */
  .header {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }

  .header .tabs {
    order: 3;
    flex-basis: 100%;
    grid-template-columns: repeat(4, 1fr);
  }

  .header .tabs .tab {
    padding: 8px 4px;
    font-size: 0.85rem;
  }

  .app {
    margin-top: 16px;
    width: min(var(--max), calc(100% - 20px));
  }

  .stage {
    min-height: 360px;
    padding: 32px 20px 24px;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  body {
    padding-bottom: 64px;
  }
}
