* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  /* Tezos-inspired palette */
  --primary: #2C7BE5;         /* Tezos blue */
  --primary-light: #5EA0FF;
  --secondary: #00C2B8;       /* Tezos teal accent */
  --success: #00C2B8;
  --danger: #ef4444;
  --pink: #ec4899;
  --cyan: #06b6d4;
  --purple: #7B61FF;          /* complementary purple for accents */
  --bg-gradient-start: #f5fbff;
  --bg-gradient-end: #f0f7ff;
  --card-bg: #ffffff;
  --text-dark: #07273f;
  --text-light: #4b6b80;
  --shadow: 0 10px 40px rgba(16, 55, 90, 0.08);
  --radius: 20px;
  --gold: #d97706;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  min-height: 100vh;
  color: var(--text-dark);
  overflow-x: hidden;
}

/* SVG Icon System */
.svg-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.svg-icon svg {
  width: 100%;
  height: 100%;
}

.svg-icon-xs { width: 16px; height: 16px; }
.svg-icon-sm { width: 20px; height: 20px; }
.svg-icon-md { width: 24px; height: 24px; }
.svg-icon-lg { width: 32px; height: 32px; }
.svg-icon-xl { width: 48px; height: 48px; }
.svg-icon-2xl { width: 64px; height: 64px; }
.svg-icon-3xl { width: 96px; height: 96px; }
.svg-icon-4xl { width: 128px; height: 128px; }

/* Header */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--purple) 100%);
  padding: 15px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.3);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: white;
  font-weight: 700;
  font-size: 1.2rem;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: white;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-stats {
  display: flex;
  gap: 15px;
}

.stat-badge {
  background: rgba(255,255,255,0.2);
  padding: 8px 15px;
  border-radius: 20px;
  color: white;
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Mascot */
.mascot {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--secondary) 0%, var(--primary) 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 30px rgba(44, 123, 229, 0.18);
  cursor: pointer;
  transition: transform 0.3s, box-shadow 0.3s;
  z-index: 99;
  animation: bounce 2s ease-in-out infinite;
}

.mascot svg {
  width: 55px;
  height: 55px;
}

.mascot:hover {
  transform: scale(1.1);
  box-shadow: 0 12px 40px rgba(245, 158, 11, 0.5);
}

.mascot.celebrate {
  animation: celebrate 0.5s ease-in-out;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes celebrate {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.2) rotate(-10deg); }
  75% { transform: scale(1.2) rotate(10deg); }
}

.mascot-speech {
  position: fixed;
  bottom: 110px;
  right: 20px;
  background: white;
  padding: 15px 20px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  max-width: 250px;
  font-weight: 500;
  z-index: 99;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
}

.mascot-speech.show {
  opacity: 1;
  transform: translateY(0);
}

.mascot-speech::after {
  content: '';
  position: absolute;
  bottom: -10px;
  right: 30px;
  border: 10px solid transparent;
  border-top-color: white;
}

/* Navigation */
.nav-tabs {
  display: flex;
  gap: 10px;
  padding: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-tab {
  background: white;
  border: none;
  padding: 15px 25px;
  border-radius: 15px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s;
  white-space: nowrap;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-tab:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.1);
}

.nav-tab.active {
  background: linear-gradient(135deg, var(--primary) 0%, var(--purple) 100%);
  color: white;
}

.nav-tab .svg-icon svg {
  fill: currentColor;
}

/* Main Container */
.main-container {
  padding: 0 20px 100px;
  max-width: 1200px;
  margin: 0 auto;
}

.section {
  display: none;
}

.section.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Level Selection */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 15px;
  margin-bottom: 30px;
}

.level-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  position: relative;
  overflow: hidden;
}

.level-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 40px rgba(0,0,0,0.15);
}

.level-card.locked {
  opacity: 0.6;
  cursor: not-allowed;
}

.level-card.completed {
  border: 3px solid var(--success);
}

.level-card.current {
  border: 3px solid var(--primary);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
}

