:root {
  /* Brain Workout's palette is driven by the shared theme variables (theme.css) so the
     universal dark mode toggle and colour theme picker apply here too. --green/--red stay
     fixed across themes/modes so correct/wrong feedback keeps a consistent meaning. */
  --deep-blue: var(--theme-primary);
  --deep-blue-dark: var(--theme-primary-dark);
  --amber: var(--theme-accent);
  --amber-dark: var(--theme-accent-dark);
  --on-accent: var(--theme-primary-dark);
  --white: var(--surface);
  --off-white: var(--surface-alt);
  --green: #2e9e4a;
  --green-light: #e3f8e8;
  --red: #d64545;
  --red-light: #fbe4e4;
  --text-dark: var(--text-primary);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  background: linear-gradient(180deg, var(--deep-blue) 0%, var(--deep-blue-dark) 100%);
  color: var(--text-dark);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 720px;
  min-height: 100vh;
  background: var(--off-white);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  padding: 24px;
}

@media (min-width: 760px) {
  body {
    padding: 20px;
  }
  #app {
    min-height: 90vh;
    border-radius: 20px;
    margin: 20px auto;
  }
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 14px;
  font-weight: bold;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s ease;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

button:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--amber);
  color: var(--on-accent);
  min-height: 56px;
  font-size: 1.2rem;
  padding: 12px 28px;
}

.btn-primary:hover {
  background: var(--amber-dark);
}

.btn-secondary {
  background: var(--deep-blue);
  color: var(--white);
  min-height: 52px;
  font-size: 1.05rem;
  padding: 10px 24px;
}

.btn-secondary:hover {
  background: var(--deep-blue-dark);
}

.btn-danger {
  background: var(--red);
  color: var(--white);
  min-height: 48px;
  padding: 10px 20px;
  font-size: 1rem;
}

.pin-modal-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: 1000;
}

.pin-modal {
  background: var(--off-white);
  border-radius: 16px;
  padding: 24px;
  width: 90%;
  max-width: 320px;
  box-shadow: var(--shadow);
}

.pin-modal h3 {
  margin: 0 0 14px;
  color: var(--deep-blue);
}

.pin-modal input[type="password"] {
  width: 100%;
  box-sizing: border-box;
  min-height: 48px;
  font-size: 1.1rem;
  padding: 8px 12px;
  border: 2px solid var(--deep-blue);
  border-radius: 8px;
}

.pin-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  justify-content: flex-end;
}

/* ---------- HOME SCREEN ---------- */

.home-screen {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  flex: 1;
  justify-content: center;
}

.home-title {
  font-size: 2.6rem;
  color: var(--deep-blue);
  margin: 0;
}

.home-subtitle {
  font-size: 1.3rem;
  color: var(--amber-dark);
  margin: 0 0 10px 0;
  font-weight: bold;
}

.edit-name-btn {
  background: none;
  border: none;
  min-height: auto;
  padding: 0 0 0 4px;
  font-size: 0.9rem;
  cursor: pointer;
  vertical-align: middle;
}

.edit-name-btn:hover {
  transform: none;
  box-shadow: none;
  opacity: 0.7;
}

/* ---------- PROFILE PICKER SCREEN ---------- */

.profile-picker-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  text-align: center;
}

.profile-picker-screen h1 {
  color: var(--deep-blue);
  margin: 0;
}

.profile-grid {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
}

.profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: var(--white);
  border: 3px solid transparent;
  border-radius: 20px;
  padding: 22px 28px;
  box-shadow: var(--shadow);
  min-width: 140px;
}

.profile-card:disabled {
  opacity: 0.6;
}

.profile-emoji {
  font-size: 3rem;
}

.profile-name {
  font-weight: bold;
  font-size: 1.1rem;
  color: var(--deep-blue);
}

/* ---------- HOME FOOTER LINKS ---------- */

.home-footer-links {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 6px;
}

.footer-link-btn {
  background: none;
  border: none;
  min-height: auto;
  padding: 4px 8px;
  font-size: 0.85rem;
  color: #667;
  cursor: pointer;
}

.footer-link-btn:hover {
  transform: none;
  box-shadow: none;
  opacity: 0.7;
}

