/* ============================================================
   TecleArte — estilos
   Tema infantil: colores vivos, formas redondeadas, objetivos
   táctiles grandes y tipografía legible.
   ============================================================ */

:root {
  /* Paleta */
  --bg: #eef1ff;
  --bg-2: #e3f6ff;
  --card: #ffffff;
  --ink: #2a2f5b;
  --ink-soft: #6b7099;
  --brand: #5b6cff;
  --brand-dark: #4150e0;
  --good: #2bbf7a;
  --good-soft: #d6f7e8;
  --bad: #ff5d73;
  --bad-soft: #ffe1e6;
  --warn: #ffb43b;
  --star: #ffc843;

  /* Colores por dedo (mano izquierda cálidos, derecha fríos) */
  --f-pinky-l: #ff8fa3;   /* meñique izq */
  --f-ring-l:  #ffb86b;   /* anular izq */
  --f-mid-l:   #ffe066;   /* medio izq */
  --f-index-l: #9ee37d;   /* índice izq */
  --f-index-r: #7ad7f0;   /* índice der */
  --f-mid-r:   #8ea7ff;   /* medio der */
  --f-ring-r:  #c79bff;   /* anular der */
  --f-pinky-r: #ff9be0;   /* meñique der */
  --f-thumb:   #d8dcf0;   /* pulgares */

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(60, 70, 160, .12);
  --shadow-sm: 0 4px 12px rgba(60, 70, 160, .12);
  --maxw: 980px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: "Segoe UI", "Nunito", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

/* ---------- Cabecera ---------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-title { flex: 1; text-align: center; }
.logo { font-weight: 800; font-size: 1.25rem; color: var(--brand); }
.header-right { display: flex; align-items: center; gap: 8px; }
.active-child { font-weight: 700; color: var(--ink-soft); }
.header-btn {
  border: none;
  background: var(--bg);
  border-radius: 12px;
  font-size: 1.2rem;
  width: 44px;
  height: 44px;
  cursor: pointer;
  transition: transform .1s ease, background .15s ease;
}
.header-btn:hover { background: #dfe3ff; }
.header-btn:active { transform: scale(.92); }

/* ---------- Contenedor de pantallas ---------- */
.screen {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 22px 16px 40px;
}

.app-footer {
  text-align: center;
  color: var(--ink-soft);
  padding: 14px;
  opacity: .8;
}

/* ---------- Tipografía y bloques ---------- */
h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); margin: .2em 0 .4em; }
h2 { font-size: clamp(1.2rem, 3vw, 1.6rem); }
.lead { color: var(--ink-soft); font-size: 1.1rem; line-height: 1.5; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card + .card { margin-top: 18px; }
.center { text-align: center; }
.stack > * + * { margin-top: 14px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  padding: 14px 26px;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--brand-dark);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s ease;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--brand-dark); }
.btn.secondary { background: #eceeffe0; color: var(--brand-dark); box-shadow: 0 6px 0 #c9d0ff; }
.btn.ghost { background: transparent; color: var(--brand-dark); box-shadow: none; border: 2px solid #d3d9ff; }
.btn.success { background: var(--good); box-shadow: 0 6px 0 #1f9e63; }
.btn.danger  { background: var(--bad);  box-shadow: 0 6px 0 #d83a51; }
.btn.small { font-size: .95rem; padding: 10px 18px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; box-shadow: none; transform: none; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ---------- Formularios ---------- */
label { font-weight: 700; display: block; margin-bottom: 6px; }
input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  font-size: 1.1rem;
  padding: 12px 14px;
  border: 2px solid #d8ddf5;
  border-radius: var(--radius-sm);
  background: #fbfcff;
  color: var(--ink);
  font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px #5b6cff22;
}
.field + .field { margin-top: 14px; }
.hint { color: var(--ink-soft); font-size: .9rem; margin-top: 4px; }

/* ---------- Rejilla de perfiles / avatares ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}
.profile-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px 12px;
  text-align: center;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform .12s ease, border-color .12s ease;
}
.profile-card:hover { transform: translateY(-4px); border-color: var(--brand); }
.profile-card.add { display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--ink-soft); border: 3px dashed #c5ccf5; }
.avatar {
  width: 84px; height: 84px;
  border-radius: 50%;
  margin: 0 auto 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 44px;
  background: var(--bg);
  object-fit: cover;
  overflow: hidden;
}
.avatar.lg { width: 120px; height: 120px; font-size: 64px; }
.profile-name { font-weight: 800; font-size: 1.05rem; }

/* ---------- PIN ---------- */
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 18px 0; }
.pin-dot { width: 18px; height: 18px; border-radius: 50%; background: #d8ddf5; transition: background .15s; }
.pin-dot.filled { background: var(--brand); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 280px; margin: 0 auto; }
.keypad button {
  font-size: 1.5rem; font-weight: 800; padding: 16px; border: none;
  border-radius: var(--radius-sm); background: var(--card); color: var(--ink);
  box-shadow: var(--shadow-sm); cursor: pointer;
}
.keypad button:active { transform: scale(.95); }

/* ---------- Mapa de lecciones ---------- */
.unit { margin-bottom: 26px; }
.unit-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.unit-emoji { font-size: 1.8rem; }
.lessons-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.lesson-tile {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 16px; cursor: pointer; border: 3px solid transparent;
  display: flex; flex-direction: column; gap: 6px; transition: transform .12s, border-color .12s;
}
.lesson-tile:hover { transform: translateY(-3px); border-color: var(--brand); }
.lesson-tile.locked { opacity: .55; cursor: not-allowed; }
.lesson-tile.done { border-color: var(--good); }
.lesson-title { font-weight: 800; }
.lesson-sub { color: var(--ink-soft); font-size: .9rem; }
.stars { color: var(--star); letter-spacing: 2px; font-size: 1.1rem; }
.stars .off { color: #e2e6f5; }

/* ---------- Motor de escritura ---------- */
.practice-text {
  font-family: "Cascadia Code", "Consolas", ui-monospace, monospace;
  font-size: clamp(1.3rem, 3.4vw, 2rem);
  line-height: 1.9;
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  word-break: break-word;
  min-height: 90px;
  letter-spacing: 1px;
}
.ch { border-radius: 4px; padding: 1px 1px; }
.ch.pending { color: var(--ink-soft); }
.ch.correct { color: var(--good); }
.ch.wrong { color: var(--bad); background: var(--bad-soft); }
.ch.current { background: #fff0b8; box-shadow: 0 2px 0 var(--warn); animation: blink 1.1s infinite; }
.ch.space.wrong { background: var(--bad); }
@keyframes blink { 50% { background: #ffe066; } }

.metrics { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin: 16px 0; }
.metric {
  background: var(--card); border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
  padding: 10px 18px; text-align: center; min-width: 96px;
}
.metric .val { font-size: 1.6rem; font-weight: 800; }
.metric .lbl { color: var(--ink-soft); font-size: .82rem; text-transform: uppercase; letter-spacing: .5px; }
.metric.good .val { color: var(--good); }
.metric.bad .val { color: var(--bad); }

/* Campo de captura oculto que recibe las teclas */
.capture { position: absolute; opacity: 0; pointer-events: none; height: 0; width: 0; }

/* ---------- Teclado en pantalla ---------- */
.keyboard {
  background: #dfe3ff;
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow-sm);
  margin: 16px auto;
  max-width: 860px;
  user-select: none;
}
.kb-row { display: flex; gap: 6px; justify-content: center; margin-bottom: 6px; }
.key {
  flex: 1 1 0;
  min-width: 0;
  height: 48px;
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem;
  box-shadow: 0 3px 0 rgba(0,0,0,.12);
  position: relative;
  transition: transform .05s, filter .1s;
}
.key .sub { position: absolute; top: 3px; right: 5px; font-size: .62rem; color: var(--ink-soft); }
.key.w-1_5 { flex-grow: 1.5; } .key.w-1_75 { flex-grow: 1.75; }
.key.w-2 { flex-grow: 2; } .key.w-2_25 { flex-grow: 2.25; }
.key.w-6 { flex-grow: 6; }
.key.next { outline: 4px solid var(--brand); outline-offset: 1px; transform: translateY(-2px); z-index: 2; }
.key.pressed { transform: translateY(2px); filter: brightness(.92); }
.key.dim { opacity: .45; }
.key.bump::after { content: ""; position: absolute; bottom: 7px; left: 50%; transform: translateX(-50%); width: 14px; height: 3px; border-radius: 3px; background: var(--ink-soft); }
.key.diff { outline: 3px dashed var(--brand-dark); outline-offset: 1px; font-weight: 900; }

/* Colores por dedo */
.fg-pinky-l { background: var(--f-pinky-l); } .fg-ring-l { background: var(--f-ring-l); }
.fg-mid-l { background: var(--f-mid-l); } .fg-index-l { background: var(--f-index-l); }
.fg-index-r { background: var(--f-index-r); } .fg-mid-r { background: var(--f-mid-r); }
.fg-ring-r { background: var(--f-ring-r); } .fg-pinky-r { background: var(--f-pinky-r); }
.fg-thumb { background: var(--f-thumb); }

.finger-legend { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; }
.finger-legend span { font-size: .8rem; padding: 4px 10px; border-radius: 999px; color: #5a4a2a; font-weight: 700; }

/* ---------- Tarjetas de explicación (Conoce el teclado) ---------- */
.explain { font-size: 1.12rem; line-height: 1.65; }
.explain p { margin: .6em 0; }
.bigemoji { font-size: 3.2rem; text-align: center; }
.steps { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }
.step-dot { width: 10px; height: 10px; border-radius: 50%; background: #cfd5f5; }
.step-dot.on { background: var(--brand); }

/* Selector de layout mundial */
.layout-tabs { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 12px; }
.layout-tabs button { border: 2px solid #d3d9ff; background: var(--card); border-radius: 999px; padding: 8px 16px; font-weight: 800; cursor: pointer; }
.layout-tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- Ilustraciones SVG ---------- */
.hands-svg, .figure-svg { width: 100%; max-width: 720px; display: block; margin: 8px auto; }
.figure-svg { max-width: 480px; }
.lesson-img { width: 100%; max-width: 420px; display: block; margin: 8px auto; border-radius: var(--radius); }
.hand-finger { cursor: pointer; transition: opacity .12s ease; }
.hand-finger:hover { opacity: 1 !important; filter: brightness(1.06); }

.finger-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 14px 0 6px; }
.finger-chips button {
  border: none; border-radius: 999px; padding: 9px 15px; font-weight: 800; cursor: pointer;
  color: #3a3320; box-shadow: var(--shadow-sm); transition: transform .08s ease;
}
.finger-chips button:active { transform: scale(.95); }
.finger-chips button.sel { outline: 3px solid var(--brand); outline-offset: 1px; }
.finger-info { text-align: center; font-weight: 700; min-height: 1.6em; margin: 6px 0 2px; font-size: 1.05rem; }

/* ---------- Vídeo embebido ---------- */
.video-wrap {
  position: relative; width: 100%; max-width: 720px; margin: 8px auto;
  aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  background: #000;
}
.video-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---------- Diario ---------- */
.diary-entry { background: var(--card); border-radius: var(--radius-sm); box-shadow: var(--shadow-sm); padding: 14px; }
.diary-entry + .diary-entry { margin-top: 12px; }
.diary-date { font-weight: 800; color: var(--brand-dark); }
.diary-text { white-space: pre-wrap; margin-top: 6px; }

/* ---------- Tabla de progreso (panel padres) ---------- */
table.progress { width: 100%; border-collapse: collapse; }
table.progress th, table.progress td { text-align: left; padding: 10px; border-bottom: 1px solid #eef0ff; }
table.progress th { color: var(--ink-soft); font-size: .85rem; text-transform: uppercase; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px;
  box-shadow: var(--shadow); z-index: 50; font-weight: 700; max-width: 90vw;
}

/* ---------- Confeti / celebración ---------- */
.celebrate { text-align: center; }
.celebrate .big { font-size: 4rem; animation: pop .5s ease; }
@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }

/* Accesibilidad: respeta reduce-motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Responsive: teclas más bajas en móvil */
@media (max-width: 560px) {
  .key { height: 38px; font-size: .82rem; }
  .keyboard { padding: 8px; }
  .screen { padding: 16px 10px 32px; }
}
