:root {
  --primary: #5b8def;
  --primary-dark: #3d6ed8;
  --accent: #ffb347;
  --success: #4ec27b;
  --danger: #e85a5a;
  --bg: #fff8f0;
  --card: #ffffff;
  --text: #2a2d3a;
  --muted: #6a6f80;
  --radius: 18px;
  --tap: 48px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: 'Nunito', system-ui, sans-serif; color: var(--text); background: var(--bg); }
h1, h2, h3, .brand { font-family: 'Fredoka', 'Nunito', sans-serif; font-weight: 700; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.skip-link { position: absolute; top: -40px; left: 0; background: #000; color: #fff; padding: 8px; }
.skip-link:focus { top: 0; }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--card); box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.app-header .brand { display: flex; align-items: center; }
.brand-logo { height: 44px; width: auto; display: block; }
.app-header nav a { margin-left: 16px; }
.app-header .hi { margin-right: 12px; color: var(--muted); }

main { max-width: 1100px; margin: 24px auto; padding: 0 16px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 10px 22px; border-radius: 999px;
  background: #eef2ff; color: var(--primary-dark); border: none; cursor: pointer;
  font-family: inherit; font-size: 1rem; font-weight: 700; text-decoration: none;
  transition: transform .1s ease, background .15s ease;
}
.btn:hover { background: #dde6ff; transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-small { min-height: 36px; padding: 6px 14px; font-size: .9rem; }
.btn-large { font-size: 1.2rem; padding: 14px 36px; }
.btn-tts { background: #fff3d6; color: #8a5b00; }

/* Flash */
.flash { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; }
.flash-error, .flash-danger { background: #fde2e2; color: var(--danger); }
.flash-success { background: #e2f6e8; color: var(--success); }

/* Home */
.hero { text-align: center; padding: 60px 20px; }
.hero h1 { font-size: 3rem; margin-bottom: 8px; display: flex; justify-content: center; }
.hero-logo { height: 80px; width: auto; }
.hero .lead { font-size: 1.2rem; color: var(--muted); }
.hero-actions { margin: 24px 0; }
.hero-features { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 32px; }
.feature { background: var(--card); padding: 12px 20px; border-radius: 999px; box-shadow: 0 2px 6px rgba(0,0,0,.05); }

/* Login */
.card { background: var(--card); border-radius: var(--radius); padding: 32px; box-shadow: 0 8px 24px rgba(0,0,0,.06); }
.login-card { max-width: 420px; margin: 40px auto; }
.login-card label { display: block; margin: 16px 0; font-weight: 700; }
.login-card input[type=text], .login-card input[type=password], .login-card input[type=email], .login-card select {
  width: 100%; min-height: var(--tap); padding: 12px 16px; border-radius: 12px;
  border: 2px solid #e4e7ee; font-size: 1.1rem; font-family: inherit;
}
.login-card select { appearance: auto; background: #fff; cursor: pointer; }
.login-card input:focus, .login-card select:focus { outline: none; border-color: var(--primary); }
.login-card .field { margin: 16px 0; }
.login-card .field label { display: block; margin-bottom: 6px; font-weight: 700; }
.login-card ul.form-errors { color: var(--danger, #dc2626); font-size: .88rem; margin: 4px 0 0; list-style: none; padding: 0; }
.remember { font-weight: 400 !important; }
.hint { font-size: .9rem; color: var(--muted); margin-top: 18px; }

/* Subjects grid */
.subjects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; margin: 24px 0; }
.subject-card {
  display: block; background: var(--card); border-radius: var(--radius); padding: 22px;
  text-decoration: none; color: var(--text); box-shadow: 0 4px 14px rgba(0,0,0,.06);
  border-top: 5px solid var(--accent, var(--primary)); transition: transform .15s ease;
}
.subject-card:hover { transform: translateY(-3px); text-decoration: none; }
.subject-icon { font-size: 2.5rem; }
.progress-ring { margin: 10px 0; }
.progress-bar { background: #eef2ff; border-radius: 999px; height: 10px; overflow: hidden; }
.progress-bar .fill { background: var(--success); height: 100%; transition: width .4s ease; }
.progress-ring span { font-size: .85rem; color: var(--muted); }

/* Badges */
.badges { display: flex; flex-wrap: wrap; gap: 12px; }
.badge { background: var(--card); padding: 12px; border-radius: 16px; text-align: center; min-width: 120px; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.badge-icon { font-size: 2rem; }

/* Stages / Lessons list */
.stage { margin-bottom: 32px; }
.unit { background: var(--card); padding: 16px 20px; border-radius: var(--radius); margin: 12px 0; box-shadow: 0 2px 8px rgba(0,0,0,.05); }
.lesson-list { list-style: none; padding: 0; margin: 0; }
.lesson-item { padding: 10px 0; border-bottom: 1px dashed #eee; font-size: 1.05rem; }
.lesson-item:last-child { border-bottom: none; }
.lesson-item.done a { color: var(--success); }
.lesson-item.locked { color: var(--muted); }

/* Lesson page */
.lesson { background: var(--card); padding: 28px; border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,.06); }
.lesson-header h1 { margin: 8px 0; }
.objective { background: #fff7e0; padding: 10px 14px; border-radius: 12px; }
.back-link { display: inline-block; margin-bottom: 8px; color: var(--muted); }
.lesson-toolbar { display: flex; gap: 8px; margin: 12px 0; }
.lesson-sections .lesson-section { margin: 28px 0; }
.readable { font-size: 1.4rem; line-height: 1.7; }
.readable .tts-word { padding: 0 2px; border-radius: 4px; transition: background .1s; }
.readable .tts-word.active { background: #ffe28a; }
.phonics-grid { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; }
.phoneme-tile {
  min-width: 80px; min-height: 80px; border-radius: 18px; background: #eef4ff; border: none; cursor: pointer;
  font-family: inherit; box-shadow: 0 2px 6px rgba(0,0,0,.08); transition: transform .1s;
  display: inline-flex; align-items: center; justify-content: center; padding: 8px 14px;
}
.phoneme-tile:hover { transform: scale(1.05); background: #dde8ff; }
.phoneme-tile.playing { background: var(--accent); color: #fff; }
.letter-big { font-size: 1.6rem; font-weight: 700; white-space: nowrap; }
.word-grid { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; }
.word-card { background: #fff7e0; padding: 14px; border-radius: 16px; text-align: center; min-width: 110px; }
.word-emoji { font-size: 2.4rem; }
.word-text { font-size: 1.2rem; font-weight: 700; margin-top: 6px; }
.sentence-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.word-chip { background: #eef4ff; padding: 10px 16px; border-radius: 12px; font-size: 1.3rem; font-weight: 700; }
.big-emoji { font-size: 5rem; text-align: center; margin: 16px 0; }
.story-page { background: #fff7e0; padding: 18px; border-radius: 16px; margin: 12px 0; }
.story-text { text-align: center; }
.activity-list { list-style: '\1F449 '; padding-left: 28px; font-size: 1.2rem; }
.lesson-footer { text-align: center; margin-top: 24px; }

/* Quiz */
.quiz { background: var(--card); padding: 28px; border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,.06); }
.question { border: none; padding: 0; margin-bottom: 18px; }
.question legend { color: var(--muted); font-weight: 700; }
.qtext { font-size: 1.4rem; font-weight: 700; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choices-2 { grid-template-columns: 1fr 1fr; }
.choice { display: block; background: #eef4ff; padding: 18px; border-radius: 14px; cursor: pointer; min-height: var(--tap); font-size: 1.1rem; text-align: center; }
.choice:hover { background: #dde8ff; }
.choice input { margin-right: 8px; }
.fill { width: 100%; padding: 14px; border-radius: 12px; border: 2px solid #e4e7ee; font-size: 1.3rem; font-family: inherit; }
.fill:focus { outline: none; border-color: var(--primary); }
.qnav { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* Quiz result */
.quiz-result { background: var(--card); padding: 36px; border-radius: var(--radius); text-align: center; box-shadow: 0 4px 16px rgba(0,0,0,.06); }
.stars { font-size: 3rem; color: #ccc; margin: 12px 0; }
.stars .on { color: var(--accent); }
.big-score { font-size: 2rem; font-weight: 700; color: var(--primary-dark); }
.review { text-align: left; margin: 20px 0; }
.review li.correct { color: var(--success); }
.review li.wrong { color: var(--danger); }
.review .explain { background: #fff7e0; padding: 6px 10px; border-radius: 8px; color: var(--text); margin-top: 4px; }
.actions { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }

/* Table */
.data-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,.05); }
.data-table th, .data-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid #eef0f5; }
.data-table th { background: #eef4ff; font-weight: 700; }

/* Accessibility helpers */
.high-contrast { --bg: #000; --card: #111; --text: #fff; --muted: #ccc; }
.dyslexia { font-family: 'OpenDyslexic', 'Nunito', sans-serif; letter-spacing: .04em; line-height: 1.8; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
.shake { animation: shake .4s ease; border: 2px solid var(--danger) !important; border-radius: var(--radius); }

@media (max-width: 600px) {
  .choices { grid-template-columns: 1fr; }
  .hero h1 { font-size: 2rem; }
}