.level-number {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary) 0%, var(--purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.level-range {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-top: 5px;
}

.level-badge {
  position: absolute;
  top: 10px;
  right: 10px;
}

/* Game Area */
.game-card {
  background: white;
  border-radius: var(--radius);
  padding: 30px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 15px;
}

.game-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-progress {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-bar {
  width: 150px;
  height: 12px;
  background: #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success) 0%, var(--cyan) 100%);
  border-radius: 10px;
  transition: width 0.5s ease;
}

/* Counting Game */
.counting-area {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  justify-content: center;
  padding: 30px;
  background: linear-gradient(135deg, #fef9c3 0%, #fef3c7 100%);
  border-radius: 20px;
  min-height: 300px;
  margin-bottom: 20px;
}

.count-object {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, opacity 0.3s;
  animation: popIn 0.3s ease backwards;
}

.count-object svg {
  width: 100%;
  height: 100%;
}

.count-object:hover {
  transform: scale(1.2);
}

.count-object.counted {
  opacity: 0.3;
  transform: scale(0.8);
}

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

.count-display {
  text-align: center;
  font-size: 4rem;
  font-weight: 800;
  color: var(--primary);
  margin: 20px 0;
}

.count-buttons {
  display: flex;
  gap: 15px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Tracing Canvas */
.tracing-container {
  position: relative;
  background: white;
  border-radius: 20px;
  overflow: hidden;
  touch-action: none;
}

.tracing-canvas {
  width: 100%;
  height: 400px;
  cursor: crosshair;
  touch-action: none;
}

.tracing-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 15rem;
  font-weight: 900;
  color: rgba(99, 102, 241, 0.15);
  pointer-events: none;
  user-select: none;
}

.tracing-controls {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* Coloring */
.coloring-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.coloring-canvas {
  width: 100%;
  max-width: 500px;
  height: 400px;
  border-radius: 20px;
  cursor: crosshair;
  touch-action: none;
  background: white;
}

.color-palette {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.color-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 4px solid white;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.color-btn:hover, .color-btn.active {
  transform: scale(1.15);
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}

.brush-sizes {
  display: flex;
  gap: 10px;
  align-items: center;
}

.brush-btn {
  background: var(--text-dark);
  border-radius: 50%;
  border: 3px solid white;
  cursor: pointer;
  transition: transform 0.2s;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.brush-btn:hover, .brush-btn.active {
  transform: scale(1.2);
}

/* Buttons */
.btn {
  padding: 15px 30px;
  border: none;
  border-radius: 15px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn .svg-icon {
  width: 20px;
  height: 20px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--purple) 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
  background: white;
  color: var(--text-dark);
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

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

.btn-success {
  background: linear-gradient(135deg, var(--success) 0%, var(--cyan) 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(16, 185, 129, 0.4);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger) 0%, #f97316 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(239, 68, 68, 0.4);
}

/* Badges Section */
.badges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 20px;
}

.badge-item {
  background: white;
  border-radius: 20px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  transition: transform 0.3s;
}

.badge-item:hover {
  transform: translateY(-5px);
}

.badge-item.locked {
  opacity: 0.4;
  filter: grayscale(1);
}

.badge-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 10px;
}

.badge-icon svg {
  width: 100%;
  height: 100%;
}

.badge-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-dark);
}

.badge-desc {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 5px;
}

/* Leaderboard */
.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px 20px;
  background: white;
  border-radius: 15px;
  margin-bottom: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.leaderboard-item.current-user {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
  border: 2px solid var(--primary);
}

.rank {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.rank-1 { background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%); color: white; }
.rank-2 { background: linear-gradient(135deg, #9ca3af 0%, #6b7280 100%); color: white; }
.rank-3 { background: linear-gradient(135deg, #d97706 0%, #b45309 100%); color: white; }
.rank-default { background: #e2e8f0; color: var(--text-dark); }

.player-info {
  flex: 1;
}

.player-name {
  font-weight: 600;
}

.player-level {
  font-size: 0.85rem;
}
.player-score {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Certificate */
.certificate-container {
  background: linear-gradient(135deg, #fef3c7 0%, #fef9c3 50%, #fef3c7 100%);
  border: 8px solid var(--secondary);
  border-radius: 20px;
  padding: 40px;
  text-align: center;
  position: relative;
  max-width: 600px;
  margin: 0 auto;
}

.certificate-border {
  position: absolute;
  inset: 15px;
  border: 3px solid var(--secondary);
  border-radius: 12px;
  pointer-events: none;
}

.certificate-title {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary) 0%, var(--purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 10px;
}

.certificate-subtitle {
  font-size: 1.2rem;
  color: var(--text-light);
  margin-bottom: 30px;
}

.certificate-name {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 20px;
  padding: 10px 0;
  border-bottom: 2px dashed var(--secondary);
}

.certificate-achievement {
  font-size: 1.1rem;
  color: var(--text-dark);
  margin-bottom: 30px;
}

.certificate-date {
  font-size: 0.9rem;
  color: var(--text-light);
}

.certificate-seal {
  width: 80px;
  height: 80px;
  margin: 20px auto;
}

.certificate-seal svg {
  width: 100%;
  height: 100%;
}

.fractal-hash {
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--text-light);
  word-break: break-all;
  margin-top: 20px;
  padding: 10px;
  background: rgba(0,0,0,0.05);
  border-radius: 10px;
}

/* Dashboard */
.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.dashboard-card {
  background: white;
  border-radius: var(--radius);
  padding: 25px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.dashboard-card-title {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 10px;
}

.dashboard-card-value {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary) 0%, var(--purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.dashboard-card-icon {
  width: 40px;
  height: 40px;
  margin-bottom: 15px;
}

.dashboard-card-icon svg {
  width: 100%;
  height: 100%;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-overlay.show {
  display: flex;
  animation: fadeIn 0.3s ease;
}

.modal-content {
  background: white;
  border-radius: var(--radius);
  padding: 30px;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-light);
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 20px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

/* Confetti */
.confetti {
  position: fixed;
  pointer-events: none;
  z-index: 300;
}

/* Timer */
.timer {
  font-size: 2rem;
  font-weight: 700;
  color: var(--danger);
  text-align: center;
  margin-bottom: 20px;
}

/* Input */
.input {
  width: 100%;
  padding: 15px 20px;
  border: 2px solid #e2e8f0;
  border-radius: 15px;
  font-size: 1rem;
  transition: border-color 0.3s;
  margin-bottom: 15px;
}

.input:focus {
  outline: none;
  border-color: var(--primary);
}

/* Added file input styling */
.file-input-wrapper {
  position: relative;
  overflow: hidden;
  display: inline-block;
}

.file-input-wrapper input[type=file] {
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* Added settings panel styling */
.settings-panel {
  background: #f8fafc;
  border-radius: 15px;
  padding: 20px;
  margin-top: 20px;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 0;
  border-bottom: 1px solid #e2e8f0;
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-label {
  font-weight: 600;
  color: var(--text-dark);
}

.settings-desc {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 3px;
}

.toggle-switch {
  position: relative;
  width: 50px;
  height: 26px;
  background: #e2e8f0;
  border-radius: 13px;
  cursor: pointer;
  transition: background 0.3s;
}

.toggle-switch.active {
  background: var(--success);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.3s;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.toggle-switch.active::after {
  transform: translateX(24px);
}

/* Added download cards styling */
.download-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-top: 20px;
}

.download-card {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
  border-radius: 15px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  border: 2px solid transparent;
}

.download-card:hover {
  border-color: var(--primary);
  transform: translateY(-3px);
}

.download-card-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 10px;
}

.download-card-icon svg {
  width: 100%;
  height: 100%;
}

.download-card-title {
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 5px;
}

.download-card-desc {
  font-size: 0.8rem;
  color: var(--text-light);
}

/* Responsive */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    gap: 10px;
  }
  
  .game-card {
    padding: 20px;
  }
  
  .tracing-guide {
    font-size: 10rem;
  }
  
  .certificate-container {
    padding: 25px;
  }
  
  .certificate-title {
    font-size: 1.8rem;
  }
}

/* Number Practice Grid */
.number-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 8px;
  margin-top: 20px;
}

.number-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.number-cell:hover {
  transform: scale(1.1);
  z-index: 1;
}

.number-cell.completed {
  background: linear-gradient(135deg, var(--success) 0%, var(--cyan) 100%);
  color: white;
}

.number-cell.current {
  background: linear-gradient(135deg, var(--primary) 0%, var(--purple) 100%);
  color: white;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(99, 102, 241, 0); }
}

/* Unlocked badge modal icon */
#unlockedBadgeIcon {
  width: 120px;
  height: 120px;
  margin: 20px auto;
}

#unlockedBadgeIcon svg {
  width: 100%;
  height: 100%;
}

/* Added welcome modal styling */
.welcome-modal .modal-content {
  max-width: 450px;
  text-align: center;
}

.welcome-mascot {
  width: 120px;
  height: 120px;
  margin: 0 auto 20px;
  background: linear-gradient(135deg, var(--secondary) 0%, #f97316 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.welcome-mascot svg {
  width: 80px;
  height: 80px;
}

.welcome-title {
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary) 0%, var(--purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 10px;
}

.welcome-text {
  color: var(--text-light);
  margin-bottom: 25px;
  line-height: 1.6;
}

.welcome-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Added custom image preview */
.custom-image-preview {
  width: 100%;
  max-width: 200px;
  height: 150px;
  border: 3px dashed #e2e8f0;
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 15px auto;
  overflow: hidden;
  background: #f8fafc;
}

.custom-image-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.custom-image-preview.has-image {
  border-style: solid;
  border-color: var(--success);
}