:root {
  color-scheme: light;
  --bg: #eee5d2;
  --panel: #f7efdf;
  --panel-2: #fff9eb;
  --card: #fffaf0;
  --line: rgba(93, 77, 51, 0.18);
  --line-strong: rgba(93, 77, 51, 0.34);
  --text: #4a4133;
  --ink: #3a342a;
  --muted: #9a8a72;
  --muted-2: #a89a82;

  --accent: #cf7a5a;
  --accent-soft: #e0a96d;
  --sage: #6f9460;
  --blue: #5f93a8;
  --gold: #d99a3f;
  --violet: #9b7fc4;
  --danger: #cf7a5a;

  --age-child: #7fb5d6;
  --age-youth: #84b37a;
  --age-adult: #e0a96d;
  --age-elder: #b89bd0;

  --r-lg: 14px;
  --r-md: 9px;
  --r-sm: 7px;
  --shadow: 0 4px 12px rgba(90, 66, 30, 0.12);
  --shadow-soft: 0 2px 6px rgba(90, 66, 30, 0.1);

  --display: "Baloo 2", ui-rounded, system-ui, sans-serif;
  --body: Nunito, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  font-family: var(--body);
  background:
    radial-gradient(circle at 18px 18px, rgba(120, 100, 70, 0.05) 1px, transparent 1.5px) 0 0 / 22px 22px,
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button,
select,
input {
  font: inherit;
}

button,
select,
input[type="search"] {
  min-height: 32px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
}

input[type="search"] {
  width: 100%;
  padding: 0 12px;
}

select {
  padding: 0 8px;
  cursor: pointer;
  /* Sin esto, el ancho minimo del select lo fija su opcion mas larga y desborda
     la rejilla que lo contiene (p. ej. "Poblacion desde cero" se recortaba). */
  min-width: 0;
  max-width: 100%;
}

button {
  cursor: pointer;
  padding: 0 10px;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

button:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-soft);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
  box-shadow: none;
  transform: none;
}

.primary-button {
  background: linear-gradient(140deg, #b8cc80, #7eaa68);
  border-color: transparent;
  color: #fff;
  font-weight: 800;
  box-shadow: 0 3px 8px rgba(111, 148, 96, 0.3);
}

.primary-button:hover {
  border-color: transparent;
  filter: brightness(1.04);
}

.app-shell {
  --left-panel-size: 264px;
  --right-panel-size: 272px;
  --timeline-size: 116px;
  position: relative;
  display: grid;
  grid-template-columns: var(--left-panel-size) minmax(360px, 1fr) var(--right-panel-size);
  grid-template-rows: minmax(260px, 1fr) var(--timeline-size);
  height: 100vh;
  gap: 0;
}

.layout-resizer {
  position: absolute;
  z-index: 60;
  display: grid;
  place-items: center;
  touch-action: none;
  outline: none;
}

.layout-resizer::before {
  content: "";
  display: block;
  border-radius: 999px;
  background: rgba(95, 147, 168, 0.48);
  box-shadow: 0 0 0 1px rgba(255, 250, 240, 0.9);
  opacity: 0.72;
  transition: opacity 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.layout-resizer:hover::before,
.layout-resizer:focus-visible::before,
.layout-resizer.is-dragging::before {
  opacity: 1;
  background: rgba(95, 147, 168, 0.82);
}

.layout-resizer-left,
.layout-resizer-right {
  top: 0;
  bottom: var(--timeline-size);
  width: 12px;
  cursor: col-resize;
}

.layout-resizer-left {
  left: calc(var(--left-panel-size) - 6px);
}

.layout-resizer-right {
  right: calc(var(--right-panel-size) - 6px);
}

.layout-resizer-left::before,
.layout-resizer-right::before {
  width: 4px;
  height: 46px;
}

.layout-resizer-timeline {
  left: 0;
  right: 0;
  bottom: calc(var(--timeline-size) - 6px);
  height: 12px;
  cursor: row-resize;
}

.layout-resizer-timeline::before {
  width: 70px;
  height: 4px;
}

body.is-resizing-layout {
  cursor: col-resize;
  user-select: none;
}

body.is-resizing-layout:has(.layout-resizer-timeline.is-dragging) {
  cursor: row-resize;
}

.side-panel {
  overflow: auto;
  padding: 8px;
  background: var(--panel);
  min-width: 0;
}

.left-panel {
  border-right: 1px solid var(--line);
}

.right-panel {
  border-left: 1px solid var(--line);
}

/* Scrollbars */
.side-panel::-webkit-scrollbar,
.timeline::-webkit-scrollbar,
.mini-grid::-webkit-scrollbar,
.event-log::-webkit-scrollbar {
  height: 9px;
  width: 9px;
}
.side-panel::-webkit-scrollbar-thumb,
.timeline::-webkit-scrollbar-thumb,
.mini-grid::-webkit-scrollbar-thumb,
.event-log::-webkit-scrollbar-thumb {
  background: rgba(120, 100, 70, 0.22);
  border-radius: 999px;
}

/* Header / brand */
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1.5px solid rgba(93, 77, 51, 0.28);
  background:
    linear-gradient(90deg, transparent 8px, rgba(93, 77, 51, 0.22) 8px 10px, transparent 10px 18px, rgba(93, 77, 51, 0.22) 18px 20px, transparent 20px),
    linear-gradient(#f8e0b0 0 8px, #fffaf0 8px);
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 800;
  font-size: 0;
  color: transparent;
  box-shadow: var(--shadow-soft);
}

.brand-mark::before {
  content: "";
  width: 22px;
  height: 18px;
  border: 2px solid #594a34;
  border-top: 0;
  box-shadow: 0 -8px 0 -5px #594a34;
}

.panel-header h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.22rem;
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
}

.panel-header p,
.timeline p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.2;
}

