/* ---------- Create a bot: the block workbench on the stage ----------
   Markup comes from js/visualizations/bot-builder.js; the class names are
   the contract. Four pages behind a row of tabs: the blocks (a palette and
   the script), the piece maps (a board painted with a brush), the code, and
   a board to try the bot. Block colours by category, Scratch style: red
   for Never, blue for Rules, purple for Decide, orange for Judging. */

.builder {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  --blk-never: #c8503f;
  --blk-rules: #3d7ed8;
  --blk-decide: #8a5ad6;
  --blk-judge: #d9892a;
}

.builder-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.builder-tab {
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 600;
}

.builder-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.builder-page {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  min-height: 420px;
}

/* ---- Blocks: the palette and the script ---- */

.builder-blocks {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.builder-palette {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 72vh;
  overflow-y: auto;
  padding-right: 6px;
}

.palette-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.palette-title {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.palette-group[data-cat="never"] .palette-title { color: var(--blk-never); }
.palette-group[data-cat="rules"] .palette-title { color: var(--blk-rules); }
.palette-group[data-cat="decide"] .palette-title { color: var(--blk-decide); }
.palette-group[data-cat="judge"] .palette-title { color: var(--blk-judge); }

.palette-hint {
  margin: 0 0 4px;
  font-size: 0.82rem;
}

.builder-workspace {
  position: relative;
  min-height: 360px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px dashed var(--line);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.builder-workspace.dragging { border-color: var(--accent); }
.builder-workspace.drop-away { border-color: var(--blk-never); }
.builder-workspace.drop-away::after {
  content: 'Let go here to drop the block';
  position: absolute;
  right: 14px;
  top: 10px;
  font-size: 0.85rem;
  color: var(--blk-never);
}

.builder-script {
  display: flex;
  flex-direction: column;
  max-width: 560px;
}

.builder-stack {
  display: flex;
  flex-direction: column;
}

.builder-drop-hint { margin: 0; }

/* A block: a rounded plate in its category colour, its sentence and its inputs in a row. */
.blk {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  color: #fff;
  background: var(--blk-rules);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  font-size: 0.95rem;
  line-height: 1.35;
}

.blk.cat-never { background: var(--blk-never); }
.blk.cat-rules { background: var(--blk-rules); }
.blk.cat-decide { background: var(--blk-decide); }
.blk.cat-judge { background: var(--blk-judge); }

.blk.hat {
  background: #4a9a4e;
  border-radius: 20px 20px 6px 6px;
  font-weight: 700;
  cursor: default;
  margin-bottom: 2px;
}

.blk.in-palette { margin: 0; }
.blk.in-palette:hover { filter: brightness(1.08); }

.blk.unreached { opacity: 0.45; }

.blk.blk-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  opacity: 0.9;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  transform: rotate(-1.5deg);
}

.blk-face {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}

.blk-text { white-space: normal; }

/* Inputs sit in the sentence like Scratch's white ovals. */
.blk-number,
.blk-check {
  font: inherit;
  font-size: 0.9rem;
  border-radius: 999px;
  border: 0;
  padding: 2px 8px;
  background: #fff;
  color: #1b1b1b;
}

.blk-number {
  width: 4.2em;
  text-align: center;
  -moz-appearance: textfield;
}

.blk-number::-webkit-inner-spin-button,
.blk-number::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.blk-number:disabled,
.blk-check input:disabled { pointer-events: none; }

.blk-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.blk-check input { width: 14px; height: 14px; }

.blk-remove {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  padding: 0;
  line-height: 1;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 1rem;
  opacity: 0;
  transition: opacity 0.1s ease;
}

.blk:hover > .blk-remove,
.blk-remove:focus-visible { opacity: 1; }
.blk-remove:hover { background: rgba(0, 0, 0, 0.5); }

/* The Think block's mouth: an indented stack with the block's colour as a left bar. */
.blk.has-mouth {
  flex-wrap: wrap;
  padding-bottom: 0;
}

.blk.has-mouth > .blk-face { flex-basis: calc(100% - 40px); }

.blk-mouth {
  flex: 0 0 100%;
  margin: 6px 0 0 14px;
  padding: 4px 0 4px 10px;
  border-left: 10px solid rgba(0, 0, 0, 0.18);
  background: var(--panel-2);
  border-radius: 0 6px 6px 0;
  min-height: 34px;
  box-sizing: border-box;
  width: calc(100% - 14px);
}

.blk-mouth-hint {
  color: var(--muted);
  font-size: 0.82rem;
  padding: 4px 6px;
  display: inline-block;
}

.blk-foot {
  flex: 0 0 100%;
  height: 12px;
  margin: 0 -12px;
  width: calc(100% + 24px);
}

/* Insertion slots: thin at rest, a gap that opens where the block would land. */
.slot {
  height: 3px;
  margin: 0;
  border-radius: 2px;
  transition: height 0.08s ease, background-color 0.08s ease;
}

.builder-workspace.dragging .slot { height: 6px; }
.builder-workspace.dragging-judge .top > .slot { height: 3px; }
.slot.active {
  height: 30px;
  background: var(--accent-soft);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

.builder-warnings { display: flex; flex-direction: column; gap: 6px; }

.builder-warning {
  margin: 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(217, 137, 42, 0.14);
  border: 1px solid rgba(217, 137, 42, 0.5);
  font-size: 0.88rem;
}

.builder-warning.alert {
  background: rgba(229, 57, 53, 0.14);
  border-color: rgba(229, 57, 53, 0.6);
}

.builder-warning.flash { animation: builder-flash 2.5s ease forwards; }

@keyframes builder-flash {
  0% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---- Piece maps ---- */

.builder-maps {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.maps-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.maps-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.maps-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 6px;
  border-radius: 999px;
}

.maps-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.maps-tab.edited .maps-tab-name::after {
  content: ' •';
  color: var(--blk-judge);
}

.maps-glyph {
  width: 22px;
  height: 22px;
  display: inline-block;
}

.maps-glyph svg { width: 100%; height: 100%; }

.maps-tools {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.maps-modes { display: flex; flex-direction: column; gap: 6px; }

.maps-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
}

.maps-legend-bar {
  flex: 1 1 auto;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(to right, rgba(229, 57, 53, 0.85), transparent 50%, rgba(110, 168, 254, 0.85));
}

.maps-note { margin: 0; }

.maps-figure {
  margin: 0;
  max-width: min(100%, 560px);
  justify-self: center;
  width: 100%;
}

.maps-board { touch-action: none; }
.maps-board .square { cursor: crosshair; }
.maps-board .square .label { font-weight: 700; }

/* ---- Code ---- */

.builder-code {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.builder-source {
  margin: 0;
  max-height: 70vh;
  overflow: auto;
  padding: 14px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  line-height: 1.45;
  tab-size: 2;
}

/* ---- Try it ---- */

.builder-try {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 300px);
  gap: 20px;
  align-items: start;
}

.try-figure {
  margin: 0;
  width: 100%;
  max-width: min(100%, 560px);
  justify-self: center;
}

.try-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.try-side .move-list {
  max-height: 320px;
  overflow-y: auto;
}

@media (max-width: 1000px) {
  .builder-blocks,
  .builder-maps,
  .builder-try { grid-template-columns: 1fr; }
  .builder-palette { max-height: none; }
}
