@font-face {
  font-family: "Andika";
  src: url("./Andika-Regular.ttf") format("truetype");
  font-display: swap;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf3 100%);
  min-height: 100vh;
  padding: 20px 16px 40px;
  color: #2c3e50;
  font-weight: 700;
}
.container { max-width: 1100px; margin: 0 auto; }
.storybook-link {
  position: absolute; top: 18px; right: 24px;
  padding: 7px 13px; border: 1px solid rgba(102,126,234,0.2);
  border-radius: 999px; background: rgba(255,255,255,0.86);
  color: #667eea; font-size: 13px; font-weight: 700;
  text-decoration: none; box-shadow: 0 4px 12px rgba(61,78,125,0.12);
  transition: all .2s;
}
.storybook-link:hover {
  color: #fff; background: linear-gradient(135deg, #667eea, #764ba2);
  border-color: transparent; transform: translateY(-1px);
}

.header { text-align: center; margin-bottom: 28px; }
.header h1 { font-size: 32px; color: #2c3e50; margin-bottom: 8px; letter-spacing: 2px; }
.header p { font-size: 15px; color: #7f8c9b; }
.header .tip {
  display: inline-block; margin-top: 10px; padding: 6px 16px;
  background: #fff; border-radius: 20px; font-size: 13px;
  color: #5b7a99; box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.header .tip::before { content: "🔊 "; }

.nav {
  display: flex; flex-wrap: wrap; gap: 10px;
  justify-content: center; margin-bottom: 24px;
}
.nav button {
  padding: 8px 18px; border: none; border-radius: 20px;
  background: #fff; color: #5b7a99; font-size: 14px;
  cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  transition: all .2s;
}
.nav button.active {
  background: linear-gradient(135deg, #667eea, #764ba2); color: #fff;
}
.mode-switch {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; margin: 0 auto 28px;
  padding: 5px; border: 1px solid rgba(102,126,234,0.14); border-radius: 18px;
  background: rgba(255,255,255,0.78); box-shadow: 0 8px 24px rgba(61,78,125,0.1);
  position: relative; left: 50%; transform: translateX(-50%);
}
.mode-switch button, .mode-switch a {
  min-width: 132px; padding: 12px 28px; border: 0; border-radius: 13px;
  background: transparent; color: #71809a; font-size: 16px; font-weight: 700;
  text-align: center; text-decoration: none; cursor: pointer;
  transition: color .2s, background .2s, box-shadow .2s, transform .2s;
}
.mode-switch button:hover, .mode-switch a:hover {
  color: #5367c9; background: rgba(102,126,234,0.08);
}
.mode-switch a.active {
  background: linear-gradient(135deg, #667eea, #764ba2); color: #fff;
  box-shadow: 0 6px 14px rgba(102,126,234,0.3);
}
.mode-switch a.active:hover {
  color: #fff; background: linear-gradient(135deg, #667eea, #764ba2);
  transform: translateY(-1px);
}
.display-mode-control { display: flex; justify-content: flex-end; margin: -16px 0 14px; }
.eye-mode-toggle {
  position: relative; top: auto; right: auto; z-index: auto; width: 76px; height: 34px; flex: 0 0 76px; padding: 0 10px 0 32px;
  border: 0; border-radius: 999px; background: #d7e0e5; color: #52656b;
  font: inherit; font-size: 12px; cursor: pointer; text-align: right;
  box-shadow: inset 0 1px 3px rgba(44,44,44,0.14), 0 3px 8px rgba(61,78,125,0.12);
  transition: background .25s, color .25s, padding .25s, box-shadow .25s;
}
.eye-mode-toggle::before {
  content: ""; position: absolute; top: 4px; left: 4px; width: 26px; height: 26px;
  border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(44,44,44,0.2);
  transition: transform .25s;
}
.eye-mode-toggle:hover { box-shadow: inset 0 1px 3px rgba(44,44,44,0.14), 0 5px 12px rgba(61,78,125,0.18); }
.eye-mode-toggle.active { padding: 0 32px 0 10px; background: #8fc8d7; color: #2C2C2C; text-align: left; }
.eye-mode-toggle.active::before { transform: translateX(42px); }
body.eye-mode { background: #E8F4F8; color: #2C2C2C; }
body.eye-mode .header h1 { color: #2C2C2C; }
body.eye-mode .section { background: #E8F4F8; box-shadow: 0 4px 16px rgba(44,44,44,0.08); }
body.eye-mode .pinyin-item { background: rgba(255,255,255,0.62); color: #2C2C2C; }
body.eye-mode .section-desc,
body.eye-mode .example { color: #52656b; }
.section {
  background: #fff; border-radius: 18px; padding: 24px 20px;
  margin-bottom: 20px; box-shadow: 0 4px 16px rgba(0,0,0,0.05);
}
.section-title {
  font-size: 20px; font-weight: 700; margin-bottom: 6px;
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; user-select: none;
}
.section-heading { display: inline-flex; align-items: center; gap: 8px; }
.shengmu-modes {
  display: inline-flex; gap: 3px; margin-left: auto; padding: 3px;
  border: 1px solid rgba(102,126,234,0.16); border-radius: 10px;
  background: #f5f6fb;
}
.shengmu-modes button {
  padding: 5px 9px; border: 0; border-radius: 7px;
  background: transparent; color: #71809a; font: inherit; font-size: 12px;
  cursor: pointer; transition: all .2s;
}
.shengmu-modes button:hover { color: #5367c9; background: rgba(102,126,234,0.1); }
.shengmu-modes button.active {
  color: #fff; background: linear-gradient(135deg, #667eea, #764ba2);
  box-shadow: 0 3px 8px rgba(102,126,234,0.25);
}
.exam-button { color: #b36b00 !important; }
.shengmu-modes button.exam-button:hover { color: #fff !important; background: linear-gradient(135deg, #f6b73c, #e67e22); }
.shengmu-modes button.exam-button.active { color: #fff !important; background: linear-gradient(135deg, #f6b73c, #e67e22); }
.section-title.playing { color: #667eea; }
.section-title .badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  font-size: 15px; color: #fff;
}
.section-desc {
  font-size: 13px; color: #95a5a6; margin-bottom: 16px;
  cursor: pointer; user-select: none;
}
.section-desc.playing { color: #667eea; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 12px;
}
.grid[id^="tone-"] {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.pinyin-item {
  position: relative; background: #f8f9fc;
  border: 2px solid transparent; border-radius: 12px;
  padding: 16px 8px 12px; text-align: center;
  cursor: pointer; transition: all .2s; user-select: none;
}
.pinyin-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 14px rgba(0,0,0,0.1);
  border-color: #667eea;
}
.pinyin-item.speaking {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff; transform: scale(1.05);
  box-shadow: 0 6px 18px rgba(102,126,234,0.4);
}
.pinyin {
  font-family: "Andika";
  font-size: 36px;
  font-weight: normal;
}
.example { font-size: 12px; color: #95a5a6; margin-top: 4px; }
.pinyin-item.speaking .example { color: rgba(255,255,255,0.85); }

.section.shengmu .badge { background: linear-gradient(135deg, #ff9a9e, #f857a6); }
.section.shengmu .pinyin-item:hover { border-color: #ff9a9e; }
.section.shengmu .pinyin-item.speaking { background: linear-gradient(135deg, #ff9a9e, #f857a6); }

.section.danyuanmu .badge { background: linear-gradient(135deg, #43cea2, #185a9d); }
.section.danyuanmu .pinyin-item:hover { border-color: #43cea2; }
.section.danyuanmu .pinyin-item.speaking { background: linear-gradient(135deg, #43cea2, #185a9d); }

.section.fuyunmu .badge { background: linear-gradient(135deg, #fa709a, #fee140); }
.section.fuyunmu .pinyin-item:hover { border-color: #fa709a; }
.section.fuyunmu .pinyin-item.speaking { background: linear-gradient(135deg, #fa709a, #fee140); }

.section.biyunmu .badge { background: linear-gradient(135deg, #667eea, #764ba2); }
.section.biyunmu .pinyin-item:hover { border-color: #667eea; }
.section.biyunmu .pinyin-item.speaking { background: linear-gradient(135deg, #667eea, #764ba2); }

.section.qianbiyin .badge { background: linear-gradient(135deg, #667eea, #764ba2); }
.section.qianbiyin .pinyin-item:hover { border-color: #667eea; }
.section.qianbiyin .pinyin-item.speaking { background: linear-gradient(135deg, #667eea, #764ba2); }

.section.houbiyin .badge { background: linear-gradient(135deg, #667eea, #764ba2); }
.section.houbiyin .pinyin-item:hover { border-color: #667eea; }
.section.houbiyin .pinyin-item.speaking { background: linear-gradient(135deg, #667eea, #764ba2); }

.section.zhengti .badge { background: linear-gradient(135deg, #56ab2f, #a8e063); }
.section.zhengti .pinyin-item:hover { border-color: #56ab2f; }
.section.zhengti .pinyin-item.speaking { background: linear-gradient(135deg, #56ab2f, #a8e063); }

.exam-result-modal {
  position: fixed; inset: 0; z-index: 20; display: none;
  align-items: center; justify-content: center; padding: 24px;
  background: rgba(31,42,68,0.58);
}
.exam-result-modal.visible { display: flex; }
.exam-result-dialog {
  width: min(92vw, 420px); padding: 26px 22px; border-radius: 18px;
  background: #fff; text-align: center; box-shadow: 0 18px 48px rgba(31,42,68,0.3);
}
.exam-result-dialog h2 { margin-bottom: 14px; color: #2c3e50; }
.exam-score { color: #667eea; font-size: 42px; font-weight: 700; }
.exam-score small { display: block; font-size: 13px; color: #95a5a6; }
.exam-result-dialog p { margin: 18px 0 10px; color: #71809a; }
.wrong-letters { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; min-height: 38px; }
.wrong-letter { display: inline-flex; flex-direction: column; min-width: 48px; padding: 6px 8px; border-radius: 10px; background: #fff1f0; color: #d9534f; font-family: "Andika"; font-size: 22px; }
.wrong-letter small { font-family: inherit; font-size: 11px; color: #b77a78; }
.no-wrong { color: #43a047; font-size: 15px; }
.exam-result-close { margin-top: 20px; padding: 9px 24px; border: 0; border-radius: 999px; color: #fff; background: linear-gradient(135deg, #667eea, #764ba2); cursor: pointer; }
.writing-modal {
  position: fixed; inset: 0; z-index: 10; display: none;
  align-items: center; justify-content: center;
  padding: 24px; background: rgba(31,42,68,0.58);
}
.writing-modal.visible { display: flex; }
.writing-dialog {
  position: relative; max-width: min(88vw, 560px); max-height: 88vh;
  padding: 12px; border-radius: 18px; background: #fff;
  box-shadow: 0 18px 48px rgba(31,42,68,0.3);
}
.writing-dialog img { display: block; max-width: 100%; max-height: 82vh; border-radius: 10px; }
.writing-close {
  position: absolute; top: -14px; right: -14px; width: 32px; height: 32px;
  border: 0; border-radius: 50%; background: #fff; color: #667eea;
  font-size: 24px; line-height: 1; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,.2);
}

.footer {
  text-align: center; margin-top: 20px;
  font-size: 13px; color: #95a5a6;
}

@media (max-width: 600px) {
  .storybook-link { top: 12px; right: 12px; padding: 6px 10px; font-size: 12px; }
  .display-mode-control { margin: -10px 0 12px; }
  .eye-mode-toggle { top: auto; right: auto; }
  .section-heading { min-width: 0; }
  .shengmu-modes { flex-shrink: 0; }
  .shengmu-modes button { padding: 5px 6px; font-size: 11px; }
  .mode-switch { width: fit-content; max-width: 100%; }
  .mode-switch button, .mode-switch a { min-width: 112px; padding: 11px 20px; }
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid[id^="tone-"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .pinyin { font-size: 32px; }
  .pinyin-item { padding: 12px 4px 10px; }
}