.toolbar,
.export-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 10px 0;
}

.export-row {
  grid-template-columns: 1fr 1fr;
}

.select-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.control-group {
  display: grid;
  gap: 4px;
  margin-bottom: 9px;
}

label,
.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* Parameters */
.parameter-list {
  display: grid;
  gap: 7px;
  margin-top: 9px;
}

.parameter-group {
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel-2);
  overflow: hidden;
}

.parameter-group summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  list-style: none;
  font-family: var(--display);
  font-weight: 700;
  color: var(--ink);
}

.parameter-group summary .metric-label {
  font-family: var(--body);
  font-weight: 700;
  color: var(--muted-2);
}

.parameter-group summary::-webkit-details-marker {
  display: none;
}

.parameter-group summary::after {
  content: "+";
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 7px;
  background: rgba(207, 122, 90, 0.14);
  color: var(--accent);
  font-weight: 800;
}

.parameter-group[open] summary::after {
  content: "−";
}

.group-controls {
  display: grid;
  gap: 8px;
  padding: 0 9px 10px;
}

.parameter {
  display: grid;
  gap: 4px;
}

.parameter header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.parameter header label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
}

.parameter header span {
  font-family: var(--display);
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.parameter input[type="range"] {
  width: 100%;
  min-height: 0;
  height: 18px;
  padding: 0;
  border: none;
  background: transparent;
  accent-color: var(--accent);
  cursor: pointer;
}

.parameter small {
  color: var(--muted-2);
  font-size: 0.66rem;
  line-height: 1.2;
}

/* ---- Modos A/B para crear sociedades: tarjetas plegables y diferenciadas ---- */
.mode-hint {
  margin: 6px 0 8px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.25;
}

.mode-card {
  margin: 0 0 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel-2);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.mode-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  min-width: 0;
}
.mode-summary::-webkit-details-marker {
  display: none;
}

.mode-texts {
  display: grid;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.mode-texts b {
  font-family: var(--display);
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--ink);
  line-height: 1.12;
}
.mode-texts em {
  font-style: normal;
  font-size: 0.65rem;
  color: var(--muted);
  line-height: 1.2;
}

.mode-summary::after {
  content: "−";
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 1.05rem;
  line-height: 1;
}
.mode-card:not([open]) .mode-summary::after {
  content: "+";
}

.mode-body {
  padding: 2px 11px 11px;
}

