* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: #e8ecff;
  background: radial-gradient(ellipse at top, #1a1040 0%, #0a0520 50%, #02010a 100%);
  overflow: hidden;
}
body { min-height: 100vh; overflow-y: auto; }

/* Animated stars */
#stars, #stars2, #stars3 {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
}
#stars {
  background-image:
    radial-gradient(2px 2px at 20% 30%, #fff, transparent),
    radial-gradient(1px 1px at 60% 70%, #fff, transparent),
    radial-gradient(1px 1px at 80% 10%, #aac, transparent),
    radial-gradient(2px 2px at 40% 80%, #fff, transparent),
    radial-gradient(1px 1px at 90% 50%, #fff, transparent),
    radial-gradient(1px 1px at 10% 60%, #ccf, transparent);
  background-size: 200% 200%;
  animation: drift 80s linear infinite;
}
#stars2 {
  background-image:
    radial-gradient(1px 1px at 15% 15%, #fff, transparent),
    radial-gradient(1px 1px at 75% 40%, #fff, transparent),
    radial-gradient(2px 2px at 35% 55%, #fff, transparent),
    radial-gradient(1px 1px at 55% 85%, #aaf, transparent);
  background-size: 300% 300%;
  animation: drift 120s linear infinite reverse;
  opacity: 0.6;
}
#stars3 {
  background:
    radial-gradient(circle at 70% 20%, rgba(120, 80, 200, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 20% 80%, rgba(80, 120, 220, 0.12) 0%, transparent 45%);
}
@keyframes drift {
  from { background-position: 0 0; }
  to { background-position: 200% 200%; }
}

#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
}

/* Screens */
.screen { display: none; position: relative; z-index: 1; }
.screen.active { display: flex; }

#welcome {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.welcome-card {
  background: rgba(20, 15, 45, 0.7);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(140, 120, 220, 0.3);
  border-radius: 24px;
  padding: 48px 40px;
  text-align: center;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(80, 40, 160, 0.3);
}
.logo {
  font-size: 80px;
  margin-bottom: 12px;
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.welcome-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
  background: linear-gradient(135deg, #a78bfa, #60a5fa, #34d399);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle { color: #b0b6d9; margin: 0 0 32px; }

.lang-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}
.lang-btn {
  padding: 16px 24px;
  font-size: 18px;
  border-radius: 16px;
  border: 1px solid rgba(140, 120, 220, 0.4);
  background: rgba(50, 30, 100, 0.5);
  color: #fff;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
}
.lang-btn:hover {
  background: rgba(90, 60, 180, 0.7);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(120, 80, 220, 0.4);
}

.ghost-btn {
  background: transparent;
  border: 1px solid rgba(180, 160, 240, 0.3);
  color: #c8ccf0;
  padding: 10px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
}
.ghost-btn.small { padding: 4px 10px; font-size: 12px; }
.ghost-btn:hover { background: rgba(120, 80, 220, 0.15); }

.primary-btn {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  border: none;
  color: #fff;
  padding: 10px 20px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}
.primary-btn:hover { filter: brightness(1.15); }

/* Main app */
#app {
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 16px;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  margin-bottom: 8px;
}
.top-left { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.logo-small { font-size: 24px; }
.app-name { font-size: 18px; }
.top-right { display: flex; align-items: center; gap: 8px; }
.xp-badge {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #1a0e00;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  gap: 4px;
  align-items: center;
  box-shadow: 0 4px 12px rgba(251, 191, 36, 0.3);
}
.streak-badge {
  background: linear-gradient(135deg, #ef4444, #f97316);
  color: #fff;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  gap: 3px;
  align-items: center;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}
.streak-badge.inactive {
  filter: grayscale(0.6) brightness(0.7);
}
.icon-btn {
  background: rgba(50, 30, 100, 0.5);
  border: 1px solid rgba(140, 120, 220, 0.3);
  color: #fff;
  width: 38px; height: 38px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 18px;
}
.icon-btn:hover { background: rgba(90, 60, 180, 0.7); }

/* Level bar */
.level-wrap {
  margin: 4px 12px 12px;
}
.level-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #c8ccf0;
  margin-bottom: 4px;
}
.level-bar {
  height: 8px;
  background: rgba(30, 20, 60, 0.8);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(140, 120, 220, 0.3);
}
.level-fill {
  height: 100%;
  background: linear-gradient(90deg, #a78bfa, #60a5fa, #34d399);
  width: 0%;
  transition: width 0.5s ease;
  border-radius: 999px;
}

.mood-bar {
  background: rgba(20, 15, 45, 0.6);
  border: 1px solid rgba(140, 120, 220, 0.25);
  border-radius: 16px;
  padding: 12px 16px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.mood-bar.hidden { display: none; }
.mood-label { font-size: 14px; color: #c8ccf0; }
.mood-options { display: flex; gap: 6px; }
.mood-opt {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 22px;
  padding: 4px 8px;
  cursor: pointer;
  transition: transform 0.15s;
}
.mood-opt:hover { transform: scale(1.2); }
.mood-opt.selected {
  background: rgba(120, 80, 220, 0.3);
  border-color: rgba(180, 160, 240, 0.6);
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 12px;
  scrollbar-width: thin;
}
.chips::-webkit-scrollbar { height: 6px; }
.chips::-webkit-scrollbar-thumb { background: rgba(140, 120, 220, 0.4); border-radius: 3px; }
.chip {
  flex-shrink: 0;
  background: rgba(30, 20, 60, 0.7);
  border: 1px solid rgba(140, 120, 220, 0.3);
  color: #e8ecff;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}
.chip:hover {
  background: rgba(120, 80, 220, 0.4);
  transform: translateY(-1px);
}
.chip.hidden { display: none; }

.chat {
  flex: 1;
  background: rgba(10, 5, 25, 0.5);
  border: 1px solid rgba(140, 120, 220, 0.2);
  border-radius: 16px;
  padding: 16px;
  overflow-y: auto;
  min-height: 280px;
  max-height: calc(100vh - 380px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.5;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble.user img {
  max-width: 220px;
  border-radius: 12px;
  margin-bottom: 6px;
  display: block;
}
.bubble.ai {
  align-self: flex-start;
  background: rgba(40, 30, 80, 0.8);
  border: 1px solid rgba(140, 120, 220, 0.3);
  border-bottom-left-radius: 4px;
}
.bubble.sys {
  align-self: center;
  background: rgba(251, 191, 36, 0.15);
  border: 1px solid rgba(251, 191, 36, 0.4);
  color: #fde68a;
  font-size: 13px;
  padding: 8px 14px;
}
.typing {
  align-self: flex-start;
  color: #b0b6d9;
  font-style: italic;
  padding: 8px 14px;
}

/* Image preview */
.image-preview {
  background: rgba(20, 15, 45, 0.8);
  border: 1px solid rgba(140, 120, 220, 0.4);
  border-radius: 12px;
  padding: 8px;
  margin-top: 8px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.image-preview.hidden { display: none; }
.image-preview img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
}
.preview-info {
  display: flex;
  gap: 10px;
  align-items: center;
  flex: 1;
  justify-content: space-between;
  font-size: 13px;
  color: #c8ccf0;
}

.composer {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}
.photo-btn {
  background: rgba(50, 30, 100, 0.6);
  border: 1px solid rgba(140, 120, 220, 0.4);
  color: #fff;
  width: 54px;
  height: 54px;
  border-radius: 16px;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
.photo-btn:hover {
  background: rgba(120, 80, 220, 0.7);
  transform: scale(1.05);
}
.composer input[type="text"] {
  flex: 1;
  background: rgba(20, 15, 45, 0.8);
  border: 1px solid rgba(140, 120, 220, 0.4);
  color: #fff;
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 16px;
  outline: none;
  min-width: 0;
}
.composer input[type="text"]:focus { border-color: rgba(180, 160, 240, 0.8); }
.send-btn {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  border: none;
  color: #fff;
  width: 54px;
  height: 54px;
  border-radius: 16px;
  font-size: 22px;
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn:hover { filter: brightness(1.15); }

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.active { display: flex; }
.modal-card {
  background: linear-gradient(180deg, #1a1040, #120828);
  border: 1px solid rgba(140, 120, 220, 0.4);
  border-radius: 20px;
  padding: 28px;
  max-width: 360px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal-card.wide { max-width: 520px; }
.modal-card h2 { margin-top: 0; font-size: 20px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.field > span { font-size: 13px; color: #c8ccf0; font-weight: 600; }
.field small { color: #8b90b8; font-size: 12px; }
.field input, .field textarea, .field select {
  background: rgba(10, 5, 25, 0.8);
  border: 1px solid rgba(140, 120, 220, 0.3);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: rgba(180, 160, 240, 0.8);
}
.toggles { display: flex; flex-wrap: wrap; gap: 10px; }
.toggles label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  background: rgba(30, 20, 60, 0.6);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
}

.curriculum-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0;
}
.curriculum-list:empty { display: none; }
.curriculum-thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(140, 120, 220, 0.4);
}
.curriculum-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.curriculum-thumb button {
  position: absolute;
  top: 2px; right: 2px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  line-height: 1;
}
.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  align-self: flex-start;
}

#pinModal .modal-card { text-align: center; }
#pinInput {
  font-size: 28px;
  text-align: center;
  letter-spacing: 8px;
  background: rgba(10, 5, 25, 0.8);
  border: 1px solid rgba(140, 120, 220, 0.4);
  color: #fff;
  padding: 14px;
  border-radius: 12px;
  width: 100%;
  margin: 12px 0;
  outline: none;
}
.error { color: #f87171; font-size: 13px; min-height: 18px; margin-bottom: 8px; }

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

/* Celebration */
.celebration {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.celebration.hidden { display: none; }
.celebration-card {
  background: linear-gradient(180deg, #2a1060, #140832);
  border: 2px solid rgba(251, 191, 36, 0.6);
  border-radius: 24px;
  padding: 40px 32px;
  text-align: center;
  max-width: 360px;
  box-shadow: 0 20px 80px rgba(251, 191, 36, 0.4);
  animation: pop 0.5s cubic-bezier(.2,.8,.2,1.2);
}
@keyframes pop {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.celebration-emoji {
  font-size: 72px;
  animation: bounce 0.8s ease-in-out infinite alternate;
}
@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-12px); }
}
.celebration-card h2 {
  margin: 12px 0 6px;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 28px;
}
.celebration-card p {
  color: #c8ccf0;
  margin: 0 0 20px;
}

@media (max-width: 600px) {
  .welcome-card { padding: 36px 24px; }
  .chat { max-height: calc(100vh - 420px); }
  .bubble { max-width: 92%; }
  .app-name { display: none; }
  .photo-btn, .send-btn { width: 46px; height: 46px; font-size: 20px; }
  .composer input[type="text"] { padding: 12px 14px; font-size: 15px; }
}
