:root {
  /* === 台湾留学101センター ブランドカラー === */
  --primary: #0A5FA6;
  --primary-dark: #084B84;
  --primary-light: #E8F0F8;
  --accent: #FFDB00;
  --accent-dark: #E6C500;
  --bg: #FAF8F5;
  --bg-card: #FFFFFF;
  --bg-input: #F3F0EB;
  --text: #333333;
  --text-secondary: #5C5650;
  --text-muted: #78716C;
  --danger: #DC2626;
  --success: #059669;
  --warning: #D97706;
  --line-green: #06C755;
  --tone-color: #0A5FA6;
  --initial-color: #059669;
  --final-color: #7C3AED;
  --overall-color: #333333;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Noto Sans JP', 'Noto Sans TC', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;600;700&family=Noto+Sans+TC:wght@400;500;700&family=Josefin+Sans:wght@600;700&display=swap');

.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: 100vh; }

/* ===== ログイン ===== */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  gap: 1rem;
}
.login-container h1 {
  font-size: 2rem;
  font-family: 'Josefin Sans', 'Noto Sans JP', sans-serif;
  color: var(--primary);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.login-container .subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}
.login-container input {
  width: 100%;
  max-width: 320px;
  padding: 0.9rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--primary);
  background: var(--bg-input);
  color: var(--text);
  font-size: 1rem;
  text-align: center;
}
.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2em;
}
.login-container button {
  width: 100%;
  max-width: 320px;
  padding: 0.9rem;
  border-radius: 12px;
  border: none;
  background: var(--primary);
  color: #FFFFFF;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  box-shadow: 0 2px 8px rgba(10, 95, 166, 0.25);
}
.login-container button:hover { background: var(--primary-dark); }