/* Insignia de "modo activo": el que genero la sociedad actual. */
.mode-active-badge {
  display: none;
  flex: 0 0 auto;
  align-items: center;
  min-height: 18px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.56rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.mode-card.is-active .mode-active-badge {
  display: inline-flex;
}

/* Modo B: acento azul */
.mode-b {
  border-color: rgba(95, 147, 168, 0.5);
}
.mode-b .mode-summary {
  background: linear-gradient(180deg, rgba(230, 244, 248, 0.85), rgba(230, 244, 248, 0.32));
}
.mode-b[open] .mode-summary {
  border-bottom: 1.5px solid rgba(95, 147, 168, 0.28);
}
.mode-b .mode-summary::after {
  background: rgba(95, 147, 168, 0.16);
  color: var(--blue);
}
.mode-b .mode-active-badge {
  background: rgba(95, 147, 168, 0.18);
  color: var(--blue);
}
.mode-b.is-active {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(95, 147, 168, 0.22), var(--shadow-soft);
}

/* Modo A: acento verde salvia */
.mode-a {
  border-color: rgba(111, 148, 96, 0.5);
}
.mode-a .mode-summary {
  background: linear-gradient(180deg, rgba(236, 244, 230, 0.85), rgba(236, 244, 230, 0.32));
}
.mode-a[open] .mode-summary {
  border-bottom: 1.5px solid rgba(111, 148, 96, 0.28);
}
.mode-a .mode-kicker {
  background: rgba(111, 148, 96, 0.16);
  color: var(--sage);
}
.mode-a .mode-summary::after {
  background: rgba(111, 148, 96, 0.16);
  color: var(--sage);
}
.mode-a .mode-active-badge {
  background: rgba(111, 148, 96, 0.18);
  color: var(--sage);
}
.mode-a.is-active {
  border-color: var(--sage);
  box-shadow: 0 0 0 2px rgba(111, 148, 96, 0.22), var(--shadow-soft);
}

.custom-people {
  margin: 10px 0;
  padding: 10px;
  border: 1.5px solid rgba(95, 147, 168, 0.5);
  border-radius: var(--r-md);
  background: linear-gradient(180deg, rgba(230, 244, 248, 0.95), rgba(250, 247, 233, 0.98));
  box-shadow: var(--shadow-soft);
}

.custom-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.mode-kicker {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 0 7px;
  border-radius: 6px;
  background: rgba(95, 147, 168, 0.14);
  color: var(--blue);
  font-size: 0.58rem;
  font-weight: 900;
  text-transform: uppercase;
}

.custom-head h2 {
  margin: 4px 0 0;
  font-family: var(--display);
  font-size: 1.03rem;
  color: var(--ink);
}

.custom-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.67rem;
  line-height: 1.25;
}

.builder-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  margin-bottom: 8px;
}

.builder-action {
  display: grid;
  gap: 3px;
  width: 100%;
  min-width: 0;
  min-height: 50px;
  padding: 8px 9px;
  border: 1.5px solid rgba(95, 147, 168, 0.35);
  border-radius: var(--r-sm);
  background: #fffaf0;
  color: var(--text);
  text-align: left;
}

.builder-action strong,
.builder-action label {
  color: var(--ink);
  font-family: var(--display);
  font-size: 0.82rem;
  font-weight: 800;
}

.builder-action span {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1.22;
}

.builder-action-form {
  cursor: default;
}

.cohort-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 0 0 10px;
}

.cohort-steps span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 30px;
  border: 1.5px solid rgba(207, 122, 90, 0.25);
  border-radius: var(--r-sm);
  background: rgba(255, 250, 240, 0.82);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.cohort-steps b {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(207, 122, 90, 0.16);
  color: var(--accent);
  font-family: var(--display);
  font-size: 0.72rem;
}

.preset-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 54px;
  gap: 6px;
  margin-top: 5px;
}

.cohort-status {
  margin: 0 0 8px;
  padding: 8px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: #fffaf0;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 800;
  line-height: 1.25;
}

.cohort-status.is-pending {
  border-color: rgba(207, 122, 90, 0.55);
  background: #fff0e6;
  color: #a9573c;
}