/* ---------- REWARDS SCREEN ---------- */

.reward-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.reward-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--white);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.reward-emoji {
  font-size: 1.8rem;
  flex-shrink: 0;
}

.reward-info {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.reward-name {
  font-weight: bold;
  color: var(--text-dark);
}

.reward-cost {
  font-size: 0.9rem;
  color: #666;
}

.reward-redeem-btn {
  flex-shrink: 0;
}

.reward-redeem-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- PARENT ZONE ---------- */

.parent-approve-actions {
  display: flex;
  gap: 6px;
}

.parent-approve-actions button {
  min-height: 36px;
  padding: 4px 12px;
  font-size: 1rem;
}

.reward-delete-btn {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 0.9rem;
}

.stats-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.stat-card {
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px 20px;
  min-width: 110px;
  flex: 1;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: bold;
  color: var(--deep-blue);
}

.stat-label {
  font-size: 0.95rem;
  color: #555;
  margin-top: 4px;
}

.reading-boost-note {
  font-size: 0.9rem;
  text-align: center;
  color: var(--deep-blue);
  opacity: 0.8;
  margin: 4px 0 2px;
}

.home-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 360px;
  margin-top: 12px;
}

/* ---------- SESSION HEADER / TIMER ---------- */

.session-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.timer-bar {
  background: var(--deep-blue);
  color: var(--white);
  border-radius: 14px;
  padding: 10px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.3rem;
  font-weight: bold;
  box-shadow: var(--shadow);
}

.timer-bar.low-time {
  background: var(--red);
  animation: pulse 1s infinite;
}

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

.part-indicator {
  font-size: 1rem;
  color: var(--deep-blue);
  font-weight: bold;
  text-align: center;
}

.progress-bar-track {
  width: 100%;
  height: 12px;
  background: #dde5f0;
  border-radius: 8px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--amber);
  transition: width 0.3s ease;
}

/* ---------- QUESTION SCREEN ---------- */

.question-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.question-card {
  background: var(--white);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  justify-content: center;
}

.question-text {
  font-size: 1.35rem;
  color: var(--text-dark);
  line-height: 1.4;
  margin: 0;
}

.passage-box {
  background: #fff8e8;
  border-left: 6px solid var(--amber);
  border-radius: 10px;
  padding: 16px 18px;
  font-size: 1.1rem;
  line-height: 1.5;
  margin-bottom: 10px;
}

.passage-title {
  font-weight: bold;
  color: var(--deep-blue);
  margin-bottom: 6px;
  font-size: 1.05rem;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 480px) {
  .options-grid {
    grid-template-columns: 1fr;
  }
}

.option-btn {
  background: var(--white);
  border: 3px solid var(--deep-blue);
  color: var(--deep-blue);
  min-height: 56px;
  font-size: 1.1rem;
  padding: 10px 14px;
}

.option-btn:hover {
  background: var(--deep-blue);
  color: var(--white);
}

.option-btn.selected {
  background: var(--amber);
  border-color: var(--amber-dark);
  color: var(--on-accent);
}

.text-input-row {
  display: flex;
  gap: 10px;
}

.text-input-row input {
  flex: 1;
  font-size: 1.2rem;
  padding: 12px 14px;
  border-radius: 12px;
  border: 3px solid var(--deep-blue);
  min-height: 52px;
}

.long-text-input {
  flex: 1;
  width: 100%;
  font-family: inherit;
  font-size: 1.1rem;
  padding: 12px 14px;
  border-radius: 12px;
  border: 3px solid var(--deep-blue);
  min-height: 120px;
  resize: vertical;
}

.word-count-hint {
  text-align: right;
  font-size: 0.9rem;
  color: var(--deep-blue);
  opacity: 0.65;
  margin-top: 4px;
}

.tf-row {
  display: flex;
  gap: 16px;
}

.tf-btn {
  flex: 1;
  min-height: 60px;
  font-size: 1.2rem;
  border: 3px solid var(--deep-blue);
  background: var(--white);
  color: var(--deep-blue);
}

.tf-btn:hover {
  background: var(--deep-blue);
  color: var(--white);
}

.tf-btn.selected {
  background: var(--amber);
  border-color: var(--amber-dark);
  color: var(--on-accent);
}

