/* ============================================================
   VARIABLES DE DISEÑO
============================================================ */
:root {
  --c-primary:       #6b5dd4;
  --c-primary-dark:  #5a51c6;
  --c-primary-light: #EEF0FF;
  --c-secondary:     #ed515f;
  --c-accent:        #f2cd3d;
  --c-success:       #3ac875;
  --c-error:         #ed515f;
  --c-bg:            #F0F4FF;
  --c-card:          #FFFFFF;
  --c-text:          #2D3436;
  --c-muted:         #636E72;
  --c-border:        #DFE6E9;
  --c-painted:       #ed515f;
  --c-unpainted:     #D6DCE4;
  --radius-lg:       20px;
  --radius-md:       12px;
  --radius-sm:       8px;
  --shadow:          0 4px 24px rgba(91, 79, 233, 0.12);
  --shadow-sm:       0 2px 8px rgba(0,0,0,0.08);
}

/* ============================================================
   RESET Y BASE
============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Nunito', sans-serif;
  background: #0f0c29;
  color: #ffffff;
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

/* ============================================================
   HEADER
============================================================ */
.app-header {
  background: linear-gradient(135deg, #6b5dd4 0%, #7b6dd4 100%);
  color: white;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 16px rgba(91,79,233,0.35);
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-logo { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.5px; }
.app-logo span { font-size: 0.8rem; opacity: 0.7; display: block; font-weight: 400; margin-top: -2px; }

.stats-bar { display: flex; gap: 8px; align-items: center; }

.stat-pill {
  background: rgba(255,248,231,0.18);
  border: 1px solid rgba(255,248,231,0.28);
  border-radius: 20px;
  padding: 5px 13px;
  font-size: 0.88rem;
  font-weight: 700;
  transition: transform 0.2s;
}

/* Animación al ganar puntos */
.bump { animation: bump 0.4s ease; }
@keyframes bump {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.25); }
}

/* ============================================================
   TABS DE NAVEGACIÓN
============================================================ */
.tabs {
  background: rgba(255,248,231,0.06);
  border: 1px solid rgba(255,248,231,0.12);
  border-radius: 18px;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  box-shadow: none;
  position: relative;
  top: 0;
  z-index: 5;
  margin-bottom: 18px;
}

.tab {
  border: 2px solid rgba(255,248,231,0.22);
  background: rgba(255,248,231,0.12);
  color: rgba(255,248,231,0.82);
  padding: 9px 20px;
  border-radius: 30px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  transition: all 0.2s;
  min-height: 44px;
}
.tab:hover { border-color: var(--c-accent); color: white; }
.tab.active {
  background: linear-gradient(145deg, var(--c-primary), var(--c-primary-dark));
  border-color: var(--c-primary);
  color: white;
  box-shadow: 0 6px 18px rgba(91,79,233,0.35);
}

header .back-btn { display: block; }

.app-hero.frac-hero {
  justify-content: space-between;
  flex-wrap: wrap;
}

.app-hero.frac-hero .stats-bar {
  margin-left: auto;
}

@media (max-width: 700px) {
  .app-hero.frac-hero { align-items: flex-start; }
  .app-hero.frac-hero .stats-bar { margin-left: 0; }
}

/* ============================================================
   LAYOUT PRINCIPAL
============================================================ */
.main { max-width: 800px; margin: 0 auto; padding: 20px 16px 48px; }

/* ============================================================
   TARJETAS
============================================================ */
.card {
  background: var(--c-card);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.card-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--c-primary);
  margin-bottom: 6px;
}

.instruccion {
  font-size: 1rem;
  color: var(--c-muted);
  margin-bottom: 14px;
  line-height: 1.6;
}

/* ============================================================
   DISPLAY FRACCIÓN GRANDE
============================================================ */
.frac-big {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
  font-weight: 900;
  color: var(--c-primary);
  background: var(--c-primary-light);
  border-radius: var(--radius-md);
  padding: 10px 32px;
  margin: 12px auto;
  width: fit-content;
  min-width: 100px;
  gap: 2px;
}

