@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/opendyslexic@1.0.3/dist/OpenDyslexic-Regular.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
}

:root {
  --bg: #1a1a2e;
  --bg-light: #16213e;
  --bg-card: #0f3460;
  --text: #f5f0e8;
  --text-muted: #a0a0b0;
  --green: #4ade80;
  --orange: #fb923c;
  --gray: #6b7280;
  --purple: #a78bfa;
  --red: #f87171;
  --blue: #60a5fa;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'OpenDyslexic', 'Comic Sans MS', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 20px;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-light);
  border-bottom: 3px solid var(--purple);
}
.header-left { display: flex; align-items: center; gap: 10px; }
.mascot { font-size: 40px; animation: bounce 2s infinite; }
@keyframes bounce {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
header h1 { font-size: 28px; color: var(--green); }

.icon-btn {
  background: none; border: none; font-size: 28px; cursor: pointer;
  padding: 8px; border-radius: 8px;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); }

/* Tabs */
.tabs {
  display: flex;
  background: var(--bg-light);
  padding: 0 10px;
  gap: 4px;
}
.tab {
  flex: 1;
  padding: 14px 8px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 8px 8px 0 0;
}
.tab.active {
  color: var(--text);
  border-bottom-color: var(--green);
  background: rgba(74,222,128,0.1);
}

main { padding: 20px; max-width: 700px; margin: 0 auto; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Level bar */
.level-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 22px;
  color: var(--purple);
}

/* Progress track */
.progress-track {
  height: 10px;
  background: var(--bg-card);
  border-radius: 5px;
  margin-bottom: 20px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--purple));
  border-radius: 5px;
  width: 0%;
  transition: width 0.4s ease;
}

/* Sentence display */
.sentence-display {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 28px 24px;
  min-height: 120px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  line-height: 1.8;
}
.word-token {
  font-size: 30px;
  padding: 4px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
}
.word-token.pending { color: var(--gray); }
.word-token.correct { color: var(--green); background: rgba(74,222,128,0.15); }
.word-token.missed { color: var(--orange); background: rgba(251,146,60,0.15); text-decoration: underline wavy; }
.word-token.current { color: var(--text); text-shadow: 0 0 12px var(--purple); }
.word-token:active { transform: scale(1.1); }

/* Buttons */
.btn {
  font-family: inherit;
  font-size: 20px;
  padding: 14px 28px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 48px;
  font-weight: bold;
}
.btn:active { transform: scale(0.95); }
.btn-primary { background: var(--purple); color: white; }
.btn-primary:hover { background: #8b6fe0; }
.btn-primary.listening { background: var(--red); animation: pulse 1.2s infinite; }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(248,113,113,0.5); }
  50% { box-shadow: 0 0 0 14px rgba(248,113,113,0); }
}
.btn-accent { background: var(--green); color: #1a1a2e; }
.btn-accent:hover { background: #3ec76e; }
.btn-secondary { background: var(--bg-card); color: var(--text); border: 2px solid var(--purple); }
.btn-secondary:hover { background: var(--purple); }
.btn-green { background: var(--green); color: #1a1a2e; }
.btn-large { font-size: 24px; padding: 18px 36px; width: 100%; }
.btn-huge { font-size: 28px; padding: 40px; width: 100%; border-radius: 24px; margin-bottom: 30px; }

.reading-controls {
  display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-bottom: 20px;
}

/* Score */
.sentence-score {
  text-align: center; font-size: 24px; margin-bottom: 16px;
  padding: 16px; background: var(--bg-card); border-radius: 12px;
}

/* Sound out panel */
.sound-out-panel {
  background: var(--bg-card);
  border: 2px solid var(--orange);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  margin-top: 12px;
}
.sound-out-word { font-size: 32px; margin-bottom: 12px; color: var(--orange); }
.phoneme-display {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  margin-bottom: 16px;
}
.phoneme-chip {
  background: var(--purple);
  color: white;
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 22px;
  transition: transform 0.2s;
}
.phoneme-chip.highlight { background: var(--green); transform: scale(1.2); }
.sound-out-panel .btn { margin: 4px; }

/* Free Word */
.free-word-result { text-align: center; margin-bottom: 24px; }
.free-word-text { font-size: 48px; margin-bottom: 16px; color: var(--green); }
.syllable-display {
  display: flex; justify-content: center; gap: 6px; margin-bottom: 16px; font-size: 24px;
}
.syllable-chip {
  padding: 6px 14px; border-radius: 8px; font-size: 24px;
}
.syllable-chip:nth-child(odd) { background: rgba(167,139,250,0.3); }
.syllable-chip:nth-child(even) { background: rgba(74,222,128,0.3); }
.free-word-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.my-words-section { margin-top: 30px; }
.my-words-section h3 { color: var(--purple); margin-bottom: 12px; font-size: 22px; }
.my-words-list { display: flex; flex-wrap: wrap; gap: 8px; }
.my-word-chip {
  background: var(--bg-card);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 20px;
  cursor: pointer;
  border: 2px solid var(--purple);
  transition: all 0.2s;
}
.my-word-chip:active { background: var(--purple); }

/* Progress tab */
.progress-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
}
.progress-card h3 { color: var(--purple); margin-bottom: 12px; }
.stat-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.1); }
.stat-label { color: var(--text-muted); }
.stat-value { color: var(--green); font-weight: bold; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-content {
  background: var(--bg-light);
  border: 2px solid var(--purple);
  border-radius: 20px;
  padding: 30px;
  width: 90%; max-width: 400px;
}
.modal-content h2 { margin-bottom: 20px; color: var(--green); }
.modal-content label {
  display: block; margin-bottom: 16px; color: var(--text-muted); font-size: 18px;
}
.modal-content input[type=range], .modal-content select {
  width: 100%; margin-top: 8px; font-family: inherit; font-size: 18px;
  padding: 8px; border-radius: 8px; border: none; background: var(--bg-card); color: var(--text);
}

/* Confetti */
.confetti-canvas {
  position: fixed; inset: 0; pointer-events: none; z-index: 200;
}

/* Compat warning */
.compat-warning {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--orange); color: #1a1a2e;
  padding: 16px; text-align: center; font-size: 18px; z-index: 300;
}

.hidden { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--purple); border-radius: 4px; }

@media (max-width: 500px) {
  .word-token { font-size: 26px; }
  .sentence-display { padding: 20px 16px; }
  main { padding: 14px; }
  .tab { font-size: 15px; padding: 12px 4px; }
}
