/* ===== CSS VARIABLES ===== */
:root {
  --ink: #16324f;
  --brand: #1565c0;
  --good: #00c853;
  --bad: #ff5252;
  --shadow: 0 6px 18px rgba(0,0,0,0.08);
  --nav-font-size: 30px;
  --card-title-font-size: 32px;
  --test-label-font-size: 48px;
}

/* ===== GLOBAL STYLES ===== */
* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow-x: auto;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Nunito', ui-rounded, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--ink);
  background: #17a0fe;
  display: flex;
  flex-direction: column;
  min-height: 100vh; /* Use min-height instead of fixed height */
  overflow-x: hidden; /* Only prevent horizontal overflow */
  overflow-y: auto; /* Allow vertical scrolling when needed */
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* App container using CSS Grid for better control */
#app {
  flex: 1; /* Take remaining space in flex container */
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-areas: 
    "header"
    "main";
  min-height: 0; /* Allow flex item to shrink */
}

[hidden] {
  display: none !important;
}

/* ===== HEADER STYLES ===== */
.app-header {
  grid-area: header;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 12px;
  position: sticky;
  top: 0;
  background: #293b96;
  border-bottom: none;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  /* Allows the title to take up remaining space */
  flex: 1;
  /* Add wrapping for very small screens */
  flex-wrap: wrap; 
  gap: 16px;
}

.app-header .title-container {
  /* Remove fixed width */
  width: auto; 
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  margin-right: 6px;
  width: 67px;
  height: 67px;
  border-radius: 50%;
  -webkit-user-select: none;
  user-select: none;
  transition: transform 0.1s ease;
  z-index: 1;
}

.brand-mark svg {
  width: 100%;
  height: 100%;
  display: block;
}

.brand-mark:active {
  transform: scale(0.96);
}


.title-chimps {
  flex-shrink: 0;
}

.brand-title {
  font-family: 'Baloo 2', cursive;
  font-weight: 800;
  font-size: 48px;
  margin: 0;
  line-height: 1;
  letter-spacing: 0.5px;
  color: #2e6bf6;
  background: transparent;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  -webkit-text-stroke: 6px #ffffff;
  paint-order: stroke fill;
  text-shadow:
    -2px -2px 0 #ffffff,
     2px -2px 0 #ffffff,
    -2px  2px 0 #ffffff,
     2px  2px 0 #ffffff,
     0px  3px 0 rgba(0,0,0,0.15);
}

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

.nav-link {
  color: #ffffff;
  font-weight: 800;
  font-size: var(--nav-font-size);
  text-decoration: none;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  transition: text-shadow 200ms ease, transform 0.1s ease;
}

.nav-link:hover {
  text-decoration: none;
  text-shadow: 0 0 8px rgba(255,255,255,0.8), 0 0 16px rgba(255,255,255,0.6);
}

/* ===== TEACHER INDICATOR ===== */
.teacher-indicator {
  color: #4caf50;
  font-weight: 800;
  font-size: 18px;
  padding: 8px 12px;
  background: rgba(76, 175, 80, 0.1);
  border: 2px solid #4caf50;
  border-radius: 20px;
  margin-right: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.1);
  box-shadow: 0 2px 4px rgba(76, 175, 80, 0.2);
  transition: all 0.2s ease;
}

.teacher-indicator[hidden] {
  display: none !important;
}

.teacher-indicator:hover {
  background: rgba(76, 175, 80, 0.2);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(76, 175, 80, 0.3);
}

/* ===== HUD STYLES ===== */
.hud {
  display: flex;
  align-items: center;
  gap: 16px;
}

.meter {
  min-width: 220px;
}

.meter-label {
  font-size: 12px;
  color: #fcfcfc;
  margin-bottom: 2px;
}

.meter-bar {
  width: 100%;
  height: 14px;
  background: rgba(255,255,255,.6);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.06);
  border: 2px solid rgba(13,71,161,.15);
}

.meter-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg,#fff200,#ffe000,#ffc400);
  transition: width .3s ease;
}







/* ===== MAIN LAYOUT ===== */
.app-main {
  grid-area: main;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 4px 20px 0 20px;
  -webkit-user-select: none;
  user-select: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  display: grid;
  place-items: center; /* Default centering for most screens */
  min-height: 0; /* Allow grid item to shrink */
}

/* Override for Lists screen - use full width and stretch alignment */
body.lists-screen .app-main {
  max-width: none;
  place-items: stretch; /* Fill available space for lists */
  padding: 4px 4px 0 4px;
}