.cohort-status.is-applied {
  border-color: rgba(111, 148, 96, 0.45);
  background: #f2f8eb;
  color: #567946;
}

#addPresetCohort,
#applyCohorts {
  background: #fff;
  border-color: rgba(95, 147, 168, 0.35);
}

#applyCohorts {
  background: linear-gradient(140deg, #5f93a8, #6f9460);
  color: #fff;
  border-color: transparent;
  font-weight: 800;
}

.parameter-mode-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 11px 0 8px;
  padding: 8px;
  border-top: 2px solid var(--line-strong);
  border-bottom: 1.5px solid var(--line);
  color: var(--muted);
}

.parameter-mode-title span {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 0 7px;
  border-radius: 6px;
  background: rgba(207, 122, 90, 0.13);
  color: var(--accent);
  font-size: 0.58rem;
  font-weight: 900;
  text-transform: uppercase;
}

.parameter-mode-title b {
  color: var(--ink);
  font-family: var(--display);
  font-size: 0.76rem;
  line-height: 1.1;
  text-align: right;
}

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

.cohort-card {
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel-2);
  padding: 9px;
}

.cohort-card.is-pending {
  border-color: rgba(207, 122, 90, 0.52);
  box-shadow: inset 4px 0 0 rgba(207, 122, 90, 0.75);
}

.cohort-card.is-applied {
  border-color: rgba(111, 148, 96, 0.42);
  box-shadow: inset 4px 0 0 rgba(111, 148, 96, 0.7);
}

.cohort-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.cohort-meta b {
  color: var(--ink);
  font-family: var(--display);
  font-size: 0.82rem;
}

.cohort-title {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 68px 30px;
  gap: 6px;
  align-items: end;
}

.cohort-card input,
.cohort-card select {
  width: 100%;
  min-width: 0;
  min-height: 28px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: #fffaf0;
  color: var(--text);
  padding: 0 8px;
}

.cohort-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.cohort-field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.cohort-field label,
.cohort-field > span {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.72rem;
  line-height: 1.2;
}

.cohort-field input[type="range"] {
  padding: 0;
  min-height: 20px;
  accent-color: var(--accent);
}

.cohort-field output {
  color: var(--accent);
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.78rem;
}

.cohort-card details {
  margin-top: 10px;
}

.wide-button {
  width: 100%;
  margin-top: 8px;
}

/* Stage / map */
.stage {
  position: relative;
  min-width: 0;
  margin: 0;
  border-left: 1.5px solid rgba(93, 77, 51, 0.16);
  border-right: 1.5px solid rgba(93, 77, 51, 0.16);
  background: #e7dbc5;
  box-shadow: inset 0 0 0 1px rgba(255, 250, 240, 0.35);
}

.top-strip {
  position: absolute;
  z-index: 2;
  left: 10px;
  top: 8px;
  display: flex;
  gap: 7px;
  align-items: center;
}

.metric-pill {
  display: grid;
  gap: 1px;
  padding: 7px 10px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.92);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow-soft);
}

.metric-pill .metric-label {
  font-size: 0.54rem;
}

.metric-pill strong {
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.76rem;
  color: var(--ink);
}

#world {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}

#world:active {
  cursor: grabbing;
}

/* Coachmark */
.coachmark {
  position: absolute;
  z-index: 4;
  left: 10px;
  bottom: 58px;
  max-width: 230px;
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--card);
  box-shadow: var(--shadow);
  animation: coachFloat 2.8s ease-in-out infinite;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.coachmark strong {
  font-family: var(--display);
  font-weight: 700;
  color: var(--accent);
  font-size: 0.78rem;
}

.coachmark span {
  color: #6b5740;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.35;
}

.coachmark.is-hidden {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

@keyframes coachFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.legend {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
  padding: 7px 10px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: rgba(255, 250, 240, 0.92);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow-soft);
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 700;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #c7b9a0;
}

.age-child { background: var(--age-child); }
.age-youth { background: var(--age-youth); }
.age-adult { background: var(--age-adult); }
.age-elder { background: var(--age-elder); }

.note {
  color: var(--muted-2);
  font-weight: 600;
}

