/* =====================================================
   PRE-TRAZOS — Escritura Cursiva 1º Grado
   Diseño landscape 16:9 para Chromebook
   Paleta: cielo suave con acentos vibrantes por trazo
   ===================================================== */

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

:root {
  /* Colores base */
  --sky:        #eef6ff;
  --sky-mid:    #daeeff;
  --white:      #ffffff;
  --ink:        #2d3a4a;
  --ink-light:  #5a6a7a;

  /* Trazos: verde cuando está bien, rojo cuando se aleja */
  --stroke-ok:  #29c46a;
  --stroke-err: #f03e3e;
  --stroke-guide: rgba(180,180,200,.45);

  /* Colores de cada pre-trazo */
  --c-ruti:        #e53935; /* rojo */
  --c-ruti-baja:   #f9a825; /* amarillo/dorado */
  --c-ruti-sha-b:  #7b1fa2; /* violeta */
  --c-ruti-sha-sha:#2e7d32; /* verde oscuro */
  --c-ruti-vuelta: #1565c0; /* azul */

  /* Tipografía */
  --font-title: 'Baloo 2', cursive;
  --font-body:  'Nunito', sans-serif;

  /* Layout */
  --header-h:  64px;
  --instr-h:   46px;
  --radius:    16px;
  --radius-sm: 10px;
}

/* ---- BASE ---- */
html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;          /* forzamos landscape sin scroll */
  background: var(--sky);
  font-family: var(--font-body);
  color: var(--ink);
}

/* ══════════════════════════════
   HEADER
══════════════════════════════ */
#app-header {
  height: var(--header-h);
  background: var(--white);
  border-bottom: 3px solid var(--sky-mid);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,.07);
  position: relative;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-icon {
  font-size: 1.6rem;
}

h1 {
  font-family: var(--font-title);
  font-size: clamp(1.1rem, 2.2vw, 1.5rem);
  font-weight: 800;
  color: var(--ink);
  white-space: nowrap;
}

/* Área de progreso */
.progress-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 0 12px;
}

.prog-label {
  font-size: clamp(.7rem, 1.2vw, .85rem);
  font-weight: 900;
  color: var(--ink-light);
  letter-spacing: .5px;
}

.prog-track {
  position: relative;
  height: 16px;
  background: var(--sky-mid);
  border-radius: 20px;
  overflow: visible;
}

.prog-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  border-radius: 20px;
  background: linear-gradient(90deg, #43a047, #66bb6a);
  transition: width .5s cubic-bezier(.34,1.56,.64,1);
  width: 0%;
}

/* Puntitos sobre la barra */
.prog-dots {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 4px;
  pointer-events: none;
}

.prog-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--white);
  border: 3px solid var(--sky-mid);
  transition: border-color .3s, background .3s;
  font-size: .6rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.prog-dot.done  { background: #43a047; border-color: #2e7d32; }
.prog-dot.active{ background: var(--white); border-color: #43a047; box-shadow: 0 0 0 3px #43a04744; }

/* Botón reintentar */
.btn-retry {
  flex-shrink: 0;
  font-family: var(--font-body);
  font-size: clamp(.76rem, 1.3vw, .9rem);
  font-weight: 800;
  padding: 8px 18px;
  border-radius: 30px;
  border: none;
  background: #ef5350;
  color: white;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,.13);
  transition: transform .12s, box-shadow .12s;
}
.btn-retry:hover  { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.btn-retry:active { transform: scale(.95); }

/* ══════════════════════════════
   BARRA DE INSTRUCCIÓN
══════════════════════════════ */
.instruction-bar {
  height: var(--instr-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(90deg, #fff9c4, #e8f5e9, #e3f2fd);
  border-bottom: 2px solid #c8e6c9;
}

.instr-icon {
  font-size: 1.3rem;
}

.instr-text {
  font-family: var(--font-title);
  font-size: clamp(.82rem, 1.6vw, 1.05rem);
  font-weight: 700;
  color: #2e7d32;
  letter-spacing: .3px;
}

/* ══════════════════════════════
   ÁREA PRINCIPAL — fila de canvas
══════════════════════════════ */
#canvas-row {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 12px;
  padding: 10px 16px;
  /* Alto fijo: cómodo para un trazo en un solo movimiento en Chromebook.
     Ajustar este valor si se necesita más o menos altura:
     - Chromebook 768px pantalla: ~340px deja margen suficiente
     - Para pantallas más altas puede subirse a 380px             */
  height: 340px;
  overflow: hidden;
}

/* Contenedor individual de cada trazo */
.trace-wrapper {
  flex: 1;
  max-width: 18vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

/* Badge de número */
.trace-badge {
  font-family: var(--font-title);
  font-size: clamp(.7rem, 1.2vw, .85rem);
  font-weight: 800;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e0e0e0;
  color: #777;
  flex-shrink: 0;
  transition: background .3s, color .3s;
}
.trace-badge.active { background: #43a047; color: white; }
.trace-badge.done   { background: #1b5e20; color: white; }

/* Canvas de cada trazo */
.trace-canvas {
  flex: 1;
  width: 100%;
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: 0 3px 14px rgba(0,0,0,.09);
  border: 3px solid #e0e0e0;
  cursor: crosshair;
  display: block;
  transition: border-color .3s, box-shadow .3s;
  touch-action: none;
}
.trace-canvas.active {
  border-color: #43a047;
  box-shadow: 0 0 0 4px #43a04744, 0 4px 20px rgba(0,0,0,.12);
  cursor: crosshair;
}
.trace-canvas.done {
  border-color: #1b5e20;
  background: #f1f8e9;
  cursor: default;
}
.trace-canvas.locked {
  opacity: .55;
  cursor: not-allowed;
  border-color: #e0e0e0;
}

/* ══════════════════════════════
   PANEL DE FELICITACIÓN
══════════════════════════════ */
.congrats-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(5px);
}
.congrats-overlay.hidden { display: none; }

.congrats-box {
  background: white;
  border-radius: 24px;
  padding: 32px 44px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  border: 4px solid #a5d6a7;
  animation: pop-in .4s cubic-bezier(.34,1.56,.64,1);
}

@keyframes pop-in {
  0%   { transform: scale(.5); opacity: 0; }
  100% { transform: scale(1);  opacity: 1; }
}

.congrats-emo {
  font-size: 3.5rem;
  margin-bottom: 8px;
}

.congrats-title {
  font-family: var(--font-title);
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  color: #2e7d32;
  margin-bottom: 6px;
}

.congrats-sub {
  font-size: clamp(.85rem, 1.4vw, 1rem);
  color: #666;
  margin-bottom: 20px;
  font-weight: 700;
}

.btn-next {
  font-family: var(--font-body);
  font-size: clamp(.9rem, 1.5vw, 1.1rem);
  font-weight: 800;
  padding: 12px 32px;
  border-radius: 30px;
  border: none;
  background: linear-gradient(135deg, #43a047, #2e7d32);
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(67,160,71,.4);
  transition: transform .12s;
}
.btn-next:hover  { transform: translateY(-3px); }
.btn-next:active { transform: scale(.95); }

/* ══════════════════════════════
   ESTADOS DEL TRAZO DURANTE DIBUJO
   (aplicados dinámicamente desde JS al borde del canvas)
══════════════════════════════ */
.trace-canvas.drawing-ok  { border-color: var(--stroke-ok)  !important; }
.trace-canvas.drawing-err { border-color: var(--stroke-err) !important; }

/* ══════════════════════════════
   SCROLLBAR mínima
══════════════════════════════ */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-thumb { background: #b0bec5; border-radius: 10px; }