/* Override for Game screen - center content */
body.game-screen .app-main {
  max-width: none;
  place-items: center; /* Center content for games */
}

/* Game screen specific optimizations */
body.game-screen .game-area {
  margin: 20px 0;
}

body.game-screen .letter-slots {
  margin-bottom: 20px;
}


/* Override for Voice screen - settings-optimized layout */
body.voice-screen .app-main {
  max-width: 800px;
  place-items: center;
  padding: 20px;
}

/* Voice screen specific optimizations */
body.voice-screen .settings-container {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

body.voice-screen .card {
  padding: 24px;
  margin-bottom: 16px;
}

body.voice-screen .form-field {
  margin-bottom: 20px;
}

body.voice-screen .voice-dropdown {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: white;
}

body.voice-screen .primary-btn {
  width: 100%;
  padding: 12px 24px;
  font-size: 16px;
}

/* Override for Settings screens - configuration-optimized layout */
body.settings-screen .app-main {
  max-width: 1000px;
  place-items: center;
  padding: 20px;
}

/* Home screen specific optimizations */
body:not(.lists-screen):not(.game-screen):not(.voice-screen) .app-main {
  /* Default home screen layout - already handled by base .app-main */
}

/* Layout is now handled by CSS Grid - no JavaScript classes needed */

/* ===== SCREEN STYLES ===== */
.screen {
  width: 100%;
  height: 100%;
}

/* Removed unused .screen-title selector */

/* .home-header class removed - not used in HTML */

.page-title {
  margin: 0;
  font-size: 42px;
  font-family: 'Baloo 2', 'Comic Sans MS', cursive, sans-serif;
  font-weight: 800;
  color: #293b96 !important;
  letter-spacing: .5px;
  text-transform: none;
  text-shadow: 2px 2px 4px rgba(41,59,150,.2);
  text-align: center;
}

.test-card-label {
  margin: 12px 0 0 0;
  font-size: var(--test-label-font-size);
  font-family: 'Baloo 2', 'Comic Sans MS', cursive, sans-serif;
  font-weight: 700;
  color: #293b96;
  text-align: center;
  max-width: 100%;
  text-shadow: 1px 1px 2px rgba(41,59,150,.15);
}

/* ===== CARDS ===== */

/* Home screen - Vertical grid for multiple wordlist groups */
#homeScreen {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 1fr;
  grid-auto-rows: auto;
  gap: 30px;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: center;
  justify-items: center;
}

/* Each wordlist group (heading + cards) in its own row */
#homeScreen .wordlist-row {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "heading cards";
  gap: 20px;
  width: 100%;
  background: transparent !important;
  align-items: center;
}

/* Title container for each wordlist group */
#homeScreen .wordlist-row .title-container {
  grid-area: heading;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-width: 200px;
  padding: 20px;
  background: #17a0fe;
  border-radius: 12px;
}

/* Cards container for each wordlist group */
#homeScreen .wordlist-row .cards-container {
  grid-area: cards;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  align-items: center;
  justify-items: center;
}

#homeScreen .wordlist-row:hover {
  background: transparent !important;
}

/* ===== MAIN CONTENT TITLE CONTAINER STYLES ===== */
/* Title styles are now handled in the aside layout above */

#homeScreen .wordlist-row .unit-title, 
#homeScreen .wordlist-row .week-title {
  margin: 0;
  font-size: 42px;
  font-family: 'Baloo 2', 'Comic Sans MS', cursive, sans-serif;
  font-weight: 800;
  color: #2e6bf6 !important;
  letter-spacing: .5px;
  text-transform: none;
  text-align: left;
  line-height: 1;
  -webkit-text-stroke: 6px #ffffff;
  paint-order: stroke fill;
  text-shadow:
    -2px -2px 0 #ffffff,
     2px -2px 0 #ffffff,
    -2px  2px 0 #ffffff,
     2px  2px 0 #ffffff,
     0px  3px 0 rgba(0,0,0,0.15);
}

/* ===== SVG CARDS ===== */
.card-container {
  flex: 0 0 auto;
  min-width: 240px;
  max-width: 280px;
  width: 260px;
  position: relative;
}

.game-card-svg {
  width: 100%;
  height: auto;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
  -webkit-user-select: none;
  user-select: none;
  border-radius: 16px;
  pointer-events: auto;
  display: block;
  /* Ensure minimum touch target size for accessibility */
  min-height: 44px;
  min-width: 44px;
}

.game-card-svg:hover {
  transform: translateY(-2px);
  filter: brightness(1.02);
}

.game-card-svg:hover .card-background {
  stroke: #90caf9;
}