/* ===== ヘッダー ===== */
header {
  padding: 1rem 1.2rem 0.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid #E8E3DC;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
header h2 {
  font-size: 1.1rem;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 0.8rem;
}
nav {
  display: flex;
  gap: 0;
}
.nav-btn {
  flex: 1;
  padding: 0.6rem 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}
.nav-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ===== タブ ===== */
.tab { display: none; flex: 1; padding: 1rem; overflow-y: auto; }
.tab.active { display: flex; flex-direction: column; }

/* ===== 発音ドリル ===== */
.drill-card {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}
.drill-target {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 2rem;
  text-align: center;
  border: 1px solid #E8E3DC;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.hanzi {
  font-size: 2.5rem;
  letter-spacing: 0.3em;
  margin-bottom: 0.5rem;
  font-family: 'Noto Sans TC', sans-serif;
}
.pinyin {
  font-size: 1.2rem;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  margin-bottom: 1rem;
}
.play-btn {
  padding: 0.5rem 1.5rem;
  border-radius: 20px;
  border: 1px solid var(--primary);
  background: transparent;
  color: var(--primary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.play-btn:hover {
  background: var(--primary);
  color: #FFFFFF;
}

/* レコーダー */
.recorder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
.record-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.record-btn.recording {
  background: var(--danger);
  border-color: var(--danger);
  color: #FFFFFF;
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
.recording-indicator {
  height: 4px;
  width: 60px;
  border-radius: 2px;
  background: transparent;
  transition: background 0.3s;
}
.recording-indicator.active {
  background: var(--danger);
  animation: blink 0.8s infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* スコア */
.score-panel {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  border: 1px solid #E8E3DC;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.score-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
.score-label {
  width: 70px;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.score-note {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  margin: 0.3rem 0 0.5rem;
  padding: 0;
}
.drill-last-score {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}
.last-score-val { font-weight: 700; }
.last-score-val.good { color: var(--success); }
.last-score-val.ok { color: var(--warning); }
.last-score-val.bad { color: var(--danger); }

.quiz-audio-btn {
  background: none;
  border: 1px solid var(--primary-light);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
  margin-top: 0.5rem;
}
.quiz-audio-btn:active { background: var(--primary-light); }

.score-bar {
  flex: 1;
  height: 8px;
  background: #E8E3DC;
  border-radius: 4px;
  overflow: hidden;
}
.score-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.8s ease;
}
.score-fill.tone { background: var(--tone-color); }
.score-fill.initial { background: var(--initial-color); }
.score-fill.final { background: var(--final-color); }
.score-fill.overall { background: var(--overall-color); }
.score-value {
  width: 36px;
  text-align: right;
  font-size: 0.85rem;
  font-weight: 600;
  flex-shrink: 0;
}

.word-scores {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
  justify-content: center;
}
.word-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  font-size: 0.85rem;
}
.word-chip .char { font-size: 1.3rem; font-family: 'Noto Sans TC', sans-serif; }
.word-chip .chip-score { font-size: 0.75rem; margin-top: 0.2rem; }
.word-chip.good { background: rgba(76, 175, 80, 0.15); color: var(--success); }
.word-chip.ok { background: rgba(255, 152, 0, 0.15); color: var(--warning); }
.word-chip.bad { background: rgba(217, 68, 68, 0.15); color: var(--danger); }

.drill-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.drill-nav button {
  padding: 0.5rem 1.5rem;
  border-radius: 8px;
  border: 1px solid #D5CEC4;
  background: #FFFFFF;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}
.drill-nav button:hover {
  border-color: var(--primary);
  color: var(--primary);
}
#drill-progress { color: var(--text-muted); font-size: 0.85rem; }

/* ===== シチュエーション選択 ===== */
.scenario-selector {
  padding: 0.8rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid #E8E3DC;
}
.scenario-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}
.scenario-back-btn {
  font-size: 0.75rem;
  padding: 0.3rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--primary);
  background: transparent;
  color: var(--primary);
  cursor: pointer;
}
.scenario-grid {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 300px;
  overflow-y: auto;
}
.scenario-level-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.5rem;
  padding-left: 0.2rem;
}
.scenario-card {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.scenario-card:hover { background: var(--primary-light); }
.scenario-icon { font-size: 1.4rem; flex-shrink: 0; }
.scenario-info { flex: 1; min-width: 0; }
.scenario-title { font-size: 0.85rem; font-weight: 500; }
.scenario-desc { font-size: 0.7rem; color: var(--text-muted); }
.scenario-active {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  font-size: 0.85rem;
  flex-wrap: wrap;
}
.scenario-zh { font-size: 0.75rem; color: var(--text-muted); }
.scenario-phrases {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.3rem;
}
.phrase-chip {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: var(--primary-light);
  color: var(--primary);
  font-family: 'Noto Sans TC', sans-serif;
}

/* ===== チャット ===== */
#chat-tab { padding: 0; background: var(--bg); }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.msg {
  display: flex;
  max-width: 85%;
}
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; }
.msg-content {
  padding: 0.8rem 1rem;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.6;
}
.msg.user .msg-content {
  background: var(--primary);
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
}
.msg.assistant .msg-content {
  background: #FFFFFF;
  border: 1px solid #E8E3DC;
  border-bottom-left-radius: 4px;
}
.msg .corrections {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 0.85rem;
}
.correction-item {
  margin: 0.3rem 0;
  color: var(--text-muted);
}
.correction-item .original { color: var(--danger); text-decoration: line-through; }
.correction-item .corrected { color: var(--success); }
.msg .hint {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--primary);
  font-style: italic;
}

.chat-input {
  display: flex;
  gap: 0.5rem;
  padding: 0.8rem 1rem;
  background: #FFFFFF;
  border-top: 1px solid #E8E3DC;
}
.chat-input input {
  flex: 1;
  padding: 0.7rem 1rem;
  border-radius: 20px;
  border: 1px solid #D5CEC4;
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.95rem;
}
.chat-input input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(10, 95, 166, 0.15);
}
.chat-input button {
  padding: 0.7rem 1.2rem;
  border-radius: 20px;
  border: none;
  background: var(--primary);
  color: #FFFFFF;
  font-weight: 600;
  cursor: pointer;
}

/* ===== 課題 ===== */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.task-card {
  background: #FFFFFF;
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  border: 1px solid #E8E3DC;
}
.task-card.completed { opacity: 0.5; }
.task-type {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.task-type.drill { background: rgba(232, 185, 49, 0.15); }
.task-type.chat { background: rgba(74, 140, 63, 0.15); }
.task-type.video { background: rgba(59, 130, 246, 0.15); }
.task-info { flex: 1; }
.task-info .task-title { font-size: 0.95rem; font-weight: 500; }
.task-info .task-desc { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.2rem; }
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
}

