.v4-master-view{
  width:100%;
  max-width:1500px;
  margin:0 auto;
}

.v4-master-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:18px;

  margin-bottom:22px;
}

.v4-master-head h1{
  margin:0;

  font-family:
    Georgia,
    "Times New Roman",
    serif;

  font-size:
    clamp(30px,4vw,48px);

  line-height:1.02;

  letter-spacing:-.035em;

  color:var(--ink);
}

.v4-master-head p{
  max-width:720px;

  margin:
    8px 0 0;

  color:var(--muted);

  line-height:1.55;
}

.v4-master-eyebrow{
  display:block;

  margin-bottom:8px;

  color:var(--gold);

  font-size:9px;
  font-weight:900;

  letter-spacing:.15em;
  text-transform:uppercase;
}

.v4-master-refresh{
  min-height:40px;

  padding:
    0 15px;

  border:
    1px solid
    var(--border);

  border-radius:12px;

  background:#fff;

  color:var(--purple);

  font-weight:800;
}

.v4-master-grid{
  display:grid;

  grid-template-columns:
    repeat(
      4,
      minmax(0,1fr)
    );

  gap:14px;

  margin-bottom:18px;
}

.v4-master-stat{
  padding:20px;

  border:
    1px solid
    var(--border);

  border-radius:17px;

  background:#fff;

  box-shadow:
    var(--shadow-soft);
}

.v4-master-stat span{
  display:block;

  color:var(--muted);

  font-size:9px;
  font-weight:800;

  letter-spacing:.06em;
  text-transform:uppercase;
}

.v4-master-stat strong{
  display:block;

  margin-top:8px;

  font-family:
    Georgia,
    "Times New Roman",
    serif;

  font-size:31px;

  color:var(--ink);
}

.v4-master-layout{
  display:grid;

  grid-template-columns:
    minmax(0,1.35fr)
    minmax(300px,.65fr);

  gap:16px;
}

.v4-master-card{
  min-width:0;

  padding:20px;

  border:
    1px solid
    var(--border);

  border-radius:18px;

  background:#fff;

  box-shadow:
    var(--shadow-soft);
}

.v4-master-card.full{
  grid-column:1/-1;
}

.v4-master-card h2,
.v4-master-card h3{
  margin:
    0 0 6px;

  color:var(--ink);
}

.v4-master-card h2{
  font-family:
    Georgia,
    "Times New Roman",
    serif;

  font-size:24px;
}

.v4-master-card > p{
  margin:
    0 0 16px;

  color:var(--muted);

  font-size:11px;
  line-height:1.5;
}

.v4-master-list{
  display:grid;
  gap:8px;
}

.v4-master-row{
  display:flex;

  align-items:center;
  justify-content:space-between;

  gap:12px;

  padding:
    11px 12px;

  border:
    1px solid
    #eee6ef;

  border-radius:12px;

  background:
    #fffdff;
}

.v4-master-row > div{
  min-width:0;
}

.v4-master-row strong{
  display:block;

  color:var(--ink);

  font-size:11px;
}

.v4-master-row small{
  display:block;

  margin-top:3px;

  color:var(--muted);

  overflow-wrap:anywhere;
}

.v4-master-status{
  flex:0 0 auto;

  padding:
    5px 8px;

  border-radius:999px;

  background:#f2e6f5;

  color:var(--purple);

  font-size:8px;
  font-weight:900;

  letter-spacing:.04em;
  text-transform:uppercase;
}

.v4-master-status.ready{
  background:#e8f7ef;
  color:#177149;
}

.v4-master-status.partial{
  background:#fff5df;
  color:#966311;
}

.v4-master-status.error{
  background:#fcebed;
  color:#a44050;
}

.v4-master-status.blocked{
  background:#ece9ef;
  color:#5f5864;
}

.v4-master-empty{
  padding:24px;

  border:
    1px dashed
    var(--border);

  border-radius:14px;

  color:var(--muted);

  text-align:center;

  font-size:11px;
}

/* ALIDAX */

.v4-alidax-layout{
  display:grid;

  grid-template-columns:
    300px
    minmax(0,1fr);

  gap:14px;
}

.v4-alidax-threads{
  max-height:520px;
  overflow:auto;
}

.v4-alidax-thread{
  width:100%;

  margin-bottom:7px;

  padding:
    11px 12px;

  border:
    1px solid
    var(--border);

  border-radius:11px;

  background:#fff;

  color:var(--ink);

  text-align:left;
}

.v4-alidax-thread.active{
  border-color:
    var(--purple);

  background:
    #f7eef8;
}

.v4-alidax-thread strong{
  display:block;
}

.v4-alidax-thread small{
  color:var(--muted);
}

.v4-alidax-messages{
  min-height:300px;
  max-height:470px;

  overflow:auto;

  padding:12px;

  border:
    1px solid
    var(--border);

  border-radius:14px;

  background:
    #fcfafc;
}

.v4-alidax-message{
  max-width:84%;

  margin-bottom:9px;

  padding:
    10px 12px;

  border-radius:13px;

  background:#fff;

  border:
    1px solid
    #ece4ee;

  white-space:pre-wrap;
}

.v4-alidax-message.user{
  margin-left:auto;

  background:
    #f4e9f6;

  border-color:
    #e2cfe6;
}

