/**
 * Estilos canónicos del Laboratorio de Teoría de Juegos
 * Fijate Tools • Game Theory Studio
 */

:root {
  --bg-body: #0a0e17;
  --bg-card: #121826;
  --bg-card-subtle: #182234;
  --bg-card-hover: #1f2c42;
  --border-color: #26334d;
  --border-focus: #3b82f6;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #ff8507;
  --accent-glow: rgba(255, 133, 7, 0.18);
  --j1-color: #38bdf8;
  --j2-color: #f97316;
  --nash-color: #10b981;
  --nash-bg: rgba(16, 185, 129, 0.14);
  --nash-border: #10b981;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font-mono: 'JetBrains Mono', monospace;
  --font-heading: 'Outfit', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="light"] {
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-card-hover: #e2e8f0;
  --border-color: #cbd5e1;
  --border-focus: #2563eb;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --accent: #ea580c;
  --accent-glow: rgba(234, 88, 12, 0.12);
  --j1-color: #0284c7;
  --j2-color: #ea580c;
  --nash-color: #059669;
  --nash-bg: rgba(5, 150, 105, 0.12);
  --nash-border: #059669;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-wrapper.tool-layout {
  max-width: 1360px;
  margin: 1rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
  flex: 1;
}

.tool-with-sidebar {
  display: flex;
  gap: 1.75rem;
  align-items: flex-start;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

/* --- Presets Bar --- */
.card-presets {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.presets-header {
  margin-bottom: 0.65rem;
}

.presets-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.presets-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn-preset {
  background: var(--bg-card-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
}

.btn-preset:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
  transform: translateY(-1px);
}

.btn-preset.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* --- Pestañas de Navegación de la Suite --- */
.game-nav-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 1.5rem;
}

.tab-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 9px 9px 0 0;
  padding: 0.65rem 1.15rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  transition: all 0.2s ease;
  position: relative;
  margin-bottom: -2px;
}

.tab-btn:hover {
  color: var(--text-main);
  background: var(--bg-card-subtle);
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--accent);
  border-color: var(--border-color) var(--border-color) var(--bg-card);
  border-top: 3px solid var(--accent);
  z-index: 2;
}

/* Paneles */
.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- VISTA 1: MATRIZ Y RESULTADOS --- */
.matrix-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 1024px) {
  .matrix-layout {
    grid-template-columns: 1fr;
  }
}