/* ===== レッスン選択（グローバル） ===== */
.global-lesson-selector {
  margin: 0.5rem 0;
}
.global-lesson-selector select {
  width: 100%;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border: 1px solid #D5CEC4;
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235C5650' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
}
.global-lesson-selector select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(10, 95, 166, 0.15);
}
.lesson-progress-info {
  margin-top: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.progress-bar-container {
  flex: 1;
  height: 6px;
  background: #E8E3DC;
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* ===== 文法タブ ===== */
#grammar-tab { padding: 0.8rem 1rem; overflow-y: auto; }
#grammar-list { display: flex; flex-direction: column; gap: 0.6rem; }
.grammar-card {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid #E8E3DC;
  overflow: hidden;
}
.grammar-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
}
.grammar-header:hover { background: var(--primary-light); }
.grammar-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.grammar-title {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.3;
}
.grammar-toggle {
  font-size: 0.7rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.grammar-video-badge {
  background: #FF0000;
  color: #fff;
  font-size: 0.55rem;
  padding: 0.15rem 0.3rem;
  border-radius: 4px;
  flex-shrink: 0;
}
.grammar-video-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  background: #FF0000;
  color: #fff;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  transition: opacity 0.2s;
}
.grammar-video-link:hover { opacity: 0.85; }
.grammar-body {
  padding: 0 1rem 1rem;
}
.grammar-section {
  margin-top: 0.8rem;
}
.grammar-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}
.grammar-explanation {
  font-size: 0.85rem;
  line-height: 1.7;
  color: var(--text);
}
.grammar-explanation br + br { content: ''; display: block; margin-top: 0.5rem; }
.grammar-exercises {
  font-size: 0.85rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg-input);
  border-radius: 8px;
  padding: 0.8rem;
}
.grammar-show-answer {
  margin-top: 0.6rem;
  padding: 0.5rem 1.2rem;
  border-radius: 8px;
  border: 1px solid var(--primary);
  background: transparent;
  color: var(--primary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
.grammar-show-answer:hover { background: var(--primary-light); }
.grammar-answers {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  line-height: 1.7;
  background: rgba(5, 150, 105, 0.08);
  border-radius: 8px;
  padding: 0.8rem;
  color: var(--text);
}
.grammar-summary {
  background: var(--primary-light);
  border-radius: 8px;
  padding: 0.8rem;
  font-size: 0.85rem;
  line-height: 1.6;
}

/* ===== 日本語訳 ===== */
.drill-target .translation {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* ===== 例文 ===== */
.drill-examples {
  background: var(--primary-light);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  margin: 0.8rem 0;
}
.example-item {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(10, 95, 166, 0.1);
}
.example-item:last-child { border-bottom: none; }
.example-item {
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
}
.example-item:hover { background: rgba(10, 95, 166, 0.08); }
.example-item.active {
  background: rgba(10, 95, 166, 0.15);
  border-left: 3px solid var(--primary);
}
.example-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.ex-text { flex: 1; display: flex; flex-direction: column; }
.ex-play-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(10, 95, 166, 0.3);
  background: rgba(10, 95, 166, 0.08);
  color: var(--primary);
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.ex-play-btn:hover { background: rgba(10, 95, 166, 0.2); }
.examples-header {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 0.3rem;
}
.drill-target.dimmed { opacity: 0.4; }
.ex-hanzi {
  font-family: 'Noto Sans TC', sans-serif;
  font-size: 1rem;
  color: var(--text);
}
.ex-pinyin {
  font-size: 0.75rem;
  color: var(--primary);
  margin-top: 0.1rem;
}
.ex-ja {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

/* ===== 進捗サマリーバー ===== */
.progress-summary {
  display: flex;
  justify-content: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--primary-light);
  border-bottom: 1px solid rgba(10, 95, 166, 0.15);
}
.progress-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 3rem;
}
.progress-stat .stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
}
.progress-stat .stat-label {
  font-size: 0.65rem;
  color: var(--text-muted);
}
.review-stat {
  cursor: pointer;
  background: rgba(220, 38, 38, 0.1);
  border-radius: 0.5rem;
  padding: 0.3rem 0.5rem;
}
.review-stat .stat-value { color: var(--danger); }
.review-stat .stat-label { color: var(--danger); }

/* ===== モード切り替えボタン ===== */
.drill-mode-toggle {
  display: flex;
  gap: 0;
  margin: 0.5rem 0;
  border-radius: 0.5rem;
  overflow: hidden;
  border: 1px solid var(--primary);
}
.mode-btn {
  flex: 1;
  padding: 0.5rem;
  border: none;
  background: white;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.mode-btn.active {
  background: var(--primary);
  color: white;
}

/* ===== カード左右ナビ ===== */
.drill-card-nav-wrapper {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.drill-card-nav-wrapper .drill-target {
  flex: 1;
}
.card-nav-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid #d1d5db;
  background: white;
  color: var(--primary);
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
.card-nav-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}
.card-nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* ===== 録音再生ボタン ===== */
.drill-audio-btns {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.5rem;
}
.playback-btn {
  background: var(--success) !important;
  color: white !important;
}
.playback-btn:hover {
  background: #047857 !important;
}

/* ===== クイズ ===== */
.quiz-setup {
  text-align: center;
  padding: 1rem 0;
}
.quiz-type-selector {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 1rem;
}
.quiz-type-btn {
  padding: 0.5rem 0.8rem;
  border: 2px solid var(--primary);
  border-radius: 0.5rem;
  background: white;
  color: var(--primary);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.quiz-type-btn.active {
  background: var(--primary);
  color: white;
}
.quiz-start-btn {
  padding: 0.8rem 2rem;
  border: none;
  border-radius: 0.5rem;
  background: var(--primary);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.quiz-start-btn:hover { background: var(--primary-dark); }

.quiz-card {
  padding: 0.5rem 0;
}
.quiz-progress-bar {
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.quiz-progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s;
}
.quiz-counter {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.quiz-question {
  text-align: center;
  margin-bottom: 1.5rem;
  min-height: 5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.quiz-hanzi {
  font-size: 2.2rem;
  font-weight: 700;
  font-family: 'Noto Sans TC', sans-serif;
  color: var(--text);
}
.quiz-pinyin {
  font-size: 1rem;
  color: var(--primary);
  margin-top: 0.3rem;
}
.quiz-pinyin-only {
  font-size: 1.8rem;
  color: var(--primary);
  font-weight: 600;
}
.quiz-text {
  font-size: 1.4rem;
  color: var(--text);
}
.quiz-choices {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.quiz-choice {
  padding: 0.9rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: 0.75rem;
  background: white;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}
.quiz-choice:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-light);
}
.quiz-choice.correct {
  border-color: var(--success);
  background: #ecfdf5;
  color: var(--success);
  font-weight: 600;
}
.quiz-choice.wrong {
  border-color: var(--danger);
  background: #fef2f2;
  color: var(--danger);
}

/* クイズ結果 */
.quiz-result {
  text-align: center;
  padding: 1.5rem 0;
}
.quiz-score-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  border: 4px solid;
}
.quiz-score-circle.great { border-color: var(--success); color: var(--success); }
.quiz-score-circle.good { border-color: var(--warning); color: var(--warning); }
.quiz-score-circle.needs-work { border-color: var(--danger); color: var(--danger); }
.quiz-score-num {
  font-size: 1.5rem;
  font-weight: 700;
}
.quiz-score-label {
  font-size: 0.7rem;
}
.quiz-wrong-header {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.quiz-wrong-item {
  padding: 0.4rem 0.6rem;
  background: #fef2f2;
  border-radius: 0.3rem;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
}
.quiz-perfect {
  font-size: 1.1rem;
  color: var(--success);
  font-weight: 600;
}
.quiz-retry-btn {
  margin-top: 1rem;
  padding: 0.7rem 2rem;
  border: none;
  border-radius: 0.5rem;
  background: var(--primary);
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.quiz-retry-btn:hover { background: var(--primary-dark); }
.quiz-result-details { margin: 1rem 0; }

/* ===== ピンインルール（第0課） ===== */
.pinyin-rule-card .grammar-header {
  background: linear-gradient(135deg, var(--primary-light) 0%, #F0E6FF 100%);
}

.pinyin-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  line-height: 1.6;
}

.pinyin-tip {
  background: #FFF8E1;
  border-left: 3px solid var(--warning);
  padding: 0.6rem 0.8rem;
  margin: 0.8rem 0;
  font-size: 0.85rem;
  border-radius: 0 8px 8px 0;
  color: var(--text);
}

/* 声調グリッド */
.pinyin-tone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.6rem;
}
.tone-card {
  padding: 0.8rem;
  border-radius: 12px;
  text-align: center;
  border: 1px solid #E5E5E5;
}
.tone-card.tone-high-flat { background: #E3F2FD; border-color: #90CAF9; }
.tone-card.tone-rising { background: #E8F5E9; border-color: #A5D6A7; }
.tone-card.tone-low { background: #FFF3E0; border-color: #FFCC80; }
.tone-card.tone-falling { background: #FCE4EC; border-color: #F48FB1; }
.tone-card.tone-neutral { background: #F5F5F5; border-color: #BDBDBD; }

.tone-symbol { font-size: 2rem; font-weight: 700; margin-bottom: 0.3rem; }
.tone-label { font-weight: 600; font-size: 0.85rem; color: var(--text); }
.tone-how { font-size: 0.8rem; color: var(--text-secondary); margin: 0.3rem 0; }
.tone-example { font-size: 0.75rem; color: var(--text-muted); }

/* 隠れた母音・ü省略テーブル */
.pinyin-rule-table { display: flex; flex-direction: column; gap: 0.5rem; }
.rule-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.7rem;
  background: var(--bg);
  border-radius: 10px;
  flex-wrap: wrap;
}
.rule-written, .rule-actual { text-align: center; }
.rule-label { display: block; font-size: 0.7rem; color: var(--text-muted); }
.rule-big { font-size: 1.4rem; font-weight: 700; }
.rule-correct { color: var(--success); }
.rule-arrow { font-size: 1.3rem; color: var(--primary); font-weight: 700; }
.rule-wrong {
  font-size: 0.8rem;
  color: var(--danger);
  background: #FEE2E2;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  margin-left: auto;
}
.rule-example-line {
  font-size: 0.82rem;
  color: var(--text-secondary);
  padding: 0 0.7rem 0.3rem;
  border-bottom: 1px solid #F0F0F0;
}

/* 有気音・無気音 */
.aspiration-grid { display: flex; flex-direction: column; gap: 0.5rem; }
.aspiration-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border-radius: 10px;
  flex-wrap: wrap;
}
.asp-pair { display: flex; align-items: center; gap: 0.4rem; }
.asp-no-air { font-size: 1.3rem; font-weight: 700; color: var(--primary); }
.asp-vs { font-size: 0.8rem; color: var(--text-muted); }
.asp-air { font-size: 1.3rem; font-weight: 700; color: var(--danger); }
.asp-label { display: flex; gap: 0.3rem; }
.asp-tag {
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-weight: 600;
}
.asp-tag.no-air { background: var(--primary-light); color: var(--primary); }
.asp-tag.with-air { background: #FEE2E2; color: var(--danger); }
.asp-example { font-size: 0.8rem; color: var(--text-secondary); }

/* そり舌音 */
.retroflex-group { margin-bottom: 0.8rem; }
.retroflex-group-title {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--primary);
  margin-bottom: 0.4rem;
  padding-left: 0.3rem;
}
.retroflex-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid #F0F0F0;
}
.retroflex-sound { font-size: 1.2rem; font-weight: 700; min-width: 2rem; color: var(--primary-dark); }
.retroflex-like { font-size: 0.82rem; color: var(--text-secondary); flex: 1; }
.retroflex-example { font-size: 0.82rem; color: var(--text-muted); }

/* 声調変化 */
.tone-change-section {
  margin-bottom: 1rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid #F0F0F0;
}
.tone-change-section:last-child { border-bottom: none; }
.tone-change-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--primary-dark);
  margin-bottom: 0.3rem;
}
.tone-change-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}
.tc-example {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0;
  font-size: 0.85rem;
  flex-wrap: wrap;
}
.tc-written { color: var(--text-muted); text-decoration: line-through; }
.tc-arrow { color: var(--primary); font-weight: 700; }
.tc-actual { color: var(--success); font-weight: 600; }
.tc-meaning { color: var(--text-muted); font-size: 0.8rem; }
.tc-context { font-weight: 600; color: var(--text); }
.tc-change { color: var(--success); }
.tc-eg { color: var(--text-muted); font-size: 0.8rem; }

/* ピンイン全音節表 */
.chart-group { margin-bottom: 1rem; }
.chart-group-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--primary-dark);
  margin-bottom: 0.4rem;
  padding-left: 0.2rem;
}
.chart-syllables {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.chart-syl-btn {
  background: var(--bg);
  border: 1px solid #E0E0E0;
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--text);
  min-width: 2.8rem;
  text-align: center;
}
.chart-syl-btn:active {
  background: var(--primary-light);
  border-color: var(--primary);
}

/* 母音バリエーション */
.variation-table { display: flex; flex-direction: column; gap: 0.3rem; }
.variation-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border-radius: 8px;
  align-items: center;
}
.var-context { font-size: 0.82rem; font-weight: 600; color: var(--primary-dark); }
.var-sound { font-size: 0.82rem; color: var(--text); }
.var-example { font-size: 0.78rem; color: var(--text-muted); }

/* ===== 進捗グラフ ===== */
.progress-expand-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.3rem 0.6rem;
  margin-left: auto;
  white-space: nowrap;
}

