:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --accent: #276ef1;
  --accent-dark: #1754c4;
  --line: #d7deea;
  --success: #14804a;
  --danger: #c62828;
  --wall: #39465e;
  --goal: #ffd54f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: .72rem 1rem;
  cursor: pointer;
  font-weight: 700;
}

button:hover { background: #f5f7fb; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: white; border-color: var(--accent); }
button.primary:hover { background: var(--accent-dark); }

.home {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.join-card {
  width: min(440px, 100%);
  background: var(--panel);
  border-radius: 20px;
  box-shadow: 0 18px 50px rgba(23, 32, 51, .13);
  padding: 2rem;
  text-align: center;
}

.robot-logo { font-size: 4rem; }
.join-card h1 { margin: .2rem 0; }
.join-card p { color: var(--muted); }
.join-card form { display: grid; gap: .75rem; margin: 1.5rem 0; text-align: left; }
.join-card input {
  width: 100%;
  padding: .9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.join-card form button { background: var(--accent); color: white; border-color: var(--accent); }
.teacher-link { color: var(--accent); text-decoration: none; font-weight: 700; }

.topbar {
  min-height: 64px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: .8rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.topbar strong { font-size: 1.1rem; }
.topbar span { margin-left: .7rem; color: var(--muted); }
.status { color: var(--muted); font-weight: 700; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(500px, 1.35fr) minmax(330px, .65fr);
  gap: 1rem;
  padding: 1rem;
  min-height: calc(100vh - 64px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 8px 24px rgba(23, 32, 51, .06);
}

.board-panel { display: flex; flex-direction: column; justify-content: center; }
canvas { width: 100%; height: auto; max-height: 72vh; }
.description { margin: .5rem 0 0; color: var(--muted); text-align: center; }

.controls-panel h2 { margin: .2rem 0 .8rem; font-size: 1rem; }
.command-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.command-buttons button { min-height: 78px; }
.algorithm-head { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; }
.algorithm-head span { color: var(--muted); font-size: .9rem; }

.algorithm {
  height: 190px;
  min-height: 190px;
  max-height: 190px;
  overflow-y: auto;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: .8rem .8rem .8rem 2.5rem;
  margin: 0 0 1rem;
}
.algorithm li { padding: .35rem .5rem; border-radius: 7px; }
.algorithm li.active { background: #dbe8ff; }
.algorithm li.error { background: #ffe0e0; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; }
.actions .primary { grid-column: 1 / -1; }
.level-nav { display: flex; justify-content: space-between; gap: .5rem; margin-top: .8rem; }

.dashboard-wrap { padding: 1rem; }
.dashboard-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.dashboard-summary div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
}
.dashboard-summary strong { display: block; font-size: 2rem; }
.dashboard-summary span { color: var(--muted); }

.table-wrap {
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}
table { border-collapse: collapse; width: 100%; min-width: 1050px; }
th, td { border-bottom: 1px solid var(--line); padding: .75rem; text-align: left; vertical-align: top; }
th { background: #f7f9fc; position: sticky; top: 0; }
.algo-chip {
  display: inline-block;
  background: #edf2ff;
  border-radius: 6px;
  padding: .18rem .35rem;
  margin: .12rem;
  font-size: .8rem;
}
.state-completed { color: var(--success); font-weight: 800; }
.state-error { color: var(--danger); font-weight: 800; }

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


/* RobotLab v0.2 */
.brand { display:flex; align-items:center; gap:.7rem; }
.brand img { width:48px; height:48px; object-fit:contain; filter:drop-shadow(0 4px 6px rgba(0,0,0,.18)); }
.brand small { display:block; color:var(--muted); font-weight:700; }
.home-robot { width:120px; height:120px; object-fit:contain; filter:drop-shadow(0 12px 14px rgba(23,32,51,.22)); animation:floatRobot 2.6s ease-in-out infinite; }
.byline { color:var(--muted); font-weight:800; letter-spacing:.08em; margin-top:-.2rem; }
@keyframes floatRobot { 50% { transform:translateY(-8px) rotate(2deg); } }
.mission-tools { display:flex; justify-content:space-between; align-items:center; margin-bottom:.5rem; }
.mission-tools a { color:var(--accent); text-decoration:none; font-weight:800; }
#stars { color:#f3b700; letter-spacing:.12em; font-size:1.35rem; }
.missions-page { min-height:100vh; background:linear-gradient(160deg,#e8f0ff,#f7f9fc 55%,#e9f8ef); }
.mission-wrap { width:min(1050px,calc(100% - 2rem)); margin:0 auto; padding:2rem 0 3rem; }
.mission-intro { text-align:center; margin-bottom:2rem; }
.mission-intro h1 { font-size:clamp(2rem,5vw,3.5rem); margin:.2rem 0; }
.mission-intro p { color:var(--muted); max-width:680px; margin:.5rem auto; }
.mission-map { display:grid; grid-template-columns:repeat(3,minmax(180px,1fr)); gap:1.2rem; position:relative; }
.mission-node { min-height:180px; padding:1.2rem; border-radius:20px; text-decoration:none; display:flex; flex-direction:column; justify-content:center; align-items:center; text-align:center; border:2px solid var(--line); background:white; box-shadow:0 10px 28px rgba(23,32,51,.09); transition:.2s transform,.2s box-shadow; }
.mission-node.unlocked:hover,.mission-node.completed:hover { transform:translateY(-5px); box-shadow:0 16px 35px rgba(23,32,51,.15); }
.mission-node.completed { border-color:#34a36f; background:linear-gradient(#fff,#eefaf4); }
.mission-node.unlocked { border-color:#4d86f7; }
.mission-node.locked { opacity:.55; cursor:not-allowed; filter:grayscale(.35); }
.mission-number { width:56px; height:56px; border-radius:50%; display:grid; place-items:center; background:var(--accent); color:white; font-size:1.5rem; font-weight:900; margin-bottom:.7rem; }
.completed .mission-number { background:#1d9a61; }
.mission-name { color:var(--ink); font-weight:900; font-size:1.08rem; }
.mission-state { color:var(--muted); margin-top:.45rem; font-size:.88rem; font-weight:700; }
.centered { display:block; text-align:center; margin-top:1.5rem; }
.group-cards { display:grid; grid-template-columns:repeat(auto-fit,minmax(310px,1fr)); gap:1rem; }
.group-card { background:white; border:1px solid var(--line); border-radius:17px; padding:1rem; box-shadow:0 8px 24px rgba(23,32,51,.06); }
.group-card-head,.group-card-foot { display:flex; align-items:flex-start; justify-content:space-between; gap:1rem; }
.group-card h2 { margin:0 0 .35rem; }
.status-pill { display:inline-block; border-radius:999px; padding:.25rem .55rem; font-size:.78rem; font-weight:800; background:#e9eef7; }
.status-pill.ok { background:#dff5e9; color:#147849; }.status-pill.bad { background:#ffe4e4;color:#a91f1f;}.status-pill.playing{background:#e4edff;color:#1d56ba;}
.progress-track { height:12px; background:#e8edf5; border-radius:999px; overflow:hidden; margin:1rem 0; }
.progress-track div { height:100%; background:linear-gradient(90deg,#276ef1,#44a36f); }
.group-stats { display:grid; grid-template-columns:repeat(3,1fr); gap:.45rem; margin-bottom:.9rem; }
.group-stats span { background:#f6f8fb; border-radius:10px; padding:.6rem; color:var(--muted); font-size:.82rem; text-align:center; }
.group-stats b { display:block; color:var(--ink); font-size:1.2rem; }
.current-algo { min-height:46px; padding:.6rem; border:1px dashed var(--line); border-radius:10px; margin-bottom:.8rem; }
.group-card-foot { align-items:center; }.group-card-foot small,.muted { color:var(--muted); }
.empty-state { background:white; border-radius:16px; padding:2rem; text-align:center; color:var(--muted); }
@media (max-width:760px){.mission-map{grid-template-columns:1fr}.brandbar{align-items:flex-start}.brandbar>div:last-child{text-align:right}}


/* RobotLab v0.3: lista fija y celebración de misión */
.controls-panel {
  align-self: start;
  max-height: calc(100vh - 96px);
  overflow: hidden;
}
.algorithm {
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  background: #fbfcff;
}
.algorithm:empty::before {
  content: "Agregá comandos para construir tu algoritmo";
  display: block;
  color: var(--muted);
  padding: 1.1rem .25rem;
  text-align: center;
  font-style: italic;
}

.victory-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(12, 20, 36, .68);
  backdrop-filter: blur(5px);
}
.victory-overlay[hidden] { display: none; }
.victory-card {
  position: relative;
  width: min(520px, 100%);
  overflow: hidden;
  border-radius: 28px;
  padding: 1.6rem 1.6rem 1.4rem;
  text-align: center;
  background: linear-gradient(160deg, #ffffff 10%, #edf5ff 65%, #eefbf3);
  border: 2px solid rgba(255,255,255,.8);
  box-shadow: 0 28px 80px rgba(0,0,0,.32);
  animation: victoryIn .38s cubic-bezier(.2,.9,.25,1.25);
}
.victory-robot {
  width: 150px;
  height: 150px;
  object-fit: contain;
  filter: drop-shadow(0 14px 12px rgba(23,32,51,.24));
  animation: robotCelebrate .8s ease-in-out infinite alternate;
}
.victory-badge {
  width: fit-content;
  margin: -.15rem auto .7rem;
  padding: .35rem .8rem;
  border-radius: 999px;
  background: #1d9a61;
  color: white;
  font-size: .8rem;
  font-weight: 900;
  letter-spacing: .08em;
}
.victory-card h2 { margin: .15rem 0; font-size: clamp(1.8rem, 6vw, 2.7rem); }
.victory-card p { color: var(--muted); margin: .5rem 0 1.1rem; }
.victory-stars { color: #f3b700; font-size: 2.2rem; letter-spacing: .16em; text-shadow: 0 2px 0 #fff; }
.victory-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; position: relative; z-index: 2; }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti-piece {
  position: absolute;
  top: -12%;
  left: var(--x);
  font-size: 1rem;
  animation: confettiFall var(--duration) var(--delay) linear infinite;
}
.confetti-piece.c0 { color: #276ef1; }.confetti-piece.c1 { color: #ffb300; }
.confetti-piece.c2 { color: #1d9a61; }.confetti-piece.c3 { color: #e5484d; }
.confetti-piece.c4 { color: #8e5ad7; }.confetti-piece.c5 { color: #00a6a6; }
@keyframes victoryIn { from { opacity: 0; transform: scale(.78) translateY(26px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes robotCelebrate { from { transform: translateY(2px) rotate(-4deg) scale(1); } to { transform: translateY(-10px) rotate(4deg) scale(1.04); } }
@keyframes confettiFall { to { transform: translateY(650px) rotate(var(--rotate)); opacity: .15; } }

@media (max-width: 900px) {
  .controls-panel { max-height: none; overflow: visible; }
  .algorithm { height: 180px; min-height: 180px; max-height: 180px; }
}
@media (max-width: 520px) {
  .victory-actions { grid-template-columns: 1fr; }
}


/* Dashboard v0.4 */
.dashboard-actions { display:flex; align-items:center; gap:.75rem; }
.general-overview { background:linear-gradient(135deg,#172a50,#276ef1); color:white; border-radius:20px; padding:1.3rem 1.5rem; margin-bottom:1rem; box-shadow:0 14px 34px rgba(39,110,241,.2); }
.overview-heading,.overview-note,.section-title,.group-progress-label { display:flex; justify-content:space-between; align-items:center; gap:1rem; }
.overview-heading h1,.section-title h2 { margin:.1rem 0; }
.overview-heading > strong { font-size:2.5rem; }
.eyebrow { margin:0; text-transform:uppercase; letter-spacing:.09em; font-size:.72rem; font-weight:800; opacity:.72; }
.general-progress { height:20px; background:rgba(255,255,255,.2); border-radius:999px; overflow:hidden; margin:1rem 0 .65rem; border:1px solid rgba(255,255,255,.18); }
.general-progress div { height:100%; width:0; background:linear-gradient(90deg,#ffd54f,#72e3a6); transition:width .45s ease; }
.overview-note { font-size:.9rem; color:rgba(255,255,255,.88); }
.dashboard-summary { grid-template-columns:repeat(4,minmax(140px,1fr)); }
.dashboard-grid { display:grid; grid-template-columns:1.45fr .8fr; gap:1rem; margin-bottom:1.25rem; }
.dashboard-section { background:white; border:1px solid var(--line); border-radius:17px; padding:1rem; box-shadow:0 8px 24px rgba(23,32,51,.06); }
.section-title { margin-bottom:.9rem; }
.section-title small { color:var(--muted); }
.groups-title { margin-top:.5rem; }
.mission-heat { display:grid; gap:.65rem; }
.heat-row { display:grid; grid-template-columns:80px 1fr 44px; align-items:center; gap:.7rem; }
.heat-row span,.heat-row strong { font-size:.86rem; }
.heat-track { height:13px; background:#e8edf5; border-radius:999px; overflow:hidden; }
.heat-track div { height:100%; background:linear-gradient(90deg,#276ef1,#72e3a6); transition:width .4s ease; }
.class-insights { display:grid; gap:.65rem; }
.insight-row { display:flex; justify-content:space-between; gap:1rem; padding:.75rem; border-radius:12px; background:#f6f8fc; }
.insight-row span { color:var(--muted); }
.insight-row strong { text-align:right; }
.insight-empty { color:var(--muted); padding:1rem 0; }
.group-progress-label { margin-top:.9rem; color:var(--muted); font-size:.84rem; }
.classroom-mode .dashboard-summary,.classroom-mode .dashboard-grid,.classroom-mode .groups-title,.classroom-mode .current-algo,.classroom-mode .group-stats,.classroom-mode .group-card-foot { display:none; }
.classroom-mode .general-overview { position:sticky; top:0; z-index:2; }
.classroom-mode .group-cards { grid-template-columns:1fr; }
.classroom-mode .group-card { padding:1.25rem 1.5rem; }
.classroom-mode .group-card-head h2 { font-size:1.65rem; }
.classroom-mode .progress-track { height:24px; }
@media(max-width:900px){.dashboard-grid{grid-template-columns:1fr}.dashboard-summary{grid-template-columns:repeat(2,1fr)}.overview-note{align-items:flex-start;flex-direction:column}.dashboard-actions{align-items:flex-end;flex-direction:column}.heat-row{grid-template-columns:72px 1fr 40px}}


/* RobotLab v0.5 */
.color-picker{border:0;padding:0;margin:.3rem 0 .6rem;display:grid;grid-template-columns:repeat(4,1fr);gap:.55rem}.color-picker legend{font-weight:800;margin-bottom:.45rem}.robot-color{display:grid;place-items:center;gap:.2rem;padding:.55rem;border:2px solid var(--line);border-radius:12px;cursor:pointer;background:#fff;text-align:center}.robot-color input{position:absolute;opacity:0}.robot-color img{width:52px;height:52px;object-fit:contain}.robot-color:has(input:checked){border-color:var(--accent);box-shadow:0 0 0 3px rgba(39,110,241,.12)}.robot-color span{font-size:.78rem;font-weight:800}.command-buttons button{border-width:2px}.command-forward{background:#e7f0ff!important;border-color:#4d86f7!important}.command-left,.command-right{background:#fff0df!important;border-color:#ed9b3b!important}.command-sound{background:#ffe9ef!important;border-color:#df5c7a!important}.algorithm li{border-left:5px solid #4d86f7;margin:.22rem 0;background:#f7f9fc}.algorithm li:nth-child(n){ }.mission-tools{gap:.55rem;flex-wrap:wrap}.mission-tools #soundToggle{padding:.45rem .7rem}.mini-board-wrap{margin:.8rem 0;border:1px solid var(--line);border-radius:12px;overflow:hidden;background:#f7f9fc}.mini-board{display:block;width:100%;height:100px}.group-card-head strong{white-space:nowrap}@media(max-width:520px){.color-picker{grid-template-columns:repeat(2,1fr)}}

.algorithm-forward{border-left-color:#4d86f7!important;background:#eef4ff!important}.algorithm-left,.algorithm-right{border-left-color:#ed9b3b!important;background:#fff7ec!important}.algorithm-sound{border-left-color:#df5c7a!important;background:#fff1f5!important}


/* ============ RobotLab v0.6 — modo diversión ============ */

/* --- Home más vivo --- */
.home { background: linear-gradient(150deg, #e8f0ff 0%, #f6f9ff 45%, #eaf8ef 100%); }
.join-card { border: 2px solid var(--line); box-shadow: 0 24px 70px rgba(23, 32, 51, .18); }
.join-card h1 { font-size: 2.4rem; }
.join-card form button { font-size: 1.05rem; padding: .95rem; border-radius: 14px; background: linear-gradient(135deg, var(--accent), #4d86f7); border: none; box-shadow: 0 5px 0 var(--accent-dark); transition: transform .12s ease, box-shadow .12s ease; }
.join-card form button:hover { transform: translateY(-2px); box-shadow: 0 7px 0 var(--accent-dark); background: linear-gradient(135deg, var(--accent-dark), #276ef1); }
.join-card form button:active { transform: translateY(1px); box-shadow: 0 2px 0 var(--accent-dark); }

/* --- Topbar con gradiente suave --- */
.topbar { background: linear-gradient(90deg, #ffffff, #f2f7ff); }

/* --- Botones de comando grandes y coloridos --- */
.command-buttons button {
  min-height: 92px;
  font-size: 1.02rem;
  border-radius: 14px;
  border-width: 2px;
  box-shadow: 0 3px 0 rgba(23, 32, 51, .12);
  transition: transform .12s ease, box-shadow .12s ease;
}
.command-buttons button:hover:not(:disabled) { transform: translateY(-3px); box-shadow: 0 6px 12px rgba(23, 32, 51, .14); }
.command-buttons button:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 1px 0 rgba(23, 32, 51, .12); }

/* --- Botón Ver plan --- */
#planBtn { border-radius: 999px; padding: .5rem .85rem; background: #f4efff; border-color: #c9b8f2; color: #6b46c1; font-weight: 800; }
#planBtn.active { background: #6b46c1; border-color: #6b46c1; color: #fff; }

/* --- Estrellas en el mapa de misiones --- */
.mission-stars {
  display: block;
  margin-top: .4rem;
  font-size: 1.15rem;
  letter-spacing: .12em;
  color: #f3b700;
  text-shadow: 0 1px 0 rgba(0,0,0,.08);
}
.mission-node.completed { border-color: #34a36f; background: linear-gradient(#fff, #eefaf4); box-shadow: 0 10px 28px rgba(52, 163, 111, .14); }

/* --- Algoritmo con bloques más lindos --- */
.algorithm li { border-radius: 8px; font-weight: 700; transition: background .15s ease, transform .1s ease; }
.algorithm li.active { transform: scale(1.04); }

/* --- Acciones principales --- */
.actions .primary {
  background: linear-gradient(135deg, #14804a, #1d9a61);
  border: none;
  color: white;
  box-shadow: 0 4px 0 #0e5c34;
  font-size: 1.08rem;
  transition: transform .12s ease, box-shadow .12s ease;
}
.actions .primary:hover { transform: translateY(-2px); box-shadow: 0 6px 12px rgba(20, 128, 74, .3); }
.actions .primary:active { transform: translateY(1px); box-shadow: 0 2px 0 #0e5c34; }
.actions button { border-radius: 12px; }

/* --- Estrellas del header --- */
#stars { font-size: 1.5rem; }

/* --- Panel del tablero --- */
.board-panel { background: linear-gradient(180deg, #ffffff, #f6faff); }
canvas { border-radius: 14px; }

/* --- Modo plan: sutil indicación --- */
.plan-hint { color: #6b46c1; font-weight: 800; }

/* --- Tarjetas de grupo con hover --- */
.group-card { transition: transform .15s ease, box-shadow .15s ease; }
.group-card:hover { transform: translateY(-3px); box-shadow: 0 16px 34px rgba(23, 32, 51, .13); }

/* --- Mini tableros --- */
.mini-board-wrap { background: linear-gradient(180deg, #f7f9fc, #eef3fb); }

/* --- Footer de victoria: más brillo --- */
.victory-card { border: 2px solid rgba(255,255,255,.9); }
.victory-stars { text-shadow: 0 3px 0 #fff, 0 0 18px rgba(243, 183, 0, .45); }

/* --- Dashboard: tarjetas con borde sutil --- */
.dashboard-section { border: 1px solid var(--line); }

/* --- Estrellas por misión en tarjetas de grupo --- */
.group-stars-line { display: flex; gap: .2rem; margin-bottom: .7rem; flex-wrap: wrap; }
.mini-star { color: #d8dee9; font-size: .95rem; letter-spacing: .05em; }
.mini-star.earned { color: #f3b700; text-shadow: 0 1px 0 rgba(0,0,0,.08); }
.heat-stars { color: #f3b700; font-size: .72rem; letter-spacing: .05em; white-space: nowrap; }
.heat-row { grid-template-columns: 80px 1fr 44px 74px; }
@media(max-width:900px){ .heat-row{grid-template-columns:72px 1fr 40px 66px} }

/* --- Responsive: botones más cómodos en pantallas chicas --- */
@media (max-width: 520px) {
  .command-buttons button { min-height: 74px; font-size: .95rem; }
  .join-card h1 { font-size: 1.9rem; }
}

/* ============ RobotLab v0.7 — bloques REPETIR ============ */
.command-repeat { background: #f4efff !important; border-color: #8e5ad7 !important; }
.algorithm-repeat { padding: .4rem .5rem; border-radius: 8px; border-left: 5px solid #8e5ad7; background: #f7f4fe; margin: .3rem 0; }
.algorithm-repeat .repeat-head { font-weight: 800; color: #6b46c1; padding: .1rem .2rem; }
.algorithm-repeat.active > .repeat-head { background: #dbe8ff; border-radius: 6px; }
.repeat-sublist { list-style: none; margin: .3rem 0 0; padding: 0 0 0 1rem; border-left: 2px dashed #c9b8f2; }
.repeat-sublist li { padding: .3rem .5rem; border-radius: 7px; margin: .15rem 0; }
.repeat-sublist li.active { background: #dbe8ff; }

.repeat-builder {
  border: 2px solid #c9b8f2;
  background: #faf8ff;
  border-radius: 14px;
  padding: .8rem;
  margin: .6rem 0;
}
.repeat-builder-head { display: flex; justify-content: space-between; align-items: center; font-weight: 800; color: #6b46c1; margin-bottom: .5rem; }
.repeat-builder-head select { padding: .35rem .5rem; border-radius: 8px; border: 1px solid var(--line); }
.repeat-body-list {
  list-style: none;
  min-height: 40px;
  margin: 0 0 .6rem;
  padding: .5rem;
  border: 1px dashed #c9b8f2;
  border-radius: 10px;
  background: #fff;
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}
.repeat-body-list:empty::before {
  content: "Tocá los comandos de abajo para armar lo que se repite";
  color: var(--muted);
  font-style: italic;
  font-size: .85rem;
}
.repeat-body-list li { cursor: pointer; padding: .3rem .55rem; border-radius: 7px; font-weight: 700; }
.command-buttons.small { grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: .4rem; }
.command-buttons.small button { min-height: 46px; font-size: .82rem; padding: .4rem .5rem; }
.repeat-builder-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }

.algo-chip-repeat { background: #f0e7fe; color: #6b46c1; font-weight: 800; }

/* ============ RobotLab v0.8 — bloque SI (condicional) ============ */
.command-if { background: #fff3e0 !important; border-color: #e08a2e !important; }
.algorithm-if { padding: .4rem .5rem; border-radius: 8px; border-left: 5px solid #e08a2e; background: #fff8f0; margin: .3rem 0; }
.algorithm-if .if-head { font-weight: 800; color: #a4590f; padding: .1rem .2rem; }
.algorithm-if.active > .if-head { background: #dbe8ff; border-radius: 6px; }
.if-builder { border-color: #f0c48a; background: #fffaf3; }
.if-builder .repeat-builder-head { color: #a4590f; }
.if-builder .repeat-body-list { border-color: #f0c48a; }
.algo-chip-if { background: #fff3e0; color: #a4590f; font-weight: 800; }


/* ============ ArduinoLab v1 ============ */
.arduino-logo { font-size: 3.6rem; line-height: 1; }
.arduino-logo.small { font-size: 1.8rem; width: 48px; height: 48px; display: grid; place-items: center; }
.secondary-link { display: block; margin-top: .6rem; color: var(--muted); }

.color-swatch { width: 34px; height: 34px; border-radius: 50%; display: block; border: 2px solid rgba(0,0,0,.08); }
.color-swatch.blue { background: #4d86f7; }
.color-swatch.red { background: #e5484d; }
.color-swatch.green { background: #34a36f; }
.color-swatch.yellow { background: #f3b700; }

.breadboard {
  min-height: 320px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1.4rem;
  padding: 1.6rem;
  border-radius: 14px;
  background:
    linear-gradient(#e9edf3 1px, transparent 1px) 0 0/22px 22px,
    linear-gradient(90deg, #e9edf3 1px, transparent 1px) 0 0/22px 22px,
    #f4f6fa;
}
.component {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.1rem 1.3rem;
  min-width: 140px;
  box-shadow: 0 8px 20px rgba(23,32,51,.07);
}
.comp-label { font-weight: 800; font-size: .84rem; text-align: center; }
.comp-state { color: var(--muted); font-size: .8rem; font-weight: 700; }

.led-bulb {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff5, transparent 40%), color-mix(in srgb, var(--led-color) 35%, #cfd6e2);
  border: 3px solid color-mix(in srgb, var(--led-color) 55%, #98a2b3);
  transition: background .25s ease, box-shadow .25s ease, opacity .25s ease;
}
.led-bulb.on {
  background: radial-gradient(circle at 35% 30%, #fff9, transparent 45%), var(--led-color);
  box-shadow: 0 0 18px 6px color-mix(in srgb, var(--led-color) 70%, transparent);
  border-color: var(--led-color);
}
.led-bulb.pwm.on { opacity: calc(.35 + var(--brightness, 1) * .65); }
.led-bulb.pwm.on { box-shadow: 0 0 calc(8px + var(--brightness, 1) * 18px) calc(2px + var(--brightness, 1) * 6px) color-mix(in srgb, var(--led-color) 70%, transparent); }

.buzzer-icon { font-size: 2.4rem; transition: transform .15s ease; }
.buzzer-icon.beeping { animation: buzzPulse .42s ease-in-out; }
@keyframes buzzPulse { 0%,100% { transform: scale(1); } 30% { transform: scale(1.28) rotate(-8deg); } 60% { transform: scale(1.1) rotate(8deg); } }

.servo-body {
  width: 70px;
  height: 70px;
  border-radius: 12px;
  background: #2b3550;
  display: grid;
  place-items: center;
  position: relative;
}
.servo-arm {
  width: 6px;
  height: 46px;
  background: #ffd54f;
  border-radius: 4px;
  transform-origin: bottom center;
  position: absolute;
  bottom: 12px;
  transition: transform .5s cubic-bezier(.3,.8,.3,1);
}

.wiring-panel { padding: .2rem 0 .6rem; }
.wiring-hint { color: var(--muted); text-align: center; margin: 0 0 1rem; font-weight: 700; }
.wiring-stage {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: flex-start;
  justify-content: space-between;
  min-height: 260px;
  padding: 1rem;
  border-radius: 14px;
  background: #f4f6fa;
}
.wiring-stage svg#wireSvg { position: absolute; inset: 0; pointer-events: none; width: 100%; height: 100%; }
.wire-jacket { fill: none; stroke: #0b1430; stroke-width: 8; stroke-linecap: round; opacity: .55; }
.wire-core { fill: none; stroke-width: 5.5; stroke-linecap: round; }
.wire-cap-shell { fill: #2b3550; stroke: #55628a; stroke-width: 1.4; }
.wire-cap-core { stroke: rgba(255,255,255,.35); stroke-width: 1; }

.wire-components { display: flex; flex-direction: column; gap: .7rem; position: relative; z-index: 1; }
.wire-component {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: .6rem .9rem;
  cursor: pointer;
  min-width: 190px;
  transition: border-color .15s ease, box-shadow .15s ease, transform .1s ease;
}
.wire-component:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(23,32,51,.1); }
.wire-component.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(39,110,241,.15); }
.wire-component.wired { cursor: default; border-color: #34a36f; background: #f2fbf6; }
.wire-component.wired:hover { transform: none; box-shadow: none; }
.wire-terminal {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e4e8f0, #98a2b3 55%, #6b7488);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.15);
  flex-shrink: 0;
}
.wire-component.selected .wire-terminal { background: radial-gradient(circle at 35% 30%, #cfe0ff, var(--accent) 60%, #1754c4); box-shadow: 0 0 0 4px rgba(39,110,241,.2); }
.wire-component.wired .wire-terminal { background: radial-gradient(circle at 35% 30%, #a9f0c9, #1d9a61 60%, #0e5c34); }
.wire-comp-label { font-weight: 800; flex: 1; font-size: .9rem; }
.wire-comp-state { color: var(--muted); font-size: .78rem; font-weight: 700; white-space: nowrap; }
.wire-component.wired .wire-comp-state { color: #147849; }

.arduino-board {
  background: #14213d;
  border-radius: 14px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  position: relative;
  z-index: 1;
  box-shadow: 0 10px 26px rgba(20,33,61,.25);
}
.arduino-label { color: #9db2e8; font-weight: 800; font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; text-align: center; }
.pin-row { display: flex; gap: .35rem; flex-wrap: wrap; justify-content: center; }
.pin-slot {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 2px solid #3a4b7a;
  background: #1e2b4e;
  color: #cdd8f7;
  font-size: .72rem;
  font-weight: 800;
  padding: 0;
  cursor: pointer;
}
.pin-slot:hover:not(:disabled) { border-color: #6f95f0; background: #26386b; }
.pin-slot:disabled { opacity: .4; cursor: not-allowed; }
.pin-slot.used { border-color: #1d9a61; background: #163a2c; color: #7de3ae; opacity: 1; }
.pin-slot.pin-error { animation: pinShake .38s ease; border-color: var(--danger); background: #4a1f1f; }
@keyframes pinShake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.wiring-lock { color: var(--muted); text-align: center; font-style: italic; padding: 1.2rem .5rem; grid-column: 1 / -1; }

#board[hidden], #wiringPanel[hidden] { display: none; }

@media (max-width: 900px) {
  .wiring-stage { flex-direction: column; align-items: stretch; }
  .arduino-board { align-self: stretch; }
}

.cmd-wait { background: #eef2f7 !important; border-color: #9aa7bd !important; }
.cmd-repeat { background: #f4efff !important; border-color: #8e5ad7 !important; }
.algorithm-wait { border-left-color: #9aa7bd !important; background: #f4f6fa !important; }
.algorithm-repeat { border-left: 5px solid #8e5ad7; }
@media (max-width: 900px) { .breadboard { min-height: 240px; } }
