/* Colores y variables de toda la página */
:root{
  /* Modo oscuro (el que se ve por defecto) */
  --bg: #14121C;
  --surface: #1C1926;
  --surface-2: #262232;
  --text: #EDEAF0;
  --muted: #93899F;
  --red: #A8456B;
  --red-soft: #7A3350;
  --green: #4C8C6B;
  --gold: #E3A7AE;
  --line: #332E42;

  /* Colores de la hoja donde se escribe (oscura, no blanca) */
  --page-bg: #17141F;
  --page-text: #E4DEE6;
  --page-text-soft: #8B8296;
  --page-border: #352E45;
  --page-input-bg: #201C2C;
  --page-placeholder: #6b6478;
  --page-shadow: 0 24px 60px -28px rgba(5,4,10,0.9), inset 0 0 0 1px rgba(255,255,255,0.02);

  --card-shadow: 0 10px 26px -20px rgba(5,4,10,0.65);

  --font-display: "Source Serif 4", Georgia, serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
  --radius: 3px;
}

/* Modo claro: mismas variables, otros valores. Se activa con
   data-theme="light" en <html>, lo pone script.js */
[data-theme="light"]{
  --bg: #F5F3EE;
  --surface: #FFFFFF;
  --surface-2: #ECE8DE;
  --text: #23222A;
  --muted: #6b7280;
  --red: #A63333;
  --red-soft: #832828;
  --green: #3f7d5c;
  --gold: #9c7a1a;
  --line: #DDD8C9;

  --page-bg: #FFFFFF;
  --page-text: #23211C;
  --page-text-soft: #6b6454;
  --page-border: #cfc7ad;
  --page-input-bg: #fbf9f2;
  --page-placeholder: #9a927a;
  --page-shadow: 0 18px 40px -24px rgba(0,0,0,0.18);

  --card-shadow: 0 8px 20px -18px rgba(0,0,0,0.12);
}

*{ box-sizing: border-box; }
html{ -webkit-font-smoothing: antialiased; }

body{
  margin:0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
}

button{ font-family: inherit; }

/* Botón de modo oscuro/claro, fijo arriba a la derecha */
.theme-toggle{
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  cursor: pointer;
  box-shadow: var(--card-shadow);
  transition: border-color 0.15s ease;
}
.theme-toggle:hover{ border-color: var(--muted); }

@media (max-width: 520px){
  .theme-toggle{ top: 0.7rem; right: 0.7rem; font-size: 0.72rem; padding: 0.4rem 0.75rem; }
}

/* Quita animaciones si el usuario las tiene desactivadas */
@media (prefers-reduced-motion: reduce){
  *{ animation: none !important; transition: none !important; }
}

/* Encabezado */
.masthead{
  border-bottom: 1px solid var(--line);
  padding: 3rem 1.5rem 2.25rem;
}
.masthead__inner{
  max-width: 920px;
  margin: 0 auto;
}
.masthead__kicker{
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--gold);
  margin: 0 0 0.9rem;
}
.masthead__title{
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.8rem, 4.5vw, 2.9rem);
  line-height: 1.1;
  margin: 0 0 0.85rem;
  max-width: 30ch;
}
.masthead__subtitle{
  font-size: 1.02rem;
  color: var(--muted);
  max-width: 62ch;
  margin: 0;
}

/* Contenedor general de la página */
.layout{
  max-width: 1180px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 2.25rem;
}