.progress-graphs {
  background: var(--bg-card);
  border-radius: 12px;
  margin: 0 0.8rem 0.8rem;
  padding: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.graph-section { margin-bottom: 1.2rem; }
.graph-section:last-child { margin-bottom: 0; }

.graph-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.6rem;
}

.chart-svg {
  width: 100%;
  height: auto;
  max-height: 120px;
}

/* レッスン別棒グラフ */
.lesson-bar-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.lesson-bar-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  min-width: 3.5rem;
  text-align: right;
}
.lesson-bar-track {
  flex: 1;
  height: 12px;
  background: #F0F0F0;
  border-radius: 6px;
  overflow: hidden;
}
.lesson-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.6s ease;
  min-width: 2px;
}
.lesson-bar-pct {
  font-size: 0.72rem;
  color: var(--text-muted);
  min-width: 2.2rem;
  text-align: right;
}

/* ===== Toast通知 ===== */
.toast {
  position: fixed;
  bottom: -60px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  color: white;
  z-index: 10000;
  transition: bottom 0.3s ease;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.toast.show { bottom: 24px; }
.toast-info { background: var(--primary); }
.toast-error { background: var(--danger); }
.toast-success { background: var(--success); }

/* ===== 使用制限モーダル ===== */
.limit-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.limit-modal {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 2rem;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.limit-modal h3 {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}
.limit-modal p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  line-height: 1.6;
}
.limit-modal button {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 24px;
  font-size: 1rem;
  cursor: pointer;
}

/* ===== 残り回数バッジ ===== */
.usage-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 8px;
  background: var(--primary-light);
  color: var(--primary);
  margin-left: 4px;
  font-weight: 500;
}
.usage-badge.depleted {
  background: rgba(220, 38, 38, 0.1);
  color: var(--danger);
}

