/* --- Core Theme Variables --- */
:root {
  --font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  
  /* Color Palette */
  --bg-color: hsl(36, 25%, 97%);         /* Soft off-white / Cream */
  --text-main: hsl(210, 17%, 21%);        /* Dark Slate */
  --text-secondary: hsl(45, 5%, 41%);   /* Medium Taupe */
  --primary-color: hsl(205, 27%, 40%);   /* Earthy Blue */
  --primary-light: hsl(205, 30%, 93%);
  --success-color: hsl(145, 29%, 43%);   /* Soft Forest Green */
  --success-light: hsl(145, 30%, 93%);
  --warning-color: hsl(27, 67%, 56%);   /* Warm Amber */
  --warning-light: hsl(27, 70%, 93%);
  
  --primary-glow: hsla(205, 27%, 40%, 0.15);
  --success-glow: hsla(145, 29%, 43%, 0.15);
  --warning-glow: hsla(27, 67%, 56%, 0.15);
  
  --card-bg: #ffffff;
  --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.03), 0 2px 8px rgba(0, 0, 0, 0.01);
  --card-shadow-hover: 0 20px 40px -12px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(205, 27%, 40%, 0.1);
  
  --border-radius-lg: 20px;
  --border-radius-md: 14px;
  --border-radius-sm: 10px;
  
  --transition-smooth: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
  --transition-elastic: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* --- Base Layout & Accessibility --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Golden Accessibility Outline Ring */
*:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px #ffffff, 0 0 0 6px var(--primary-color) !important;
}

body {
  font-family: var(--font-family);
  background: linear-gradient(135deg, hsl(36, 30%, 98%) 0%, hsl(205, 40%, 96%) 100%);
  background-attachment: fixed;
  color: var(--text-main);
  line-height: 1.6;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

.container {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* --- Header & Branding --- */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--primary-light);
  padding-bottom: 20px;
  margin-top: 12px;
}

header h1 {
  font-size: 1.9rem;
  color: var(--primary-color);
  font-weight: 700;
  letter-spacing: -0.5px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.child-badge {
  background-color: var(--primary-light);
  color: var(--primary-color);
  padding: 6px 16px;
  border-radius: 24px;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 2px 6px rgba(205, 27%, 40%, 0.05);
  transition: var(--transition-smooth);
}

.child-badge:hover {
  transform: translateY(-1px);
  background-color: var(--primary-color);
  color: white;
}

/* --- Card Styles --- */
.card {
  background-color: var(--card-bg);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--card-shadow);
  padding: 36px;
  border: 1px solid rgba(205, 27%, 40%, 0.06);
  display: flex;
  flex-direction: column;
  gap: 22px;
  transition: var(--transition-elastic);
}

.card:hover {
  transform: translateY(-6px);
  box-shadow: var(--card-shadow-hover);
}

/* --- Buttons --- */
.btn {
  font-family: var(--font-family);
  font-size: 1.1rem;
  font-weight: 600;
  padding: 12px 28px;
  border-radius: var(--border-radius-md);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.2), 
              background-color 0.2s ease, 
              box-shadow 0.2s ease;
  min-height: 48px; /* Touch Target Compliance */
  text-decoration: none;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.03);
}

.btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

.btn:active {
  transform: translateY(1px) scale(0.97);
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background-color: hsl(205, 27%, 34%);
}

.btn-secondary {
  background-color: var(--primary-light);
  color: var(--primary-color);
}

.btn-secondary:hover {
  background-color: hsl(205, 30%, 88%);
}

.btn-success {
  background-color: var(--success-color);
  color: white;
}

.btn-success:hover {
  background-color: hsl(145, 29%, 36%);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Custom Components UI --- */

/* Ten Frame */
.ten-frame-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 480px;
  margin: 20px auto;
  aspect-ratio: 5 / 2;
}

.ten-frame-cell {
  background-color: var(--bg-color);
  border: 3px dashed var(--primary-color);
  border-radius: var(--border-radius-md);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-elastic);
  position: relative;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.ten-frame-cell:hover {
  background-color: var(--primary-light);
  transform: scale(1.05);
  border-style: solid;
}

.ten-frame-counter {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--warning-color) 0%, hsl(27, 67%, 45%) 100%);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.16);
  animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ten-frame-cell.filled {
  border-style: solid;
}

