/* ============================================================
   Japanese Learning App — Styles
   Clean, calm, minimal Japanese aesthetic
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #FDFBF7;
  --bg-card: #FFFFFF;
  --bg-hover: #F5F0E8;
  --text: #1A1A1A;
  --text-muted: #6B6B6B;
  --text-light: #999999;
  --accent: #C8102E;
  --accent-light: #E8394D;
  --accent-bg: #FEF2F2;
  --success: #16A34A;
  --success-bg: #F0FDF4;
  --error: #DC2626;
  --error-bg: #FEF2F2;
  --border: #E8E4DC;
  --border-light: #F0ECE4;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --font-jp: "Noto Sans JP", sans-serif;
  --font-en: "Inter", "Noto Sans JP", sans-serif;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --max-width: 680px;
}

/* --- Dark Mode --- */
[data-theme="dark"] {
  --bg: #0F0F0F;
  --bg-card: #1A1A1A;
  --bg-hover: #252525;
  --text: #E8E4DC;
  --text-muted: #999999;
  --text-light: #666666;
  --accent: #E8394D;
  --accent-light: #F06070;
  --accent-bg: #2A1215;
  --success: #22C55E;
  --success-bg: #0A2015;
  --error: #EF4444;
  --error-bg: #2A1215;
  --border: #2A2A2A;
  --border-light: #222222;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-en);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition), color var(--transition);
}

/* --- Typography --- */
h1, h2, h3 {
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.jp-text {
  font-family: var(--font-jp);
}

/* --- Layout --- */
.app-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
  transition: background var(--transition);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-btn {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all var(--transition);
}

.back-btn:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

.back-btn.visible {
  display: flex;
}

.app-logo {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.app-logo .logo-jp {
  font-family: var(--font-jp);
  font-size: 20px;
  color: var(--accent);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all var(--transition);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--text-muted);
}

.streak-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
}

.streak-badge.empty {
  background: var(--bg-hover);
  color: var(--text-muted);
}

/* --- Main Content --- */
.app-content {
  flex: 1;
  padding: 24px 0 80px;
}

/* --- Home Screen --- */
.home-greeting {
  margin-bottom: 32px;
}

.home-greeting h1 {
  font-size: 28px;
  margin-bottom: 4px;
}

.home-greeting p {
  color: var(--text-muted);
  font-size: 15px;
}

/* Daily challenge card */
.daily-challenge {
  background: linear-gradient(135deg, var(--accent) 0%, #A00D24 100%);
  color: white;
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 32px;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  position: relative;
  overflow: hidden;
}

.daily-challenge::before {
  content: "";
  position: absolute;
  top: -30px;
  right: -30px;
  width: 120px;
  height: 120px;
  background: rgba(255,255,255,0.08);
  border-radius: 50%;
}

.daily-challenge:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(200, 16, 46, 0.3);
}

.daily-challenge h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.85;
  margin-bottom: 8px;
}

.daily-challenge .challenge-chars {
  font-family: var(--font-jp);
  font-size: 32px;
  letter-spacing: 12px;
  margin-bottom: 8px;
}

.daily-challenge .challenge-sub {
  font-size: 14px;
  opacity: 0.8;
}

/* Level cards */
.levels-section h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.level-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 16px;
}

.level-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.level-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  background: var(--accent-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-jp);
  font-size: 24px;
  color: var(--accent);
  flex-shrink: 0;
}

.level-info {
  flex: 1;
  min-width: 0;
}