.game-card-svg:active {
  transform: translateY(0px) scale(0.98);
}

/* Card level labels */
.card-level-label {
  font-family: 'Nunito', ui-rounded, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 26px;
  font-weight: 800;
  color: #1a237e;
  text-align: center;
  margin-top: 8px;
  -webkit-user-select: none;
  user-select: none;
  display: block;
  width: 100%;
}

/* ===== UPLOAD INSTRUCTIONS ===== */
.upload-instruction {
  width: 100%;
  background: linear-gradient(180deg, #f8f9ff 0%, #e8f5e8 100%);
  border: 3px dashed #81c784;
  border-radius: 16px;
  padding: 40px 20px;
  text-align: center;
  max-width: 500px;
  margin: 0 auto;
}

.upload-instruction .upload-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.upload-instruction h3 {
  font-family: 'Baloo 2', cursive;
  font-weight: 700;
  font-size: 24px;
  color: #2e7d32;
  margin: 0 0 12px;
}

.upload-instruction p {
  font-size: 16px;
  color: #1b5e20;
  margin: 0;
  line-height: 1.5;
}

/* ===== GAME STYLES ===== */
.game-header {
  padding: 8px 0 12px 0;
}

.game-progress {
  font-size: 18px;
  color: #000000;
  font-weight: 700;
  text-align: center;
  width: 100%;
  display: block;
}


.letter-slots {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 5px;
  margin: 0;
}

.slot {
  width: clamp(35px, 30vw, 80px);
  height: clamp(35px, 30vw, 80px);
  border-radius: 8px;
  background: #e3f2fd;
  border: 2px dashed #bbdefb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(18px, 18vw, 48px);
  font-weight: 800;
  color: #7c75a8;
  position: relative;
  box-sizing: border-box;
}

.slot.filled {
  border-style: solid;
  background: #fff;
  color: var(--ink);
  border-color: #90caf9;
}

.hint-letter {
  position: absolute;
  font-size: clamp(18px, 18vw, 48px);
  font-weight: 800;
  color: #d0d0d0;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

.slot.filled .hint-letter {
  display: none;
}

.letter-bank {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  padding: 5px;
  margin: 0;
  align-items: center;
}

.tile {
  -webkit-user-select: none;
  user-select: none;
  background: #fff;
  border-radius: 8px;
  width: clamp(35px, 30vw, 80px);
  height: clamp(35px, 30vw, 80px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(18px, 18vw, 48px);
  font-weight: 900;
  border: 2px solid #90caf9;
  box-shadow: var(--shadow);
  cursor: grab;
  transition: transform .12s ease, box-shadow .12s ease, border .12s ease;
  box-sizing: border-box;
}

.tile:active {
  cursor: grabbing;
  transform: scale(.98);
}

.tile.wrong {
  animation: shake .3s ease;
  border-color: var(--bad);
}

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

/* ===== GAME SCREENS ===== */
#gameScreen {
  width: 100%;
  padding: 10px 5px 5px 5px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 35px;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 0; /* Allow flex item to shrink */
  -webkit-user-select: none;
  user-select: none;
  overflow-y: auto; /* Enable scrolling when content exceeds viewport */
}

.game-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

#finalTestScreen {
  width: 100%;
  max-width: none;
  padding: 10px 5px 5px 5px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-items: center;
  justify-content: flex-start;
  flex: 1;
  min-height: 0; /* Allow flex item to shrink */
  -webkit-user-select: none;
  user-select: none;
  overflow-y: auto; /* Enable scrolling when content exceeds viewport */
}

/* ===== BUTTONS ===== */
/* Base button styles - shared by all button types */
.primary-btn, .secondary-btn, .repeat-btn {
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 800;
  letter-spacing: .3px;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  border: 3px solid transparent;
  -webkit-user-select: none;
  user-select: none;
  font-family: 'Nunito', ui-rounded, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
  transition: transform 0.2s ease;
}

/* Primary button - blue gradient */
.primary-btn {
  background: linear-gradient(90deg,#1e88e5,#42a5f5);
  color: #fff;
}

.primary-btn:disabled {
  filter: grayscale(.6) brightness(.9);
  cursor: not-allowed;
}

/* Secondary and repeat buttons - white with blue border */
.secondary-btn, .repeat-btn {
  background: #fff;
  border-color: #90caf9;
  color: #0d47a1;
  border-radius: 999px;
}

/* Shared hover and active states */
.primary-btn:hover:not(:disabled),
.secondary-btn:hover,
.repeat-btn:hover {
  transform: translateY(-1px);
}

.primary-btn:active:not(:disabled),
.secondary-btn:active,
.repeat-btn:active {
  transform: scale(.98);
}

.repeat-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  width: 100%;
  margin-bottom: 20px;
}

#finalTestScreen .repeat-controls {
  margin-bottom: 20px;
}