.map-tools {
  position: absolute;
  z-index: 3;
  right: 10px;
  top: 8px;
  display: grid;
  grid-template-columns: 32px 48px 32px;
  gap: 4px;
  padding: 4px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: rgba(255, 250, 240, 0.92);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow-soft);
}

.map-tools button {
  padding: 0;
  min-height: 28px;
  font-weight: 800;
  background: #fff;
}

.map-tools button:first-child,
.map-tools button:last-child {
  background: linear-gradient(140deg, #b7d5e4, #79a9c0);
  border-color: rgba(95, 147, 168, 0.3);
  color: #fff;
}

/* Right panel */
.panel-section {
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
}

.panel-section.first {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.panel-section h2 {
  margin: 0 0 9px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.stat {
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-areas:
    "icon label"
    "icon value"
    "bar bar";
  gap: 2px 8px;
  align-items: center;
  padding: 8px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.stat-icon {
  grid-area: icon;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  border: 1.5px solid rgba(93, 77, 51, 0.16);
  background: rgba(255, 250, 240, 0.85);
}

.stat .metric-label {
  grid-area: label;
  font-size: 0.54rem;
}

.stat strong {
  grid-area: value;
  display: block;
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.stat-bar {
  grid-area: bar;
  height: 7px;
  border-radius: 6px;
  background: rgba(120, 100, 70, 0.14);
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.4s ease;
}

.analysis-item,
.agent-card,
.comparison-card {
  margin-bottom: 8px;
  padding: 9px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.72rem;
  line-height: 1.35;
}

.analysis-item b,
.agent-card b,
.comparison-card b {
  color: var(--ink);
  font-family: var(--display);
  font-weight: 700;
}

.inspector-empty {
  padding: 14px 10px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--r-md);
  background: rgba(255, 248, 236, 0.6);
  color: var(--muted);
  font-weight: 600;
  text-align: center;
  font-size: 0.74rem;
}

.tag {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(111, 148, 96, 0.16);
  color: #5b7a4e;
  font-size: 0.68rem;
  font-weight: 800;
}

.mini-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  max-height: 220px;
  overflow: auto;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.mini-grid span:nth-child(odd) {
  color: var(--muted);
  font-size: 0.78rem;
}

.mini-grid span:nth-child(even) {
  color: var(--ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#compareSocieties {
  width: 100%;
  margin-bottom: 10px;
}

/* Timeline */
.timeline {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 144px 1fr;
  grid-template-areas:
    "head log"
    "notes notes";
  gap: 5px 8px;
  overflow: auto;
  padding: 8px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.timeline-head {
  grid-area: head;
  display: flex;
  align-items: center;
  gap: 12px;
}

.timeline-head h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--ink);
}

.event-log {
  grid-area: log;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  align-items: stretch;
  padding-bottom: 4px;
}

.event {
  flex: 0 0 146px;
  min-height: 66px;
  padding: 7px 8px;
  border: 1.5px solid var(--line);
  border-left: 4px solid var(--accent-soft);
  background: var(--panel-2);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.62rem;
  line-height: 1.25;
}

.event b {
  font-family: var(--display);
  font-weight: 700;
  color: var(--ink);
}

.method-notes {
  grid-area: notes;
  display: flex;
  flex-wrap: wrap;
  gap: 5px 16px;
  align-items: start;
}

.method-notes details {
  flex: 1 1 240px;
  min-width: 0;
}

summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--accent);
  font-size: 0.68rem;
}

.method-notes p {
  font-size: 0.64rem !important;
}

a {
  color: var(--sage);
  font-weight: 700;
}

/* Person card (inspector) */
.person-card {
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel-2);
  padding: 10px;
}
.pcard-head {
  display: flex;
  align-items: center;
  gap: 11px;
}
.pcard-avatar {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  box-shadow: 0 3px 8px rgba(90, 66, 30, 0.18);
}
.pcard-name {
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--ink);
  line-height: 1;
}
.pcard-sub {
  margin-top: 3px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.8rem;
}
.pcard-story {
  margin: 12px 0;
  padding: 11px 12px;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.45;
  text-wrap: pretty;
}
.pcard-bars {
  display: grid;
  gap: 7px;
  margin: 10px 0;
}
.pcard-bar {
  display: grid;
  grid-template-columns: 104px 1fr 34px;
  align-items: center;
  gap: 9px;
}
.pcard-bar > span {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}
.pcard-track {
  height: 8px;
  border-radius: 6px;
  background: rgba(120, 100, 70, 0.14);
  overflow: hidden;
}
.pcard-track > div {
  height: 100%;
  border-radius: 6px;
  transition: width 0.4s ease;
}
.pcard-bar > b {
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.84rem;
  color: var(--ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.pcard-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}
.chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(207, 122, 90, 0.12);
  color: #b5623f;
  font-weight: 800;
  font-size: 0.72rem;
}
.pcard-section-title {
  margin: 14px 0 8px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}