.level-info h3 {
  font-size: 16px;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.level-info h3 .jp-sub {
  font-family: var(--font-jp);
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 400;
}

.level-info p {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.level-progress {
  flex-shrink: 0;
  text-align: right;
}

.level-progress .pct {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

.progress-bar-mini {
  width: 48px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}

.progress-bar-mini .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* --- Level Detail / Mode Selection --- */
.level-header {
  text-align: center;
  margin-bottom: 32px;
}

.level-header .level-icon-lg {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-lg);
  background: var(--accent-bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-jp);
  font-size: 36px;
  color: var(--accent);
  margin-bottom: 16px;
}

.level-header h1 {
  font-size: 24px;
  margin-bottom: 4px;
}

.level-header p {
  color: var(--text-muted);
  font-size: 14px;
  max-width: 400px;
  margin: 0 auto;
}

/* Progress bar */
.progress-section {
  margin-bottom: 28px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* Mode cards */
.modes-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mode-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}

.mode-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.mode-card .mode-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.mode-card h3 {
  font-size: 14px;
  margin-bottom: 4px;
}

.mode-card p {
  font-size: 12px;
  color: var(--text-muted);
}

/* --- Character Grid --- */
.char-grid-section {
  margin-top: 28px;
}

.char-grid-section h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.row-group {
  margin-bottom: 20px;
}

.row-group .row-label {
  font-size: 12px;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.char-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.char-cell {
  aspect-ratio: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.char-cell:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.char-cell .char {
  font-family: var(--font-jp);
  font-size: 24px;
  line-height: 1;
}

.char-cell .romaji {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.char-cell.mastered {
  background: var(--success-bg);
  border-color: var(--success);
}

.char-cell.mastered .char {
  color: var(--success);
}

.char-cell.learning {
  background: var(--accent-bg);
  border-color: var(--accent);
}

/* --- Flashcard / Learn Mode --- */
.flashcard-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 20px;
}

.flashcard-progress {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.flashcard-progress .count {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.flashcard {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 3/4;
  perspective: 1000px;
  cursor: pointer;
  margin-bottom: 24px;
}

.flashcard-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-xl);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.flashcard-back {
  transform: rotateY(180deg);
}

.flashcard-face .big-char {
  font-family: var(--font-jp);
  font-size: 120px;
  line-height: 1;
  color: var(--text);
  margin-bottom: 16px;
}

.flashcard-face .hint-text {
  font-size: 14px;
  color: var(--text-light);
}

.flashcard-back .romaji-big {
  font-size: 36px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
}

.flashcard-back .english-text {
  font-size: 18px;
  color: var(--text-muted);
  text-align: center;
}

.flashcard-back .jp-reading {
  font-family: var(--font-jp);
  font-size: 48px;
  color: var(--text);
  margin-bottom: 16px;
}

.flashcard-nav {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 360px;
}

.flashcard-nav button {
  flex: 1;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-en);
}

.flashcard-nav button:hover {
  background: var(--bg-hover);
}

.flashcard-nav button.know-btn {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

.flashcard-nav button.know-btn:hover {
  background: #15803D;
}

.flashcard-nav button.dont-know-btn {
  background: var(--error-bg);
  color: var(--error);
  border-color: var(--error);
}

.flashcard-nav button.dont-know-btn:hover {
  background: #FECACA;
}

.audio-btn {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all var(--transition);
}

.audio-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* --- Quiz Mode --- */
.quiz-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 20px;
}

.quiz-stats {
  display: flex;
  gap: 24px;
  margin-bottom: 20px;
  font-size: 14px;
  color: var(--text-muted);
}

.quiz-stats span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.quiz-stats .correct-count {
  color: var(--success);
  font-weight: 600;
}

.quiz-stats .wrong-count {
  color: var(--error);
  font-weight: 600;
}

.quiz-prompt {
  text-align: center;
  margin-bottom: 32px;
}

.quiz-prompt .big-char {
  font-family: var(--font-jp);
  font-size: 100px;
  line-height: 1;
  color: var(--text);
  margin-bottom: 8px;
}

.quiz-prompt .quiz-instruction {
  font-size: 14px;
  color: var(--text-muted);
}

/* For reverse quiz — show romaji, pick character */
.quiz-prompt .romaji-prompt {
  font-size: 48px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
}

.quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 400px;
}

.quiz-option {
  padding: 20px;
  border-radius: var(--radius-md);
  border: 2px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  text-align: center;
  font-size: 18px;
  font-weight: 500;
  transition: all var(--transition);
  font-family: var(--font-en);
}

.quiz-option .option-char {
  font-family: var(--font-jp);
  font-size: 36px;
}

.quiz-option:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.quiz-option.correct {
  border-color: var(--success);
  background: var(--success-bg);
  color: var(--success);
  animation: popCorrect 0.4s ease;
}

.quiz-option.wrong {
  border-color: var(--error);
  background: var(--error-bg);
  color: var(--error);
  animation: shake 0.4s ease;
}

.quiz-option.disabled {
  pointer-events: none;
  opacity: 0.5;
}

.quiz-next-btn {
  margin-top: 24px;
  padding: 14px 32px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: white;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-en);
}

.quiz-next-btn:hover {
  background: var(--accent-light);
}

/* --- Speed Round --- */
.speed-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 20px;
}

.speed-timer {
  font-size: 48px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  margin-bottom: 8px;
}

.speed-timer.low {
  color: var(--error);
  animation: pulse 0.5s ease infinite;
}

.speed-score {
  font-size: 18px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.speed-start-btn {
  padding: 16px 48px;
  border-radius: var(--radius-lg);
  border: none;
  background: var(--accent);
  color: white;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-en);
}

.speed-start-btn:hover {
  background: var(--accent-light);
  transform: scale(1.02);
}

/* --- Writing Practice --- */
.writing-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 20px;
}