#finalTestScreen .game-controls {
  margin-top: 20px;
}

/* ===== VIRTUAL KEYBOARD STYLES ===== */
.virtual-keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 15px 10px;
  background: #17a0fe;
  border-radius: 12px;
}

.keyboard-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.keyboard-key {
  -webkit-user-select: none;
  user-select: none;
  background: #fff;
  border-radius: 8px;
  width: 60px !important;
  height: 60px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px !important;
  font-weight: 700;
  color: var(--ink);
  border: 2px solid #90caf9;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, border .12s ease, background-color .12s ease;
  box-sizing: border-box;
  font-family: inherit;
  outline: none;
}

.keyboard-key:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.15);
  border-color: #64b5f6;
  background: #f8f9fa;
}

.keyboard-key:active {
  transform: scale(.95);
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.keyboard-key:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--shadow);
  border-color: #e0e0e0;
  background: #f5f5f5;
}

.keyboard-key:disabled:hover {
  transform: none;
  box-shadow: var(--shadow);
  border-color: #e0e0e0;
  background: #f5f5f5;
}

.keyboard-backspace {
  background: #ffebee;
  border-color: #ffcdd2;
  color: #d32f2f;
  font-weight: 800;
}

.keyboard-backspace:hover {
  background: #ffcdd2;
  border-color: #ef9a9a;
}

.keyboard-backspace:active {
  background: #ef9a9a;
}

/* Spacing between keyboard and controls */
.keyboard-controls-spacing {
  height: 20px;
  width: 100%;
}

/* Responsive adjustments for very small screens */
@media (max-width: 480px) {
  .virtual-keyboard {
    padding: 10px 5px;
    gap: 6px;
  }
  
  .keyboard-row {
    gap: 4px;
  }
  
  .keyboard-key {
    width: 60px !important;
    height: 60px !important;
    font-size: 20px !important;
  }
  
  .keyboard-controls-spacing {
    height: 15px;
  }
}

/* Responsive adjustments for larger screens */
@media (min-width: 768px) {
  .virtual-keyboard {
    padding: 20px 15px;
    gap: 10px;
  }
  
  .keyboard-row {
    gap: 8px;
  }
  
  .keyboard-key {
    width: 60px !important;
    height: 60px !important;
    font-size: 20px !important;
  }
  
  .keyboard-controls-spacing {
    height: 25px;
  }
}

/* ===== DIALOGS ===== */
.dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: none;
  border-radius: 24px;
  padding: 0;
  box-shadow: 0 30px 80px rgba(0,0,0,0.3);
  max-width: 90vw;
  max-height: 90vh;
  z-index: 1000;
  margin: 0;
}

/* Modal backdrop styling */
.dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.dialog-content {
  padding: 48px 40px;
  min-width: 400px;
  text-align: center;
}

.dialog-content h2 {
  font-size: 42px;
  margin: 16px 0 24px;
  font-weight: 800;
  color: #1f3fb6;
}

/* Smaller font size for confirmation dialog title */
#confirmDialog .dialog-content h2 {
  font-size: 28px;
  margin: 14px 0 18px;
  font-weight: 700;
}



.dialog-actions {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

/* 3-button layout for Level 2 dialog */
.dialog-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.dialog-actions .primary-btn,
.dialog-actions .secondary-btn {
  font-size: 16px;
  padding: 12px 20px;
  flex: 1;
  min-width: 140px;
  max-width: 200px;
  text-align: center;
  justify-content: center;
}

/* Score display in winner dialog */
.score-display {
  text-align: center;
  margin: 20px 0;
  padding: 20px;
  background: linear-gradient(135deg, #e8f5e8 0%, #f1f8e9 100%);
  border-radius: 16px;
  border: 3px solid #81c784;
}

#winnerDialog .score-percentage {
  font-size: 32px !important;
  font-weight: 800 !important;
  color: #1F3FB6 !important;
  font-family: 'Nunito', sans-serif !important;
  text-shadow: 2px 2px 4px rgba(31, 63, 182, 0.2);
  margin-bottom: 8px;
}

#winnerDialog .score-label {
  font-size: 32px !important;
  font-weight: 800 !important;
  color: #1F3FB6 !important;
  font-family: 'Nunito', sans-serif !important;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ===== EFFECTS LAYER ===== */
.fx-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 1000;
  overflow: hidden;
}

