/* =====================================================================
   The Brain.

   The rule list is the lesson, so it gets the weight: numbered, draggable,
   and laid out so "the first one that fits is the one that runs" is visible
   from the shape of the page rather than only stated in a sentence.
   ===================================================================== */

.brain-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 380px);
  gap: 16px;
  align-items: start;
}
.brain-main, .brain-side { display: flex; flex-direction: column; gap: 14px; }

.panel.incoming {
  border-left: 3px solid var(--cyan);
  margin-bottom: 14px;
}
.panel.incoming p { margin: 0; color: var(--paper); }

/* --------------------------------------------------------------- rules */
.rules-head { margin-bottom: 12px; }
.rules-head h2 { margin: 0; }
.slot-count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--dim);
  border: 1px solid var(--edge2);
  border-radius: 3px;
  padding: 2px 7px;
}
.slot-count.over { color: var(--coral); border-color: var(--coral); }

.rules { display: flex; flex-direction: column; gap: 8px; }
.no-rules { margin: 6px 0; }

.rule-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--well);
  border: 1px solid var(--edge2);
  border-radius: var(--r-sm);
  cursor: grab;
}
.rule-row:active { cursor: grabbing; }
.rule-row.dragging { opacity: .4; }
.rule-row.drop-target { border-color: var(--cyan); background: color-mix(in srgb, var(--cyan) 10%, var(--well)); }

/* The number is the whole point: rules are ordered, and the order runs. */
.rule-n {
  flex: none;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--raise);
  border: 1px solid var(--edge2);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--cyan);
  margin-top: 3px;
}

.rule-body {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.kw {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--cyan);
}
.kw.then { color: var(--lantern); }
.op-fixed { font-size: 13px; color: var(--dim); }

/* Touch floor: children tap these to write their AI, on tablets. */
.field.mini {
  min-height: 44px;
  padding: 8px 10px;
  font-size: 13.5px;
  max-width: 100%;
}
.field.mini.num { width: 74px; }
.field.mini.action { font-weight: 600; }

.rule-tools { display: flex; gap: 3px; flex: none; }
/* Move-up / move-down / delete on a rule. Reordering rules IS the AI
   lesson here ("the order is the strategy"), so these must be genuinely
   tappable on a tablet — 28px was not. */
.icon-btn {
  appearance: none;
  cursor: pointer;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--edge2);
  border-radius: 5px;
  background: transparent;
  color: var(--soft);
  font-size: 14px;
  line-height: 1;
}
.icon-btn:hover:not(:disabled) { background: var(--raise); color: var(--paper); }
.icon-btn:disabled { opacity: .3; cursor: not-allowed; }
.icon-btn.danger:hover { color: var(--coral); border-color: var(--coral); }

/* ----------------------------------------------------------- otherwise */
.otherwise {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--edge);
}
.ot-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--dim);
}
.otherwise .field { min-height: 44px; }

.validation { margin-top: 10px; }
.problem {
  margin: 0 0 6px;
  padding: 8px 11px;
  border-left: 2px solid var(--coral);
  background: color-mix(in srgb, var(--coral) 8%, transparent);
  color: var(--soft);
  font-size: 13.5px;
}

/* -------------------------------------------------------------- python */
.python-panel {
  margin: 0 0 8px;
  padding: 12px 14px;
  background: var(--sunk);
  border: 1px solid var(--edge2);
  border-radius: var(--r-sm);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--jade);
  white-space: pre;
  overflow-x: auto;
  min-height: 90px;
}

/* ------------------------------------------------------------- presets */
.presets { display: flex; flex-direction: column; gap: 7px; }
.btn.preset {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  min-height: 0;
  padding: 9px 12px;
  width: 100%;
}
.btn.preset b { font-size: 14px; color: var(--paper); }
.btn.preset small { font-size: 12px; color: var(--dim); font-weight: 400; line-height: 1.4; }

.panel.next-tier { border-left: 3px solid var(--gold); }
.panel.next-tier p { margin: 0; color: var(--soft); }

/* ---------------------------------------------------------- sparring */
.spar-result { margin-top: 12px; }
.spar-score {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}
.spar-score b {
  font-family: var(--display);
  font-weight: 700;
  font-size: 34px;
  line-height: 1;
}
.spar-score span { color: var(--dim); font-size: 13px; }
.spar-score.good b { color: var(--jade); }
.spar-score.even b { color: var(--gold); }
.spar-score.poor b { color: var(--coral); }

.spar-advice {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-left: 2px solid var(--cyan);
  background: color-mix(in srgb, var(--cyan) 8%, transparent);
  color: var(--paper);
  font-size: 14px;
}

/* -------------------------------------------------------------- mobile */
@media (max-width: 900px) {
  .brain-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .rule-row { flex-wrap: wrap; }
  .rule-body { width: 100%; order: 2; }
  .rule-tools { order: 1; margin-left: auto; }
  .field.mini { flex: 1 1 auto; min-width: 0; }
}