.writing-canvas-wrap {
  position: relative;
  width: 280px;
  height: 280px;
  margin-bottom: 24px;
}

.writing-canvas {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-lg);
  border: 2px solid var(--border);
  background: var(--bg-card);
}

.writing-guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.writing-guide line {
  stroke: var(--border-light);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.stroke-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 200;
  stroke-dashoffset: 200;
}

.stroke-path.animate {
  animation: drawStroke 0.8s ease forwards;
}

.stroke-path.complete {
  stroke-dashoffset: 0;
  stroke: var(--text-muted);
  stroke-width: 2.5;
  opacity: 0.5;
}

.stroke-path.active {
  stroke: var(--accent);
  stroke-width: 3;
  opacity: 1;
}

.writing-char-label {
  font-family: var(--font-jp);
  font-size: 20px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.writing-romaji-label {
  font-size: 16px;
  color: var(--text-light);
  margin-bottom: 16px;
}

.writing-controls {
  display: flex;
  gap: 12px;
}

.writing-controls button {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-en);
}

.writing-controls button:hover {
  background: var(--bg-hover);
}

.writing-controls button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.writing-controls button.primary:hover {
  background: var(--accent-light);
}

/* --- Stats Page --- */
.stats-container {
  padding-top: 8px;
}

.stats-container h1 {
  font-size: 24px;
  margin-bottom: 24px;
}

.stats-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
}

.stat-card .stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-section {
  margin-bottom: 28px;
}

.stat-section h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.accuracy-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.accuracy-bar .label {
  font-size: 14px;
  width: 80px;
  flex-shrink: 0;
}

.accuracy-bar .bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.accuracy-bar .bar .fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.accuracy-bar .bar .fill.good { background: var(--success); }
.accuracy-bar .bar .fill.ok { background: #F59E0B; }
.accuracy-bar .bar .fill.bad { background: var(--error); }

.accuracy-bar .pct {
  font-size: 13px;
  font-weight: 600;
  width: 40px;
  text-align: right;
}

.reset-btn {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--error);
  background: transparent;
  color: var(--error);
  font-size: 14px;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-en);
  margin-top: 20px;
}

.reset-btn:hover {
  background: var(--error-bg);
}

/* --- Completion / Results Screen --- */
.results-container {
  text-align: center;
  padding-top: 40px;
}

.results-container .result-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.results-container h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.results-container .result-subtitle {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 32px;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 32px;
}

.result-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.result-stat .val {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.result-stat .lbl {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 320px;
  margin: 0 auto;
}

.results-actions button {
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-en);
}

.results-actions button.primary-btn {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.results-actions button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* --- Confetti --- */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -10px;
  animation: confettiFall 3s linear forwards;
}

/* --- Animations --- */
@keyframes drawStroke {
  to { stroke-dashoffset: 0; }
}

@keyframes popCorrect {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.3s ease forwards;
}

.slide-up {
  animation: slideUp 0.4s ease forwards;
}

/* --- Responsive --- */
@media (max-width: 480px) {
  .app-container {
    padding: 0 16px;
  }

  .flashcard-face .big-char {
    font-size: 80px;
  }

  .quiz-prompt .big-char {
    font-size: 72px;
  }

  .char-grid {
    gap: 6px;
  }

  .char-cell .char {
    font-size: 20px;
  }

  .modes-grid {
    grid-template-columns: 1fr;
  }

  .stats-cards {
    grid-template-columns: 1fr 1fr;
  }

  .result-stats {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .daily-challenge .challenge-chars {
    font-size: 24px;
    letter-spacing: 8px;
  }
}

@media (min-width: 768px) {
  .flashcard {
    max-width: 400px;
  }

  .quiz-options {
    max-width: 440px;
  }
}

/* --- Utility --- */
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 14px;
  z-index: 10000;
  transition: transform 0.3s ease;
  white-space: nowrap;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   Achievement Badges
   ============================================================ */

.badges-section {
  margin-bottom: 28px;
}

.badges-section h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.badge-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.badge-cell {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 8px;
  text-align: center;
  transition: all var(--transition);
}

.badge-cell.unlocked {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(200, 16, 46, 0.15);
}

.badge-cell.locked {
  opacity: 0.4;
  filter: grayscale(1);
}

.badge-cell .badge-icon {
  font-size: 32px;
  margin-bottom: 6px;
  display: block;
}

.badge-cell .badge-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  display: block;
}