.frac-barra { width: 100%; height: 4px; background: var(--c-primary); border-radius: 2px; margin: 2px 0; }

/* ============================================================
   CONTROLES — SLIDERS
============================================================ */
.slider-group { margin-bottom: 14px; }

.slider-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--c-muted);
  margin-bottom: 7px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.slider-val { font-size: 1.3rem; font-weight: 800; color: var(--c-primary); min-width: 32px; text-align: right; }

input[type="range"] {
  width: 100%;
  height: 8px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(to right,
    var(--c-primary) 0%,
    var(--c-primary) var(--pct, 0%),
    var(--c-border) var(--pct, 0%),
    var(--c-border) 100%);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--c-primary);
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(91,79,233,0.45);
  border: 3px solid white;
}

/* ============================================================
   SELECTOR DE VISUALIZACIÓN
============================================================ */
.vis-tabs { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; flex-wrap: wrap; }

.vis-tab {
  border: 2px solid var(--c-border);
  background: white;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 700;
  transition: all 0.2s;
  min-height: 40px;
}
.vis-tab.active { background: var(--c-accent); border-color: #d9a800; color: #333; }

/* ============================================================
   ÁREA DE VISUALIZACIÓN
============================================================ */
.viz-area {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 14px 0;
  min-height: 200px;
  overflow: hidden;
}

/* SVG — Pizza */
.pizza-slice { cursor: pointer; stroke: white; stroke-width: 2.5; transition: filter 0.15s; }
.pizza-slice:hover { filter: brightness(1.08); }
.pizza-slice.painted   { fill: var(--c-painted);   }
.pizza-slice.unpainted { fill: var(--c-unpainted);  }
.pizza-slice.static    { cursor: default;            }

/* SVG — Barra */
.bar-seg { cursor: pointer; stroke: white; stroke-width: 2.5; transition: filter 0.15s; }
.bar-seg:hover { filter: brightness(1.08); }
.bar-seg.painted   { fill: var(--c-painted);  }
.bar-seg.unpainted { fill: var(--c-unpainted); }
.bar-seg.static    { cursor: default;           }

/* Conjunto (objetos) */
.conjunto { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 360px; }

.obj {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 3px solid var(--c-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.65rem;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, border-color 0.15s;
  background: white;
  user-select: none;
}
.obj:hover { transform: scale(1.1); }
.obj.painted   { background: var(--c-painted); border-color: var(--c-painted); }
.obj.static    { cursor: default; }

/* ============================================================
   FEEDBACK
============================================================ */
.feedback {
  border-radius: var(--radius-md);
  padding: 13px 16px;
  margin-top: 14px;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.6;
  animation: popIn 0.3s ease;
}

.feedback.ok   { background: #E9FBF0; color: #1a7540; border-left: 5px solid var(--c-success); }
.feedback.ko   { background: #FFF0F0; color: #a8472d; border-left: 5px solid var(--c-error);   }
.feedback.info { background: var(--c-primary-light); color: var(--c-primary); border-left: 5px solid var(--c-primary); }

@keyframes popIn {
  from { transform: scale(0.94); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0);  }
  25%       { transform: translateX(-8px); }
  75%       { transform: translateX(8px);  }
}
.shake { animation: shake 0.4s ease; }

/* ============================================================
   BOTONES
============================================================ */
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

.btn {
  border: none;
  border-radius: 30px;
  padding: 11px 24px;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.18s, filter 0.18s;
  min-height: 44px;
}
.btn:hover  { transform: translateY(-2px); filter: brightness(1.06); }
.btn:active { transform: translateY(0);    }

.btn-primary { background: var(--c-primary);   color: white; }
.btn-success { background: var(--c-success);   color: white; }
.btn-accent  { background: var(--c-accent);    color: #333;  }
.btn-outline { background: white; color: var(--c-primary); border: 2px solid var(--c-primary); }
.btn-danger  { background: white; color: var(--c-error);   border: 2px solid var(--c-error);   }

/* ============================================================
   CONTADOR DE PARTES
============================================================ */
.count-display {
  text-align: center;
  font-size: 1rem;
  color: var(--c-muted);
  margin-top: 6px;
}
.count-display strong { color: var(--c-primary); }

/* ============================================================
   INPUTS DEL RETO
============================================================ */
.reto-inputs { display: flex; justify-content: center; align-items: center; gap: 14px; margin: 18px 0; }

.reto-fraction { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.reto-input {
  width: 78px; height: 62px;
  text-align: center;
  font-size: 2rem; font-weight: 800;
  border: 3px solid var(--c-border);
  border-radius: var(--radius-sm);
  color: var(--c-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -moz-appearance: textfield;
}
.reto-input::-webkit-inner-spin-button,
.reto-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.reto-input:focus { border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(91,79,233,0.15); }

.reto-barra { width: 78px; height: 4px; background: var(--c-primary); border-radius: 2px; }

/* ============================================================
   HISTORIAL Y PROGRESO
============================================================ */
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }

.chip {
  padding: 4px 11px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 700;
}
.chip.ok { background: #E9FBF0; color: #1a7540; }
.chip.ko { background: #FFF0F0; color: #a8472d; }

.progreso-dots { display: flex; gap: 6px; justify-content: center; margin-top: 12px; }

.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c-border); transition: background 0.2s; }
.dot.ok { background: var(--c-success); }
.dot.ko { background: var(--c-error);   }

/* ============================================================
   TOGGLE ACCESIBILIDAD
============================================================ */
.toggle-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--c-border); margin-top: 10px;
}
.toggle-label { font-size: 0.9rem; color: var(--c-muted); }

.toggle {
  width: 48px; height: 26px;
  background: var(--c-border);
  border-radius: 13px;
  position: relative; cursor: pointer;
  transition: background 0.2s;
}
.toggle.on { background: var(--c-primary); }
.toggle-dot {
  position: absolute;
  width: 20px; height: 20px;
  background: white; border-radius: 50%;
  top: 3px; left: 3px;
  transition: transform 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.toggle.on .toggle-dot { transform: translateX(22px); }

/* ============================================================
   CONFETTI
============================================================ */
.confetti-wrap {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 999; overflow: hidden;
}
.confetti-p {
  position: absolute;
  animation: fall linear forwards;
  border-radius: 2px;
}
@keyframes fall {
  from { transform: translateY(-20px) rotate(0deg);   opacity: 1; }
  to   { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ============================================================
   EQUIVALENCIAS (badge pequeño)
============================================================ */
.equiv-badge {
  display: inline-flex; align-items: center;
  background: rgba(91,79,233,0.1);
  color: var(--c-primary);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 0.82rem;
  font-weight: 700;
  margin: 0 3px;
}

/* ============================================================
   RESPONSIVO
============================================================ */
@media (max-width: 520px) {
  .app-logo { font-size: 1.2rem; }
  .stat-pill { font-size: 0.78rem; padding: 4px 9px; }
  .frac-big  { font-size: 2rem; padding: 8px 22px; }
  .card      { padding: 16px; }
  .tab       { padding: 8px 13px; font-size: 0.82rem; }
}

/* ============================================================
   ALTO CONTRASTE (accesibilidad)
============================================================ */
body.alto-contraste {
  --c-primary:       #3333cc;
  --c-primary-light: #E0E0FF;
  --c-bg:            #FFF8E7;
  --c-card:          #FFF8E7;
  --c-text:          #000000;
  --c-muted:         #333333;
  --c-border:        #555555;
  --c-painted:       #a8472d;
  --c-unpainted:     #BBBBBB;
}
body.alto-contraste .app-header { background: #3333cc; }