/* Formulario de datos del participante */
.student-info{
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  box-shadow: var(--card-shadow);
}
.student-info__title{
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  margin: 0 0 1rem;
}
.student-info__fields{
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}
.field{
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.field label{
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
}
.field input{
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface-2);
  color: var(--text);
}
.field input:focus{ outline: 1px solid var(--gold); outline-offset: 1px; }
.student-info__hint{
  margin: 0.9rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

/* Campos en una sola columna en pantallas angostas */
@media (max-width: 700px){
  .student-info__fields{ grid-template-columns: 1fr; }
}

/* Área de escritura: hoja + barra lateral */
.writing{
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 1.75rem;
  align-items: start;
}

.page{
  background: var(--page-bg);
  color: var(--page-text);
  border: 1px solid var(--page-border);
  border-radius: 4px;
  padding: 1.9rem 1.9rem 1.1rem;
  box-shadow: var(--page-shadow);
  min-height: 560px;
  display: flex;
  flex-direction: column;
}

.page__topbar{
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.1rem;
  padding-bottom: 1rem;
  border-bottom: 1px dashed var(--page-border);
}
.page__topic-label{
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--page-text-soft);
}
.page__topic-select, .page__topic-custom{
  font-family: var(--font-body);
  font-size: 0.88rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--page-border);
  background: var(--page-input-bg);
  color: var(--page-text);
  border-radius: 2px;
  flex: 1 1 220px;
  min-width: 0;
}
/* selector de Fase, más angosto que el de Tema */
.page__topic-select--phase{
  flex: 0 1 130px;
}

.page__prompt{
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.4rem;
  margin: 0 0 1.1rem;
  color: var(--page-text);
}

.page__editor{
  flex: 1;
  min-height: 320px;
  resize: vertical;
  border: none;
  background: transparent;
  color: var(--page-text);
  font-family: var(--font-display);
  font-size: 1.14rem;
  line-height: 1.85;
  letter-spacing: 0.01em;
  outline: none;
}
.page__editor::placeholder{ color: var(--page-placeholder); }

.page__footer{
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--page-text-soft);
  padding-top: 0.9rem;
  margin-top: 0.6rem;
  border-top: 1px dashed var(--page-border);
}