.badge-cell .badge-desc {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  display: block;
}

/* Badge toast notification */
.badge-toast {
  position: fixed;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, var(--accent) 0%, #A00D24 100%);
  color: white;
  padding: 16px 24px;
  border-radius: var(--radius-lg);
  z-index: 10001;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 30px rgba(200, 16, 46, 0.4);
  transition: top 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
}

.badge-toast.show {
  top: 24px;
}

.badge-toast .bt-icon {
  font-size: 32px;
}

.badge-toast .bt-text {
  font-size: 14px;
  font-weight: 600;
}

.badge-toast .bt-sub {
  font-size: 12px;
  opacity: 0.85;
  font-weight: 400;
}

/* Home badge count */
.badge-count-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  cursor: pointer;
  transition: all var(--transition);
}

.badge-count-bar:hover {
  border-color: var(--accent);
}

.badge-count-bar .bcb-icons {
  font-size: 18px;
  letter-spacing: 2px;
}

.badge-count-bar .bcb-text {
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
}

.badge-count-bar .bcb-count {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

/* ============================================================
   Study Streak Calendar (GitHub-style heatmap)
   ============================================================ */

.calendar-section {
  margin-bottom: 28px;
}

.calendar-section h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.calendar-stats {
  display: flex;
  gap: 20px;
  margin-bottom: 12px;
  font-size: 13px;
}

.calendar-stats .cs-val {
  font-weight: 600;
  color: var(--accent);
}

.calendar-wrap {
  overflow-x: auto;
  padding-bottom: 4px;
}

.calendar-grid {
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: column;
  gap: 3px;
}

.cal-day {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--border);
}

.cal-day.l1 { background: rgba(200, 16, 46, 0.25); }
.cal-day.l2 { background: rgba(200, 16, 46, 0.5); }
.cal-day.l3 { background: rgba(200, 16, 46, 0.75); }
.cal-day.l4 { background: var(--accent); }

.cal-month-labels {
  display: flex;
  gap: 3px;
  margin-bottom: 4px;
  font-size: 10px;
  color: var(--text-light);
}

.cal-day-labels {
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  gap: 3px;
  font-size: 9px;
  color: var(--text-light);
  margin-right: 4px;
  float: left;
}

.cal-day-labels span {
  height: 12px;
  display: flex;
  align-items: center;
}

/* ============================================================
   Share Button
   ============================================================ */

.share-btn {
  padding: 14px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: white;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-en);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.share-btn:hover {
  background: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* ============================================================
   Mastery Celebrations
   ============================================================ */

@keyframes goldenShimmer {
  0% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.6); }
  50% { box-shadow: 0 0 16px 4px rgba(255, 215, 0, 0.4); }
  100% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0); }
}

.char-cell.just-mastered {
  animation: goldenShimmer 1.5s ease 2;
  border-color: #FFD700 !important;
  background: linear-gradient(135deg, var(--success-bg), rgba(255, 215, 0, 0.1)) !important;
}

.milestone-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

.milestone-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 40px 32px;
  text-align: center;
  max-width: 360px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.4s ease;
}

.milestone-card .ms-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.milestone-card h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

.milestone-card p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.milestone-card .ms-pct {
  font-size: 48px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}

.milestone-card button {
  padding: 14px 32px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: white;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font-en);
  transition: all var(--transition);
}

.milestone-card button:hover {
  background: var(--accent-light);
}

/* ============================================================
   Lesson Roulette
   ============================================================ */

.roulette-btn {
  width: 100%;
  padding: 18px 24px;
  border-radius: var(--radius-lg);
  border: 2px dashed var(--border);
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-en);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 24px;
}

.roulette-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}

.roulette-btn .roulette-icon {
  font-size: 20px;
  display: inline-block;
}

.roulette-btn.spinning .roulette-icon {
  animation: spin 0.3s linear infinite;
}

.roulette-btn.spinning .roulette-text {
  animation: textCycle 0.15s steps(1) infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Hidden canvas for share card generation */
.share-canvas {
  position: fixed;
  top: -9999px;
  left: -9999px;
  pointer-events: none;
}

@media (max-width: 480px) {
  .badge-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .badge-cell {
    padding: 12px 6px;
  }
  .badge-cell .badge-icon {
    font-size: 28px;
  }
}