/* Hundred Chart Component */
.hundred-chart-container {
  width: 100%;
  max-width: 560px;
  margin: 16px auto;
  overflow-x: auto;
}

.hundred-chart-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
  width: 100%;
}

.hundred-chart-cell {
  min-width: 48px;
  min-height: 48px;
  aspect-ratio: 1;
  background-color: var(--card-bg);
  border: 2px solid var(--primary-light);
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-main);
  cursor: pointer;
  user-select: none;
  transition: var(--transition-elastic);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
}

.hundred-chart-cell:hover {
  transform: scale(1.08);
  border-color: var(--primary-color);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.hundred-chart-cell.selected {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  box-shadow: 0 4px 12px var(--primary-glow);
}

.hundred-chart-cell.highlighted {
  background-color: var(--warning-light);
  border-color: var(--warning-color);
  color: var(--warning-color);
}

.hundred-chart-cell.selected.highlighted {
  background-color: var(--warning-color);
  color: white;
}

.hundred-chart-cell.even {
  border-bottom: 3px solid var(--primary-color);
}

.hundred-chart-cell.odd {
  border-bottom: 3px dashed var(--warning-color);
}

/* Number Line */
.number-line-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  padding: 28px 16px;
  position: relative;
}

.number-line-rail {
  height: 10px;
  background-color: var(--primary-light);
  border-radius: 5px;
  position: relative;
  width: 100%;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.05);
}

.number-line-notches {
  position: absolute;
  top: -8px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.number-line-notch {
  width: 4px;
  height: 26px;
  background-color: var(--primary-color);
  border-radius: 2px;
}

.number-line-points {
  position: absolute;
  top: -16px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
}

.number-line-point {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background-color: white;
  border: 3.5px solid var(--primary-color);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--primary-color);
  transform: translateX(-45%);
  transition: var(--transition-elastic);
  box-shadow: 0 4px 8px rgba(0,0,0,0.05);
}

.number-line-point:hover, .number-line-point.active {
  background-color: var(--primary-color);
  color: white;
  transform: scale(1.18) translateX(-40%);
  box-shadow: 0 8px 16px var(--primary-glow);
}

.number-line-labels {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-top: 14px;
}

.number-line-label {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 1.15rem;
  width: 0;
  display: flex;
  justify-content: center;
}

/* Drag Counter */
.drag-workspace {
  display: flex;
  flex-direction: column;
  gap: 28px;
  align-items: center;
  width: 100%;
}

.drag-source {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  justify-content: center;
  padding: 20px;
  border-radius: var(--border-radius-md);
  min-height: 110px;
  width: 100%;
  background-color: var(--bg-color);
  border: 1px solid rgba(0,0,0,0.02);
}

.draggable-item {
  width: 64px;
  height: 64px;
  cursor: grab;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  user-select: none;
}

.draggable-item:active {
  cursor: grabbing;
  transform: scale(1.2) rotate(5deg);
}

.drop-target-basket {
  width: 280px;
  height: 190px;
  border: 4px dashed var(--primary-color);
  border-radius: var(--border-radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background-color: white;
  transition: var(--transition-elastic);
  position: relative;
  box-shadow: 0 4px 12px rgba(0,0,0,0.02);
}

.drop-target-basket.drag-over {
  background-color: var(--primary-light);
  border-style: solid;
  transform: scale(1.04);
  box-shadow: 0 10px 24px var(--primary-glow);
  animation: pulseBasket 1.2s infinite ease-in-out;
}

.basket-count {
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--primary-color);
}

/* --- Parent Guide Drawer --- */
.parent-guide-details {
  border: 2px solid var(--primary-light);
  border-radius: var(--border-radius-lg);
  background-color: var(--card-bg);
  overflow: hidden;
  transition: var(--transition-smooth);
  width: 100%;
}

.parent-guide-summary {
  list-style: none;
  padding: 22px 26px;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--primary-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  background-color: var(--primary-light);
  transition: background-color 0.2s ease;
}

.parent-guide-summary:hover {
  background-color: hsl(205, 30%, 88%);
}

.parent-guide-summary::-webkit-details-marker {
  display: none;
}

