  * { box-sizing: border-box; margin: 0; padding: 0; }
  html, body {
    height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
    overflow: hidden;
    background: #f3f4f6;
  }

  :root {
    --purple:        #7c3aed;
    --purple-dark:   #6d28d9;
    --purple-darker: #5b21b6;
    --purple-light:  #a78bfa;
    --purple-panel:  #2d1b69;
    --purple-bg:     #1e1b4b;
    --text-muted:    #c4b5fd;
    --border:        #4c1d95;
  }

  body {
    display: flex;
    flex-direction: column;
    height: 100vh;
  }

  /* ============================================================
     TOP BAR
     ============================================================ */
  .topbar {
    flex: 0 0 44px;
    background: linear-gradient(180deg, var(--purple) 0%, var(--purple-dark) 100%);
    display: flex;
    align-items: center;
    padding: 0 10px;
    gap: 6px;
    color: #fff;
    font-size: 13px;
    box-shadow: 0 2px 4px rgba(0,0,0,.25);
    z-index: 100;
    position: relative;
  }
  .brand {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    font-size: 14px;
    padding-right: 14px;
    margin-right: 4px;
    border-right: 1px solid rgba(255,255,255,.2);
    white-space: nowrap;
  }
  .logo-icon { font-size: 18px; }

  .toolbar { display: flex; align-items: center; gap: 4px; }

  .toolbar button,
  .modes button,
  .right-tools button {
    background: rgba(255,255,255,.10);
    color: #fff;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 5px;
    padding: 0 10px;
    font-size: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 28px;
    transition: background .15s, transform .05s;
    font-family: inherit;
  }
  .toolbar button:hover,
  .modes button:hover,
  .right-tools button:hover { background: rgba(255,255,255,.22); }
  .toolbar button:active { transform: scale(.96); }
  .toolbar button:disabled { opacity: .35; cursor: not-allowed; }

  .toolbar button.primary { background: #3b82f6; border-color: #2563eb; }
  .toolbar button.primary:hover { background: #2563eb; }
  .toolbar button.success { background: #22c55e; border-color: #16a34a; }
  .toolbar button.success:hover { background: #16a34a; }

  .sep {
    width: 1px;
    height: 22px;
    background: rgba(255,255,255,.22);
    margin: 0 4px;
  }

  .center-title {
    flex: 1;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    font: bold;
    white-space: nowrap;
    overflow: hidden;
   }

  .modes { display: flex; gap: 2px; margin-right: 4px; }
  .modes button {
    width: 32px;
    padding: 0;
    font-size: 15px;
    font-weight: 700;
  }
  .modes button.active {
    background: rgba(255,255,255,.32);
    border-color: rgba(255,255,255,.55);
  }

  .right-tools { display: flex; gap: 4px; position: relative; }

  /* ---------- FILE DROPDOWN ---------- */
  .file-wrapper { position: relative; }
  .file-dropdown {
    position: absolute;
    top: 34px;
    right: 0;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(0,0,0,.18);
    min-width: 180px;
    padding: 5px;
    display: none;
    z-index: 300;
    color: #1f2937;
  }
  .file-dropdown.visible { display: block; }
  .file-dropdown button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    background: transparent;
    border: none;
    color: #1f2937;
    padding: 8px 12px;
    text-align: left;
    border-radius: 5px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    height: auto;
  }
  .file-dropdown button:hover { background: #f3f4f6; }
  .file-dropdown button .ico { font-size: 15px; width: 18px; text-align: center; }
  .file-dropdown .divider {
    height: 1px;
    background: #e5e7eb;
    margin: 4px 6px;
  }

  /* ============================================================
     WORKSPACE
     ============================================================ */
  .workspace {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .editor {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    background: #fafafa;
    overflow: hidden;
  }
  #blockmirror-editor {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  /* ============================================================
     SERIAL MONITOR
     ============================================================ */
  #serial-output {
    flex: 0 0 0;
    height: 0;
    background: #1e1b4b;
    color: #e0e7ff;
    border-top: 1px solid var(--purple-light);
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: flex-basis .18s ease, height .18s ease;
  }
  #serial-output.visible {
    flex: 0 0 190px;
    height:190px;
  }
  #serial-output .header {
    background: #2d1b69;
    padding:  4px 12px;
    border-bottom: 1px solid rgba(255,255,255,.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: var(--purple-light);
    font-size: 12px;
    flex: 0 0 auto;
  }
  #serial-output .header button {
    background: transparent;
    border: none;
    color: var(--purple-light);
    cursor: pointer;
    font-size: 15px;
    padding: 0 4px;
    border-radius: 4px;
    transition: background .15s;
  }
  #serial-output .header button:hover { background: rgba(255,255,255,.1); }
  #serial-output .content {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 8px 12px;
    white-space: pre-wrap;
    word-break: break-word;
  }
  #serial-output .content::-webkit-scrollbar { width: 8px; }
  #serial-output .content::-webkit-scrollbar-thumb { background: rgba(167,139,250,.35); border-radius: 4px; }

  /* ============================================================
     BOTTOM BAR
     ============================================================ */
  .bottombar {
    flex: 0 0 30px;
    background: linear-gradient(180deg, var(--purple) 0%, var(--purple-dark) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 10px;
    gap: 12px;
    font-size: 11px;
    z-index: 100;
    box-shadow: 0 -2px 4px rgba(0,0,0,.15);
  }
  .bottombar button {
    background: rgba(255,255,255,.10);
    color: #fff;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 4px;
    padding: 0 10px;
    font-size: 11px;
    cursor: pointer;
    height: 22px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: inherit;
  }
  .bottombar button:hover { background: rgba(255,255,255,.22); }
  .bottombar .spacer { flex: 1; }
  .bottombar .status { color: var(--text-muted); }
  .bottombar .lang,
  .bottombar .board {
    padding: 2px 8px;
    background: rgba(255,255,255,.10);
    border-radius: 10px;
    font-weight: 600;
  }

  /* ============================================================
     BLOCKLY TOOLBOX
     ============================================================ */
  .blocklyToolboxDiv,
  .blocklyToolbox {
    background: #ede9fe !important;
    border-right: 1px solid var(--border) !important;
    padding: 6px 0 !important;
    min-width: 190px;
  }
  .blocklyTreeRow {
    color: #4c1d95 !important;
    font-weight: 500;
    font-size: 13px;
    padding: 6px 10px !important;
    margin: 2px 6px !important;
    border-radius: 6px;
    min-height: 30px;
    transition: background .12s;
  }
  .blocklyTreeRow:hover  { background: rgba(124, 58, 237, 0.10) !important; }
  .blocklyTreeSelected   { background: rgba(124, 58, 237, 0.22) !important; }
  .blocklyFlyoutBackground {
    fill: #f5f3ff !important;
    fill-opacity: 0.97 !important;
  }
  .blocklyFlyoutLabelText { fill: #5b21b6 !important; }
  .blocklyTreeLabel { font-family: inherit !important; }

  .CodeMirror {
    font-family: 'Consolas', 'Monaco', monospace !important;
    font-size: 12px !important;
    height: 100% !important;
  }
  .CodeMirror-gutters {
    background: #f5f3ff !important;
    border-right: 1px solid #ddd6fe !important;
  }

  ::-webkit-scrollbar { width: 8px; height: 8px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: rgba(124,58,237,.4); border-radius: 4px; }
  ::-webkit-scrollbar-thumb:hover { background: rgba(124,58,237,.65); }

  /* ============================================================
     MODAL DIALOGS (centrados, llaman la atención)
     ============================================================ */
  .clu-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 8, 40, .55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    transition: opacity .18s ease;
  }
  .clu-modal-backdrop.show { opacity: 1; }

  .clu-modal {
    background: #ffffff;
    border-radius: 14px;
    box-shadow:
      0 20px 60px rgba(0,0,0,.4),
      0 0 0 1px rgba(124,58,237,.25),
      0 0 40px rgba(124,58,237,.25);
    width: 420px;
    max-width: calc(100vw - 40px);
    overflow: hidden;
    transform: translateY(14px) scale(.94);
    opacity: 0;
    transition: transform .22s cubic-bezier(.2,.9,.3,1.4), opacity .18s ease;
  }
  .clu-modal-backdrop.show .clu-modal {
    transform: translateY(0) scale(1);
    opacity: 1;
  }

  .clu-modal .m-header {
    background: linear-gradient(180deg, var(--purple) 0%, var(--purple-dark) 100%);
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 700;
  }
  .clu-modal .m-header .m-icon {
    font-size: 20px;
    line-height: 1;
  }
  .clu-modal .m-body {
    padding: 20px 20px 8px;
    color: #1f2937;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
  }
  .clu-modal .m-body input[type="text"] {
    width: 100%;
    margin-top: 12px;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
  }
  .clu-modal .m-body input[type="text"]:focus {
    border-color: var(--purple);
    box-shadow: 0 0 0 3px rgba(124,58,237,.18);
  }
  .clu-modal .m-footer {
    padding: 14px 20px 18px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
  }
  .clu-modal .m-footer button {
    padding: 9px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, transform .05s, box-shadow .15s;
    min-width: 90px;
  }
  .clu-modal .m-footer button:active { transform: scale(.96); }

  .clu-modal .m-btn-cancel {
    background: #f3f4f6;
    color: #374151;
    border-color: #e5e7eb;
  }
  .clu-modal .m-btn-cancel:hover { background: #e5e7eb; }

  .clu-modal .m-btn-ok {
    background: linear-gradient(180deg, var(--purple) 0%, var(--purple-dark) 100%);
    color: #fff;
    border-color: var(--purple-darker);
    box-shadow: 0 2px 8px rgba(124,58,237,.4);
  }
  .clu-modal .m-btn-ok:hover {
    background: linear-gradient(180deg, var(--purple-dark) 0%, var(--purple-darker) 100%);
    box-shadow: 0 3px 12px rgba(124,58,237,.55);
  }

  .clu-modal .m-btn-danger {
    background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%);
    color: #fff;
    border-color: #b91c1c;
    box-shadow: 0 2px 8px rgba(239,68,68,.4);
  }
  .clu-modal .m-btn-danger:hover {
    background: linear-gradient(180deg, #dc2626 0%, #b91c1c 100%);
  }