:root {
  --bg: #0f1020;
  --panel: #1a1c33;
  --panel-2: #232544;
  --txt: #e7e9ff;
  --muted: #9aa0c7;
  --acc: #7c5cff;
  --acc-2: #3bc9db;
  --ok: #40d486;
  --bad: #ff5656;
  --warn: #ffd43b;
  --line: #2c2f50;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #1d1f3d, var(--bg));
  color: var(--txt);
  min-height: 100vh;
}

header.barra {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  background: rgba(20, 22, 45, .7);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.logo {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: .5px;
  background: linear-gradient(90deg, var(--acc), var(--acc-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.barra .crece { flex: 1; }

a.link, .navbtn {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 14px;
  cursor: pointer;
}
a.link:hover, .navbtn:hover { color: var(--txt); border-color: var(--acc); }

.contenido {
  max-width: 1100px;
  margin: 22px auto;
  padding: 0 18px;
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 880px) { .contenido { grid-template-columns: 1fr; } }

.lienzo-caja {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  background: #0c0d1c;
  touch-action: none;
  cursor: crosshair;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}
.panel h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

.titulo-nivel { font-size: 20px; font-weight: 700; margin: 2px 0 4px; }
.hint { color: var(--muted); font-size: 13px; min-height: 34px; }

.metricas { display: grid; gap: 10px; margin: 8px 0 14px; }
.metrica {
  display: flex; justify-content: space-between; align-items: baseline;
  background: var(--panel-2); padding: 10px 12px; border-radius: 10px;
}
.metrica span { color: var(--muted); font-size: 13px; }
.metrica b { font-size: 18px; }
.v-ok { color: var(--ok); }
.v-bad { color: var(--bad); }
.v-acc { color: var(--acc-2); }
.v-warn { color: var(--warn); }

.barra-prog {
  height: 12px; background: var(--panel-2); border-radius: 8px; overflow: hidden; margin-top: 4px;
}
.barra-prog > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--acc), var(--ok)); transition: width .25s; }

.fila { display: flex; gap: 10px; flex-wrap: wrap; }

button.btn {
  flex: 1;
  min-width: 90px;
  padding: 11px 12px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--txt);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
}
button.btn:hover { border-color: var(--acc); transform: translateY(-1px); }
button.btn.primario { background: linear-gradient(90deg, var(--acc), #5b8cff); border: none; }
button.btn.peligro:hover { border-color: var(--bad); }
button.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--txt);
  border: 1px solid var(--line);
  font-size: 14px;
}

.fila-chk { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; margin-top: 10px; }

.medalla {
  text-align: center; padding: 12px; border-radius: 12px; margin-top: 12px;
  background: var(--panel-2); font-size: 14px;
}
.medalla b { color: var(--warn); }

/* ---------- Editor ---------- */
.editor-grid {
  max-width: 1200px; margin: 22px auto; padding: 0 18px;
  display: grid; grid-template-columns: 220px 1fr 280px; gap: 18px; align-items: start;
}
@media (max-width: 1000px) { .editor-grid { grid-template-columns: 1fr; } }

.herramientas { display: grid; gap: 8px; }
.herramientas .htitulo { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; margin: 10px 0 2px; }

.campo { margin-bottom: 10px; }
.campo label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.campo input[type="text"], .campo input[type="number"] {
  width: 100%; padding: 8px 10px; border-radius: 9px;
  background: var(--panel-2); color: var(--txt); border: 1px solid var(--line); font-size: 13px;
}
.campo input[type="color"] { width: 100%; height: 38px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); }

.lista-figuras { display: grid; gap: 6px; max-height: 240px; overflow: auto; margin-top: 6px; }
.item-figura {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: var(--panel-2); border-radius: 9px; font-size: 13px; cursor: pointer;
  border: 1px solid transparent;
}
.item-figura.sel { border-color: var(--acc); }
.item-figura .punto { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.item-figura .crece { flex: 1; }
.item-figura .tag { font-size: 10px; color: var(--warn); }

textarea {
  width: 100%; min-height: 120px; border-radius: 10px; background: #0c0d1c;
  color: var(--ok); border: 1px solid var(--line); padding: 10px; font-family: ui-monospace, monospace; font-size: 12px;
}

.aviso { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.5; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--acc); color: #fff; padding: 10px 18px; border-radius: 12px;
  font-weight: 600; opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 50;
}
.toast.ver { opacity: 1; }

/* ---------- Pantallas ---------- */
.pantalla { min-height: 100vh; }
.oculto { display: none !important; }
.centro { display: flex; align-items: center; justify-content: center; padding: 30px 18px; }

/* ---------- Menú ---------- */
.menu {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 30px 18px;
  background: radial-gradient(900px 500px at 50% 0%, #241a44, var(--bg));
}
.menu-caja { text-align: center; max-width: 560px; }
.menu-sub { color: var(--acc-2); letter-spacing: 4px; text-transform: uppercase; font-size: 13px; margin-bottom: 10px; }
.menu-titulo {
  font-size: clamp(40px, 9vw, 78px); line-height: .98; margin: 0 0 18px; font-weight: 900;
  background: linear-gradient(90deg, #b197fc, var(--acc-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 10px 40px rgba(124,92,255,.25);
}
.menu-lema { color: var(--muted); font-size: 16px; margin: 0 auto 28px; max-width: 420px; }
.menu-botones { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.btn.grande { flex: 0 1 auto; min-width: 180px; padding: 16px 26px; font-size: 17px; }
.menu-editor { display: inline-block; margin-top: 26px; }

/* ---------- Reloj y barra de tiempo ---------- */
.nivel-cont { color: var(--muted); font-size: 15px; }
.nivel-cont b { color: var(--txt); }
.reloj {
  font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums;
  color: var(--acc-2); min-width: 78px; text-align: right;
}
.reloj.urgente { color: var(--bad); animation: latido .6s infinite; }
@keyframes latido { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }

.tiempo-barra { height: 6px; background: var(--panel-2); overflow: hidden; }
.tiempo-barra > i {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--bad), var(--warn), var(--ok));
  transition: width .1s linear;
}

/* ---------- Resultados / Puntuaciones ---------- */
.resultado-caja {
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: 30px; max-width: 520px; width: 100%; text-align: center;
  box-shadow: 0 25px 60px rgba(0,0,0,.4);
}
.res-titulo {
  font-size: clamp(30px, 6vw, 46px); margin: 0 0 6px; font-weight: 900;
  background: linear-gradient(90deg, var(--ok), var(--acc-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tabla { display: grid; gap: 6px; margin: 18px 0; text-align: left; max-height: 320px; overflow: auto; }
.fila-tabla {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel-2); padding: 10px 14px; border-radius: 10px; font-size: 14px;
}
.fila-tabla b { color: var(--ok); font-variant-numeric: tabular-nums; }
.total-caja {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px; border-radius: 14px; margin-top: 8px;
  background: linear-gradient(90deg, rgba(124,92,255,.25), rgba(59,201,219,.2));
  border: 1px solid var(--acc);
}
.total-caja span { color: var(--muted); font-size: 15px; }
.total-caja b { font-size: 34px; font-weight: 900; color: var(--txt); }
.record-msg { color: var(--muted); font-size: 14px; margin: 14px 0 4px; min-height: 20px; }
.record-msg.destacado { color: var(--warn); font-weight: 700; }
.resultado-caja .menu-botones { margin-top: 22px; }