/* ===== BALLOON STYLES ===== */
.balloon {
  position: absolute;
  width: 40px;
  height: 50px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  pointer-events: none;
  z-index: 1001;
}

@keyframes float-up {
  0% {
    transform: translateY(0) translateX(0);
    opacity: 1;
  }
  100% {
    transform: translateY(calc(-100vh - 100px)) translateX(var(--drift, 0));
    opacity: 0;
  }
}

/* ===== CONFETTI STYLES ===== */
.confetti {
  position: absolute;
  width: 6px;
  height: 8px;
  background: #ff7675;
  pointer-events: none;
  z-index: 1002;
  border-radius: 2px;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(-10vh) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(calc(100vh + 50px)) rotate(720deg);
    opacity: 0;
  }
}

/* ===== BALLOON POP EFFECTS ===== */
.pop-ring {
  position: absolute;
  width: 20px;
  height: 20px;
  border: 3px solid #ff6b6b;
  border-radius: 50%;
  pointer-events: none;
  z-index: 1003;
  animation: pop-ring-expand 0.6s ease-out forwards;
  transform: translate(-50%, -50%);
}

@keyframes pop-ring-expand {
  0% {
    transform: translate(-50%, -50%) scale(0);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(3);
    opacity: 0;
  }
}

.confetti-pop {
  position: absolute;
  width: 4px;
  height: 4px;
  background: #ff7675;
  pointer-events: none;
  z-index: 1004;
  border-radius: 1px;
  animation: confetti-pop-burst 0.8s ease-out forwards;
  transform: translate(-50%, -50%);
}

@keyframes confetti-pop-burst {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0);
    opacity: 0;
  }
}

/* ===== CONFIGURATION PAGES ===== */
.settings-container {
  max-width: 800px;
  width: 100%;
  flex: 1;
  min-height: 0; /* Allow flex item to shrink */
  margin: 0 auto;
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto; /* Enable scrolling when content exceeds viewport */
}

/* ===== LISTS MANAGEMENT PAGE ===== */
.lists-page-container {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-areas: 
    "header"
    "content";
  width: 100%;
  max-width: 6000px;
  margin: 0 auto;
  padding: 8px;
  height: 100%;
}

.lists-header {
  grid-area: header;
  text-align: center;
  margin-bottom: 6px;
  padding: 6px 0;
}

.lists-header .page-title {
  margin: 0;
  font-size: 36px;
  font-family: 'Baloo 2', cursive;
  font-weight: 800;
  color: #293b96;
}

.lists-main-content {
  grid-area: content;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 0 300px;
  overflow-y: auto;
  min-height: 0; /* Allow grid item to shrink */
}

.wordlists-panel {
  background: #ffffff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 12px;
  overflow-y: auto;
  box-shadow: var(--shadow);
  max-height: 60vh; /* Limit height to 60% of viewport height */
  min-height: 300px; /* Ensure minimum usable height */
}

.preview-panel {
  background: #ffffff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 12px;
  overflow-y: auto;
  box-shadow: var(--shadow);
  max-height: 60vh; /* Limit height to 60% of viewport height */
  min-height: 300px; /* Ensure minimum usable height */
}





/* Wordlists Table Styles */
.wordlists-table {
  width: 100%;
}

/* Table Headers */
.wordlist-header-row {
  display: flex;
  align-items: center;
  padding: 4px 6px;
  border-bottom: 1px solid #ddd;
  background-color: #f8f9fa;
  font-weight: 800;
  color: #555;
  font-size: 18px;
  text-transform: none;
  letter-spacing: 0.3px;
}

.wordlist-header-description {
  flex: 1;
  text-align: left;
  padding: 4px 6px;
}



/* Wordlists Screen: Data table rows */
#wordlistsScreen .wordlists-table .wordlist-row {
  display: flex;
  align-items: center;
  padding: 3px 6px;
  border-bottom: 1px solid #e0e0e0;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

/* Removed hover background for home page compatibility */

/* Selected wordlist styling - default green style */


/* Wordlists Screen: Auto-selected styling - items selected automatically in Auto mode */
#wordlistsScreen .wordlists-table .wordlist-row.selected.auto-selected {
  background-color: #e8f5e8;  /* Light green for auto-selected */
  border-left: 4px solid #4caf50;  /* Green border for auto-selected */
}

#wordlistsScreen .wordlists-table .wordlist-row.selected.auto-selected .wordlist-description {
  font-weight: 800;
  font-size: 18px;
  color: #2e7d32;  /* Darker green text for auto-selected */
}

