/* ─── Variables ──────────────────────────────────────────────────────────── */
:root {
  --azul-oscuro:  #1A4A7A;
  --azul-medio:   #2E7BCF;
  --azul-claro:   #E8F0FA;
  --verde-oscuro: #1A5C2A;
  --verde-claro:  #E8F5EC;
  --naranja:      #C45000;
  --fondo-naranja:#FFF3E0;
  --rojo:         #A32D2D;
  --fondo-rojo:   #FAE8E8;
  --gris-texto:   #333333;
  --gris-fondo:   #F0F2F5;
  --gris-borde:   #E0E0E0;
  --shadow-sm:    0 1px 4px rgba(0,0,0,0.08);
  --shadow-md:    0 2px 10px rgba(0,0,0,0.10);
  --r:            12px;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gris-fondo);
  color: var(--gris-texto);
  min-height: 100vh;
  padding-bottom: 32px;
}

/* ─── Navbar ─────────────────────────────────────────────────────────────── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--azul-oscuro);
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  box-shadow: var(--shadow-md);
}

.nav-brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.3px;
}

.nav-stats { display: flex; gap: 8px; }

.stat-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255,255,255,0.15);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
}

/* ─── Tab bar ────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  background: #fff;
  border-bottom: 2px solid var(--gris-borde);
  position: sticky;
  top: 53px;
  z-index: 99;
}

.tab-btn {
  flex: 1;
  padding: 11px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: #888;
  transition: color 0.15s;
  position: relative;
}

.tab-btn.active {
  color: var(--azul-medio);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--azul-medio);
  border-radius: 3px 3px 0 0;
}

/* ─── Views ──────────────────────────────────────────────────────────────── */
.view {
  display: none;
  padding: 14px 14px 0;
  max-width: 580px;
  margin: 0 auto;
}
.view.active { display: block; }

/* ─── Card ───────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--r);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--azul-oscuro);
}

.card-sub {
  font-size: 0.78rem;
  color: #888;
}

/* ─── Level card ─────────────────────────────────────────────────────────── */
.level-card {
  background: linear-gradient(135deg, var(--azul-oscuro) 0%, #2563a8 100%);
  color: #fff;
  padding: 20px 20px 16px;
}

.level-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.level-emoji { font-size: 2rem; margin-bottom: 6px; }

.level-name {
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 3px;
}

.level-prize {
  font-size: 0.82rem;
  opacity: 0.85;
}

.level-financing {
  font-size: 2.2rem;
  font-weight: 900;
  opacity: 0.95;
  line-height: 1;
  text-align: right;
}

.level-progress-bar {
  background: rgba(255,255,255,0.22);
  border-radius: 10px;
  height: 8px;
  overflow: hidden;
  margin-bottom: 7px;
}

.level-progress-fill {
  height: 100%;
  background: #7EFFD4;
  border-radius: 10px;
  transition: width 0.6s ease;
}

.level-progress-label {
  font-size: 0.75rem;
  opacity: 0.8;
  text-align: right;
}

/* ─── Stats row ──────────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: #fff;
  border-radius: var(--r);
  padding: 14px 8px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-val {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--azul-oscuro);
  line-height: 1;
}

.stat-val.orange { color: var(--naranja); }
.stat-val.green  { color: var(--verde-oscuro); }
.stat-val.red    { color: var(--rojo); }

.stat-lbl {
  font-size: 0.65rem;
  color: #999;
  margin-top: 4px;
  white-space: nowrap;
}

/* ─── Day grid ───────────────────────────────────────────────────────────── */
.day-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.day-cell {
  aspect-ratio: 1;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: default;
  transition: transform 0.12s;
  user-select: none;
}

.day-cell.clickable { cursor: pointer; }
.day-cell.clickable:hover { transform: scale(1.06); }

.day-num { font-size: 1rem; font-weight: 800; }
.day-ico { font-size: 0.75rem; margin-top: 1px; }

.day-cell.completed {
  background: var(--verde-claro);
  border: 2px solid var(--verde-oscuro);
  color: var(--verde-oscuro);
}

.day-cell.current {
  background: var(--azul-claro);
  border: 2px solid var(--azul-medio);
  color: var(--azul-oscuro);
  animation: pulse 2s infinite;
}

.day-cell.pending {
  background: #f0f0f0;
  border: 2px solid #ddd;
  color: #bbb;
}

.day-cell.rest {
  background: var(--fondo-naranja);
  border: 2px dashed #e0a060;
  color: var(--naranja);
}

@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(46,123,207,0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(46,123,207,0); }
}

/* ─── CTA ────────────────────────────────────────────────────────────────── */
.cta-area {
  text-align: center;
  margin-bottom: 16px;
}

