/* ============================================================
   Brain Adventure — Main Stylesheet
   Aesthetic: Playful pastel adventure with bold accents
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Nunito:wght@400;600;700;800&display=swap');

/* ---- TOKENS ---- */
:root {
  --sky:       #e8f4fd;
  --mint:      #d4f5e9;
  --lemon:     #fef9c3;
  --blush:     #fde8f0;
  --lavender:  #ede9fe;

  --blue:      #3b82f6;
  --blue-d:    #2563eb;
  --green:     #10b981;
  --green-d:   #059669;
  --yellow:    #f59e0b;
  --pink:      #ec4899;
  --purple:    #8b5cf6;
  --red:       #ef4444;

  --text:      #1e293b;
  --text-soft: #64748b;
  --bg:        #f0f9ff;
  --card:      #ffffff;
  --border:    #e2e8f0;
  --shadow:    0 4px 24px rgba(59,130,246,.12);
  --shadow-lg: 0 8px 40px rgba(59,130,246,.18);

  --radius:    1.2rem;
  --radius-sm: .8rem;

  --font-head: 'Fredoka One', cursive;
  --font-body: 'Nunito', sans-serif;
}

/* ---- RESET ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   AUTH PAGE
   ============================================================ */
.auth-page {
  background: linear-gradient(135deg, #e0f2fe 0%, #fce7f3 50%, #ede9fe 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  min-height: 100vh;
}

.auth-container {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
  animation: slideUp .4s ease;
}

.auth-logo {
  text-align: center;
  margin-bottom: 1.8rem;
}
.logo-icon {
  font-size: 4rem;
  animation: float 3s ease-in-out infinite;
  display: block;
}
.logo-text {
  font-family: var(--font-head);
  font-size: 2rem;
  color: var(--blue-d);
  letter-spacing: .5px;
}
.logo-sub {
  color: var(--text-soft);
  font-size: .9rem;
  margin-top: .3rem;
}

.auth-tabs {
  display: flex;
  gap: .5rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: .3rem;
  margin-bottom: 1.5rem;
}
.tab-btn {
  flex: 1;
  padding: .6rem 1rem;
  border: none;
  border-radius: calc(var(--radius-sm) - .2rem);
  background: transparent;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: .95rem;
  cursor: pointer;
  color: var(--text-soft);
  transition: all .2s;
}
.tab-btn.active {
  background: var(--card);
  color: var(--blue-d);
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.form-group { margin-bottom: 1.1rem; }
.form-group label {
  display: block;
  font-weight: 700;
  margin-bottom: .4rem;
  font-size: .9rem;
  color: var(--text);
}
.form-group input {
  width: 100%;
  padding: .8rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 1rem;
  transition: border-color .2s, box-shadow .2s;
  outline: none;
  background: var(--bg);
}
.form-group input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
  background: var(--card);
}

.avatar-pick { margin-bottom: 1.2rem; }
.avatar-pick label { display: block; font-weight: 700; margin-bottom: .6rem; font-size: .9rem; }
.avatar-grid {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
.avatar-option {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 3px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all .2s;
  background: var(--bg);
}
.avatar-option input { display: none; }
.avatar-option:hover { border-color: var(--blue); transform: scale(1.08); }
.avatar-option.selected { border-color: var(--blue); background: var(--sky); box-shadow: 0 0 0 2px var(--blue); }
.avatar-emoji { font-size: 1.8rem; }

.alert {
  padding: .8rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-weight: 600;
  font-size: .9rem;
}
.alert-error   { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--green-d); border: 1px solid #bbf7d0; }

.auth-footer {
  text-align: center;
  margin-top: 1.2rem;
  color: var(--text-soft);
  font-size: .85rem;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .75rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  transition: transform .15s, box-shadow .15s, opacity .15s;
  letter-spacing: .3px;
}
.btn:hover   { transform: translateY(-2px); box-shadow: var(--shadow); }
.btn:active  { transform: translateY(0); }
.btn-primary {
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-d) 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(59,130,246,.35);
}
.btn-secondary {
  background: linear-gradient(135deg, var(--purple) 0%, #6d28d9 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(139,92,246,.35);
}
.btn-ghost {
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--border);
}
.btn-full { width: 100%; }

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  background: var(--card);
  box-shadow: 0 2px 12px rgba(0,0,0,.07);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left, .header-right { display: flex; align-items: center; gap: .7rem; }
.header-center { font-weight: 700; }
.header-logo { font-size: 1.6rem; }
.header-title {
  font-family: var(--font-head);
  font-size: 1.3rem;
  color: var(--blue-d);
}
.streak-badge {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #92400e;
  padding: .35rem .7rem;
  border-radius: 2rem;
  font-weight: 700;
  font-size: .85rem;
}
.btn-back {
  color: var(--blue-d);
  font-weight: 700;
  text-decoration: none;
  font-size: .95rem;
}
.btn-back:hover { text-decoration: underline; }
.btn-logout {
  font-size: 1.3rem;
  text-decoration: none;
  opacity: .7;
  transition: opacity .2s;
}
.btn-logout:hover { opacity: 1; }
.level-badge {
  background: var(--lavender);
  color: var(--purple);
  padding: .3rem .8rem;
  border-radius: 2rem;
  font-weight: 700;
  font-size: .85rem;
}
.diff-badge { font-size: 1rem; }

/* ============================================================
   HERO CARD (Dashboard)
   ============================================================ */
.hero-card {
  margin: 1.2rem;
  padding: 1.3rem;
  background: linear-gradient(135deg, #dbeafe 0%, #ede9fe 100%);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
}
.hero-avatar { font-size: 3.5rem; flex-shrink: 0; }
.hero-info { flex: 1; min-width: 0; }
.hero-name { font-family: var(--font-head); font-size: 1.4rem; color: var(--blue-d); }
.hero-level { font-size: .8rem; color: var(--text-soft); margin-bottom: .4rem; }
.xp-bar-wrap {
  height: 10px;
  background: rgba(255,255,255,.5);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: .25rem;
}
.xp-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--blue) 0%, var(--purple) 100%);
  border-radius: 5px;
  transition: width .8s cubic-bezier(.25,.8,.25,1);
}
.xp-label { font-size: .75rem; color: var(--text-soft); }
.hero-stats { flex-shrink: 0; }
.stat-pill {
  background: var(--card);
  padding: .35rem .8rem;
  border-radius: 2rem;
  font-weight: 700;
  font-size: .9rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

/* ============================================================
   MAP
   ============================================================ */
.map-header {
  text-align: center;
  padding: .8rem 1rem .4rem;
}
.map-title { font-family: var(--font-head); font-size: 1.5rem; color: var(--text); }
.map-sub { color: var(--text-soft); font-size: .9rem; }

.map-container {
  padding: .5rem 1.2rem 3rem;
  overflow-y: auto;
}
.map-track {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 480px;
  margin: 0 auto;
}

.map-step {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.map-step.node-right { align-items: flex-end; }

.map-connector {
  width: 4px;
  height: 36px;
  background: var(--border);
  margin-left: calc(80px / 2 - 2px);
  border-radius: 2px;
  transition: background .4s;
}
.node-right .map-connector { margin-left: auto; margin-right: calc(80px / 2 - 2px); }
.map-connector.connector-active {
  background: linear-gradient(180deg, var(--green) 0%, var(--blue) 100%);
}

.map-node {
  display: flex;
  align-items: center;
  gap: .8rem;
  background: var(--card);
  border: 3px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1.1rem;
  width: calc(100% - 2.5rem);
  cursor: default;
  transition: transform .2s, box-shadow .2s, border-color .2s;
  position: relative;
  user-select: none;
}
.node-unlocked, .node-completed { cursor: pointer; }
.node-unlocked:hover, .node-completed:hover {
  transform: translateY(-3px) scale(1.01);
  box-shadow: var(--shadow-lg);
}

.node-icon { font-size: 1.8rem; flex-shrink: 0; }
.node-label { flex: 1; }
.node-label strong { display: block; font-size: 1rem; }
.node-type { font-size: .8rem; color: var(--text-soft); }
.node-xp {
  font-size: .8rem;
  font-weight: 700;
  color: var(--yellow);
  background: #fef3c7;
  padding: .2rem .5rem;
  border-radius: 1rem;
}

.node-completed {
  background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
  border-color: var(--green);
}
.node-unlocked {
  background: var(--card);
  border-color: var(--blue);
  box-shadow: 0 4px 16px rgba(59,130,246,.15);
}
.node-locked {
  opacity: .55;
  filter: grayscale(.4);
}
.node-current { border-color: var(--yellow); animation: pulseBorder 2s ease-in-out infinite; }

.node-pulse {
  position: absolute;
  inset: -6px;
  border-radius: calc(var(--radius) + 2px);
  border: 3px solid var(--yellow);
  animation: pulseRing 2s ease-in-out infinite;
  pointer-events: none;
}

.map-finish {
  margin-top: 2rem;
  text-align: center;
  color: var(--text-soft);
  font-size: .9rem;
}
.finish-icon { font-size: 2.5rem; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem .8rem;
  justify-content: center;
  padding: .8rem 1rem 2rem;
  color: var(--text-soft);
  font-size: .82rem;
}

/* ============================================================
   LEVEL PAGE
   ============================================================ */
.level-page { background: var(--bg); }

.level-card {
  margin: 1.2rem;
  padding: 1.4rem;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.level-title-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.level-title { font-family: var(--font-head); font-size: 1.5rem; color: var(--text); }
.xp-reward-badge {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #92400e;
  padding: .35rem .8rem;
  border-radius: 2rem;
  font-weight: 800;
  font-size: .9rem;
  white-space: nowrap;
}
.level-desc { color: var(--text-soft); margin-top: .5rem; font-size: .95rem; }
.already-done-banner {
  margin-top: .8rem;
  padding: .6rem .9rem;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm);
  color: var(--green-d);
  font-weight: 700;
  font-size: .9rem;
}

.challenge-container {
  margin: 0 1.2rem 2rem;
  padding: 1.5rem;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.challenge-question {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1.2rem;
  line-height: 1.4;
}

/* ---- LOGIC OPTIONS ---- */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .8rem;
  margin-bottom: 1rem;
}
.option-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .4rem;
  padding: 1rem .8rem;
  background: var(--bg);
  border: 3px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: .95rem;
  cursor: pointer;
  transition: all .2s;
}
.option-btn:hover:not(:disabled) {
  border-color: var(--blue);
  background: var(--sky);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.option-btn.correct { border-color: var(--green); background: #f0fdf4; animation: bounceIn .4s; }
.option-btn.wrong   { border-color: var(--red);   background: #fef2f2; animation: shake .4s; }
.option-btn:disabled { cursor: default; transform: none; }
.opt-emoji { font-size: 2.2rem; }
.opt-label { font-size: .9rem; }

/* ---- MEMORY ---- */
.phase-hint {
  color: var(--text-soft);
  font-size: .95rem;
  margin-bottom: 1rem;
  font-weight: 600;
}
.memory-sequence {
  display: flex;
  gap: .7rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}
.mem-item {
  font-size: 2.8rem;
  padding: .6rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  animation: popIn .3s ease;
}

.memory-buttons {
  display: flex;
  gap: .6rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.mem-btn {
  font-size: 2.2rem;
  padding: .7rem .9rem;
  background: var(--bg);
  border: 3px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
}
.mem-btn:hover { border-color: var(--blue); transform: scale(1.1); }
.mem-btn:active { transform: scale(.95); }

.mem-progress {
  display: flex;
  gap: .5rem;
  justify-content: center;
  min-height: 2.5rem;
  align-items: center;
  font-size: 1.6rem;
  margin-bottom: .8rem;
  flex-wrap: wrap;
}

/* ---- PUZZLE ---- */
.puzzle-hint {
  padding: .6rem 1rem;
  background: var(--lemon);
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: .9rem;
  margin-bottom: .8rem;
  color: #78350f;
}
.puzzle-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-bottom: 1.2rem;
}
.puzzle-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .8rem 1rem;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background .2s, border-color .2s;
}
.puzzle-item.dragging { opacity: .5; }
.puzzle-emoji { font-size: 1.6rem; }
.puzzle-label { font-weight: 700; flex: 1; font-size: 1rem; }
.puzzle-arrow {
  background: none;
  border: 1px solid var(--border);
  border-radius: .4rem;
  width: 32px; height: 32px;
  font-size: 1rem;
  cursor: pointer;
  transition: background .15s;
}
.puzzle-arrow:hover { background: var(--border); }

/* ---- FEEDBACK ---- */
.feedback-box {
  padding: .9rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: .95rem;
  display: none;
  animation: slideUp .3s ease;
}
.feedback-box.show { display: block; }
.feedback-correct { background: #f0fdf4; color: var(--green-d); border: 2px solid #86efac; }
.feedback-wrong   { background: #fef2f2; color: #dc2626; border: 2px solid #fca5a5; }

/* ============================================================
   OVERLAYS
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 1.5rem;
  animation: fadeIn .3s ease;
}
.overlay-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: bounceIn .5s cubic-bezier(.34,1.56,.64,1);
}
.success-card { border-top: 6px solid var(--green); }
.fail-card    { border-top: 6px solid var(--yellow); }
.overlay-emoji { font-size: 4.5rem; margin-bottom: .8rem; animation: float 2s ease-in-out infinite; }
.overlay-title { font-family: var(--font-head); font-size: 2rem; margin-bottom: .5rem; }
.overlay-msg { color: var(--text-soft); margin-bottom: 1rem; font-size: .95rem; }
.xp-gained {
  font-family: var(--font-head);
  font-size: 1.8rem;
  color: var(--yellow);
  margin-bottom: 1.3rem;
}
.overlay-actions { display: flex; flex-direction: column; gap: .7rem; }

/* ---- XP FLOAT ---- */
.xp-float {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  font-family: var(--font-head);
  font-size: 2.5rem;
  color: var(--yellow);
  text-shadow: 0 2px 8px rgba(0,0,0,.3);
  pointer-events: none;
  opacity: 0;
  z-index: 1000;
}
.xp-float.animate {
  animation: xpFloat 1.4s cubic-bezier(.25,.8,.25,1) forwards;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes float {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes bounceIn {
  0%   { transform: scale(.7);    opacity: 0; }
  60%  { transform: scale(1.08);  opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes popIn {
  0%   { transform: scale(.5); opacity: 0; }
  80%  { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%  { transform: translateX(-6px); }
  40%  { transform: translateX(6px); }
  60%  { transform: translateX(-4px); }
  80%  { transform: translateX(4px); }
}
@keyframes xpFloat {
  0%   { opacity: 0;   transform: translate(-50%,-50%) scale(.5); }
  30%  { opacity: 1;   transform: translate(-50%,-70%) scale(1.2); }
  70%  { opacity: 1;   transform: translate(-50%,-120%) scale(1); }
  100% { opacity: 0;   transform: translate(-50%,-170%) scale(.8); }
}
@keyframes pulseBorder {
  0%,100% { box-shadow: 0 0 0 0 rgba(245,158,11,.4); }
  50%     { box-shadow: 0 0 0 8px rgba(245,158,11,0); }
}
@keyframes pulseRing {
  0%   { opacity: .7; transform: scale(1); }
  100% { opacity: 0;  transform: scale(1.15); }
}
@keyframes unlockBounce {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.15) rotate(-3deg); }
  60%  { transform: scale(.95) rotate(2deg); }
  100% { transform: scale(1); }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 400px) {
  .auth-container { padding: 1.8rem 1.3rem; }
  .hero-avatar { font-size: 2.5rem; }
  .options-grid { grid-template-columns: 1fr 1fr; gap: .5rem; }
  .opt-emoji { font-size: 1.8rem; }
  .overlay-card { padding: 1.8rem 1.2rem; }
}

@media (min-width: 600px) {
  .map-track { padding: 0 1rem; }
  .options-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 768px) {
  .level-card, .challenge-container { margin: 1.5rem auto; max-width: 600px; }
  .hero-card { margin: 1.5rem auto; max-width: 600px; }
  .map-container { max-width: 620px; margin: 0 auto; }
}