.parent-guide-summary::after {
  content: "💡 Open Parent Educator Guide";
  font-size: 0.95rem;
}

.parent-guide-details[open] .parent-guide-summary::after {
  content: "✖ Close Guide";
}

.parent-guide-content {
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  border-top: 1px solid var(--primary-light);
}

.parent-guide-content h3 {
  font-size: 1.35rem;
  color: var(--primary-color);
  margin-top: 10px;
}

.parent-guide-content p, .parent-guide-content li {
  color: var(--text-main);
  font-size: 1.05rem;
}

.parent-guide-content ul {
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* --- Quiz Runner Component --- */
.quiz-runner-container {
  display: flex;
  flex-direction: column;
  gap: 26px;
  width: 100%;
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.quiz-mode-pill {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 6px 14px;
  border-radius: 14px;
  letter-spacing: 0.6px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.03);
}

.quiz-mode-pill.practice {
  background-color: var(--warning-light);
  color: var(--warning-color);
}

.quiz-mode-pill.test {
  background-color: var(--primary-light);
  color: var(--primary-color);
}

.quiz-progress-dots {
  display: flex;
  gap: 10px;
}

.quiz-progress-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: var(--primary-light);
  transition: var(--transition-elastic);
}

.quiz-progress-dot.active {
  background-color: var(--primary-color);
  transform: scale(1.25);
  box-shadow: 0 0 8px var(--primary-glow);
}

.quiz-progress-dot.correct {
  background-color: var(--success-color);
}

.quiz-progress-dot.incorrect {
  background-color: var(--warning-color);
}

.quiz-prompt {
  font-size: 1.45rem;
  font-weight: 600;
  text-align: center;
  margin: 16px 0;
  line-height: 1.5;
}

.quiz-options-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 18px;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
}

.quiz-option-btn {
  background-color: var(--bg-color);
  border: 3.5px solid var(--primary-light);
  border-radius: var(--border-radius-md);
  aspect-ratio: 1;
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--primary-color);
  cursor: pointer;
  transition: var(--transition-elastic);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 8px rgba(0,0,0,0.02);
}

.quiz-option-btn:hover {
  border-color: var(--primary-color);
  transform: translateY(-4px) scale(1.06);
  box-shadow: 0 10px 20px var(--primary-glow);
}

.quiz-feedback {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
  border-radius: var(--border-radius-md);
  padding: 8px 20px;
  opacity: 0;
  transform: translateY(12px);
  transition: var(--transition-elastic);
}

.quiz-feedback.show {
  opacity: 1;
  transform: translateY(0);
}

.quiz-feedback.success {
  background-color: var(--success-light);
  color: var(--success-color);
}

.quiz-feedback.error {
  background-color: var(--warning-light);
  color: var(--warning-color);
}

.quiz-feedback.shake {
  animation: shake 0.4s;
}

.quiz-actions {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 18px;
}

/* --- Mastery Badge --- */
.mastery-badge-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 18px auto;
}

.mastery-badge-svg {
  width: 110px;
  height: 110px;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.08));
  transition: var(--transition-elastic);
}

.mastery-badge-svg.mastered {
  animation: shineSpin 2.5s ease-in-out infinite alternate;
}

/* --- Dashboard Styles --- */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 24px;
  width: 100%;
}

.dashboard-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.04);
}

.dashboard-card.mastered {
  border-top: 5px solid var(--success-color);
}

.dashboard-card.attempted {
  border-top: 5px solid var(--warning-color);
}

.dashboard-card.unlocked {
  border-top: 5px solid var(--primary-light);
}

.dashboard-card-status {
  position: absolute;
  top: 18px;
  right: 18px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.dashboard-card-status.mastered {
  background-color: var(--success-light);
  color: var(--success-color);
}

.dashboard-card-status.attempted {
  background-color: var(--warning-light);
  color: var(--warning-color);
}

.dashboard-card-status.unlocked {
  background-color: var(--primary-light);
  color: var(--primary-color);
}

/* --- Keyframe Animations --- */
@keyframes popIn {
  0% { transform: scale(0); }
  75% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}

@keyframes shineSpin {
  0% { transform: rotate(-6deg) scale(1); filter: drop-shadow(0 4px 8px rgba(217, 136, 69, 0.15)); }
  100% { transform: rotate(6deg) scale(1.06); filter: drop-shadow(0 10px 20px rgba(217, 136, 69, 0.45)); }
}

@keyframes pulseBasket {
  0% { transform: scale(1.04); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1.04); }
}