/* Barra lateral: cronómetro, meta de palabras y recordatorios */
.sidebar{
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  position: sticky;
  top: 1.5rem;
}
.sidebar__block{
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--card-shadow);
}
.sidebar__label{
  display: block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.sidebar__timer{
  display: block;
  font-family: var(--font-mono);
  font-size: 1.8rem;
  color: var(--text);
  margin-bottom: 0.7rem;
}
.sidebar__timer-controls{
  display: flex;
  gap: 0.5rem;
}

/* Barra de progreso: ancho y color los cambia script.js */
.meter{
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.meter__bar{
  height: 100%;
  width: 0%;
  background: var(--gold);
  transition: width 0.25s ease, background 0.25s ease;
}
.sidebar__hint{
  font-size: 0.78rem;
  color: var(--muted);
}

.sidebar__tips{
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Botones: primario (relleno) y secundario (solo borde) */
.btn{
  border-radius: 2px;
  border: 1px solid transparent;
  padding: 0.65rem 1.1rem;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
}
.btn--primary{
  background: var(--red);
  color: #fff;
  width: 100%;
}
.btn--primary:hover:not(:disabled){ background: var(--red-soft); }
.btn--primary:disabled{ opacity: 0.4; cursor: not-allowed; }

.btn--ghost{
  background: transparent;
  border-color: var(--line);
  color: var(--text);
  flex: 1;
}
.btn--ghost:hover:not(:disabled){ border-color: var(--muted); }
.btn--ghost:disabled{ opacity: 0.4; cursor: not-allowed; }

/* Pantalla de confirmación (oculta hasta entregar) */
.confirmation{
  border-top: 1px solid var(--line);
  padding-top: 2rem;
}
.confirmation h2{
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.6rem;
  margin: 0 0 0.8rem;
}
.confirmation p{
  color: var(--muted);
  margin: 0 0 0.5rem;
}
.confirmation strong{ color: var(--text); }
.confirmation__actions{
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-top: 1.2rem;
}
.confirmation__actions .btn{ width: auto; min-width: 200px; }

/* Comparación pre-test / post-test (oculta hasta pedirla) */
.comparison{
  border-top: 1px solid var(--line);
  padding-top: 2rem;
}
.comparison h2{
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.6rem;
  margin: 0 0 1rem;
}
.comparison p{ color: var(--muted); }

.compare-grid{
  display: grid;
  grid-template-columns: 120px 1fr 1fr;
  gap: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  box-shadow: var(--card-shadow);
}
.compare-grid > div{
  padding: 0.4rem 0;
  font-size: 0.88rem;
}
.compare-grid > div:nth-child(3n+1){
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  align-self: center;
}
.compare-row-header{
  font-weight: 600;
  color: var(--gold);
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.6rem !important;
  margin-bottom: 0.3rem;
}

@media (max-width: 520px){
  .compare-grid{ grid-template-columns: 90px 1fr 1fr; font-size: 0.8rem; }
}

/* Pie de página */
.site-footer{
  border-top: 1px solid var(--line);
  padding: 1.6rem 1.5rem 2.4rem;
  text-align: center;
}
.site-footer p{
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  max-width: 60ch;
  margin: 0 auto;
}

/* Ajustes para pantallas medianas: hoja y barra lateral se apilan */
@media (max-width: 860px){
  .writing{ grid-template-columns: 1fr; }
  .sidebar{
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .sidebar__block{ flex: 1 1 220px; }
  .sidebar__block--tips{ flex-basis: 100%; }
  #submitBtn{ flex-basis: 100%; }
}

/* Ajustes para celulares */
@media (max-width: 520px){
  .masthead{ padding: 2.2rem 1.1rem 1.8rem; }
  .layout{ padding: 1.6rem 1.1rem 3rem; }
  .page{ padding: 1.4rem 1.2rem 0.9rem; }
  .confirmation__actions .btn{ width: 100%; min-width: 0; }
}
/* ===========================================================================
   Estado de conexión y código de participante
   =========================================================================== */
.student-info__status{ margin: 6px 0 0; display: flex; gap: 8px; flex-wrap: wrap; }

.pill{
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
}
.pill--ok{ color: var(--green); border-color: var(--green); }
.pill--error{ color: var(--red); border-color: var(--red); }
.pill--wait{ color: var(--muted); }
.pill--code{ color: var(--gold); border-color: var(--gold); }

/* ===========================================================================
   Panel de resultados de la rúbrica
   =========================================================================== */
.rubric{ margin-top: 18px; display: grid; gap: 14px; }

.rubric__aviso{
  margin: 0;
  padding: 8px 10px;
  border-left: 2px solid var(--gold);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}

.rubric__dim{
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.rubric__dim-head{
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.rubric__dim-head h4{
  margin: 0;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  flex: 1;
}
.rubric__peso{ font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.rubric__prom{ font-family: var(--font-mono); font-size: 13px; font-weight: 500; }

.rubric__params{ list-style: none; margin: 0; padding: 0; }
.rubric__param{ padding: 9px 12px; border-top: 1px solid var(--line); }
.rubric__param:first-child{ border-top: 0; }

.rubric__param-head{ display: flex; align-items: center; gap: 10px; }
.rubric__param-name{ flex: 1; font-size: 13px; }

.rubric__chip{
  font-family: var(--font-mono);
  font-size: 12px;
  min-width: 26px;
  text-align: center;
  padding: 2px 7px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

.nivel--alto{ color: var(--green); border-color: var(--green); }
.nivel--medio-alto{ color: var(--green); }
.nivel--medio{ color: var(--gold); }
.nivel--medio-bajo{ color: var(--gold); border-color: var(--gold); }
.nivel--bajo{ color: var(--red); border-color: var(--red); }

.rubric__just{
  margin: 6px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

.rubric__evid{
  margin: 6px 0 0;
  padding-left: 14px;
  font-size: 12px;
  color: var(--page-text-soft);
  font-style: italic;
}

.rubric__notas{
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px 12px;
}
.rubric__notas h4{
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 14px;
}
.rubric__notas ul{ margin: 0; padding-left: 16px; font-size: 13px; line-height: 1.55; }

/* Cambio por parámetro en la comparación pre/post */
.delta-list{ list-style: none; padding: 0; }
.delta-list li{
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  border-bottom: 1px dotted var(--line);
}
.delta-list li:last-child{ border-bottom: 0; }
.delta--sube{ color: var(--green); font-family: var(--font-mono); }
.delta--baja{ color: var(--red); font-family: var(--font-mono); }
.delta--igual{ color: var(--muted); font-family: var(--font-mono); }

.compare-delta{
  margin-top: 10px;
  font-size: 14px;
}