/* Wordlists Screen: Current week styling - special indicator for auto-selected current week */
#wordlistsScreen .wordlists-table .wordlist-row.selected.current-week {
  background-color: #e3f2fd;  /* Light blue for current week */
  border-left: 4px solid #2196f3;  /* Blue border for current week */
}

#wordlistsScreen .wordlists-table .wordlist-row.selected.current-week .wordlist-description {
  font-weight: 900;  /* Extra bold for current week */
  color: #1976d2;  /* Darker blue text for current week */
}

/* Wordlists Screen: Manual-selected styling - items selected manually in Manual mode */
#wordlistsScreen .wordlists-table .wordlist-row.selected.manual-selected {
  background-color: #fff3e0;  /* Light orange for manual-selected */
  border-left: 4px solid #ff9800;  /* Orange border for manual-selected */
}

#wordlistsScreen .wordlists-table .wordlist-row.selected.manual-selected .wordlist-description {
  font-weight: 800;
  font-size: 18px;
  color: #e65100;  /* Darker orange text for manual-selected */
}



.wordlists-table .wordlist-description {
  flex: 1;
  font-weight: 600;
  color: #333;
  padding: 3px 6px;
  font-size: 13px;
  text-align: left;
}





/* Preview Panel Styles */
.preview-content {
  height: 100%;
}

.preview-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #999;
  font-style: italic;
  text-align: center;
}

.preview-columns {
  display: flex;
  gap: 12px;
  height: 100%;
}

.preview-column {
  flex: 1;
  min-width: 0; /* Allow column to shrink */
  text-align: center;
}

.preview-column-header {
  background: #f8f9fa;
  padding: 6px 8px;
  border-radius: 6px;
  margin-bottom: 8px;
  font-weight: 800;
  color: #333;
  text-align: center;
  border: 1px solid #e9ecef;
  font-size: 18px;
}

.preview-words-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.preview-word-item {
  padding: 4px 8px;
  border-bottom: 1px solid #f0f0f0;
  color: #555;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
}

.preview-word-item:nth-child(even) {
  background-color: #f9f9f9;
}

.no-wordlists {
  text-align: center;
  color: #999;
  font-style: italic;
  padding: 40px 20px;
}

/* Admin Elements Removed - Replaced with Reset Button */

/* ===== LISTS MANAGEMENT RESPONSIVE ===== */
@media (max-width: 768px) {
  .lists-main-content {
    grid-template-columns: 1fr; /* Single column on tablet */
    gap: 12px;
    padding: 0 50px; /* Reduced padding for tablet */
    overflow: hidden; /* Maintain overflow control on tablet */
  }
  
  .wordlists-panel,
  .preview-panel {
    min-height: 200px;
    max-height: 50vh; /* Reduced height for tablet */
  }
  
  #homeScreen .wordlist-row,
  #wordlistsScreen .wordlist-row {
    padding: 2px 4px;
  }
  
  .preview-columns {
    flex-direction: column;
    gap: 8px;
  }
  
  .reset-btn {
    padding: 12px 24px;
    font-size: 16px;
  }
  
  .reset-section {
    padding: 18px 0;
    flex-shrink: 0; /* Maintain flex-shrink on tablet */
  }
}

@media (max-width: 480px) {
  .lists-page-container {
    padding: 4px;
  }
  
  .lists-header .page-title {
    font-size: 24px;
  }
  
  .lists-header {
    padding: 4px 0;
    margin-bottom: 4px;
  }
  
  .lists-main-content {
    padding: 0 20px; /* Minimal padding for mobile */
    overflow: hidden; /* Maintain overflow control on mobile */
  }
  
  #homeScreen .wordlist-row,
  #wordlistsScreen .wordlist-row {
    padding: 2px 4px;
  }
  
  .wordlist-description {
    font-size: 11px;
  }
  
  .wordlist-header-row {
    font-size: 14px;
    padding: 2px 4px;
  }
  
  .reset-section {
    flex-shrink: 0; /* Maintain flex-shrink on mobile */
  }
}