/* Utility Animations */
.animate-pop {
  animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.animate-shake {
  animation: shake 0.4s;
}

/* Responsive Overrides */
@media(max-width: 600px) {
  body { padding: 14px; }
  .card { padding: 22px; }
  .quiz-option-btn { font-size: 1.6rem; }
  header h1 { font-size: 1.6rem; }
}

/* --- Parent Neurodiversity & Sensory Assist Modes --- */
body.dyslexia-mode,
body.dyslexia-mode *,
html.dyslexia-mode,
html.dyslexia-mode * {
  letter-spacing: 0.11em !important;
  word-spacing: 0.16em !important;
  line-height: 1.8 !important;
}

body.warm-mode {
  filter: sepia(0.32) contrast(0.96) saturate(0.9) !important;
}

/* --- High-Contrast & Colorblind Theme Modes (Issue #22) --- */

/* High Contrast Mode */
body.high-contrast-mode,
[data-theme="high-contrast"] {
  --bg-color: #ffffff;
  --text-main: #000000;
  --text-secondary: #111111;
  --primary-color: #002b80;
  --primary-light: #e6f0ff;
  --success-color: #006600;
  --success-light: #e6ffe6;
  --warning-color: #802b00;
  --warning-light: #fff0e6;
  --card-bg: #ffffff;
  --card-shadow: 0 0 0 3px #000000;
  --card-shadow-hover: 0 0 0 4px #002b80;
}

body.high-contrast-mode .card,
[data-theme="high-contrast"] .card {
  border: 3px solid #000000 !important;
}

body.high-contrast-mode .btn,
[data-theme="high-contrast"] .btn {
  border: 2px solid #000000 !important;
}

/* Deuteranopia (Red-Green Color Blindness - Green-blindness) Mode */
body.deuteranopia-mode,
[data-theme="deuteranopia"] {
  --primary-color: hsl(210, 75%, 40%);     /* Deep Cobalt Blue */
  --primary-light: hsl(210, 75%, 93%);
  --success-color: hsl(190, 85%, 32%);     /* Deep Teal / Cyan */
  --success-light: hsl(190, 85%, 92%);
  --warning-color: hsl(40, 95%, 44%);      /* Deep Amber Gold */
  --warning-light: hsl(40, 95%, 93%);
}

/* Protanopia (Red-Green Color Blindness - Red-blindness) Mode */
body.protanopia-mode,
[data-theme="protanopia"] {
  --primary-color: hsl(220, 70%, 42%);     /* Vibrant Royal Blue */
  --primary-light: hsl(220, 70%, 93%);
  --success-color: hsl(175, 80%, 30%);     /* Emerald Teal */
  --success-light: hsl(175, 80%, 92%);
  --warning-color: hsl(45, 90%, 42%);      /* Pure Yellow-Gold */
  --warning-light: hsl(45, 90%, 93%);
}

/* --- Non-Color Correctness Indicators (Pattern Overlays & Icons) --- */

/* Option Buttons Correct/Incorrect Visual Badging */
.quiz-option-btn.correct,
.btn-option.correct {
  border: 3px solid var(--success-color) !important;
  position: relative;
}

.quiz-option-btn.correct::after,
.btn-option.correct::after {
  content: " ✓";
  font-weight: 900;
  color: var(--success-color);
  margin-left: 8px;
}

.quiz-option-btn.incorrect,
.btn-option.incorrect {
  border: 3px dashed var(--warning-color) !important;
  position: relative;
}

.quiz-option-btn.incorrect::after,
.btn-option.incorrect::after {
  content: " ✕";
  font-weight: 900;
  color: var(--warning-color);
  margin-left: 8px;
}

/* Feedback Box Patterning & Indicators */
.feedback-box.correct {
  border-left: 8px solid var(--success-color) !important;
  background-image: repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(0,0,0,0.015) 10px, rgba(0,0,0,0.015) 20px);
}

.feedback-box.incorrect {
  border-left: 8px dashed var(--warning-color) !important;
}