/* ===== ログイン/登録切り替え ===== */
.login-switch {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.login-switch a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}
.login-switch a:hover {
  text-decoration: underline;
}
#reg-code {
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: 600;
}

/* ===== レスポンシブ ===== */
@media (min-width: 768px) {
  #main-screen { max-width: 600px; margin: 0 auto; }
}

/* ===== シェア機能 ===== */
.share-btn {
  background: none;
  border: 1px solid var(--primary);
  color: var(--primary);
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  margin-left: auto;
}
.share-btn:hover {
  background: var(--primary);
  color: white;
}
.quiz-share-btn {
  background: none;
  border: 2px solid var(--primary);
  color: var(--primary);
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}
.quiz-share-btn:hover {
  background: var(--primary-light);
}

/* ===== ゲーミフィケーション ===== */
@keyframes confetti-fall {
  0% { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
.confetti-piece {
  position: fixed;
  top: -10px;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  z-index: 10001;
  pointer-events: none;
}
.level-badge-display {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--text);
  font-weight: 600;
  margin-left: 6px;
  vertical-align: middle;
}
.achievement-banner {
  position: fixed;
  top: -80px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, var(--accent), #FFE566);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 16px;
  font-weight: 600;
  font-size: 0.95rem;
  z-index: 10002;
  transition: top 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  text-align: center;
  white-space: nowrap;
}
.achievement-banner.show { top: 20px; }
.achievement-icon { font-size: 1.3rem; margin-right: 6px; }