.pcard-section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.pcard-more {
  margin-top: 12px;
}
.pcard-more > summary {
  color: var(--accent);
  font-size: 0.8rem;
}
.pcard-more-inner {
  margin-top: 10px;
}
.pcard-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
  font-size: 0.8rem;
  color: var(--muted);
}
.pcard-row b {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.pcard-more-inner > b {
  display: block;
  margin-top: 12px;
  font-family: var(--display);
  color: var(--ink);
  font-size: 0.84rem;
}

/* Analysis + event icon heads */
.ai-head,
.event-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}
.ai-icon,
.event-icon {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: rgba(207, 122, 90, 0.12);
}
.ai-head b,
.event-head b {
  font-family: var(--display);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.1;
}

/* Map hover tooltip */
.map-tooltip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  max-width: 230px;
  padding: 8px 11px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s ease;
}
.map-tooltip.is-on {
  opacity: 1;
  transform: translateY(0);
}
.map-tooltip .mt-ic {
  display: inline-flex;
  vertical-align: -3px;
  margin-right: 4px;
}
.map-tooltip b {
  font-family: var(--display);
  color: var(--ink);
}
.map-tooltip .mt-sub {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.74rem;
}

@media (max-width: 1280px) {
  .cohort-grid {
    grid-template-columns: 1fr;
  }

  .preset-row {
    grid-template-columns: 1fr;
  }
}

/* Tablet (2 columnas): el panel de controles queda junto al mapa, y el panel de
   estadisticas y la linea de tiempo pasan debajo a lo ancho. Evita el salto
   brusco a una sola columna, que dejaba el mapa enterrado bajo una lista larga. */
@media (max-width: 1180px) and (min-width: 761px) {
  body {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .app-shell {
    grid-template-columns: minmax(230px, 320px) minmax(0, 1fr);
    grid-template-rows: minmax(320px, 62vh) auto auto;
    grid-template-areas:
      "left  stage"
      "right right"
      "time  time";
    height: auto;
  }

  .left-panel { grid-area: left; }
  .stage { grid-area: stage; }
  .right-panel { grid-area: right; }
  .timeline { grid-area: time; overflow: visible; }

  .layout-resizer {
    display: none;
  }
}

/* Movil (1 columna): todo apilado, con scroll vertical y sin desborde lateral
   (overflow-x hidden evita la barra horizontal que "atasca" la vista). */
@media (max-width: 760px) {
  body {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 60vh auto auto;
    grid-template-areas: none;
    height: auto;
  }

  .layout-resizer {
    display: none;
  }

  .top-strip {
    flex-wrap: wrap;
    max-width: calc(100% - 20px);
  }

  .timeline {
    overflow: visible;
    grid-template-columns: 1fr;
    grid-template-areas:
      "head"
      "log"
      "notes";
  }
}

/* Movil: controles y rejillas a una sola columna para que todo quepa. */
@media (max-width: 560px) {
  .app-shell {
    grid-template-rows: auto 58vh auto auto;
  }

  .toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .select-row,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .metric-pill {
    padding: 5px 8px;
  }

  .metric-pill strong {
    font-size: 0.68rem;
  }

  .legend {
    font-size: 0.6rem;
  }

  .stage {
    border-left: 0;
    border-right: 0;
  }
}
