/* styles.css — Diseño "hoja de ejercicios": limpio, monoespaciada para las
   ecuaciones, acento violeta. Responsive y accesible. */

:root {
  --bg: #eaeef5;
  --surface: #ffffff;
  --ink: #1b2230;
  --muted: #5b6472;
  --line: #dbe1ec;
  --accent: #5b4be1;
  --accent-dark: #4636c9;

  --ok: #15803d;
  --ok-bg: #e8f6ee;
  --ok-line: #b6e2c6;
  --err: #d13a3a;
  --err-bg: #fcecec;
  --err-line: #f2c4c4;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(27, 34, 48, .06), 0 8px 24px rgba(27, 34, 48, .06);
  --mono: ui-monospace, SFMono-Regular, "Cascadia Code", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 2rem 1rem 4rem;
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--bg);
  /* Papel cuadriculado sutil */
  background-image:
    linear-gradient(rgba(91, 75, 225, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91, 75, 225, .05) 1px, transparent 1px);
  background-size: 26px 26px;
  line-height: 1.5;
}

/* --- Cabecera --- */
.site-header { max-width: 760px; margin: 0 auto 1.5rem; }
.site-title {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  letter-spacing: -.02em;
}
.site-subtitle { margin: .35rem 0 0; color: var(--muted); }

.layout { max-width: 760px; margin: 0 auto; }

/* --- Controles --- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  justify-content: space-between;
  padding: 1rem;
  margin-bottom: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.controls-label {
  margin: 0 0 .5rem;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}
.level-selector { display: flex; flex-wrap: wrap; gap: .5rem; }

.level-btn {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  padding: .5rem .8rem;
  font-family: inherit;
  text-align: left;
  background: #f4f6fb;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .05s;
}
.level-btn:hover { border-color: var(--accent); }
.level-btn:active { transform: translateY(1px); }
.level-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.level-btn.is-active .level-hint { color: rgba(255, 255, 255, .8); }
.level-name { font-weight: 600; font-size: .92rem; }
.level-hint { font-family: var(--mono); font-size: .72rem; color: var(--muted); }

.score-block { text-align: right; }
.score {
  margin: 0;
  font-family: var(--mono);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--accent);
}

/* --- Tablero de ecuaciones --- */
.eq-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.eq-row {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) 6.5rem auto auto;
  align-items: center;
  gap: .75rem;
  padding: .6rem .9rem;
  border-top: 1px solid var(--line);
}
.eq-row:first-child { border-top: none; }

.eq-number {
  font-family: var(--mono);
  font-size: .8rem;
  color: var(--muted);
  text-align: right;
}
.eq-display {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}
.eq-input {
  width: 100%;
  padding: .45rem .55rem;
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.eq-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.eq-check {
  padding: .45rem .7rem;
  font-family: inherit;
  font-size: .85rem;
  font-weight: 600;
  color: var(--accent);
  background: #fff;
  border: 1px solid var(--accent);
  border-radius: 8px;
  cursor: pointer;
  transition: background-color .15s, color .15s;
}
.eq-check:hover { background: var(--accent); color: #fff; }

.eq-status {
  min-width: 6.5rem;
  font-size: .82rem;
  font-weight: 600;
}

/* Estados de fila */
.eq-row.is-correct { background: var(--ok-bg); }
.eq-row.is-correct .eq-input { border-color: var(--ok-line); }
.eq-row.is-correct .eq-status { color: var(--ok); }

.eq-row.is-wrong { background: var(--err-bg); }
.eq-row.is-wrong .eq-input { border-color: var(--err-line); }
.eq-row.is-wrong .eq-status { color: var(--err); }

/* --- Acciones --- */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-top: 1.25rem;
}
.btn {
  padding: .65rem 1.1rem;
  font-family: inherit;
  font-size: .95rem;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

/* Foco visible global para navegación por teclado */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Solo lectores de pantalla */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Responsive --- */
@media (max-width: 560px) {
  .eq-row {
    grid-template-columns: 1.6rem minmax(0, 1fr);
    grid-template-areas:
      "num eq"
      ".   input"
      ".   actions";
    row-gap: .5rem;
  }
  .eq-number { grid-area: num; }
  .eq-display { grid-area: eq; }
  .eq-input  { grid-area: input; }
  .eq-check  { grid-area: actions; justify-self: start; }
  .eq-status { grid-column: 2; }
}

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