.odd-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.odd-btn {
  min-height: 64px;
  font-size: 1.15rem;
  border: 3px solid var(--deep-blue);
  background: var(--white);
  color: var(--deep-blue);
}

.odd-btn:hover {
  background: var(--deep-blue);
  color: var(--white);
}

.odd-btn.selected {
  background: var(--amber);
  border-color: var(--amber-dark);
  color: var(--on-accent);
}

.sequence-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 1.4rem;
  font-weight: bold;
  color: var(--deep-blue);
}

.sequence-blank-input {
  width: 70px;
  text-align: center;
  font-size: 1.3rem;
  padding: 8px;
  border-radius: 10px;
  border: 3px solid var(--amber-dark);
  min-height: 52px;
}

.submit-row {
  display: flex;
  justify-content: center;
  margin-top: 6px;
}

/* ---------- FEEDBACK ---------- */

.feedback-flash {
  border-radius: 18px;
  padding: 22px;
  text-align: center;
  font-size: 1.15rem;
  animation: flashIn 0.25s ease;
}

.feedback-flash.correct {
  background: var(--green-light);
  border: 3px solid var(--green);
  color: #1b6b30;
}

.feedback-flash.wrong {
  background: var(--red-light);
  border: 3px solid var(--red);
  color: #9c2b2b;
}

/* Writing feedback is effort-based, not right/wrong, so it gets its own tones - a neutral
   amber for "needs more" (not the failure-implying red) and the standard green tones for
   "good"/"great" - fixed hex rather than theme variables, same rationale as .correct/.wrong
   staying constant across themes. */
.feedback-flash.writing.needs_more {
  background: #fdf1dc;
  border: 3px solid #e8a13a;
  color: #8a5a12;
}

.feedback-flash.writing.good,
.feedback-flash.writing.great {
  background: var(--green-light);
  border: 3px solid var(--green);
  color: #1b6b30;
}

.writing-stats {
  font-size: 0.9rem;
  opacity: 0.75;
  margin-top: 4px;
}

.feedback-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 8px;
}

@keyframes flashIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* ---------- PART COMPLETE / SESSION COMPLETE ---------- */

.center-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 18px;
}

.big-score {
  font-size: 2.6rem;
  color: var(--deep-blue);
  font-weight: bold;
}

.stars-row {
  display: flex;
  gap: 10px;
  font-size: 3rem;
}

.star {
  opacity: 0.25;
  transform: scale(0.6);
  animation: starPop 0.5s ease forwards;
}

.star.earned {
  opacity: 1;
}

.star:nth-child(1) { animation-delay: 0.1s; }
.star:nth-child(2) { animation-delay: 0.35s; }
.star:nth-child(3) { animation-delay: 0.6s; }

