:root {
  /* Paleta base del IDE: neutros limpios con acentos por sistema/bloque. */
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-soft: #f6f9fc;
  --ink: #17202a;
  --muted: #617086;
  --line: #dce5ef;
  --topbar: #26384d;
  --accent: #10a8a3;
  --accent-dark: #087f7b;
  --orange: #f28c38;
  --blue: #3d7cff;
  --green: #27ae60;
  --red: #e74c3c;
  --purple: #8e5ad7;
  --yellow: #d4a11e;
  --shadow: 0 16px 42px rgba(25, 43, 61, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

.hidden {
  display: none !important;
}

.entry-view,
.dashboard-view {
  min-height: 100vh;
  overflow: auto;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(24, 168, 165, 0.18), transparent 34%),
    linear-gradient(315deg, rgba(47, 128, 237, 0.16), transparent 42%),
    var(--bg);
}

.entry-view {
  display: grid;
  place-items: center;
}

.entry-card {
  width: min(680px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 34px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.entry-card.compact {
  width: min(460px, calc(100vw - 32px));
}

.brand-mark.large {
  width: 58px;
  height: 58px;
  margin-bottom: 18px;
}

.entry-kicker {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 850;
  text-transform: uppercase;
}

.entry-card h1,
.dashboard-header h1 {
  margin: 0;
  color: #172033;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1.05;
}

.entry-card p {
  max-width: 58ch;
  margin: 16px 0 0;
  color: #516173;
  font-size: 16px;
  line-height: 1.55;
}

.entry-card label {
  display: block;
  margin: 18px 0 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.entry-card input {
  width: 100%;
  height: 44px;
  border: 2px solid #d7e3ef;
  border-radius: 7px;
  padding: 0 12px;
  color: var(--ink);
  font: inherit;
  font-weight: 750;
  outline: 0;
}

.entry-primary {
  min-height: 46px;
  margin-top: 24px;
  border: 0;
  border-radius: 7px;
  padding: 0 20px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
}

.entry-actions,
.dashboard-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.dashboard-view {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.dashboard-header,
.dashboard-main {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(46, 68, 91, 0.08);
}

.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
}

.dashboard-main {
  flex: 1;
  padding: 20px;
}

.dashboard-empty {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.project-card {
  display: grid;
  gap: 10px;
  border: 1px solid #dce6f1;
  border-radius: 8px;
  padding: 14px;
  background: #f8fbff;
}

.project-card h3 {
  margin: 0;
  color: #172033;
  font-size: 18px;
}

.project-meta {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dce6f1;
}

.progress-bar {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.project-card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.save-status {
  display: inline-block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.save-status.saving {
  color: #7a5a00;
}

.save-status.saved {
  color: #187b50;
}

.save-status.error {
  color: #c72d4e;
}

button {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
}

/* Barra superior fija, pensada como software de aula y no como navegación web. */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 18px;
  background: var(--topbar);
  color: #fff;
  box-shadow: 0 4px 18px rgba(9, 22, 36, 0.24);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 310px;
  gap: 12px;
  border-radius: 8px;
  cursor: pointer;
}

.brand:focus-visible {
  outline: 3px solid rgba(35, 203, 198, 0.75);
  outline-offset: 4px;
}

.brand-mark {
  position: relative;
  width: 46px;
  height: 46px;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 12px;
  background: linear-gradient(145deg, #16c7be, #1c7894);
}

.brand-lock::before {
  content: "";
  position: absolute;
  top: 9px;
  left: 14px;
  width: 14px;
  height: 13px;
  border: 3px solid #fff;
  border-bottom: 0;
  border-radius: 9px 9px 0 0;
}

.brand-lock::after {
  content: "";
  position: absolute;
  top: 21px;
  left: 11px;
  width: 22px;
  height: 17px;
  border-radius: 5px;
  background: #fff;
  box-shadow: inset 0 -5px 0 rgba(23, 32, 42, 0.12);
}

.brand-kicker,
.project-session,
.workspace-header p {
  margin: 0;
  color: rgba(255, 255, 255, 0.68);
  font-size: 12px;
  font-weight: 600;
}

.brand h1,
.panel-title-row h2,
.workspace-header h2 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  font-weight: 750;
}

.project-session {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.82);
  cursor: pointer;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.toolbar-btn,
.sim-btn,
.icon-btn,
.category-tab {
  border: 0;
  cursor: pointer;
}

.toolbar-btn {
  min-height: 38px;
  padding: 0 13px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.toolbar-btn:hover,
.toolbar-btn:focus-visible {
  background: rgba(255, 255, 255, 0.2);
}

.toolbar-btn.run {
  background: var(--accent);
  color: #062c2b;
}

.toolbar-btn.run:hover,
.toolbar-btn.run:focus-visible {
  background: #31d3c9;
}

.ide-layout {
  display: grid;
  grid-template-columns: 280px minmax(420px, 1fr) 360px;
  min-height: 0;
  padding: 12px;
  gap: 12px;
}

.block-library,
.workspace-panel,
.simulation-panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(46, 68, 91, 0.08);
}

.block-library,
.simulation-panel {
  display: flex;
  flex-direction: column;
  padding: 14px;
}

.block-library {
  position: relative;
  z-index: 4;
  height: 100%;
  overflow: hidden;
}

.panel-title-row,
.workspace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title-row h2,
.workspace-header h2 {
  font-size: 18px;
}

.panel-badge {
  border-radius: 999px;
  padding: 5px 10px;
  background: #e7f8f7;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.category-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  flex: 0 0 auto;
  max-height: 152px;
  gap: 6px;
  margin: 12px 0 10px;
  overflow-y: auto;
  padding-right: 4px;
}

.category-tab {
  min-height: 30px;
  padding: 0 8px;
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  text-align: left;
  border-left: 6px solid var(--cat-color);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-tab.active {
  color: #fff;
  background: var(--cat-color);
}

.block-list {
  display: flex;
  min-height: 260px;
  flex: 1 1 260px;
  flex-direction: column;
  gap: 11px;
  overflow-x: hidden;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 10px 4px 12px 0;
}

.block-list-title {
  position: sticky;
  top: 0;
  z-index: 2;
  border-left: 6px solid var(--cat-color);
  padding: 6px 8px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}

.trash-zone {
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 2px 10px;
  flex: 0 0 auto;
  min-height: 56px;
  margin-top: 10px;
  border: 2px dashed #c8d4df;
  border-radius: 8px;
  padding: 8px;
  background: #f7fafc;
  color: #526579;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease, transform 180ms ease;
}

.trash-zone strong {
  font-size: 14px;
}

.trash-zone small {
  grid-column: 2;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
}

.trash-icon {
  position: relative;
  grid-row: 1 / 3;
  width: 26px;
  height: 31px;
  border: 3px solid currentColor;
  border-top: 0;
  border-radius: 0 0 7px 7px;
}

.trash-icon::before {
  content: "";
  position: absolute;
  top: -9px;
  left: -4px;
  width: 36px;
  height: 5px;
  border-radius: 999px;
  background: currentColor;
}

.trash-icon::after {
  content: "";
  position: absolute;
  top: -15px;
  left: 9px;
  width: 12px;
  height: 5px;
  border-radius: 999px 999px 0 0;
  border: 3px solid currentColor;
  border-bottom: 0;
}

.block-library.delete-ready .trash-zone {
  border-color: #8ba5bb;
  background: #eef4f8;
}

.trash-zone.trash-active {
  border-color: var(--red);
  background: #fff0ee;
  color: var(--red);
  transform: scale(1.02);
}

/* Bloques grandes tipo MakeCode: cada color representa una categoría del proyecto. */
.block {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  width: 250px;
  min-height: 40px;
  padding: 8px 16px 8px 20px;
  border-radius: 8px;
  background: var(--block-color);
  color: #fff;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.16), 0 4px 9px rgba(26, 42, 60, 0.14);
  font-size: 13px;
  font-weight: 850;
  user-select: none;
  touch-action: none;
}

.block-function::before,
.block-hat::before,
.block-flow::before,
.block-if::before,
.block-else::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 28px;
  width: 34px;
  height: 12px;
  border-radius: 0 0 9px 9px;
  background: rgba(255, 255, 255, 0.36);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08);
}

.block-function::after,
.block-hat::after,
.block-flow::after,
.block-event::after,
.block-if::after,
.block-else::after {
  content: "";
  position: absolute;
  right: -11px;
  top: 12px;
  width: 22px;
  height: 16px;
  border-radius: 0 9px 9px 0;
  background: var(--block-color);
  filter: brightness(0.94);
}

.block-hat {
  width: 226px;
  border-radius: 18px 18px 7px 7px;
}

.block-hat::before {
  top: -14px;
  left: 18px;
  width: 95px;
  height: 20px;
  border-radius: 24px 24px 0 0;
  background: var(--block-color);
  filter: brightness(1.08);
}

.block-event {
  border-radius: 8px;
}

.block-event::before {
  display: none;
}

.block-boolean {
  width: 236px;
  min-height: 36px;
  padding-left: 24px;
  padding-right: 24px;
  border-radius: 999px;
  clip-path: polygon(9% 0, 91% 0, 100% 50%, 91% 100%, 9% 100%, 0 50%);
}

.block-string,
.block-value,
.block-number {
  min-height: 36px;
  border-radius: 999px;
  padding-left: 24px;
  padding-right: 24px;
}

.block-button {
  min-height: 34px;
  border-radius: 5px;
  padding: 7px 12px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.14), 0 4px 9px rgba(26, 42, 60, 0.12);
}

.block-button.palette-block[data-category="variables"] {
  border: 2px solid #f97316;
  background: #4b5552;
  box-shadow: none;
}

.block-button::before,
.block-button::after {
  display: none;
}

.variable-manager {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.variable-manager h3 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.variable-empty {
  margin: 0;
  color: #8290a2;
  font-size: 12px;
  font-weight: 700;
}

.variable-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.variable-row .variable-reporter {
  grid-column: 1 / -1;
  width: max-content;
  min-width: 86px;
}

.variable-action {
  min-height: 26px;
  border: 0;
  border-radius: 5px;
  background: #eef2f7;
  color: #415066;
  cursor: pointer;
  font-size: 11px;
  font-weight: 850;
}

.variable-action.danger {
  background: #ffe9ed;
  color: #c72d4e;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 25, 38, 0.42);
  z-index: 100;
}

.modal-backdrop.open {
  display: flex;
}

.variable-dialog {
  width: min(420px, calc(100vw - 32px));
  border-radius: 8px;
  padding: 18px;
  background: #fff;
  box-shadow: 0 22px 60px rgba(13, 29, 46, 0.28);
}

.project-dialog {
  width: min(560px, calc(100vw - 32px));
}

.variable-dialog h2 {
  margin: 0 0 14px;
  color: var(--ink);
  font-size: 20px;
}

.variable-dialog label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.variable-dialog input,
.project-dialog textarea {
  width: 100%;
  border: 2px solid #d7e3ef;
  border-radius: 7px;
  padding: 0 11px;
  color: var(--ink);
  font: inherit;
  font-weight: 750;
  outline: 0;
}

.variable-dialog input {
  height: 42px;
}

.project-dialog textarea {
  min-height: 260px;
  padding: 12px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
}

.variable-dialog input:focus,
.project-dialog textarea:focus {
  border-color: #e83f63;
  box-shadow: 0 0 0 4px rgba(232, 63, 99, 0.14);
}

.project-modal-body {
  display: grid;
  gap: 12px;
}

.project-list {
  display: grid;
  max-height: 320px;
  gap: 8px;
  overflow: auto;
}

.project-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid #d7e3ef;
  border-radius: 7px;
  padding: 10px;
  background: #f7faff;
}

.project-item strong,
.project-item span {
  display: block;
}

.project-item span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.modal-error {
  min-height: 18px;
  margin: 8px 0 0;
  color: #c72d4e;
  font-size: 12px;
  font-weight: 800;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.modal-btn {
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  padding: 0 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 850;
}

.modal-btn.neutral {
  background: #e9eef5;
  color: #415066;
}

.modal-btn.primary {
  background: #e83f63;
  color: #fff;
}

.block-flow,
.block-event,
.block-if,
.block-else {
  display: block;
  width: 520px;
  height: var(--block-height);
  min-height: 92px;
  padding: 10px 16px 14px 18px;
}

.block-flow .block-label,
.block-event .block-label,
.block-if .block-label,
.block-else .block-label {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  font-size: 13px;
}

.else-label {
  position: absolute;
  left: 18px;
  top: calc(50% - 5px);
  z-index: 2;
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.branch-control {
  position: absolute;
  z-index: 3;
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--block-color);
  font-size: 13px;
  font-weight: 950;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}

.branch-add {
  left: 18px;
  bottom: 10px;
}

.branch-remove {
  right: 16px;
  top: calc(50% - 8px);
}

.block-flow .block-meta,
.block-event .block-meta,
.block-if .block-meta,
.block-else .block-meta {
  position: absolute;
  left: 18px;
  bottom: 10px;
  z-index: 2;
}

.flow-cavity {
  position: absolute;
  left: 26px;
  right: 14px;
  top: 48px;
  bottom: 18px;
  min-height: 28px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.16);
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.06),
    inset 0 8px 0 rgba(255, 255, 255, 0.12);
  z-index: 1;
}

.flow-cavity::before {
  content: "";
  position: absolute;
  top: -7px;
  left: 16px;
  width: 34px;
  height: 12px;
  border-radius: 0 0 8px 8px;
  background: rgba(255, 255, 255, 0.38);
}

.block-if .flow-cavity,
.block-event .flow-cavity,
.block-else .flow-cavity {
  left: 24px;
  right: 12px;
}

.block-if .flow-cavity-else {
  top: calc(50% + 20px);
  bottom: 18px;
}

.block-if:has(.flow-cavity-else) > .flow-cavity:not(.flow-cavity-else) {
  bottom: calc(50% + 20px);
}

.condition-pill {
  display: inline-grid;
  min-height: 22px;
  place-items: center;
  padding: 2px 15px;
  border-radius: 0;
  background: rgba(255, 255, 255, 0.96);
  color: #233448;
  font-size: 11px;
  line-height: 1;
  clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 10px 100%, 0 50%);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}

.block-label {
  line-height: 1.18;
}

.block-meta {
  display: none;
  align-items: center;
  max-width: 100%;
  gap: 6px;
  margin-top: 4px;
  opacity: 0.82;
}

.block.palette-block .block-meta {
  display: none;
}

.block-op,
.block-type {
  display: inline-block;
  max-width: 120px;
  overflow: hidden;
  border-radius: 999px;
  padding: 2px 6px;
  background: rgba(0, 0, 0, 0.18);
  color: rgba(255, 255, 255, 0.92);
  font-size: 10px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.block-type {
  background: rgba(255, 255, 255, 0.2);
}

.block-input {
  display: inline-grid;
  min-width: 30px;
  height: 21px;
  place-items: center;
  border-radius: 7px;
  padding: 0 7px;
  margin: 0 2px;
  background: rgba(255, 255, 255, 0.95);
  color: #233448;
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.08);
}

.input-variable {
  border-radius: 999px;
  background: #e53935;
  color: #fff;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.16);
  cursor: pointer;
}

.input-operator {
  border-radius: 999px;
}

.block-input.input-target,
.condition-pill.input-target {
  background: #fff4a8;
  color: #172033;
  box-shadow:
    inset 0 2px 0 rgba(0, 0, 0, 0.08),
    0 0 0 4px rgba(255, 215, 64, 0.38);
}

.embedded-reporter {
  display: inline-grid;
  min-height: 22px;
  place-items: center;
  border-radius: 999px;
  padding: 2px 12px;
  background: var(--embedded-color);
  color: #ffffff;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16), 0 2px 5px rgba(26, 42, 60, 0.16);
}

.embedded-boolean {
  padding-inline: 16px;
  clip-path: polygon(10% 0, 90% 0, 100% 50%, 90% 100%, 10% 100%, 0 50%);
}

.condition-pill:has(.embedded-reporter),
.block-input:has(.embedded-reporter) {
  padding: 0;
  background: transparent;
  clip-path: none;
  box-shadow: none;
}

.block.palette-block {
  display: flex;
  flex: 0 0 auto;
  max-width: 100%;
  margin-bottom: 2px;
  cursor: grab;
  pointer-events: auto;
}

.block.palette-block:active {
  cursor: grabbing;
}

.block-flow.palette-block,
.block-event.palette-block {
  width: 250px;
  height: 118px;
  min-height: 118px;
  padding: 12px 14px 14px 20px;
}

.block-if.palette-block,
.block-else.palette-block {
  width: 250px;
  height: 128px;
  min-height: 128px;
  padding: 12px 14px 14px 20px;
}

.block-if.palette-block:has(.flow-cavity-else) {
  height: 176px;
}

.block-flow.palette-block .block-label,
.block-event.palette-block .block-label,
.block-if.palette-block .block-label,
.block-else.palette-block .block-label {
  align-items: center;
  flex-wrap: wrap;
  width: calc(100% - 8px);
  min-height: 34px;
  font-size: 12px;
  line-height: 1.25;
}

.block-flow.palette-block .flow-cavity,
.block-event.palette-block .flow-cavity,
.block-if.palette-block .flow-cavity,
.block-else.palette-block .flow-cavity {
  left: 30px;
  right: 14px;
  top: 58px;
  bottom: 18px;
  min-height: 34px;
  background: rgba(255, 255, 255, 0.2);
}

.block-if.palette-block .flow-cavity-else {
  top: calc(50% + 24px);
  bottom: 18px;
}

.block-if.palette-block:has(.flow-cavity-else) > .flow-cavity:not(.flow-cavity-else) {
  bottom: calc(50% + 22px);
}

.block-if.palette-block .else-label {
  top: calc(50% - 4px);
  font-size: 12px;
}

.block.workspace-block {
  position: absolute;
  width: 224px;
  z-index: 3;
  cursor: grab;
}

.block-flow.workspace-block,
.block-event.workspace-block,
.block-if.workspace-block,
.block-else.workspace-block {
  z-index: 2;
}

.block-flow.workspace-block,
.block-event.workspace-block {
  width: 360px;
}

.block-if.workspace-block,
.block-else.workspace-block {
  width: 334px;
}

.block.dragging {
  cursor: grabbing;
  opacity: 0.92;
  transform: scale(var(--workspace-drag-zoom, 1.02));
  z-index: 20;
}

.block.drag-group {
  opacity: 0.94;
  z-index: 19;
}

.block.snapped {
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.14), 0 0 0 4px rgba(16, 168, 163, 0.18);
}

.block.snap-preview {
  opacity: 0.98;
  z-index: 24;
  box-shadow:
    inset 0 -5px 0 rgba(0, 0, 0, 0.16),
    0 0 0 5px rgba(47, 128, 237, 0.2),
    0 10px 20px rgba(26, 42, 60, 0.2);
}

.block.snap-target {
  filter: brightness(1.04);
  box-shadow:
    inset 0 -5px 0 rgba(0, 0, 0, 0.16),
    0 0 0 4px rgba(56, 189, 248, 0.22);
}

.workspace-panel {
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
  overflow: visible;
  z-index: 3;
}

.workspace-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.workspace-header p {
  margin-top: 3px;
  color: var(--muted);
}

.workspace-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.template-btn {
  min-width: 54px;
  height: 36px;
  border: 0;
  border-radius: 7px;
  background: #26384d;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16);
}

.template-btn:hover,
.template-btn:focus-visible {
  background: #334a64;
}

.icon-btn {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 7px;
  background: #eaf0f7;
  color: #29425c;
  font-size: 21px;
  font-weight: 800;
}

.icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.zoom-indicator {
  display: grid;
  min-width: 54px;
  height: 36px;
  place-items: center;
  border: 1px solid #d9e3ef;
  border-radius: 7px;
  background: #f5f8fc;
  color: #29425c;
  font-size: 12px;
  font-weight: 850;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  background: #dce8f4;
}

/* Lienzo central con grilla suave para construir programas visuales. */
.workspace {
  position: relative;
  min-height: 0;
  overflow: auto;
  background: #f8fbff;
  --workspace-zoom: 1;
  --workspace-drag-zoom: 1.02;
  --workspace-grid: 28px;
  --workspace-width: 1400px;
  --workspace-height: 1200px;
}

.workspace.workspace-dragging {
  overflow: visible;
}

.grid-layer {
  position: absolute;
  inset: 0;
  min-width: var(--workspace-width);
  min-height: var(--workspace-height);
  background-image:
    linear-gradient(rgba(61, 124, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(61, 124, 255, 0.08) 1px, transparent 1px);
  background-size: var(--workspace-grid) var(--workspace-grid);
}

.start-block {
  position: absolute;
  top: 28px;
  left: 30px;
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 220px;
  height: 48px;
  padding: 0 18px;
  border-radius: 9px;
  background: #303b4e;
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 800;
  z-index: 2;
}

.start-dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(39, 174, 96, 0.18);
}

.workspace-empty {
  position: absolute;
  top: 102px;
  left: 38px;
  color: #90a0b4;
  font-size: 15px;
  font-weight: 700;
  z-index: 1;
  transform: scale(var(--workspace-zoom));
  transform-origin: top left;
}

.workspace-block {
  flex-shrink: 0;
  transform: scale(var(--workspace-zoom));
  transform-origin: top left;
}

.simulation-panel {
  overflow: hidden;
}

/* Simulación lateral: cada pieza cambia de estado desde JavaScript. */
.safe-scene {
  position: relative;
  flex: 1;
  min-height: 330px;
  margin: 14px 0 12px;
  border-radius: 8px;
  background: linear-gradient(180deg, #eef7fa, #dde7ef);
  overflow: hidden;
}

.safe-scene::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 72px;
  background: #c7d5df;
}

.lcd-screen {
  position: absolute;
  top: 18px;
  left: 22px;
  right: 22px;
  min-height: 44px;
  padding: 10px 12px;
  border: 5px solid #26384d;
  border-radius: 7px;
  background: #0e3632;
  color: #8cf4cf;
  font-family: Consolas, monospace;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
  z-index: 3;
}

.safe-body {
  position: absolute;
  left: 50%;
  bottom: 42px;
  width: 240px;
  height: 230px;
  border-radius: 8px;
  background: #5d6d7e;
  box-shadow: inset 0 -10px 0 rgba(0, 0, 0, 0.13), 0 20px 35px rgba(18, 30, 43, 0.24);
  transform: translateX(-50%);
  z-index: 2;
}

.safe-door {
  position: absolute;
  left: 16px;
  top: 22px;
  width: 142px;
  height: 176px;
  border-radius: 8px;
  transform-origin: left center;
  transition: transform 650ms ease, box-shadow 650ms ease;
}

.safe-door.open {
  transform: perspective(500px) rotateY(-48deg);
  box-shadow: 18px 10px 20px rgba(0, 0, 0, 0.18);
}

.door-panel {
  position: absolute;
  inset: 0;
  border: 7px solid #33485f;
  border-radius: 8px;
  background: #90a4b8;
}

.door-rivets,
.door-rivets::before,
.door-rivets::after {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34495e;
  content: "";
}

.door-rivets {
  top: 16px;
  left: 16px;
  box-shadow: 88px 0 0 #34495e, 0 126px 0 #34495e, 88px 126px 0 #34495e;
}

.safe-handle {
  position: absolute;
  top: 68px;
  right: 22px;
  width: 38px;
  height: 38px;
  border: 7px solid #26384d;
  border-radius: 50%;
}

.rfid-reader {
  position: absolute;
  top: 32px;
  right: 18px;
  display: grid;
  width: 58px;
  height: 70px;
  place-items: center;
  border-radius: 7px;
  background: #27394d;
  color: #93eae2;
  font-size: 12px;
  font-weight: 900;
  transition: background 250ms ease, color 250ms ease;
}

.rfid-reader.reading {
  background: #12aaa3;
  color: #073433;
  box-shadow: 0 0 0 7px rgba(18, 170, 163, 0.25);
}

.reader-wave {
  width: 28px;
  height: 28px;
  border: 3px solid currentColor;
  border-radius: 50%;
  opacity: 0.8;
}

.servo {
  position: absolute;
  right: 19px;
  bottom: 24px;
  width: 54px;
  height: 42px;
  border-radius: 6px;
  background: #233448;
}

.servo-arm {
  position: absolute;
  top: 17px;
  left: 25px;
  width: 44px;
  height: 8px;
  border-radius: 999px;
  background: #f4c542;
  transform-origin: left center;
  transform: rotate(70deg);
  transition: transform 600ms ease;
}

.servo.unlocked .servo-arm {
  transform: rotate(160deg);
}

.buzzer {
  position: absolute;
  right: 88px;
  bottom: 24px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #29394d;
}

.buzzer span,
.buzzer span::before,
.buzzer span::after {
  position: absolute;
  border: 2px solid #f4c542;
  border-left: 0;
  border-bottom: 0;
  border-radius: 0 100% 0 0;
  content: "";
}

.buzzer span {
  top: 11px;
  left: 10px;
  width: 10px;
  height: 10px;
}

.buzzer span::before {
  top: -6px;
  left: 3px;
  width: 18px;
  height: 18px;
}

.buzzer span::after {
  top: -11px;
  left: 6px;
  width: 26px;
  height: 26px;
}

.buzzer.alert {
  animation: buzzerPulse 450ms ease 3;
}

.led {
  position: absolute;
  right: 31px;
  top: 118px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #83909e;
  border: 3px solid rgba(0, 0, 0, 0.24);
}

.led-red {
  top: 146px;
}

.led.on.led-green {
  background: var(--green);
  box-shadow: 0 0 16px var(--green);
}

.led.on.led-red {
  background: var(--red);
  box-shadow: 0 0 16px var(--red);
}

.rfid-card {
  position: absolute;
  right: -34px;
  top: 20px;
  width: 74px;
  height: 48px;
  border-radius: 7px;
  background: linear-gradient(135deg, #fefefe, #d9e2ea);
  color: #38506a;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 900;
  transform: translate(88px, 92px) rotate(-8deg);
  transition: transform 620ms ease;
}

.rfid-card.near {
  transform: translate(-24px, 32px) rotate(-4deg);
}

.rfid-card span {
  width: 13px;
  height: 17px;
  border-radius: 2px;
  background: #f2c14e;
}

.sim-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sim-btn {
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 7px;
  color: #fff;
  font-size: 13px;
  font-weight: 850;
}

.sim-btn.primary {
  background: var(--blue);
}

.sim-btn.success {
  background: var(--green);
}

.sim-btn.danger {
  background: var(--red);
}

.sim-btn.neutral {
  background: #526579;
}

.status-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.status-board div {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  background: var(--surface-soft);
}

.status-board span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-board strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 15px;
}

@keyframes buzzerPulse {
  50% {
    transform: scale(1.12);
    box-shadow: 0 0 0 8px rgba(244, 197, 66, 0.28);
  }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .ide-layout {
    grid-template-columns: 250px minmax(360px, 1fr) 330px;
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
  }

  .ide-layout {
    grid-template-columns: 1fr;
  }

  .workspace-panel {
    min-height: 560px;
  }

  .block {
    width: min(100%, 260px);
  }
}