.v4-alidax-message strong{
  display:block;

  margin-bottom:4px;

  color:var(--purple);

  font-size:8px;

  text-transform:uppercase;
}

.v4-alidax-compose{
  display:grid;

  grid-template-columns:
    1fr auto;

  gap:9px;

  margin-top:10px;
}

.v4-alidax-compose textarea{
  min-height:82px;

  padding:11px;

  border:
    1px solid
    var(--border);

  border-radius:12px;

  resize:vertical;
}

.v4-master-button{
  min-height:40px;

  padding:
    0 14px;

  border:0;

  border-radius:11px;

  background:
    var(--purple);

  color:#fff;

  font-weight:800;
}

.v4-master-button.secondary{
  border:
    1px solid
    var(--border);

  background:#fff;

  color:var(--purple);
}

.v4-master-button.danger{
  background:#a94657;
}

.v4-learning-actions{
  display:flex;
  gap:7px;
  flex-wrap:wrap;
}

/* GAME FACTORY */

.v4-game-drop{
  padding:22px;

  border:
    1px dashed
    #cdb7d2;

  border-radius:16px;

  background:
    linear-gradient(
      135deg,
      #fff,
      #fbf5fc
    );

  text-align:center;
}

.v4-game-drop input{
  max-width:100%;
}

.v4-game-frame-wrap{
  margin-top:15px;

  border:
    1px solid
    var(--border);

  border-radius:17px;

  overflow:hidden;

  background:#18151c;
}

.v4-game-frame{
  display:block;

  width:100%;
  min-height:620px;

  border:0;

  background:#fff;
}

.v4-game-toolbar{
  display:flex;

  align-items:center;
  justify-content:space-between;

  gap:10px;

  margin-top:10px;

  flex-wrap:wrap;
}

.v4-game-status{
  color:var(--muted);

  font-size:10px;
}

/* RESPONSIVE */

@media(max-width:1000px){

  .v4-master-grid{
    grid-template-columns:
      repeat(
        2,
        minmax(0,1fr)
      );
  }

  .v4-master-layout{
    grid-template-columns:1fr;
  }

  .v4-alidax-layout{
    grid-template-columns:1fr;
  }

}

@media(max-width:650px){

  .v4-master-head{
    flex-direction:column;
  }

  .v4-master-grid{
    grid-template-columns:1fr;
  }

  .v4-alidax-compose{
    grid-template-columns:1fr;
  }

  .v4-game-frame{
    min-height:440px;
  }

}

/* ==========================================================
   MAG V4 · MASTER WIDE OVERRIDE
   ========================================================== */

.v4-master-view{
  width:100%;
  max-width:none;
  margin:0;
}

.v4-master-head{
  width:100%;

  margin-bottom:20px;

  padding:
    2px 2px 0;
}

.v4-master-head > div:first-child{
  max-width:
    min(
      900px,
      75%
    );
}

/* Métricas: aprovechar ancho real */
.v4-master-grid{
  width:100%;

  grid-template-columns:
    repeat(
      4,
      minmax(0,1fr)
    );

  gap:16px;
}

/* Dashboard principal */
.v4-master-layout{
  width:100%;

  grid-template-columns:
    minmax(0,1.45fr)
    minmax(360px,1fr);

  gap:18px;
}

.v4-master-card{
  width:100%;
}

/*
 * Integraciones y Runtime crecen con el lienzo.
 * Nada de columna angosta a la izquierda.
 */
.v4-master-card.full{
  grid-column:1 / -1;
}

/* ALIDAX: verdadera consola horizontal */
.v4-alidax-layout{
  grid-template-columns:
    minmax(280px,340px)
    minmax(0,1fr);

  gap:18px;
}

.v4-alidax-threads{
  width:100%;
}

.v4-alidax-messages{
  min-height:
    clamp(
      360px,
      48vh,
      620px
    );

  max-height:
    62vh;
}

.v4-alidax-compose{
  width:100%;

  grid-template-columns:
    minmax(0,1fr)
    auto;
}

/* Conversaciones y memoria a ancho completo */
.v4-master-view
.v4-master-card.full{
  width:100%;
}

/* Fábrica de Juegos */
.v4-game-frame{
  min-height:
    max(
      620px,
      calc(100vh - 270px)
    );
}

/* Pantallas muy grandes */
@media(min-width:1700px){

  .v4-master-grid{
    gap:18px;
  }

  .v4-master-layout{
    grid-template-columns:
      minmax(0,1.55fr)
      minmax(420px,.85fr);
  }

  .v4-alidax-layout{
    grid-template-columns:
      380px
      minmax(0,1fr);
  }

}

/* Tablet */
@media(max-width:1150px){

  .v4-master-grid{
    grid-template-columns:
      repeat(
        2,
        minmax(0,1fr)
      );
  }

  .v4-master-layout{
    grid-template-columns:1fr;
  }

  .v4-alidax-layout{
    grid-template-columns:
      280px
      minmax(0,1fr);
  }

}

/* Móvil */
@media(max-width:760px){

  .v4-master-grid{
    grid-template-columns:1fr;
  }

  .v4-master-layout,
  .v4-alidax-layout{
    grid-template-columns:1fr;
  }

  .v4-master-head{
    flex-direction:column;
  }

  .v4-master-head > div:first-child{
    max-width:100%;
  }

  .v4-alidax-compose{
    grid-template-columns:1fr;
  }

}