.matrix-card, .results-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.matrix-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.section-title {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.section-desc {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.matrix-size-selector {
  display: flex;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.btn-size {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
}

.btn-size.active {
  background: var(--accent);
  color: #ffffff;
}

/* Tabla de Matriz de Pagos */
.matrix-wrapper {
  overflow-x: auto;
  padding: 0.5rem 0;
}

.game-matrix-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 6px;
}

.game-matrix-table th {
  padding: 0.5rem;
  text-align: center;
  font-size: 0.85rem;
}

.header-p2-cell {
  background: rgba(249, 115, 22, 0.12);
  border: 1px solid var(--j2-color);
  border-radius: var(--radius-sm);
  color: var(--j2-color);
  font-weight: 700;
}

.header-p1-cell {
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid var(--j1-color);
  border-radius: var(--radius-sm);
  color: var(--j1-color);
  font-weight: 700;
  width: 120px;
}

.strat-input {
  width: 100%;
  background: transparent;
  border: none;
  text-align: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: inherit;
  outline: none;
}

.cell-payoff {
  background: var(--bg-card-subtle);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.5rem;
  text-align: center;
  transition: all 0.2s ease;
  position: relative;
}

.cell-payoff.is-nash {
  background: var(--nash-bg);
  border-color: var(--nash-border);
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.25);
}

.payoff-pair {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.payoff-input {
  width: 54px;
  min-height: 38px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  outline: none;
}

.payoff-input:focus {
  border-color: var(--border-focus);
}

.p1-val { color: var(--j1-color); }
.p2-val { color: var(--j2-color); }

.payoff-input.best-response {
  text-decoration: underline;
  text-decoration-thickness: 3px;
  background: rgba(255, 255, 255, 0.05);
}

.p1-val.best-response { text-decoration-color: var(--j1-color); }
.p2-val.best-response { text-decoration-color: var(--j2-color); }

.nash-badge-star {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.7rem;
  background: var(--nash-color);
  color: #ffffff;
  padding: 1px 4px;
  border-radius: 4px;
  font-weight: 700;
}

.matrix-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-color);
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.chip-color {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.chip-j1 .chip-color { background: var(--j1-color); }
.chip-j2 .chip-color { background: var(--j2-color); }
.chip-nash .chip-color { background: var(--nash-color); }

/* Resumen de Equilibrios */
.nash-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

@media (max-width: 640px) {
  .nash-summary-grid {
    grid-template-columns: 1fr;
  }
}

.summary-box {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.summary-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
}

.summary-val {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.summary-list {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.summary-list strong {
  color: var(--text-main);
}

/* Caja de Deducción Algebraica */
.algebra-steps-box {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.algebra-title {
  font-family: var(--font-heading);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.algebra-content {
  font-size: 0.86rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.algebra-step {
  margin-bottom: 0.65rem;
  padding-left: 0.75rem;
  border-left: 2px solid var(--accent);
}

.algebra-step strong {
  color: var(--text-main);
}

.math-mono {
  font-family: var(--font-mono);
  color: var(--text-main);
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.84rem;
}

/* --- VISTA 2: MEJORES RESPUESTAS --- */
.reactions-layout {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .reactions-layout {
    grid-template-columns: 1fr;
  }
}

.reactions-graph-card, .reactions-info-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.reactions-svg-box {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
}

#reactions-svg {
  width: 100%;
  height: auto;
  min-height: 380px;
  display: block;
}

.info-card-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

.info-content {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.reactions-legend {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
}

.rx-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.rx-line {
  width: 24px;
  height: 3px;
  border-radius: 2px;
}

.rx-j1 { background: var(--j1-color); }
.rx-j2 { background: var(--j2-color); }
.rx-point {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--nash-color);
}

/* --- VISTA 3: SIMULADOR REPETIDO --- */
.repeated-layout {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.repeated-controls-card, .repeated-graph-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

.strategy-selectors-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin: 1.25rem 0 1rem;
}

@media (max-width: 768px) {
  .strategy-selectors-grid {
    grid-template-columns: 1fr;
  }
}

.strategy-col {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.strat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

.form-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  background: var(--bg-card-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  min-height: 40px;
  cursor: pointer;
}

.btn-run-sim {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.65rem 1.5rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  min-height: 40px;
  transition: all 0.2s ease;
}

.btn-run-sim:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.repeated-stats-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.score-badge {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.65rem 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
}

.badge-p1 strong { color: var(--j1-color); font-family: var(--font-mono); font-size: 1.1rem; }
.badge-p2 strong { color: var(--j2-color); font-family: var(--font-mono); font-size: 1.1rem; }
.badge-winner strong { color: var(--accent); font-family: var(--font-heading); font-size: 1.05rem; }

.timeline-svg-container {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  margin-bottom: 1.25rem;
}

#timeline-svg {
  width: 100%;
  height: auto;
  min-height: 220px;
  display: block;
}

.rounds-history-table-container {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.rounds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.rounds-table th {
  position: sticky;
  top: 0;
  background: var(--bg-card-hover);
  color: var(--text-muted);
  text-align: left;
  padding: 0.65rem 0.85rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
}

.rounds-table td {
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  font-family: var(--font-mono);
}

.rounds-table tr:hover {
  background: var(--bg-card-subtle);
}

/* Modales Canónicos */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
}

.modal-dialog-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
}

.modal-body {
  font-size: 0.92rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1.25rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  min-height: 40px;
}