.card {
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
  text-align: center;
  margin-bottom: 24px;
  background: linear-gradient(180deg, #ffffff 0%, #f8f9ff 100%);
  border: 3px solid #bbdefb;
}


.card h3 {
  font-family: 'Baloo 2', cursive;
  font-weight: 700;
  font-size: var(--card-title-font-size);
  color: #1f3fb6;
  margin: 0 0 12px;
}


.card p {
  font-size: 16px;
  color: #102a56;
  margin-bottom: 20px;
}


.form-field {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.form-field label {
  font-weight: 600;
  color: #1f3fb6;
  font-size: 16px;
}

.voice-dropdown {
  width: 100%;
  padding: 12px 16px;
  border: 3px solid #bbdefb;
  border-radius: 12px;
  font-size: 16px;
  font-family: 'Nunito', sans-serif;
  background: white;
  color: #1f3fb6;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.voice-dropdown:focus {
  outline: none;
  border-color: #42a5f5;
  box-shadow: 0 0 0 3px rgba(66, 165, 245, 0.1);
}

.voice-dropdown:hover {
  border-color: #90caf9;
}

.form-field input {
  padding: 12px 16px;
  border: 2px solid #90caf9;
  border-radius: 8px;
  font-size: 16px;
  width: 200px;
  text-align: center;
  font-family: monospace;
  letter-spacing: 1px;
}

.form-field input:focus {
  outline: none;
  border-color: #42a5f5;
  box-shadow: 0 0 0 3px rgba(66, 165, 245, 0.2);
}

.form-field input::placeholder {
  color: #d0d0d0;
  opacity: 1;
}



.message {
  border-radius: 8px;
  padding: 8px 16px;
  margin-top: 12px;
  font-weight: 600;
  border: 2px solid;
}




/* ===== MODE TOGGLE SWITCH ===== */
.mode-selector {
  padding: 16px 0 0 0;
  text-align: center;
  margin-bottom: 20px;
}

.mode-toggle-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.mode-label {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  font-family: 'Nunito', sans-serif;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
  cursor: pointer;
}

.toggle-switch input[type="checkbox"] {
  opacity: 0 !important;
  width: 0 !important;
  height: 0 !important;
  position: absolute !important;
  pointer-events: none !important;
  border: none !important;
  padding: 0 !important;
  margin: 0 !important;
}

.toggle-slider {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #007bff;
  border-radius: 34px;
  transition: all 0.3s ease;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  border-radius: 50%;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-switch input[type="checkbox"]:checked + .toggle-slider {
  background-color: #dc3545;
}

.toggle-switch input[type="checkbox"]:checked + .toggle-slider:before {
  transform: translateX(26px);
}

.toggle-switch:hover .toggle-slider {
  box-shadow: 0 0 8px rgba(0,123,255,0.3);
}

.toggle-switch input[type="checkbox"]:checked:hover + .toggle-slider {
  box-shadow: 0 0 8px rgba(220,53,69,0.3);
}

/* ===== RESET BUTTON INTERFACE ===== */
.reset-section {
  padding: 0 0 0 0;
  text-align: center;
  margin-top: auto; /* Push to bottom of container */
  background: transparent;
  flex-shrink: 0; /* Prevent reset section from shrinking */
}

.reset-btn {
  background: linear-gradient(90deg, #ff7043, #ff5722);
  color: white;
  border: none;
  padding: 15px 30px;
  font-size: 18px;
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 3px 6px rgba(255, 112, 67, 0.3);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: 'Nunito', ui-rounded, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

.reset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(255, 112, 67, 0.4);
  background: linear-gradient(90deg, #ff5722, #f4511e);
}

.reset-btn:active {
  transform: translateY(0);
}

.reset-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  opacity: 0.6;
}

.reset-description {
  margin: 12px 0 0 0;
  font-size: 14px;
  color: #1a237e;
  font-style: italic;
}

/* ===== SETTINGS BUTTON OVERRIDES ===== */
#testVoiceBtn {
  padding: 8px 12px;
  font-size: 14px;
  border-radius: 8px;
  margin-top: 15px;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Large tablets and small desktops - 2 card columns */
@media (max-width: 900px) {
  
  #homeScreen {
    gap: 16px;
    padding: 16px;
  }
}

/* Tablets - 2 card columns */
@media (max-width: 768px) {
  .page-title {
    text-align: center;
    font-size: 32px;
    margin-bottom: 12px;
  }
  
  /* Fix header title container width on tablets */
  .app-header .title-container {
    width: auto;
    max-width: 100%;
    flex-shrink: 1;
  }
  
  #homeScreen {
    gap: 16px;
    padding: 16px;
  }
  
  .app-main {
    padding: 2px 16px 0 16px;
    overflow-y: auto;
  }
  
  /* Dialog responsive adjustments for tablets */
  .dialog {
    max-width: 85vw;
    max-height: 80vh;
  }
  
  .dialog-content {
    padding: 40px 32px;
    min-width: 350px;
  }
  
  .dialog-content h2 {
    font-size: 36px;
    margin: 14px 0 22px;
  }
  
  .test-card-label {
    font-size: var(--test-label-font-size);
    margin: 8px 0 0 0;
  }
  
  /* Force cards to stack on tablets if space is limited */
  #homeScreen .wordlist-row .cards-container {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

/* Mobile - stack heading and cards vertically within each group */
@media (max-width: 600px) {
  /* Fix header title container width on mobile */
  .app-header .title-container {
    width: auto;
    max-width: 100%;
    flex-shrink: 1;
  }
  
  #homeScreen {
    gap: 20px;
    padding: 12px;
    height: auto; /* Allow natural height on mobile */
    min-height: auto; /* Remove height constraints on mobile */
  }
  
  #homeScreen .wordlist-row {
    grid-template-columns: 1fr;
    grid-template-areas: "heading" "cards";
    gap: 0px;
  }
  
  #homeScreen .wordlist-row .title-container {
    min-width: auto;
    text-align: center;
    margin-bottom: 20px !important;
    background: red !important;
  }
  
  /* Ensure cards stack in single column on mobile */
  #homeScreen .wordlist-row .cards-container {
    grid-template-columns: 1fr !important;
    justify-items: center;
    gap: 20px !important;
  }
}