@keyframes starPop {
  0% { transform: scale(0.4) rotate(-15deg); }
  60% { transform: scale(1.2) rotate(10deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.motivate-msg {
  font-size: 1.25rem;
  color: var(--amber-dark);
  font-weight: bold;
  max-width: 420px;
}

/* ---------- PROGRESS SCREEN ---------- */

.progress-screen {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.streak-banner {
  background: var(--deep-blue);
  color: var(--white);
  border-radius: 16px;
  padding: 18px;
  text-align: center;
  font-size: 1.6rem;
  font-weight: bold;
  box-shadow: var(--shadow);
}

.chart-box {
  background: var(--white);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.chart-title {
  font-weight: bold;
  color: var(--deep-blue);
  margin-bottom: 12px;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 140px;
  border-bottom: 2px solid #ccc;
  padding-bottom: 4px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}

.bar {
  width: 100%;
  background: var(--amber);
  border-radius: 4px 4px 0 0;
  min-height: 4px;
}

.bar-label {
  font-size: 0.65rem;
  color: #666;
  margin-top: 4px;
}

.weak-areas-box {
  background: var(--white);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.weak-area-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
  font-size: 1.05rem;
}

.weak-area-item:last-child {
  border-bottom: none;
}

.backup-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.backup-actions .btn-secondary {
  min-height: 44px;
  font-size: 0.9rem;
  padding: 8px 16px;
}

.interrupted-box {
  background: var(--red-light);
  border: 3px solid var(--red);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  color: #9c2b2b;
  font-size: 1.1rem;
}

.hidden {
  display: none !important;
}

.top-nav-back {
  align-self: flex-start;
  background: none;
  color: var(--deep-blue);
  font-weight: bold;
  font-size: 1rem;
  padding: 6px 4px;
  box-shadow: none;
}

.top-nav-back:hover {
  transform: none;
  text-decoration: underline;
}

/* ---------- LEVEL / COINS / BADGES ---------- */

.level-pill {
  background: var(--deep-blue);
  color: var(--white);
  font-size: 1rem;
  font-weight: bold;
  padding: 8px 16px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.coin-pill {
  background: var(--amber);
  color: var(--on-accent);
  border-radius: 14px;
  padding: 3px 10px;
  font-size: 0.95rem;
  font-weight: bold;
}

.badges-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 420px;
}

.badge-icon {
  font-size: 1.6rem;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--white);
  box-shadow: var(--shadow);
}

.badge-icon.locked {
  opacity: 0.25;
  filter: grayscale(1);
}

.combo-badge {
  align-self: center;
  background: var(--amber);
  color: var(--on-accent);
  font-weight: bold;
  border-radius: 14px;
  padding: 6px 16px;
  text-align: center;
  animation: comboPop 0.3s ease;
}

@keyframes comboPop {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.coin-earned {
  font-weight: bold;
  color: var(--amber-dark);
  margin-top: 8px;
  font-size: 1.1rem;
}

.coin-total-line {
  font-weight: bold;
  color: var(--amber-dark);
}

.badge-unlock-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.badge-unlock-item {
  background: #fff8e8;
  border: 2px solid var(--amber);
  border-radius: 12px;
  padding: 8px 16px;
  font-weight: bold;
  color: var(--deep-blue-dark);
  animation: starPop 0.5s ease;
}

/* ---------- BRAIN GAMES MENU ---------- */

.games-title {
  color: var(--deep-blue);
  text-align: center;
  margin: 4px 0 0 0;
}

.games-sub {
  text-align: center;
  color: #555;
  margin: 0 0 10px 0;
}

.game-card {
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color 0.15s ease, transform 0.08s ease;
}

.game-card:hover {
  border-color: var(--amber);
  transform: translateY(-2px);
}

.game-card-emoji {
  font-size: 2.4rem;
}

.game-card-name {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--deep-blue);
}

.game-card-meta {
  color: #666;
  font-size: 0.95rem;
}

/* ---------- SPEED ROUND ---------- */

.speed-timer-bar {
  background: var(--amber-dark);
}

.speed-question {
  font-size: 2rem;
  text-align: center;
  font-weight: bold;
  color: var(--deep-blue);
}

.speed-solved {
  text-align: center;
  color: var(--amber-dark);
  font-weight: bold;
}

.flash-correct-quick {
  animation: flashGreenQuick 0.35s ease;
}

.flash-wrong-quick {
  animation: flashRedQuick 0.35s ease;
}

@keyframes flashGreenQuick {
  0% { background: var(--green-light); }
  100% { background: var(--white); }
}

@keyframes flashRedQuick {
  0% { background: var(--red-light); }
  100% { background: var(--white); }
}

/* ---------- MEMORY MATCH ---------- */

.memory-stats {
  display: flex;
  justify-content: space-between;
  font-weight: bold;
  color: var(--deep-blue);
  font-size: 1.1rem;
  padding: 0 4px;
}

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

.memory-card {
  aspect-ratio: 1 / 1;
  background: var(--deep-blue);
  border-radius: 12px;
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, background 0.2s ease;
}

.memory-card.flipped {
  background: var(--white);
  border: 3px solid var(--amber);
  transform: rotateY(0deg) scale(1.03);
}

.memory-card.matched {
  background: var(--green-light);
  border: 3px solid var(--green);
  opacity: 0.85;
}

/* ---------- CONFETTI ---------- */

.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 999;
}

.confetti-piece {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  animation-name: confettiFall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}

@keyframes confettiFall {
  to { transform: translateY(110vh) rotate(360deg); opacity: 0.3; }
}