.cta-hint {
  font-size: 0.82rem;
  color: #999;
  margin-top: 9px;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn-primary {
  display: block;
  width: 100%;
  background: var(--azul-medio);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 15px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  text-align: center;
}

.btn-primary:hover:not(:disabled) { background: var(--azul-oscuro); }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }
.btn-primary:disabled { background: #ccc; cursor: not-allowed; }

.btn-back {
  background: none;
  border: none;
  color: var(--azul-medio);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  padding: 6px 0;
}

/* ─── Exercise view ──────────────────────────────────────────────────────── */
.exercise-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.exercise-progress {
  font-size: 0.8rem;
  color: #888;
  font-weight: 600;
}

.exercise-tags {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.tag {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
}

.tag-type { background: var(--azul-claro); color: var(--azul-oscuro); }
.tag-diff { background: #f0f0f0; color: #555; }
.tag-km   { background: var(--fondo-naranja); color: var(--naranja); }

.exercise-card { margin-bottom: 12px; }

.ex-context {
  background: var(--azul-claro);
  border-left: 4px solid var(--azul-medio);
  padding: 10px 13px;
  border-radius: 0 8px 8px 0;
  font-size: 0.82rem;
  color: #444;
  font-style: italic;
  line-height: 1.5;
  margin-bottom: 16px;
}

.ex-question {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.5;
  margin-bottom: 18px;
  color: var(--gris-texto);
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.option-btn {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  background: #fff;
  border: 2px solid var(--gris-borde);
  border-radius: 10px;
  padding: 13px 14px;
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  color: var(--gris-texto);
  line-height: 1.4;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--azul-medio);
  background: var(--azul-claro);
}

.option-btn.selected {
  border-color: var(--azul-medio);
  background: var(--azul-claro);
  font-weight: 600;
}

.option-btn.correct {
  border-color: var(--verde-oscuro);
  background: var(--verde-claro);
  color: var(--verde-oscuro);
  font-weight: 700;
}

.option-btn.wrong {
  border-color: var(--rojo);
  background: var(--fondo-rojo);
  color: var(--rojo);
}

.option-letter {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #eee;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.8rem;
  transition: background 0.12s, color 0.12s;
}

.option-btn.selected .option-letter  { background: var(--azul-medio); color: #fff; }
.option-btn.correct  .option-letter  { background: var(--verde-oscuro); color: #fff; }
.option-btn.wrong    .option-letter  { background: var(--rojo); color: #fff; }

#btn-submit { margin-bottom: 12px; }

/* ─── Feedback ───────────────────────────────────────────────────────────── */
.feedback-card {
  background: #fff;
  border-radius: var(--r);
  padding: 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.feedback-header {
  font-size: 1.05rem;
  font-weight: 800;
  margin-bottom: 10px;
}

.feedback-header.correct { color: var(--verde-oscuro); }
.feedback-header.wrong   { color: var(--rojo); }

.feedback-explanation {
  font-size: 0.875rem;
  line-height: 1.65;
  color: #444;
  margin-bottom: 10px;
}

.feedback-multa {
  background: var(--fondo-rojo);
  border-left: 4px solid var(--rojo);
  padding: 9px 13px;
  border-radius: 0 8px 8px 0;
  font-size: 0.82rem;
  color: var(--rojo);
  font-weight: 600;
  margin-bottom: 10px;
}

.feedback-km {
  background: var(--fondo-naranja);
  border-radius: 8px;
  padding: 10px 13px;
  font-size: 0.88rem;
  color: var(--naranja);
  font-weight: 700;
  text-align: center;
}

/* ─── Topics ─────────────────────────────────────────────────────────────── */
.topics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.topic-card {
  border-radius: 10px;
  padding: 14px 12px;
  text-align: center;
  transition: transform 0.12s;
}

.topic-card.unlocked {
  background: var(--verde-claro);
  border: 2px solid var(--verde-oscuro);
}

.topic-card.locked {
  background: #f5f5f5;
  border: 2px solid #e0e0e0;
}

.topic-emoji { font-size: 1.7rem; margin-bottom: 5px; }

.topic-name {
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--gris-texto);
}

.topic-card.locked .topic-name { color: #aaa; }

.topic-status {
  font-size: 0.74rem;
  font-weight: 600;
}

.topic-card.unlocked .topic-status { color: var(--verde-oscuro); }
.topic-card.locked   .topic-status { color: #bbb; }

/* ─── Parent levels ──────────────────────────────────────────────────────── */
.parent-levels { display: flex; flex-direction: column; gap: 9px; }

.parent-level {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  background: var(--gris-fondo);
  border: 2px solid transparent;
  transition: border-color 0.2s;
}

.parent-level.achieved {
  background: var(--verde-claro);
  border-color: var(--verde-oscuro);
}

.parent-level.current-lvl {
  background: var(--azul-claro);
  border-color: var(--azul-medio);
}

.pl-emoji { font-size: 1.4rem; }

.pl-info { flex: 1; }

.pl-name {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--gris-texto);
}

.parent-level.achieved .pl-name { color: var(--verde-oscuro); }

.pl-req {
  font-size: 0.74rem;
  color: #888;
  margin-top: 2px;
}

.pl-financing {
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--azul-oscuro);
}

.parent-level.achieved .pl-financing { color: var(--verde-oscuro); }

/* ─── km toast ───────────────────────────────────────────────────────────── */
.km-toast {
  position: fixed;
  top: 76px;
  right: 16px;
  background: var(--naranja);
  color: #fff;
  padding: 9px 16px;
  border-radius: 20px;
  font-weight: 800;
  font-size: 1rem;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s, transform 0.25s;
  z-index: 300;
}

.km-toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

.modal-box {
  background: #fff;
  border-radius: 20px;
  padding: 36px 28px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  animation: pop 0.28s ease;
}

.modal-emoji { font-size: 4rem; margin-bottom: 12px; }

.modal-box h2 {
  font-size: 1.4rem;
  color: var(--azul-oscuro);
  margin-bottom: 8px;
}

.modal-box p {
  color: #555;
  margin-bottom: 8px;
  line-height: 1.5;
  font-size: 0.9rem;
}

.modal-prize {
  font-weight: 700;
  color: var(--verde-oscuro) !important;
  font-size: 1rem !important;
  margin-bottom: 20px !important;
}

.modal-box .btn-primary { margin-top: 4px; }

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

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 380px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .stat-val  { font-size: 1.4rem; }
  .day-grid  { grid-template-columns: repeat(5, 1fr); gap: 6px; }
}