@media (max-width: 480px) {
  /* Fix header title container width on very small screens */
  .app-header .title-container {
    width: auto;
    max-width: 100%;
    flex-shrink: 1;
  }
  
  .page-title {
    font-size: 28px;
  }
  
  .test-card-label {
    font-size: var(--test-label-font-size);
    margin: 6px 0 0 0;
  }
  
  .app-main {
    padding: 2px 12px 0 12px;
    overflow-y: auto;
  }
  
  #homeScreen {
    gap: 20px;
    padding: 12px;
    height: auto;
    min-height: auto;
  }
  
  #homeScreen .wordlist-row {
    grid-template-columns: 1fr;
    grid-template-areas: "heading" "cards";
    gap: 0px;
  }
  
  #homeScreen .wordlist-row .title-container {
    margin-bottom: 20px !important;
  }
  
  /* Force single column layout on very small screens */
  #homeScreen .wordlist-row .cards-container {
    grid-template-columns: 1fr !important;
    gap: 20px !important;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  .game-card-svg:hover {
    transform: none;
    filter: none;
  }
  
  .game-card-svg:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
  }
  
  /* Enhanced touch feedback for all interactive elements */
  .primary-btn:active,
  .secondary-btn:active,
  .repeat-btn:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
  
  .key-btn:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
  }
  
  .nav-link:active {
    transform: scale(0.98);
  }
  
  .brand-mark:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
  }
}

/* iOS-specific optimizations */
@supports (-webkit-touch-callout: none) {
  /* iOS Safari specific fixes */
  .game-card-svg {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Improve iOS text rendering */
  .card-level-label,
  .unit-title,
  .week-title {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  
  /* Fix iOS viewport issues */
  body {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* iOS-specific button optimizations */
  .primary-btn,
  .secondary-btn,
  .repeat-btn {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
  }
}

/* Mobile responsive adjustments */
@media (max-width: 480px) {
  .dialog {
    max-width: 95vw;
    max-height: 85vh;
    /* Note: Centering properties inherited from base .dialog class */
  }
  
  .dialog-content {
    padding: 32px 24px;
    min-width: 300px;
  }
  
  .dialog-content h2 {
    font-size: 32px;
    margin: 12px 0 20px;
  }
  
  .dialog-actions {
    gap: 8px;
  }
  
  .dialog-actions .primary-btn,
  .dialog-actions .secondary-btn {
    font-size: 14px;
    padding: 10px 16px;
    min-width: 120px;
    max-width: 160px;
  }
}

/* Safe area support for notched devices */
@supports (width: max(100vw, 100vh)) {
  .app-main {
    padding-top: max(4px, env(safe-area-inset-top));
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    padding-bottom: max(40px, env(safe-area-inset-bottom));
  }
  
  .app-header {
    padding-top: max(4px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  
  /* Ensure content doesn't get hidden behind home indicator */
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Media query for smaller mobile devices */
@media (max-width: 600px) {
  /* Reduce header font size */
  .brand-title {
    font-size: 32px;
  }
  
  /* Reduce navigation font size */
  .nav-link {
    font-size: 18px;
    padding: 8px 10px;
  }
  
  /* Reduce gap between brand logo and title */
  .brand {
    gap: 8px;
  }
}